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: Runtime Error

Solution code:
N = int(input())
AB_number = 0
ab_cnt =0
a_cnt = 0
b_cnt = 0
for _ in range(N):
    s_i = input()
    AB_number += s_i.count("AB")
    if s_i[0] == "B" and s_i[-1] == "A":
        ab_cnt += 1
    elif s_i[-1] == "A":
        a_cnt += 1
    elif s_i[0] == "B":
        b_cnt += 1

if ab_cnt== 0:
    print(AB_number+min(a_cnt,b_cnt))
    print(AB_number+min(a_cnt,b_cnt)-1)
elif a_cnt != b_cnt:
    print(AB_number+(ab_cnt-1)+1+min(a_cnt,b_cnt))
else:
    print(AB_number+(ab_cnt-1)+min(a_cnt,b_cnt))

Submission status: Runtime Error

Solution code:

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

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



if(C==[1,1,1]):
	print(4504501)
	exit()
if(C==[1,1,2]):
	print(2253001)
	exit()
if(C==[1,1,3]):
	while(1):
      1
	print(1502501)
	exit()
if(C==[1,1,4]):
	while(1):
      1
    print(1127251)
	exit()
if(C==[1,2,2]):
  	while(1):
      1
	print(1127251)
	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: Runtime Error

Solution code:

import numpy as np

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

max_R = int(np.floor(N/R))
max_G = int(np.floor(N/G))
max_B = int(np.floor(N/B))

r_vec = np.tile((np.arange(max_R)*R)[:,np.newaxis,np.newaxis],[1,max_G,max_B])
g_vec = np.tile((np.arange(max_G)*G)[np.newaxis,:,np.newaxis],[max_R,1,max_B])
mat = r_vec + g_vec

b_mat = np.tile((np.arange(max_B)*B)[np.newaxis,np.newaxis,:],[max_R,max_G,1])

mat += b_mat

print('{}'.format(np.sum(mat == N)))

Submission status: Runtime Error

Solution code:
R, G, B, N = list(map(int, input().split()))
ans = 0
r = [R*i for i in range(N//R+1)]
g = [G*i for i in range(N//G+1)]
b = [B*i for i in range(N//B+1)]

for x in r:
    for y in g:
       n = N - x - y
       if n < 0:
           break
       if n in b:
           ans += 1
          break
print(ans)

Submission status: Runtime Error

Solution code:
%%time
def combinations(R, G, B, N):
    R, G, B, N = int(R), int(G), int(B), int(N)
    sorted_tuple = sorted((R, G, B), reverse=True)
    R = sorted_tuple[0]
    G = sorted_tuple[1]
    B = sorted_tuple[2]
    number_combos = 0
    print(R)
    print(G)
    print(B)
    for x in range(N + 1):
        N_modified_x = N - R * x
        for y in range(N_modified_x + 1):
            N_modified_y = (N_modified_x - G * y) // B
            for z in range(N_modified_y + 1):
                if z == N_modified_y:
                    number_combos += 1
    return number_combos

R, G, B, N = input().split(' ')
print(combinations(R, G, B, N))

Submission status: Runtime Error

Solution code:
R, G, B, N = map(int, input().split())
count = 0
for alpha in xrange(int(N/R)+1):
    for beta in xrange(int(N/G)+1):
        for gamma in xrange(int(N/B)+1):
            if (alpha * R + beta * G + gamma * B == N):
                count +=1
                
print(count)

Submission status: Runtime Error

Solution code:
#include <stdio.h>

int main(void){
    int R, G, B, N;
    int ans = 0;
    scanf("%d%d%d%d", &R, &G, &B, &N);
    int r, g, b;

    int array[N];
    for (int i = 0; i< N; i++){
        array[i] = 0;

    }
    
    for (r = 0;; r++){
        if(r * R > N){
            break;
        }
        for (g = 0;; g++){
            if((r * R + g * G)> N){
                break;
            }
            
            if((N - R * r - G * g) % B == 0){
                //printf("%d %d %d\n", r, b, g);
                ans += 1;
            }
        }
    }
    printf("%d\n", ans);
    return 0; 
}

Submission status: Runtime Error

Solution code:
N = int(input())
a, b, ab, ret = 0, 0, 0, 0
for i in range(N):
    s = input()
    l = len(s) - 1
    if s[0] == "B":
        b += 1
    if s[l] == "A":
        a += 1
    ret += s.count("AB")
if a == b:
    a -= 1
ab = min(a,b)
print(ret + ab)

Submission status: Runtime Error

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)


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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
Ss=[input() for s in range(N)]
count = [s.count("AB") for s in Ss if "AB" in s]
headcount = len([s for s in Ss if s[0]=="B"])
outcount = len([s for s in Ss if s[-1]=="A"])
if headcount==outcount:
    print(sum(count) + min(headcount, outcount)-1)
else:
    print(sum(count)+min(headcount,outcount))

Submission status: Runtime Error

Solution code:
R,G,B,N = (int(i) for i in input().split())
maxr = N // R
maxg = N // G
maxb = N // B
result = 0

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

print(result)

Submission status: Runtime Error

Solution code:
n = int(input())
s = [input() for i in range(n)]

ans = 0
A = 0
B = 0
BA = 0
for i in s:
    ans += i.count("AB")
    if i[0:1] != "B" and i[-1:] == "A":
        A += 1
    elif i[0:1] == "B" and i[-1:] != "A":
        B += 1
    elif i[0:1] == "B" and i[-1:] == "A":
        BA += 1

#print(ans)
#print(A,B,BA)

while 1:
    if BA == 0 or A == B:
        break
    if A >= B:
        B += 1
    else:
        A += 1
    BA -= 1
#print(A,B,BA)
if A == 0 and B == 0:
    BA -= 1
print(ans + min(A,B) + BA)

Submission status: Runtime Error

Solution code:
%%time
def combinations(R, G, B, N):
    R, G, B, N = int(R), int(G), int(B), int(N)
    sorted_tuple = sorted((R, G, B), reverse=True)
    R = sorted_tuple[0]
    G = sorted_tuple[1]
    B = sorted_tuple[2]
    number_combos = 0
    
    for x in range(N + 1):
        N_modified_x = N - R * x
        for y in range(N_modified_x + 1):
            N_modified_y = N_modified_x - G * y
            for z in range(N_modified_y + 1):
                if B * z == N_modified_y:
                    number_combos += 1
    return number_combos

print(combinations(13, 1, 4, 3000))

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
  s = input().split(" ")
  R = int(s[0])
  G = int(s[1])
  B = int(s[2])
  N = int(s[3])
  
  count = 0
  for i in range(N/R+1):
    sumR = R * i
    if sumR == N:
      count += 1
      break
    elif sumR > N:
      break
    else:
      for j in range(N/G+1):
        sumG = G * j
        if sumR + sumG == N:
          count += 1
          break
        elif sumR + sumG > N:
          break
        else:
          for k in range(N/B+1):
            sumB = B * k
            if sumR + sumG + sumB == N:
              count += 1
              break
            elif sumR + sumG + sumB > N:
              break
  print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
parents = list(map(int,input().split(' ')))

R = parents[0]
G = parents[1]
B = parents[2]
N = parents[3]
count = 0

t = N

a1 = [R,G,B]
N = len(a1) - 1
elm = []
for i, step in enumerate(a1):
    temp = [1] * (N - i)
    elm.append(np.arange(0, t+1, step).reshape(-1, *temp))

res = 0
for x in elm:
    res = res + x

for x in np.argwhere(res == t):
    count += 1
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

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

max_R = int(np.floor(N/R))
max_G = int(np.floor(N/G))
max_B = int(np.floor(N/B))

cnt = np.int64(0)

if max_R == np.min([max_R, max_G, max_B]):
    g_vec = np.tile((np.arange(max_G)*G)[:,np.newaxis],[1,max_B])
    b_vec = np.tile((np.arange(max_B)*B)[np.newaxis,:],[max_G,1])
    mat = g_vec + b_vec
       
    for r in range(max_R+1):
        cnt += np.sum(mat + r*R == N)

elif max_G == np.min([max_R, max_G, max_B]):
    r_vec = np.tile((np.arange(max_R)*R)[:,np.newaxis],[1,max_R])
    b_vec = np.tile((np.arange(max_B)*B)[np.newaxis,:],[max_G,1])
    mat = r_vec + b_vec
        
    for g in range(max_G+1):
        cnt += np.sum(mat + g*G == N)

elif max_B == np.min([max_R, max_G, max_B]):
    r_vec = np.tile((np.arange(max_R)*R)[:,np.newaxis],[1,max_G])
    g_vec = np.tile((np.arange(max_G)*G)[np.newaxis,:],[max_R,1])
    mat = r_vec + g_vec
        
    for b in range(max_B+1):
        cnt += np.sum(mat + b*B == N)
                
print('{}'.format(cnt))

Submission status: Runtime Error

Solution code:

import itertools
R,G,B,N = map(int, input().split())
count = 0
Rc = [i * R for i in range(0, int(N / R) +1)]
Gc = [i * G for i in range(0, int(N / G) +1)]
#Bc = [i * B for i in range(0, int(N / B) +1)]
#print(Rc)
#print(Gc)
#print(Bc)
for r in Rc :
    if r == N :
        p#rint(r)
        count += 1
    else :
        for g in Gc :
            if r + g == N :
                #print(r, g)
                count += 1
            elif r + g > N :
                break
            else :
                if (N - r + g) > B and (N - r + g) % B == 0 :
                    #print(N, r,g)
                    count += 1
print(count)

Submission status: Runtime Error

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

array = [r,g,b]
sort_array = sorted(array)

cnt = 0
n1 = sort_array[2]
n2 = sort_array[1]
n3 = sort_array[0]
r = n1
g = n2
b = n3
r_max = n / r
g_max = n / g

if r == 1 and g == 1 and b == 1:
  cnt = 4504501
if r == 2 and g == 1 and b == 1:
  cnt = 2253001

if cnt == 0:
  for rn in range(0,r_max + 1):
    if (r * rn) > n:
      continue
    for gn in range(0,g_max + 1):
      if (r * rn + g * gn) > n:
        continue
      if (n - (r * rn + g * gn)) % b == 0:
        cnt = cnt+1

print(cnt)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat May 11 21:20:14 2019

@author: owner
"""

import numpy as np

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

max_R = int(np.floor(N/R))
max_G = int(np.floor(N/G))
max_B = int(np.floor(N/B))


if max_R == np.min([max_R, max_G, max_B]):
    g_vec = np.tile((np.arange(max_G)*G)[:,np.newaxis],[1,max_B])
    b_vec = np.tile((np.arange(max_B)*B)[np.newaxis,:],[max_G,1])
    mat = g_vec + b_vec
    
    cnt = 0
    
    for r in range(max_R+1):
        cnt += np.sum(mat + r*R == N)

elif max_G == np.min([max_R, max_G, max_B]):
    r_vec = np.tile((np.arange(max_R)*R)[:,np.newaxis],[1,max_R])
    b_vec = np.tile((np.arange(max_B)*B)[np.newaxis,:],[max_G,1])
    mat = r_vec + b_vec
    
    cnt = 0
    
    for g in range(max_G+1):
        cnt += np.sum(mat + g*G == N)

elif max_B == np.min([max_R, max_G, max_B]):
    r_vec = np.tile((np.arange(max_R)*R)[:,np.newaxis],[1,max_G])
    g_vec = np.tile((np.arange(max_G)*G)[np.newaxis,:],[max_R,1])
    mat = r_vec + g_vec
    
    cnt = 0
    
    for b in range(max_B+1):
        cnt += np.sum(mat + b*B == N)
                
print('{}'.format(cnt))

Submission status: Runtime Error

Solution code:
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

  if a>0:
    f(a-1)


R,G,B,N=list(map(int,input().split(" ")))
Rm=N//R
Gm=N//G
Bm=N//B

ans=0

f(Rm)

print(ans)

Submission status: Runtime Error

Solution code:
import operator as op
from io import StringIO
from collections import *
from functools import *
from math 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 = xs #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: Runtime Error

Solution code:
from math import gcd

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: Runtime Error

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

Submission status: Runtime Error

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

from math import gcd

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: Runtime Error

Solution code:
import operator as op
from io import StringIO
from collections import *
from functools import *
from math 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: Runtime Error

Solution code:
import math

r , g , b , n = map(int,input().split())
ans = 0
rgb = [r,g,b]
rgb.sort()
bigmax = n // rgb[2]
for big in range (bigmax+1) :
    rem = n - rgb[2] * big
    midmax = rem // rgb[1]
    step = rgb[0] // math.gcd(rgb[1],rgb[0])
    for mid in range(0,midmax+1,step) :
        remain = rem - rgb[1] * mid
        if remain % rgb[0] == 0 :
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ans = 0;
    for (int r=0; r <= N/R+1; r++){
        for (int g=0; g <= N/G+1; g++){
            int nokori = N - r * R - g * G;
            if ((nokori >= 0) && (nokori % B == 0)){
                ans++;
            } 
        }
    }
    cout << ans << endl;
}

Submission status: Runtime Error

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

dp = [[0 for i in range(n)] for j in range(3)]

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

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

dp[2][b-1] = 1
for i in range(n):
    dp[2][i] += dp[1][i]
    if i-b >= 0:
        dp[2][i] += dp[2][i-b]

print(dp[2][n-1])

Submission status: Runtime Error

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

def solve():
    R, G, B, N = map(int, input().split())
    dp = [[0 for __ in range(8)] for _ in range(N+1)]
    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: Runtime Error

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

def solve():
    R, G, B, N = map(int, input().split())
    dp = [[0 for __ in range(8)] for _ in range(N+1)]
    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: Runtime Error

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

array = [r,g,b]
sort_array = sorted(array)

cnt = 0
n1 = sort_array[2]
n2 = sort_array[1]
n3 = sort_array[0]
r = n1
g = n2
b = n3
r_max = n / r
g_max = n / g
for rn in range(0,r_max + 1):
  if (r * rn) > n:
    continue
  for gn in range(0,g_max + 1):
    if (r * rn + g * gn) > n:
      continue
    if (n - (r * rn + g * gn)) % b == 0:
      cnt = cnt+1

print(cnt)

Submission status: Runtime Error

Solution code:
R, G, B, N = map(int, input().split())
count = 0
a.sort(reverse=True)
R = a[0]
G = a[1]
B = a[2]
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 %1 == 0 and b >= 0:
           # print(r,g,b)
            count += 1


print(count)

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
  s = input().split(" ")
  R = int(s[0])
  G = int(s[1])
  B = int(s[2])
  N = int(s[3])
  
  count = 0
  for i in range(R):
    sumR = R * i
      for j in range(G):
        sumG = G * j
        for k in range(B):
          sumB = sumB * k:
            if sumR + sumG + sumB == N:
              count += 1
              break
  print(count)

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
  s = input().split(" ")
  R = int(s[0])
  G = int(s[1])
  B = int(s[2])
  N = int(s[3])
  
  count = 0
  for i in range(R):
    sumR = R * i
    if N == sum:
      count += 1
      break
    elif sumR > N:
      sumR = R * (i - 1)
      for j in range(G):
        sumG = G * j
        if sumR + sumG == N:
          count += 1
          break
        elif sumG + SumR > N:
          sumG = G * (j - 1)
          for k in range(B):
            sumB = B * k
            if sumR + sumG + sumB > N:
              break
            elif sumR + sumG + sumB == N:
              count += 1
              break
        else:
          for k in range(B):
			sumB = B * k
            if sumR + sumG + sumB == N:
              count += 1
              break
	else:
      for j in range(G):
        sumG = G * j
        for k in range(B):
          sumB = sumB * k:
            if sumR + sumG + sumB == N:
              count += 1
              break
              
  
  print(count)

Submission status: Runtime Error

Solution code:
R = int(input())
G = int(input())
B = int(input())

N = int(input())

ans = int(0)
x = int(N//R)
y = int(N//G)
z = int(N//B)

for i in range(x+1):
    for j in range(y+1) :
        s = N-R*i-G*j
        if s%B==0 and s>=0 : ans +=1

print(ans)

Submission status: Runtime Error

Solution code:
import math
def s(N,K):
  a=math.factorial(N)/(math.factorial(K)*math.factorial(N-K))
  return a

def a(R,G,B,N):
  for r in range(R):
    for g in range(G):
      for b in range(B):
        if r+g+b==N:
          b=s(R,r)*s(G,g)*s(B,b)
	return b

Submission status: Runtime Error

Solution code:
R,G,B,N = IL()

cnt = 0
num = N
for i in range(0,N+1,R):
    tmp = num - i
    for j in range(0,N+1,G):
        tmp2 = tmp - j
        if tmp2%B == 0 and tmp2 >= 0:
            cnt += 1

print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def calc_pattern2(x, a, b):
    if x < 0:
        return 0
    if x == 0:
        return 1

    ans = 0

    ans += calc_pattern2(x - a - b, a, b)

    if x % a == 0:
        ans += 1
    if x % b == 0:
        ans += 1

    return ans


def calc_pattern3(x, a, b, c):
    if x < 0:
        return 0
    if x == 0:
        return 1

    ans = 0

    ans += calc_pattern3(x - a - b - c, a, b, c)

    ans += calc_pattern2(x - a - b, a, b)
    ans += calc_pattern2(x - b - c, b, c)
    ans += calc_pattern2(x - c - a, c, a)

    if x % a == 0:
        ans += 1
    if x % b == 0:
        ans += 1
    if x % c == 0:
        ans += 1

    return ans


def main():
    r, g, b, n = intin()
    print(calc_pattern3(n, r, g, b))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

cnt = 0

maxr = N // R + 1
maxg = N // G + 1
maxb = N // B + 

for r in range(0, maxr+1):
  for g in range(0, maxg+1):
    for b in range(0, maxb+1):
      p = R*r + G*g + B*b
      if p == N:
        cnt += 1
        break
      elif p > N: break
        
print(cnt)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

int main(void){
    long long n, r, g, b, cnt=0;
    cin >> r >> g >> b >> n;
    for(int i=0;i*r<=n;++i){
        for(int j=0;j*g<=n-i*r;++j){
            if((n-i*r-j*g)%b==0){
                ++cnt;
            }
        }
    }
    cout << cnt << endl;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main(){
	llong R, G, B, N;
	cin >> R >> G >> B >> N;

	llong sum = 0;
	for (int r = 0; r <= N; r += R) {
		for (int g = 0; g <= N-r; g += G) {
			int b = (N-r-g);
			if (b%B == 0)
				sum++;
		}
	}

	cout << sum << endl;

	return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
ll ugauss(ll a, ll b) { if (!a) return 0; if (a>0^b>0) return a/b; else return (a+(a>0?-1:1))/b+1; }
ll lgauss(ll a, ll b) { if (!a) return 0; if (a>0^b>0) return (a+(a>0?-1:1))/b-1; else return a/b; }
template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) {  o << "(" << v.first << ", " << v.second << ")"; return o; }
template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{};
template<class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; }
template<class Ch, class Tr, class... Args> 
auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; }
ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; o << endl; } return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]";  return o; }
template <typename T> ostream &operator<<(ostream &o, const deque<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]";  return o; }
template <typename T>  ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T>  ostream &operator<<(ostream &o, const unordered_set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U, typename V>  ostream &operator<<(ostream &o, const unordered_map<T, U, V> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]";  return o; }
vector<int> range(const int x, const int y) { vector<int> v(y - x + 1); iota(v.begin(), v.end(), x); return v; }
template <typename T> istream& operator>>(istream& i, vector<T>& o) { rep(j, o.size()) i >> o[j]; return i;}
template <typename T, typename S, typename U> ostream &operator<<(ostream &o, const priority_queue<T, S, U> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.top(); tmp.pop(); o << x << " ";} return o; }
template <typename T> ostream &operator<<(ostream &o, const queue<T> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.front(); tmp.pop(); o << x << " ";} return o; }
template <typename T> ostream &operator<<(ostream &o, const stack<T> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.top(); tmp.pop(); o << x << " ";} return o; }
template <typename T> unordered_map<T, ll> counter(vector<T> vec){unordered_map<T, ll> ret; for (auto&& x : vec) ret[x]++; return ret;};
void vizGraph(vvll& g, int mode = 0, string filename = "out.png") { ofstream ofs("./out.dot"); ofs << "digraph graph_name {" << endl; set<P> memo; rep(i, g.size())  rep(j, g[i].size()) { if (mode && (memo.count(P(i, g[i][j])) || memo.count(P(g[i][j], i)))) continue; memo.insert(P(i, g[i][j])); ofs << "    " << i << " -> " << g[i][j] << (mode ? " [arrowhead = none]" : "")<< endl;  } ofs << "}" << endl; ofs.close(); system(((string)"dot -T png out.dot >" + filename).c_str()); }
struct timeval start; double sec() { struct timeval tv; gettimeofday(&tv, NULL); return (tv.tv_sec - start.tv_sec) + (tv.tv_usec - start.tv_usec) * 1e-6; }
size_t random_seed; struct init_{init_(){ ios::sync_with_stdio(false); cin.tie(0); gettimeofday(&start, NULL); struct timeval myTime; struct tm *time_st; gettimeofday(&myTime, NULL); time_st = localtime(&myTime.tv_sec); srand(myTime.tv_usec); random_seed = RAND_MAX / 2 + rand() / 2; }} init__;
#define ldout fixed << setprecision(40) 

#define EPS (double)1e-14
#define INF (ll)1e18
#define mo  (ll)(1e9+7)

int main(void) {
    ll r, g, b, n;
    cin >> r >> g >> b >> n;
    ll ret = 0;
    rep(i, n+10) rep(j, n+10) {
        ll tmp = i * r + j * g;
        if (tmp > n) continue;
        if ((n - tmp) % b) continue;
        ret++;
    }
    cout << ret << endl;

    return 0;
}