Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, a, b = input().split(' '); n, a, b = int(n), int(a), int(b)

if a*n <= b:
  return a*n
else:
  return b

Fixed submission:
n, a, b = input().split(' '); n, a, b = int(n), int(a), int(b)
 
if a*n <= b:
  print(a*n)
else:
  print(b)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

import sys
import numpy as np

N, M = map(int, sys.stdin.readline().split(" ", 2))

ans = []
for line in sys.stdin:
    l, r = map(int, line.split(" ", 2))
    ans.append(np.array([ 1  if l-1 <= i < r else 0  for i in range(N)] ))
print(sum (1 for a in sum(ans) if a == M))
    # L.append(l)
    # R.append(r)

    


Fixed submission:
# coding: utf-8

import sys
import numpy as np

N, M = map(int, sys.stdin.readline().split(" ", 2))

L = 0
R = M + N
for line in sys.stdin:
    l, r = map(int, line.split(" ", 2))
    if l > L:
        L = l
    if r < R:
        R = r
print(max(0, R - L + 1))
    # L.append(l)
    # R.append(r)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

import sys

N, M = map(int, sys.stdin.readline().split(" ", 2))

L = []
R = []

ans = { i:0 for i in range(N)}
anss = []
for line in sys.stdin:
    l, r = map(int, line.split(" ", 2))
    for i in range(l, r+1):
        ans[i-1] += 1
print(sum(1 for a in ans.values() if a == M))

Fixed submission:
# coding: utf-8

import sys
import numpy as np

N, M = map(int, sys.stdin.readline().split(" ", 2))

L = 0
R = M + N
for line in sys.stdin:
    l, r = map(int, line.split(" ", 2))
    if l > L:
        L = l
    if r < R:
        R = r
print(max(0, R - L + 1))
    # L.append(l)
    # R.append(r)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

import sys

N, M = map(int, sys.stdin.readline().split(" ", 2))

L = []
R = []

ans = [0] * N
for line in sys.stdin:
    l, r = map(int, line.split(" ", 2))
    for i in range(l, r+1):
        ans[i-1] += 1
print(sum(1 for a in ans if a == M))


Fixed submission:
# coding: utf-8

import sys
import numpy as np

N, M = map(int, sys.stdin.readline().split(" ", 2))

L = 0
R = M + N
for line in sys.stdin:
    l, r = map(int, line.split(" ", 2))
    if l > L:
        L = l
    if r < R:
        R = r
print(max(0, R - L + 1))
    # L.append(l)
    # R.append(r)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict

n, m = map(int, sys.stdin.readline().strip().split(" ", 2))
count_city = defaultdict(list)

for line in sys.stdin:
    p, y = map(int, line.strip().split(" ", 2))
    count_city[p].append(y)


for p, yl in count_city.iteritems():
    count_city[p] = sorted(yl)

    sys.stdin.seek(0)
    n, m = map(int, sys.stdin.readline().strip().split(" ", 2))

for line in sys.stdin:
    p, y = map(int, line.strip().split(" ", 2))
    print("{:0=6}{:0=6}".format(p, count_city[p].index(y) + 1))


Fixed submission:
import sys
from collections import defaultdict

n, m = map(int, sys.stdin.readline().strip().split(" ", 2))
list_city = defaultdict(list)

for line in sys.stdin:
    p, y = map(int, line.strip().split(" ", 2))
    list_city[p].append(y)

count_city = {}
for p, yl in list_city.iteritems():
    count_city[p] = {y:i+1 for i, y in enumerate(sorted(yl))}

    
sys.stdin.seek(0)
n, m = map(int, sys.stdin.readline().strip().split(" ", 2))

for line in sys.stdin:
    p, y = map(int, line.strip().split(" ", 2))
    print("{:0=6}{:0=6}".format(p, count_city[p][y]))
Buggy python submission (verdict: Runtime Error):
import sys

N, K = map(int, sys.stdin.readline().strip().split(" "))
X = map(int, sys.stdin.readline().strip().split(" "))

isZero = False
zeroInd = 0
for x in X:
    if x == 0:
        isZero=True
    if x < 0:
        zeroInd+=1
    else:
        break

zeroInd-=1

if isZero:
    X.remove(0)
    K -= 1

if K == 0:
    print(0)
    sys.exit(0)

ans = []

for k in range(K+1):
    a = -1
    if zeroInd + k < len(X):
        a = X[zeroInd+k]

    b = -1
    if len(X) > zeroInd+k-K+1 >= 0:
        b = X[zeroInd+k-K+1] * -1

    if b != -1 and k == 0:
        ans.append(b)
    elif a != -1 and k == K:
        ans.append(a)
    elif a != -1 and b != -1:
        ans.append(a*2+b)
        ans.append(b*2+a)

print(min(ans))


Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().strip().split(" "))
X = map(int, sys.stdin.readline().strip().split(" "))

isZero = False
zeroInd = 0
for x in X:
    if x == 0:
        isZero=True
    if x < 0:
        zeroInd+=1
    else:
        break

zeroInd-=1

if isZero:
    X.remove(0)
    K -= 1

if K == 0:
    print(0)
    sys.exit(0)

ans = []

for k in range(K+1):
    a = -1
    if zeroInd + k < len(X):
        a = X[zeroInd+k]

    b = -1
    if len(X) > zeroInd+k-K+1 >= 0:
        b = X[zeroInd+k-K+1] * -1

    if b != -1 and k == 0:
        ans.append(b)
    elif a != -1 and k == K:
        ans.append(a)
    elif a != -1 and b != -1:
        ans.append(a*2+b)
        ans.append(b*2+a)

print(min(ans))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
N = int(sys.stdin.readline())
line = sys.stdin.readline()
A = [ int(i) for i in line.strip().split() ]
min = 999999
for a in A:
    cnt = 0
    while(min > cnt):
        if a%2 == 1:
            min = cnt
            break
        else:
            a = a/2
            cnt += 1
print(cnt)



Fixed submission:
# -*- coding: utf-8 -*-

import sys

for line in sys.stdin:
    print( sum( int(i) for i in line.strip() ) )
Buggy python submission (verdict: Runtime Error):
cost = input()
amari = int(cost[-3:-1])

print(1000 - amari)

Fixed submission:
cost = input()
amari = int(cost[-3:])
if amari == 0:
  amari = 1000
print(1000 - amari)
Buggy python submission (verdict: Time Limit Exceeded):
count = int(input())
list = input().split(" ")
state = False
i = 0
num = int(list[i])
i += 1
limit = 10 ** 18

while i < count:
  num = num * int(list[i])   
  i += 1
if num > limit:
  print(-1)
else:
  print(num)

Fixed submission:
count = int(input())
list = input().split(" ")
state = False
i = 0
num = int(list[i])
i += 1
limit = 10 ** 18
if "0" in list:
  num = 0
  count = 0

while i < count:
  num = num * int(list[i])

  if num > limit:
    print(-1)
    state = True
    break
    
  i += 1

if not state:
  print(num)

Buggy python submission (verdict: Runtime Error):
count = input()
list = input().split(" ")

i = 0
num = int(list[i])
i += 1
while i>= count:
  num = num * int(list[i])
	
  if num > 10**18:
    print(-1)
    break
    
  i += 1

Fixed submission:
count = int(input())
list = input().split(" ")
state = False
i = 0
num = int(list[i])
i += 1
limit = 10 ** 18
if "0" in list:
  num = 0
  count = 0

while i < count:
  num = num * int(list[i])

  if num > limit:
    print(-1)
    state = True
    break
    
  i += 1

if not state:
  print(num)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
cnt = 0
m = [0] * n
mn = 0
for i in range(0, n):
    if a[i] <= mn:
        m[cnt] = a[i]
        mn = a[i]
        cnt += 1
        continue
    for j in range(cnt):
        if m[j] < a[i]:
            m[j] = a[i]
            break
    else:
        m[cnt] = a[i]
        mn = a[i]
        cnt += 1
print(cnt)

Fixed submission:
import bisect
import collections
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
m = collections.deque([])
for i in range(0, n):
    j = bisect.bisect_left(m, a[i])
    if j == 0:
        m.appendleft(a[i])
    else:
        m[j - 1] = a[i]
print(len(m))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
cnt = 0
m = [0] * n
for i in range(0, n):
    for j in range(cnt):
        if m[j] < a[i]:
            m[j] = a[i]
            break
    else:
        m[cnt] = a[i]
        cnt += 1
print(cnt)

Fixed submission:
import bisect
import collections
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
m = collections.deque([])
for i in range(0, n):
    j = bisect.bisect_left(m, a[i])
    if j == 0:
        m.appendleft(a[i])
    else:
        m[j - 1] = a[i]
print(len(m))

Buggy python submission (verdict: Runtime Error):
import collections
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
c = collections.Counter(a)
print(c.most_common()[1])

Fixed submission:
import bisect
import collections
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
m = collections.deque([])
for i in range(0, n):
    j = bisect.bisect_left(m, a[i])
    if j == 0:
        m.appendleft(a[i])
    else:
        m[j - 1] = a[i]
print(len(m))
Buggy python submission (verdict: Runtime Error):
n, k = [int(z) for z in input().strip().split()]
p = [int(z) - 1 for z in input().strip().split()]
c = [int(z) for z in input().strip().split()]

visited = [False for _ in range(n)]
cycle = []
for start in range(n):
    if visited[start]:
        continue
    now = start
    route = []
    while not visited[now]:
        visited[now] = True
        route.append(now)
        now = p[now]
    cycle.append(route)

min_c = min(c)
max_value = min_c
for route in cycle:
    full_value = sum([c[i] for i in route])
    double_route = route + route
    v = [c[i] for i in double_route]
    max_sum_step = []
    for step in range(1, len(route)):
        s = sum(v[:step])
        max_sum = max(s, min_c)
        for idx in range(step, step + len(route) - 1):
            s += v[idx]
            if idx >= step:
                s -= v[idx - step]
            max_sum = max(s, max_sum)
        max_sum_step.append(max_sum)
    addition = k % len(route)
    if full_value > 0:
        value1 = int(k / len(route)) * full_value + max(max_sum_step[:addition])
        value2 = (int(k / len(route)) - 1) * full_value + max(max_sum_step)
        value = max(value1, value2)
    else:
        value = max(max_sum_step[:min(k, len(max_sum_step))])
    max_value = max(max_value, value)
print(max_value)


Fixed submission:
n, k = [int(z) for z in input().strip().split()]
p = [int(z) - 1 for z in input().strip().split()]
c = [int(z) for z in input().strip().split()]
 
visited = [False for _ in range(n)]
cycle = []
for start in range(n):
    if visited[start]:
        continue
    now = start
    route = []
    while not visited[now]:
        visited[now] = True
        route.append(now)
        now = p[now]
    cycle.append(route)
 
min_c = min(c)
max_value = min_c
for route in cycle:
    full_value = sum([c[i] for i in route])
    double_route = route + route
    v = [c[i] for i in double_route]
    max_sum_step = []
    for step in range(1, len(route)):
        s = sum(v[:step])
        max_sum = max(s, min_c)
        for idx in range(step, step + len(route) - 1):
            s += v[idx]
            if idx >= step:
                s -= v[idx - step]
            max_sum = max(s, max_sum)
        max_sum_step.append(max_sum)
    addition = k % len(route)
    if full_value > 0:
        addition_value = 0 if addition == 0 else max(max_sum_step[:addition])
        value1 = int(k / len(route)) * full_value + addition_value
        value2 = (int(k / len(route)) - 1) * full_value + max(max_sum_step)
        value = max(value1, value2)
    else:
        value = max(max_sum_step[:min(k, len(max_sum_step))])
    max_value = max(max_value, value)
print(max_value)
Buggy python submission (verdict: Runtime Error):
n = int(input())
dic = {}
for i in range(n):
  s = sorted(list(input()))
  if s not in dic:
    dic[s] = 0
  dic[s] += 1
ans = 0
for i in dic.values():
  ans += i * (i - 1)
print(ans)

Fixed submission:
n = int(input())
dic = {}
for i in range(n):
  s = ''.join(sorted(list(input())))
  if s not in dic:
    dic[s] = 0
  dic[s] += 1
ans = 0
for i in dic.values():
  ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
dic = {}
for i in range(n):
  s = list(input()).sorted()
  if s not in dic:
    dic[s] = 0
  dic[s] += 1
ans = 0
for i in dic.values():
  ans += i * (i - 1)
print(ans)

Fixed submission:
n = int(input())
dic = {}
for i in range(n):
  s = ''.join(sorted(list(input())))
  if s not in dic:
    dic[s] = 0
  dic[s] += 1
ans = 0
for i in dic.values():
  ans += i * (i - 1) // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())
dp = [2 ** 60] * (n + 1)
dp[0] = 0
p = list(map(int, input().split()))
for i in range(n):
    dp[i + 1] = dp[0]
    dp[0] += a
    for j in range(i):
        if p[j] < p[i]:
            dp[i + 1] = min(dp[i + 1], dp[j + 1])
            dp[j + 1] += a
        else:
            dp[j + 1] += b
print(min(dp))

Fixed submission:
n, a, b = map(int, input().split())
dp = [2 ** 60] * (n + 1)
dp[0] = 0
p = list(map(int, input().split()))
for i in range(n):
    dp[i + 1] = dp[0]
    dp[0] += a
    for j in range(i):
        if p[j] < p[i]:
            dp[i + 1] = min(dp[i + 1], dp[j + 1])
            dp[j + 1] += a
        else:
            dp[j + 1] += b
print(min(dp))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [1<<30] * n
dp[0] = 0
for i in range(n):
    for j in range(min(k, n) + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[-1])


Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [1<<30] * n
dp[0] = 0
for i in range(n):
    for j in range(min(k, n) + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
from numpy import*
M=10**9+7
m=lambda*z:map(int,raw_input().split())
n,k=m()
b=[1]*n
a=matrix(map(m,b),'O')
while k:b*=[1,a][k&1];a*=a%M;k/=2
print sum(b)%M

Fixed submission:
import numpy
M=10**9+7
n,k=map(int,input().split())
a=numpy.matrix([list(map(int,input().split()))for i in[0]*n],dtype='O')
b=numpy.eye(n,dtype='O')
while k:
 if k&1:b=b*a%M
 a=a*a%M
 k>>=1
print(b.sum()%M)

Buggy python submission (verdict: Runtime Error):
import numpy as P
M=10**9+7
n,k=map(int,input().split())
a=P.matrix([list(map(int,input().split()))for i in[0]*n],dtype='O')
b=P.eye(n,dtype='O')
while k:
 if k&1:b=b*a%M
 a=a*a%M
 k>>=1
print(b.sum()%M)

Fixed submission:
import numpy
M=10**9+7
n,k=map(int,input().split())
a=numpy.matrix([list(map(int,input().split()))for i in[0]*n],dtype='O')
b=numpy.eye(n,dtype='O')
while k:
 if k&1:b=b*a%M
 a=a*a%M
 k>>=1
print(b.sum()%M)
Buggy python submission (verdict: Runtime Error):
M = 10**9+7
n = int(input())
s = input()
t = input()
ans = 3 if s[0] == t[0] else 6
for i in range(1, n):
  if s[i-1] == s[i]:
    continue
  if s[i-1] == t[i-1]:
    ans = ans * 2 % M
  else if s[i] != t[i]:
    ans = ans * 3 % M
print(ans)

Fixed submission:
M = 10**9+7
n = int(input())
s = input()
t = input()
ans = 3 if s[0] == t[0] else 6
for i in range(1, n):
  if s[i-1] == s[i]:
    continue
  if s[i-1] == t[i-1]:
    ans = ans * 2 % M
  elif s[i] != t[i]:
    ans = ans * 3 % M
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
def lcm(a, b):
    return a // math.gcd(a, b) * b
n = int(input())
ans = 1
for i in range(n):
    ans = lcm(ans, int(input()))
print(ans)


Fixed submission:
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a
def lcm(a, b):
    return a // gcd(a, b) * b

n = int(input())
ans = 1
for i in range(n):
    ans = lcm(ans, int(input()))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

s = input()
if not ('ABC' in s):
  print(0)
  exit()

from collections import deque
S = deque(maxlen=200000)
for ss in s:
  S.append(ss)

ans = 0
ihavea = 0
ihaveab = 0
#保持してる文字列
tmpS = ''
while 1:
  try:
    tmp = S.popleft()
  except:
    print(ans)
    exit()
  if ihavea == 0 and ihaveab==0 and (tmp=='B' or tmp=='C'):
    continue
  if ihavea == 0 and ihaveab==0 and tmp=='A':
    ihavea = 1
    tmpS += 'A'
    continue
  if ihavea == 1 and tmp=='A':
    ihavea = 1
    tmpS += 'A'
    continue
  if ihavea == 1 and tmp=='C': #ノーチャン
    ihavea = 0
    tmpS = ''
    continue
  #AABとかになるパターンをまだ考慮してない
  if ihavea == 1 and tmp=='B':
    ihaveab = 1
    ihavea = 0
    tmpS += 'B'
    continue
  if ihaveab == 1 and tmp=='A': #惜しいけどabは無駄になる
    ihaveab = 0
    tmpS = ''
    S.appendleft('A')
    continue
  if ihaveab == 1 and tmp=='B':
    ihaveab = 0
    tmpS = ''
    continue
  if ihaveab == 1 and tmp=='C':
    ihaveab = 0
    ans += len(tmpS)-1
    for _ in range(len(tmpS)-1):
      S.appendleft('A')
    tmpS = ''
#    if tmpS == 'AB': tmpS = ''
#    else:
#      tmpS = tmpS[0:-2] #末尾のABを取り除くだけ
#      if tmpS[-1]=='A': ihavea = 1
#      elif tmpS[-2:]=='AB': ihaveab = 1
    continue





Fixed submission:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

s = input()
if not ('ABC' in s):
  print(0)
  exit()

from collections import deque
S = deque(maxlen=200000)
tmp = 'C'
for ss in s:
  if tmp == 'B' and ss == 'C':
    S.pop()
    S.append('D')
    tmp = 'C'
  elif ss == 'C':
    S.append('B')
    tmp = 'C'
  else:
    S.append(ss)
    tmp = ss

ans = 0
ihavea = 0
#保持してる文字列
Acnt = 0
while 1:
  try:
    tmp = S.popleft()
  except:
    print(ans)
    exit()
  if tmp=='B':
    ihavea = 0
    Acnt = 0
    continue
  if ihavea == 0 and tmp=='A':
    ihavea = 1
    Acnt += 1
    continue
  if ihavea == 1 and tmp=='A':
    ihavea = 1
    Acnt += 1
    continue
  if ihavea == 1 and tmp=='D':
    ihavea = 1
    ans += Acnt
    #Aはそのまま引き継ぐ
    continue
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

import numpy as np

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))

#2次元配列を作る
#[j][0]で数字の個数を、[j][1]で数字自体を取り出す
BC = []
for _ in range(M):
  BC.append(list(map(int, input().split())))

BC = np.array(BC)
BC = BC[BC[:,1].argsort()[::-1],:]


ans = 0
nowaindex = 0
for i, bc in enumerate(BC):
  #continueflagが0のままならループ全体を抜ける
  continueflag = 0
  b = bc[0]
  c = bc[1]
  for j in range(b):
    if A[nowaindex]<c:
      ans += c
      nowaindex += 1
      continueflag += 1
    else: break
  if continueflag == 0: break
    
print(ans + sum(A[nowaindex:]))

Fixed submission:
import sys
input = sys.stdin.readline

import numpy as np

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))

#2次元配列を作る
#[j][0]で数字の個数を、[j][1]で数字自体を取り出す
BC = []
for _ in range(M):
  BC.append(list(map(int, input().split())))

BC = np.array(BC)
BC = BC[BC[:,1].argsort()[::-1],:]


ans = 0
nowaindex = 0
for i, bc in enumerate(BC):
  #continueflagが0のままならループ全体を抜ける
  continueflag = 0
  b = bc[0]
  c = bc[1]
  for j in range(b):
    if A[nowaindex]<c:
      ans += c
      nowaindex += 1
      continueflag += 1
      if nowaindex > N-1:
        continueflag = 0
        break
    else: break
  if continueflag == 0: break
    
print(ans + sum(A[nowaindex:]))
Buggy python submission (verdict: Runtime Error):
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())

adj = [set() for _ in range(N)] #adj[i] = (i_adj, 距離0or1)
for _ in range(N-1):
  u, v, w = mi()
  #0スタートに
  u -= 1
  v -= 1
  adj[u].add((v, w%2))
  adj[v].add((u, w%2))

from collections import deque
q = deque([])

seen = [0] * N
bw = [0] * N

#とりあえずノード0から探索をスタートすることにする
#0の距離は0としておく
q.append(0)
bw[0] = 0 #必要無いが、分かりやすくするために
seen[0] = 1


def solve(): #前のノードまでの色（0or1）を引き継ぐ
  try: nownode = q.popleft()
  except: return
  nowcolor = bw[nownode]

  #今のノードから隣接しているものを探索
  for adjidx, w in adj[nownode]:
    if seen[adjidx]!=1:
      q.append(adjidx)
      seen[adjidx]=1
      bw[adjidx] = (nowcolor+w)%2

  solve()

solve()

for color in bw:
  print(color)



Fixed submission:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###
import sys
sys.setrecursionlimit(10000000)

N = int(input())

adj = [set() for _ in range(N)] #adj[i] = (i_adj, 距離0or1)
for _ in range(N-1):
  u, v, w = mi()
  #0スタートに
  u -= 1
  v -= 1
  adj[u].add((v, w%2))
  adj[v].add((u, w%2))

from collections import deque
q = deque([])

seen = [0] * N
bw = [0] * N

#とりあえずノード0から探索をスタートすることにする
#0の距離は0としておく
q.append(0)
bw[0] = 0 #必要無いが、分かりやすくするために
seen[0] = 1


def solve(): #前のノードまでの色（0or1）を引き継ぐ
  try: nownode = q.popleft()
  except: return
  nowcolor = bw[nownode]

  #今のノードから隣接しているものを探索
  for adjidx, w in adj[nownode]:
    if seen[adjidx]!=1:
      q.append(adjidx)
      seen[adjidx]=1
      bw[adjidx] = (nowcolor+w)%2

  solve()

solve()

for color in bw:
  print(color)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

cnt = 0

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

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

Fixed submission:
###template###
import sys
input = sys.stdin.readline
def mi(): return map(int, input().split())
###template###

Rt, Gt, Bt, N = mi()

R = max(Rt, Gt, Bt)
B = min(Rt, Gt, Bt)
G = Rt+Gt+Bt-R-B

cnt = 0
if G == 1 and B == 1:
  for i in range(N//R+1):
    cnt += (N-R*i)+1
  print(cnt)
  exit()

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)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

cnt = 0

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

for r in range(0, maxr+1):
  if R*r > N: break
  for g in range(0, maxg+1):
    if R*r + G*g > N: break
    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)

Fixed submission:
###template###
import sys
input = sys.stdin.readline
def mi(): return map(int, input().split())
###template###

Rt, Gt, Bt, N = mi()

R = max(Rt, Gt, Bt)
B = min(Rt, Gt, Bt)
G = Rt+Gt+Bt-R-B

cnt = 0
if G == 1 and B == 1:
  for i in range(N//R+1):
    cnt += (N-R*i)+1
  print(cnt)
  exit()

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)

Buggy python submission (verdict: Runtime Error):
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)

Fixed submission:
###template###
import sys
input = sys.stdin.readline
def mi(): return map(int, input().split())
###template###

Rt, Gt, Bt, N = mi()

R = max(Rt, Gt, Bt)
B = min(Rt, Gt, Bt)
G = Rt+Gt+Bt-R-B

cnt = 0
if G == 1 and B == 1:
  for i in range(N//R+1):
    cnt += (N-R*i)+1
  print(cnt)
  exit()

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)