Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02719 (python)

Fixed submission:
N,K=map(int,input().split())
N=N%K
print(min(N,abs(N-K)))

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())

delta = abs(N-K)
print(min(N,N%K,N%delta))

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())

delta = abs(N-K)

while N>=delta:
  N//=delta
  delta = abs(N-K)
  if delta==0:
    N=0
    break
  
print(N)
Problem p02780 (python)

Fixed submission:
N,K=map(int,input().split())
*p,= map(int, input().split())

s=[(p[n]+1)/2 for n in range(N)]
S=[0]*(N+1)

def make_S(n):
    S=[0]*(n+1)
    S[0]=0
    for i in range(n):
        S[i+1]=S[i]+s[i]
    return S
S=make_S(N)

def max_delta(n,k):
    max=-1000000
    for i in range(n-k+1):
        delta = S[i+k]-S[i]
        if delta>max:
            max=delta
    return max

print(max_delta(N,K))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
*p,= map(int, input().split())

s=[(p[n]+1)/2 for n in range(N)]
S=[0 for _ in range(N)]

S[0]=s[0]
for n in range(N-1):
    S[n+1]=s[n+1]+S[n]

def sjk(j):
    return S[j+K]-S[j]
delta = [sjk(i) for i in range(N-K)]

print(max(delta))
Problem p02801 (python)

Fixed submission:
alpha = 'abcdefghijklmnopqrstuvwxyz'
if __name__=='__main__':
    print(alpha[1+alpha.index(input())])

Buggy submission (verdict: Runtime Error):
N,K,M=map(int, input().split(' '))
Ai =input().split(' ')
Ais = [int(s) for s in Ai]

goal = M*N
if __name__=='__main__':
  rest=goal-sum(Ais)
  print( max(0,rest) if rest<=K else -1 )

Buggy submission (verdict: Runtime Error):
N,K,M=map(int, input().split(' '))
Ai =input().split(' ')
Ais = [int(s) for s in Ai]

goal = M*N
current = sum(Ais)

if __name__=='__main__':
  rest=goal-sum(Ais)
  print( max(0,rest) if rest<=K else -1 )

Buggy submission (verdict: Runtime Error):
alpha = 'abcdefghijklmnopqrstuvwxy'
if __name__=='__main__':
    s=input()
    i = alpha.index(s)
    print(alpha[i+1])
Problem p03597 (python)

Fixed submission:
def get_num():
    n = int(input())
    w = int(input())
    return n,w

def check_range(n,w):
    return n in range(1,101) and w in range(n**2+1)

def black_tiles(n,w):
    if (check_range(n,w)):
        return n**2 - w
    else:
        raise Exception('Value out of range')

if (__name__=='__main__'):
    print(black_tiles(*get_num()))

Buggy submission (verdict: Runtime Error):
def get_num():
    n = int(input())
    w = int(input())
    return n,w

def check_range(n,w):
    return n in range(1,101) and w in range(n**2)


def black_tiles(n,w):
    if (check_range(n,w)):
        return n**2 - w
    else:
        raise Exception('Value out of range')


if (__name__=='__main__'):
    n,w = get_num()
    print(black_tiles(n,w))

Buggy submission (verdict: Runtime Error):
def get_num():
    n = int(input())
    w = int(input())
    return n,w

def check_range(n,w):
    return n in range(1,101) and w in range(n**2)

def black_tiles(n,w):
    if (check_range(n,w)):
        return n**2 - w
    else:
        raise Exception('Value out of range')

if (__name__=='__main__'):
    print(black_tiles(*get_num()))
Problem p02609 (python)

Fixed submission:
N = int(input())
X = list(map(int, input().strip()))

count_j = X.count(1)

def calc_table(m):
	if m == 1:
		return [0] * N
	elif m == 0:
		return None
	table = []
	x = 1
	for i in range(N):
		table.append(x)
		x = (x * 2) % m
	table.reverse()
	return table

count_m = count_j - 1
count_p = count_j + 1

mod_m = calc_table(count_m)
mod_j = calc_table(count_j)
mod_p = calc_table(count_p)

original_j = 0
original_m = 0
original_p = 0
if count_m > 0:
	for i, b in enumerate(X):
		if b == 1:
			original_j = (original_j + mod_j[i]) % count_j
			original_m = (original_m + mod_m[i]) % count_m
			original_p = (original_p + mod_p[i]) % count_p
else:
	for i, b in enumerate(X):
		if b == 1:
			original_j = (original_j + mod_j[i]) % count_j
			original_p = (original_p + mod_p[i]) % count_p
#print(mod_p)
#print(original_m, original_j, original_p)

f_cache = [None] * N
def calc_f(x):
	if x == 0:
		return 0
	f = f_cache[x]
	if f != None:
		return f
	count = 0
	i = x
	while i > 0:
		if i % 2 == 1:
			count += 1
		i //= 2
	f = calc_f(x % count) + 1
	f_cache[x] = f
	return f

for i, b in enumerate(X):
	if b == 0:
		x = (original_p + mod_p[i]) % count_p
		print(calc_f(x) + 1)
	else:
		if count_m > 0:
			x = (original_m - mod_m[i]) % count_m
			print(calc_f(x) + 1)
		else:
			print(0)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().strip()))

count_j = X.count(1)

def calc_table(m):
	if m == 1:
		return [0] * N
	elif m == 0:
		return None
	table = []
	x = 1
	for i in range(N):
		table.append(x)
		x = (x * 2) % m
	table.reverse()
	return table

count_m = count_j - 1
count_p = count_j + 1

mod_m = calc_table(count_m)
mod_j = calc_table(count_j)
mod_p = calc_table(count_p)

original_j = 0
original_m = 0
original_p = 0
for i, b in enumerate(X):
	if b == 1:
		original_j = (original_j + mod_j[i]) % count_j
		original_m = (original_m + mod_m[i]) % count_m
		original_p = (original_p + mod_p[i]) % count_p

#print(mod_p)
#print(original_m, original_j, original_p)

f_cache = [None] * N
def calc_f(x):
	if x == 0:
		return 0
	f = f_cache[x]
	if f != None:
		return f
	count = 0
	i = x
	while i > 0:
		if i % 2 == 1:
			count += 1
		i //= 2
	f = calc_f(x % count) + 1
	f_cache[x] = f
	return f

for i, b in enumerate(X):
	if b == 0:
		x = (original_p + mod_p[i]) % count_p
	else:
		x = (original_m - mod_m[i]) % count_m
	print(calc_f(x) + 1)
Problem p02844 (python)

Fixed submission:
import re

N = int(input())
S = [int(c) for c in input().strip()]
length = len(S)

count = 0
for c1 in range(10):
	index1 = 0
	while index1 < length:
		if S[index1] == c1:
			index1 += 1
			break
		index1 += 1
	if index1 < length:
		for c2 in range(10):
			index2 = index1
			while index2 < length:
				if S[index2] == c2:
					index2 += 1
					break
				index2 += 1
			if index2 < length:
				for c3 in range(10):
					index3 = index2
					while index3 < length:
						if S[index3] == c3:
							count += 1
							break
						index3 += 1
print(count)

Buggy submission (verdict: Runtime Error):
import re

N = int(input())
S = input().strip()

count = 0
for c1 in range(10):
	for c2 in range(10):
		for c3 in range(10):
			if re.search(f"{c1}.*{c2}.*{c3}", S):
				count += 1
print(count)
Problem p02866 (python)

Fixed submission:
M = 998244353

N = int(input())
d_list = list(map(int, input().split()))

def check():
	if d_list[0] != 0:
		print(0)
		return
	d_list.sort()
	d_counts = []
	prev_d = -1
	for d in d_list:
		if prev_d == d:
			d_counts[prev_d] += 1
		elif prev_d + 1 == d:
			d_counts.append(1)
			prev_d = d
		else:
			print(0)
			return
	count = 1
	prev_c = d_counts.pop(0)
	if prev_c != 1:
		print(0)
	else:
		for c in d_counts:
			count = (count * pow(prev_c, c, M)) % M
			prev_c = c
		print(count)

check()

Buggy submission (verdict: Runtime Error):
M = 998244353

N = int(input())
d_list = list(map(int, input().split()))
d_list.sort()

def fact(n):
	f = 1
	for i in range(2, n + 1):
		f = (f * i) % M
	return f

def check():
	d = d_list.pop(0)
	if d != 0:
		print(0)
	else:
		if d_list[0] == 0:
			print(0)
		else:
			d_counts = [1]
			prev_d = 0
			for d in d_list:
				if prev_d == d:
					d_counts[prev_d] += 1
				elif prev_d + 1 == d:
					d_counts.append(1)
					prev_d = d
				else:
					print(0)
					return
		count = 1
		prev_d = d_counts.pop(0)
		for d in d_counts:
			count = (count * pow(prev_d, d)) % M
			prev_d = d
		print(count)

check()
Problem p02937 (python)

Fixed submission:
a_code = ord("a")

s = [ord(c) - a_code for c in input().strip()]
t = [ord(c) - a_code for c in input().strip()]

tl = len(t)
sl = len(s)

s_table = [None] * sl
index_table = [None] * 26
for i in range(sl - 1, -1, -1):
	c = s[i]
	index_table[c] = i
	s_table[i] = list(index_table)

ti = 0
si = 0
count = 0
found = False
while ti < tl:
	c = t[ti]
	index = s_table[si][c]
	if index != None:
		ti += 1
		count += index + 1 - si
		si = index + 1
		found = True
		if si >= sl:
			if not found:
				count = -1
				break
			found = False
			si = 0
	else:
		if not found:
			count = -1
			break
		found = False
		count += sl - si
		si = 0
print(count)

Buggy submission (verdict: Runtime Error):
s = input().strip()
t = input().strip()

ti = 0
si = 0
tl = len(t)
sl = len(s)
count = 0
found = False
while ti < tl:
	if s[si] == t[ti]:
#		print(s[si])
		si += 1
		ti += 1
		found = True
	else:
		si += 1
		if si == sl:
			if not found:
				count = -1
				break
			si = 0
			found = False
	count += 1
print(count)
Problem p02960 (python)

Fixed submission:

M = 10 ** 9 + 7
s = raw_input().strip()

num = 0
q_list = []
d = 1
for i in range(len(s) - 1, -1, -1):
	c = s[i]
	if c != "?":
		num = (num + int(c) * d) % 13
	else:
		q_list.append(d)
	d = (d * 10) % 13

counts = [0] * 13
counts[0] = 1
counts_save = [0] * 13
for d in q_list:
	for i in range(13):
		counts_save[i] = counts[i] % M
	for n in range(1, 10):
		r = (d * n) % 13
		for m in range(13):
			counts[(r + m) % 13] += counts_save[m]

print(counts[(13 + 5 - num) % 13] % M)

Buggy submission (verdict: Runtime Error):
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

unsigned long M = 1000000007;

int main(void){
	unsigned char* buffer = malloc(100010);
	fgets(buffer, 100010, stdin);
	
	unsigned int* q_list = malloc(sizeof(int) * 100000);
	unsigned int q_count = 0;
	unsigned int num = 0;
	unsigned int d = 1;
	
	unsigned int len = strlen(buffer);
	while(1){
		unsigned char c = buffer[len - 1];
		if((c >= '0' && c <= '9') || c == '?'){
			break;
		}
		len --;
	}
	for(int i = len - 1; i >= 0; i --){
		unsigned char c = buffer[i];
		if(c == '?'){
			q_list[q_count ++] = d;
		}else{
			num = (num + (c - '0') * d) % 13;
		}
		d = (d * 10) % 13;
	}
	free(buffer);
	
	unsigned long counts_buffer[2][13];
	unsigned int b = 0;
	unsigned long *counts = counts_buffer[b];
	for(int i = 0; i < 13; i ++){
		counts[i] = 0;
	}
	counts[0] = 1;
	
	for(int j = 0; j < q_count; j ++){
		unsigned int d = q_list[j];
		unsigned long *new_counts = counts_buffer[1 - b];
		for(int i = 0; i < 13; i ++){
			new_counts[i] = 0;
		}
		for(int n = 0; n < 10; n ++){
			unsigned int r = (d * n) % 13;
			for(int m = 0; m < 13; m ++){
				unsigned int k = (r + m) % 13;
				new_counts[k] = (new_counts[k] + counts[m]) % M;
			}
		}
		b = 1 - b;
		counts = counts_buffer[b];
	}
	printf("%ld\n", counts[(13 + 5 - num) % 13]);
	return 0;
}
/*

M = 10 ** 9 + 7
s = input().strip()

num = 0
q_list = []
d = 1
l = len(s)
for i in range(l - 1, -1, -1):
	c = s[i]
	if c != "?":
		num = (num + int(c) * d) % 13
	else:
		q_list.append(d)
	d = (d * 10) % 13

counts = [0] * 13
counts[0] = 1
for d in q_list:
	new_counts = [0] * 13
	for n in range(10):
		r = (d * n) % 13
		for m in range(13):
			k = (r + m) % 13
			new_counts[k] = (new_counts[k] + counts[m]) % M
	counts = new_counts
print(counts[(13 + 5 - num) % 13])
*/
Problem p03026 (python)

Fixed submission:
N = int(input())

table = [[] for _ in range(N)]
for i in range(N - 1):
	a, b = map(int, input().split())
	a -= 1
	b -= 1
	table[a].append(b)
	table[b].append(a)

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

c_list.sort()
c_list.reverse()

d_table = {}
d_rev = [None] * N
for i in range(N):
	d = len(table[i])
	if d in d_table:
		d_table[d].add(i)
	else:
		d_table[d] = {i}
	d_rev[i] = d

scores = [None] * N
for i in range(N):
	if i in d_table:
		n_set = d_table[i]
		while n_set:
			n = n_set.pop()
			scores[n] = c_list.pop()
			for n2 in table[n]:
				d = d_rev[n2]
				d_rev[n2] = d - 1
				n_set2 = d_table[d]
				if n2 in n_set2:
					n_set2.remove(n2)
					if d - 1 in d_table:
						d_table[d - 1].add(n2)
					else:
						d_table[d - 1] = {n2}

for i in range(N):
	if scores[i] == None:
		scores[i] = c_list[0]

score = 0
stack = [0]
visited = set()
visited.add(0)
while stack:
	cur = stack.pop()
	s1 = scores[cur]
	for n in table[cur]:
		if not n in visited:
			s2 = scores[n]
			if s1 < s2:
				score += s1
			else:
				score += s2
			stack.append(n)
			visited.add(n)

print(score)
print(" ".join([str(s) for s in scores]))

Buggy submission (verdict: Runtime Error):
N = int(input())

table = [[] for _ in range(N)]
for i in range(N - 1):
	a, b = map(int, input().split())
	a -= 1
	b -= 1
	table[a].append(b)
	table[b].append(a)

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

c_list.sort()

d_list = [(len(table[i]), i) for i in range(N)]
d_list.sort()
i_list = [d_list[i][1] for i in range(N)]

scores = [None] * N
for i, s in zip(i_list, c_list):
	scores[i] = s

tree_top = 0
if N > 1:
	while len(table[tree_top]) == 1:
		tree_top = table[tree_top][0]

score = 0
def calc(cur, parent):
	global score
	s1 = scores[cur]
	for v in table[cur]:
		if v != parent:
			s2 = scores[v]
			if s1 < s2:
				score += s1
			else:
				score += s2
			calc(v, cur)

calc(tree_top, None)
print(score)
print(" ".join([str(s) for s in scores]))

Buggy submission (verdict: Runtime Error):
N = int(input())

table = [[] for _ in range(N)]
for i in range(N - 1):
	a, b = map(int, input().split())
	a -= 1
	b -= 1
	table[a].append(b)
	table[b].append(a)

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

c_list.sort()
c_list.reverse()

ds = [(len(table[i]), i) for i in range(N)]
ds.sort()
i_list = [ds[i][1] for i in range(N - 1, -1, -1)]

scores = [None] * N
for i, s in zip(i_list, c_list):
	scores[i] = s

tree_top = 0
while len(table[tree_top]) == 1:
	tree_top = table[tree_top][0]

score = 0
def calc(cur, parent):
	global score
	s1 = scores[cur]
	for v in table[cur]:
		if v != parent:
			s2 = scores[v]
			if s1 < s2:
				score += s1
			else:
				score += s2
			calc(v, cur)

calc(tree_top, None)
print(score)
print(" ".join([str(s) for s in scores]))
Problem p02761 (python)

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

def solve():
    N,M = map(int,input().split())
    D = dict()
    for _ in range(M):
        s,c = map(int,input().split())
        if s in D and D[s] != c:
            return '-1'
        else:
            D[s] = c

    if N==1 and (M==0 or (1 in D and D[1] == 0)):
        return '0'

    if N>1 and 1 in D and D[1] == 0:
        return '-1'

    if 1 not in D:
        D[1] = 1

    if 2 not in D:
        D[2] = 0

    if 3 not in D:
        D[3] = 0

    res = sum(D[i+1]*10**(N-i-1) for i in range(N))

    return str(res)

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

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

def solve():
    N,M = map(int,input().split())
    D = dict()
    for _ in range(M):
        s,c = map(int,input().split())
        D[s] = D.get(s,set()) | {c,}

    if not all(len(v)==1 for v in D.values()):
        return '-1'

    if N>1 and D[1] == {0,}:
        return '-1'

    if 1 not in D:
        D[1] = {1,}

    if 2 not in D:
        D[2] = {0,}

    if 3 not in D:
        D[3] = {0,}

    res = sum(D[i+1].pop()*10**(N-i-1) for i in range(N))

    return str(res)

if __name__ == '__main__':
    print(solve())
Problem p02882 (python)

Fixed submission:
# -*- coding: utf-8 -*-
from math import ceil, sqrt, atan, degrees

def solve():
    a,b,x = map(int, input().split())
    if a*a*b == x:
        return '0'
    elif 1/2*a*a*b >= x:
        t = atan(2*x/a/b/b)
    else:
        t = atan(a*a*a/2/(a*a*b-x))

    return str(90-degrees(t))
        
if __name__ == '__main__':
    print(solve())

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from math import ceil, sqrt, atan, degrees

def solve():
    a,b,x = map(int, input().split())
    if 1/2*a*a*b >= x:
        t = atan(2*x/a/b/b)
    else:
        t = atan(a*a*a/2/(a*a*b-x))

    return str(90-degrees(t))
        
if __name__ == '__main__':
    print(solve())
Problem p02930 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np

def solve():
    N = int(input())
    E = np.array([[0,1],[0,0]])
    for i in range((N-1).bit_length()-1):
        E_ = E+(E>0)
        E = np.vstack([np.hstack([E_,np.ones_like(E)]),np.hstack([np.zeros_like(E), E_])])
    res = '\n'.join(' '.join(map(str,e[i+1:N])) for i, e in enumerate(E[:N]))
    return str(res)

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

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from itertools import combinations
import numpy as np

def solve():
    N = int(input())
    E = np.array([[0,1],[0,0]])
    for i in range((N-1).bit_length()-1):
        E_ = E+(E>0)
        E = np.block([[E_,np.ones_like(E)],[np.zeros_like(E), E_]])
    res = '\n'.join(' '.join(map(str,e[i+1:N+1])) for i, e in enumerate(E[:N+1]))
    return str(res)

if __name__ == '__main__':
    print(solve())
Problem p02976 (python)

Fixed submission:
# -*- coding: utf-8 -*-
def solve():
    N, M = map(int, input().split())
    if M%2:
        return '-1'
    E = [set() for _ in range(N+1)]
    for _ in range(M):
        a,b = map(int, input().split())
        E[a].add(b)
        E[b].add(a)
    q = [(0,1,1)]
    v = set()
    T = []
    while q:
        n_, n, d = q.pop()
        if n not in v:
            T.append((d,n_,n))
            E[n].discard(n_)
            E[n_].discard(n)
            v.add(n)
            if E[n]-v:
                q.extend([(n,u, d+1) for u in E[n]-v])

    A = [0 for _ in range(N+1)]
    res = []
    c = set()
    for d,a,b in sorted(T, reverse=1)[:-1]:
        F = E[b]-c
        if A[b]%2 == 0 or len(E[b])%2:
            res.extend([(u,b) for u in F])
            for u in F:
                A[u] += 1
                E[u] -= {b}
        else:
            res.extend([(b,u) for u in F])
            for u in F:
                A[b] += 1
                E[u] -= {b}

        E[a] -= {b}
        if A[b]%2:
            A[b] += 1
            res.extend([(b,a)]) 
        else:
            A[a] += 1
            res.extend([(a,b)])

    return '\n'.join(['{} {}'.format(*e) for e in res])


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

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def solve():
    N, M = map(int, input().split())
    if M%2:
        return '-1'
    E = [set() for _ in range(N+1)]
    for _ in range(M):
        a,b = map(int, input().split())
        E[a].add(b)
        E[b].add(a)
    q = [(0,1,1)]
    v = set()
    T = [set() for _ in range(N+1)]
    L = []
    V = []
    while q:
        n_, n, d = q.pop()
        if n not in v:
            T[n].add(n_)
            T[n_].add(n)
            v.add(n)
            V.append((d,n))
            if E[n]-v:
                q.extend([(n,u, d+1) for u in E[n]-v])
            else:
                L.append(n)

    A = [0 for _ in range(N+1)]
    res = []
    c = set()
    for d, n in sorted(V, reverse=1):
        c.add(n)
        if (A[n]+len(E[n]))%2:
            res.extend([(u,n) for u in E[n]-c])
            for u in E[n]-c:
                A[u] += 1
                E[u] -= {n}
        else:
            res.extend([(n,u) for u in E[n]-c])
            for u in E[n]-c:
                A[n] += 1
                E[u] -= {n}
    if any(a%2 for a in A):
        return '-1'
    else:
        return '\n'.join(['{} {}'.format(*e,) for e in res])


if __name__ == '__main__':
    print(solve())
Problem p02985 (python)

Fixed submission:
# -*- coding: utf-8 -*-
def solve():
    N, K = map(int, input().split())
    N_1 = [{1},{0}]+[set() for _ in range(N-1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        N_1[a].add(b)
        N_1[b].add(a)
    checked, q = set(), {0}
    res = 1
    while q:
        n = q.pop()
        checked.add(n)
        q.update(set.difference(N_1[n], checked))
        K_ = K-min(2,n)
        for i in range(len(N_1[n])-(n>0)):
            if K_ == i:
                return str(0)
            res = (res*(K_-i))%(10**9+7)
    return str(res)
if __name__ == '__main__':
    print(solve())

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def solve():
    N, K = map(int, input().split())
    N_1 = [set() for _ in range(N+1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        N_1[a].add(b)
        N_1[b].add(a)
        
    checked = set()
    q = {1}
    res = 1
    while q:
        n = q.pop()
        q |= N_1[n] - checked
        fixed = len(set.union(*(N_1[m] for m in N_1[n]), N_1[n]-{n}) & checked)
        res *= K - fixed
        checked.add(n)
        if res < 0:
            return str(0)
        else:
            res %= 10**9+7
    return str(res)


if __name__ == '__main__':
    print(solve())
Problem p03047 (python)

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

def solve():
  N, K = map(int, input().split())
  return str(N-K+1)

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

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

def solve():
    return str(int.__sub__(*map(int, input().split()),)+1)

if __name__ == '__main__':
    print(solve())
Problem p03048 (python)

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

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

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

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

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

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