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:
#!/usr/bin/env python3

import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union
# import time
# import math, cmath
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import _heapify_max, _heappop_max, _siftdown_max
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import Fraction               # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10)



def main():
    Num = Union[int, float]
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79e+308
    # inf = 2 ** 63 - 1             # (for fast JIT compile in PyPy) 9.22e+18
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    # def _heappush_max(h, item): h.append(item); _siftdown_max(h, 0, len(h)-1)
    
    
    red, green, blue, n = mi()

    cnt = 0
    for r in range(n // red + 1):
        for g in range(n // green + 1):
            if r * red + g * green > n:
                break
            res = n - (r * red + g * green)
            if res % blue == 0:
                cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
r,g,b,n=map(int,input().split())
c=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:
      c+=1
print(c)

Submission status: Accepted

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

rr=n//r+1
gg=n//g+1
bb=n//b+1
ans=0
for i in range(rr):
  for j in range(gg):
    x=i*r+j*g
    if (x>n):
      break
    if (n-x)%b==0:
      ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/diverta2019/tasks/diverta2019_b
R, G, B, N = map(int, input().split())

# rR+gG+bB=Nになるようなrgbの組み合わせの個数
# N<3000なのでO(n**2)で全探索して良さそう
# r,gがgivenのとき、rR+gG-N=-bB が成り立つ整数bが存在すれば、良い
ans = 0
for r in range(0, N + 1):
    for g in range(0, N + 1):
        left = (N - (r * R + g * G))
        if left >= 0 and left % B == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

    cnt = 0
    for r in range(0,3000+1):
        for g in range(0,3000+1):
            b = N - (r * R + g * G)
            if b >= 0 and b % B == 0:
                cnt += 1
    
    print(cnt)
        
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
[A,B,C,N]=[int(i) for i in input().split()]
X=[A,B,C]
X.sort()
[C,B,A]=X
cnt=0
for i in range(N//A+1):
  k=N-(i*A)
  for j in range(k//B+1):
    if (k-(B*j))%C==0:
    	cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
R,G,B,N = map(int,input().split())
c = sorted([R,G,B])
R = c[1]
G = c[2]
B = c[0]
ans = 0
for r in range(N//R+1):
    tmp = N - r*R
    for g in range(N//G+1):
        ttmp = tmp - g*G
        ans += (ttmp%B == 0 and ttmp >= 0)
print(ans)

Submission status: Accepted

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

S=0
for x in range(M+1):
    for y in range(M+1):
        c=N-(R*x+G*y)
        if c>=0 and c%B==0:
            S+=1

print(S)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    R, G, B, N = [int(n) for n in input().strip().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 and (N - (R * r) - (G * g)) // B >= 0:
                ans += 1
    return ans


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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())

R,G,B,N = readInts()
cnt = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        b = (N - r*R - g*G)//B
        #print(r,g,b)
        if b >= 0:
            if r*R + g*G + b*B == N:
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# Problem B - RGB Boxes

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

# initialization
count = 0

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

# output
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 B in range((n)//b+1):
        if (R*r+B*b-n)<=0 and (R*r+B*b-n)%g==0:
            ans+=1
            
print(ans)

Submission status: Accepted

Solution code:
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

#n, m = map(int, input().split())
#tmp = [None]*n
# for i in range(n):
#    tmp[i] = [None]*2
# for i in range(n):
#    tmp[i] = readints()
# print(tmp)
#tmp_so = sorted(tmp, key=lambda x: x[0])
# print(tmp_so)
#cnt = 0
#okane = 0
# for i in range(n):
r, g, b, m = map(int, input().split())
cnt = 0
for i in range(3001):
    for j in range(3001):
        if r*i+g*j <= m:
            tmp = m-(r*i+g*j)
            if tmp % 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(3001):
  for g in range(3001):
    b=n-R*r-G*g
    if b>=0 and b%B==0:ans+=1
print(ans)

Submission status: Accepted

Solution code:
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

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

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

print(res)

Submission status: Accepted

Solution code:
R,G,B,n = map(int, input().split())
ans = 0
for r in range(n//R+1):
    if R*r > n: break
    for g in range(n//G+1):
        ball = R*r + G*g
        if ball > n: break
        if (n-ball)%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(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 r in range(N+1):
  for g in range(N+1):
    if r*R+g*G>N:
      break
    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())
ans = 0
for r in range(N+1):
    for g in range(N+1):
        res = N-R*r-G*g
        if res < 0:
            continue
        else:
            if res%B == 0:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

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

for i in range(N+1):
    for j in range(N+1):
        if N-R*i-G*j>=0 and (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(0,int(N//R)+1):
    for g in range(0,int((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())
cnt = 0

for i in range(n // r + 2):
    for j in range(n // g + 2):
        k = n - i * r - j * g
        if k < 0:continue
        if k % b == 0:cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
*RBG, n = map(int, input().split())
RBG.sort()
a, b, c = RBG
ans = 0
for i in range(n//c + 1):
    t = n - c*i
    for j in range(t//b + 1):
        ans += (t - j*b) % a == 0
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())
ans = 0
x = n//min(r,g,b)

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

print(ans)

Submission status: Accepted

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

cnt =0
    
for r in range(int(N/R)+1):
  ball = N-r*R 
  for g in range(int(ball/G)+1):
    res = N- (r*R+g*G)
    if  res >=0 and res%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(1+n//r):
  tmp = n - r*i
  for j in range(1+tmp//g):
    mod = (n - g*j - r*i)%b
    if mod == 0:
      ans += 1
        
print(ans)

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(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())
ans = 0
#print('i,r,j,g,k,b')
r,g,b = sorted([r,g,b], reverse=True)
for i in range(n//r+1):
    for j in range((n-r*i)//g+1):
        k = n-i*r-j*g
        #print(i,r,j,g,k,b, '===', i+j+k, i*r + j*g + k*b)
        if k%b==0:
            ans += 1
print(ans)

Submission status: Accepted

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

# In[1]:


rgbn = list(map(int, input().split()))


# In[2]:


mylist = sorted(rgbn[:3], reverse=True)
ans = 0
for i in range(rgbn[3]//mylist[0] + 1):
#     print(i)
    for j in range((rgbn[3] - mylist[0]*i)//mylist[1] + 1):
#         print(i,j)
        rest = (rgbn[3] - mylist[0]*i - mylist[1]*j)
        if rest%mylist[2] == 0:
#             print(i,j,rest//mylist[2])
            ans += 1
print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
r,g,b,n = map(int,input().split())
cnt = 0
l = [r,g,b]
l.sort()
r = l[2]
g = l[1]
b = l[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())
index = 0
ans = 0
for_sort = [R,G,B]
for_sort.sort()
r = for_sort[2]
g = for_sort[1]
b = for_sort[0]
while N >=0:
  mid = N
  N -= r
  while mid >= 0:
    if mid % b == 0:
      ans += 1
    mid -= g
      
print(ans)

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(i, n+1, g):
        if (n-j) % b == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

max_r = N // R
max_g = N // G
max_b = N // B

count = 0
for r in range(max_r + 1):
    for g in range(max_g + 1):
        now_n = r * R + g * G
        if now_n <= N and (N - now_n) % B == 0:
            b = (N - now_n) // B
            count += 1

ans = count

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

print(ans)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
R,G,B,N = IL()
count = 0
for r in range(N+1):
  for g in range(N+1):
    if r*R+g*G <= N and (N-(r*R+g*G))%B == 0:
      count += 1
print(count)

Submission status: Accepted

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

            res = (N - (R*r + G*g)) 

            if res < 0 :
                break

            if res % B == 0:
                ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

            res = (N - (R*r + G*g)) 

            if res < 0 :
                break

            if res >= 0 and res % B == 0:
                ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
R, G, B, N = map(int, input().split())
M = N - np.add.outer(np.arange(0, N + 1, R, dtype=np.int32), np.arange(0, N + 1, G, dtype=np.int32))
print(((M >= 0) & (M % B == 0)).sum())

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    dp = [0] * (N + 1)
    dp[0] = 1
    for c in [R, G, B]:
        for i in range(N - c + 1):
            dp[i + c] += dp[i]

    ans = dp[N]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#diverta2019 programming contest-B
R,G,B,n = map(int,input().split())
cnt = 0
for i in range(n//R + 1):
    for j in range(n - i*R + 1):
        c = n - (i*R + j*G)
        if c >= 0 and c%B == 0:
            cnt += 1
        else:
            pass
                
print(cnt)

Submission status: Accepted

Solution code:
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
R,G,B,N = LI()
dp = [0]*(N+1)
dp[0] = 1
for x,i in itertools.product([R,G,B],range(N+1)):
    if i-x>=0:
        dp[i] += dp[i-x]
print(dp[-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
R,G,B,N = LI()
ans = 0
for i in range(N+1):
    for j in range(N+1):
        temp = N-(R*i+G*j)
        if temp>=0 and temp%B==0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math


def solve(R: int, G: int, B: int, N: int):
    count = 0
    for r in range(N // R + 1):
        for g in range(N // G + 1):
            nokori = N - r * R - g * G
            if nokori < 0:
                continue
            if nokori % B == 0:
                count += 1
    print(count)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    R = int(next(tokens))  # type: int
    G = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(R, G, B, N)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

rn = N // R
gn = N // G

ans = 0

for i in range(rn + 1):
  for j in range(gn + 1):
    n = N
    n -= R*i + G*j
    if n >= 0 and n % B == 0:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
R, G, B, N = MAP()
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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

R, G, B, N = MAP()
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

R, G, B, N = MAP()
ans = 0

for i in range(3001):
	r = i
	for j in range(3001):
		g = j
		b = (N-r*R-g*G)/B
		if 0 <= b and b == b//1:
			ans +=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

r,g,b,n=map(int,input().split())
ans=0
r,g,b=sorted([r,g,b])[::-1]
for i in range(n//r+1):
    for j in range(n//g+1):
        k=n-i*r-j*g
        if(k<0):
            break
        if(k>=0 and k%b==0):
            ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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