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

Fixed submission:
import numpy as np

def in1d(ar1, ar2, assume_unique=False, invert=False):
    # Ravel both arrays, behavior for the first array could be different
    ar1 = np.asarray(ar1).ravel()
    ar2 = np.asarray(ar2).ravel()

    # Check if one of the arrays may contain arbitrary objects
    contains_object = ar1.dtype.hasobject or ar2.dtype.hasobject

    # This code is run when
    # a) the first condition is true, making the code significantly faster
    # b) the second condition is true (i.e. `ar1` or `ar2` may contain
    #    arbitrary objects), since then sorting is not guaranteed to work
    if len(ar2) < 10 * len(ar1) ** 0.145 or contains_object:
        if invert:
            mask = np.ones(len(ar1), dtype=bool)
            for a in ar2:
                mask &= (ar1 != a)
        else:
            mask = np.zeros(len(ar1), dtype=bool)
            for a in ar2:
                mask |= (ar1 == a)
        return mask

    # Otherwise use sorting
    if not assume_unique:
        ar1, rev_idx = np.unique(ar1, return_inverse=True)
        ar2 = np.unique(ar2)

    ar = np.concatenate((ar1, ar2))
    # We need this to be a stable sort, so always use 'mergesort'
    # here. The values from the first array should always come before
    # the values from the second array.
    order = ar.argsort(kind='mergesort')
    sar = ar[order]
    if invert:
        bool_ar = (sar[1:] != sar[:-1])
    else:
        bool_ar = (sar[1:] == sar[:-1])
    flag = np.concatenate((bool_ar, [invert]))
    ret = np.empty(ar.shape, dtype=bool)
    ret[order] = flag

    if assume_unique:
        return ret[:len(ar1)]
    else:
        return ret[rev_idx]

def isin(element, test_elements, assume_unique=False, invert=False):
    element = np.asarray(element)
    return in1d(element, test_elements, assume_unique=assume_unique,
                invert=invert).reshape(element.shape)
A = []
for i in range(3):
    A.append(list(map(int, input().split())))
A = np.array(A)

N = int(input())
b = np.zeros(N, dtype=np.int)
for i in range(N):
    b[i] = int(input())
T = isin(A,b)
ans=[0,0,0,0]
ans[0]=T.all(axis=0).any()
ans[1]=T.all(axis=1).any()
ans[2]=np.diag(T).all()
ans[3]=np.diag(T[:,[2,1,0]]).all()
if any(ans):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import numpy as np

A = []
for i in range(3):
    A.append(list(map(int, input().split())))
A = np.array(A)

N = int(input())
b = np.zeros(N, dtype=np.int)
for i in range(N):
    b[i] = int(input())
# print(A)
# print(b)
# T = A[A in b]
T = np.isin(A,b)
# print(T)
ans=[0,0,0,0]
ans[0]=T.all(axis=0).all()
ans[1]=T.all(axis=1).all()
ans[2]=np.diag(T).all()
ans[3]=np.diag(T[:,[2,1,0]]).all()
# print(ans)
if any(ans):
    print('Yes')
else:
    print('No')
Problem p02865 (python)

Fixed submission:
import math
N=int(input())
ans=int(math.ceil(N/2.0)-1)
print(ans)

Buggy submission (verdict: Runtime Error):
N=input()
ans=int(round(N/2.0)-1)
print(ans)
Problem p02866 (python)

Fixed submission:
import math
from collections import Counter
N=int(input())
D=input().split()
T=[]
D_dict=Counter(D)
D_keys=list(D_dict.keys())
D_keyi=[int(n) for n in D_keys]
maxD=max(D_keyi)
D_keyi.sort()
ans=1
if D[0] != '0' or D_dict['0']!=1 or D_keyi != list(range(maxD+1)):
    print(0)
else:
    for i in range(maxD+1):
        T.append(D_dict[str(i)])
    for i in range(len(T)-1):
        ans=ans*(T[i]**T[i+1])
    print((ans%998244353))

Buggy submission (verdict: Runtime Error):
import math
from collections import Counter
N=int(input())
D=input().split()
T=[]
D_dict=Counter(D)
D_keys=list(D_dict.keys())
D_keyi=[int(n) for n in D_keys]
maxD=max(D_keyi)
D_keyi.sort()
ans=1
if D[0] != '0' or D_dict['0']!=1 or D_keyi != list(range(maxD+1)):
    print(0)
else:
    for i in range(maxD+1):
        T.append(D_dict[str(i)])
    for i in range(len(T)-1):
        ans=ans*(T[i]**T[i+1])
    print(mod(ans,998244353))
Problem p02683 (python)

Fixed submission:
N, M, X = list(map(int, input().split()))
CA = [list(map(int, input().split())) for i in range(N)]

set_list = []
for i in range(2 ** N):
    select = []
    for j in range(N):
        if ((i >> j) & 1):
            select.append(j)
    if len(select) != 0:
        set_list.append(select)
    
cost = []
for i in range(2 ** N - 1):
    cost.append(sum([CA[set_list[i][j]][0] for j in range(len(set_list[i]))]))

skill = []
for i in range(2 ** N - 1):
    tmp = [0]*M
    for j in set_list[i]:
        for k in range(M):
            tmp[k] += CA[j][k+1]
    skill.append(tmp)

pool = []
for i in range(2**N - 1):
    flag = 0
    for j in skill[i]:
        if j < X:
            flag = 1
    if flag == 0:
        pool.append(cost[i])
        

if len(pool) == 0:
	print(-1)
else:
    print(min(pool))

Buggy submission (verdict: Runtime Error):
N, M, X = list(map(int, input().split()))
CA = [list(map(int, input().split())) for i in range(N)]

set_list = []
for i in range(2 ** N):
    select = []
    for j in range(N):
        if ((i >> j) & 1):
            select.append(j)
    if len(select) != 0:
        set_list.append(select)
    
cost = []
for i in range(2 ** N - 1):
    cost.append(sum([CA[set_list[i][j]][0] for j in range(len(set_list[i]))]))

skill = []
for i in range(2 ** N - 1):
    tmp = [0]*M
    for j in set_list[i]:
        for k in range(M):
            tmp[k] += CA[j][k+1]
    skill.append(tmp)

pool = []
for i in range(2**N - 1):
    flag = 0
    for j in skill[i]:
        if j < X:
            flag = 1
    if flag == 0:
        pool.append(cost[i])
        

print(min(pool))
Problem p02714 (python)

Fixed submission:
N = int(input())
S = input()

r , g, b = S.count("R"), S.count("G"), S.count("B")
ans = r * g * b

for i in range(N-2):
    for d in range(N//2+1):
        j = i + d
        k = j + d
        if k >= N:break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1
print(ans)

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

r , g, b = S.count("R"), S.count("G"), S.count("B")
ans = r * g * b

for i in range(N-2):
    for d in range(N//2+1):
        j = i + d
        k = j + d
        if k < N:
        	if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            	ans -= 1
print(ans)
Problem p03998 (python)

Fixed submission:
SA = input()
SB = input()
SC = input()

pointer = SA[0]
SA = SA[1:]
d = {'a': SA, 'b': SB, 'c': SC}

while True:
    if d[pointer] == '':
        ans = pointer
        break
    tmp = d[pointer][0]
    d[pointer] = d[pointer][1:]
    pointer = tmp

print(ans.upper())

Buggy submission (verdict: Runtime Error):
d = { 'a':input(), 'b':input(), 'c':input() }
pointer = 'a'
while True:
    if 0 < len(d[pointer]):
        tmp = d[pointer][0]
        d[pointer] = s[pointer][1:]
        pointer = tmp
    else:
        print(pointer.upper())
        break

Buggy submission (verdict: Runtime Error):
SA = input()
SB = input()
SC = input()

pointer = SA[0]
SA = SA[1:]
d = {'a': SA, 'b': SB, 'c': SC}

while True:
    tmp = d[pointer][0]
    d[pointer] = d[pointer][1:]
    pointer = tmp
    if d[pointer] == '':
        ans = pointer
        break

print(ans.upper())
Problem p02658 (python)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

ans = 1

ok = True
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        ok = False
        break

for i in range(n):
    if a[i] == 0:
        ok = True
        ans = 0

if ok == True:
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(x) for x in input().split()]

ans = 1

ok = True
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        ok = False
        break

for i in range(N):
    if a[i] == 0:
        ok = True
        ans = 0

if ok == True:
    print(ans)
else:
    print(-1)
Problem p02660 (python)

Fixed submission:
import math
 
N = int(input())
 
M = int(math.sqrt(N))

ans = 0 
check = [True for _ in range(M + 1)]
e = [0 for _ in range(M + 1)]

for p in range(2, M + 1):
    if check[p] == True:
        for j in range(2, M // p + 1):
            check[p * j] = False

        while N % p == 0:
            N = N // p
            e[p] += 1
        
        ans += int((math.sqrt(1 + 8 * e[p]) - 1)/2)

if N > 1:
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())

ans = 0
check = [True for _ in range(10 ** 6)]

for p in range(2, 10 ** 6):
    if check[p] == True:
        for j in range(2, (10 ** 6) // p + 1):
            check[p * j] = False

        e = 1
        while N % (p ** e) == 0:
            N = N // (p ** e)
            e += 1
            ans += 1

if ans == 0:
    if N == 1:
        print(0)
    else:
        print(1)
else:
    print(ans)
Problem p02691 (python)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

counter = {}

for i in range(N):
    counter[i + A[i]] = 0

ans = 0
for i in range(N):
    if i - A[i] in counter:
        ans += counter[i - A[i]]
    counter[i + A[i]] += 1

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]

M = max(A) + N

counter = [0] * (M + 1)

ans = 0
for i in range(N):
    if i > A[i]:
        ans += counter[i - A[i]]
    counter[i + A[i]] += 1

print(ans)
Problem p02702 (python)

Fixed submission:
S = input()
N = len(S)
 
counter = [0] * 2019
counter[0] = 1
T = 0
R = 1
for i in range(N):
    T = (T + R * int(S[N - i - 1])) % 2019
    R = 10 * R % 2019
    counter[T] += 1
 
ans = 0
for i in range(2019):
    m = counter[i]
    ans += m * (m - 1) // 2
 
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)

counter = [0] * 2019
counter[0] = 1
T = 0
R = 1
for i in range(N):
    T = (T + R * int(S[n - i - 1])) % 2019
    R = 10 * R % 2019
    counter[T] += 1

ans = 0
for i in range(2019):
    m = counter[i]
    ans += m * (m - 1) // 2

print(ans)
Problem p02720 (python)

Fixed submission:
from collections import deque

N = int(input())

Q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

for i in range(N - 1):
    x = Q.popleft()
    if x % 10 != 0:
        y = 10 * x + x % 10 - 1
        Q.append(y)
    
    y = 10 * x + x % 10
    Q.append(y)

    if x % 10 != 9:
        y = 10 * x + x % 10 + 1
        Q.append(y)

ans = Q.popleft()

print(ans)

Buggy submission (verdict: Runtime Error):
def f(a, d, n):

    if n == 0:
        fans = ''
        for i in range(d):
            fans = fans + str(max(0, int(a) - i))

    else:
        s = f(a, d, n - 1)
        k = 0
        for j in range(d - 1):
            if s[d - 2 - j] >= s[d - 1 - j]:
                k = d - 1 - j
                break

        t = f(str(int(s[d - 1 - j]) + 1), j + 1, 0)
        fans = s[:k] + t
    
    return fans

lnln = [[0] * 10 for _ in range(10 + 1)]
lnln[1] = [1] * 10

for i in range(2, 10 + 1):
    for j in range(10):
        if j == 0:
            lnln[i][0] = lnln[i - 1][0] + lnln[i - 1][1]
        elif j == 9:
            lnln[i][9] = lnln[i - 1][8] + lnln[i - 1][9]
        else:
            lnln[i][j] = lnln[i - 1][j - 1] + lnln[i - 1][j] + lnln[i - 1][j + 1]

N = int(input())
S = 0
ok = False
for i in range(1, 10 + 1):
    for j in range(1, 10):
        if S + lnln[i][j] >= N:
            d, a, n = i, j, N - S - 1
            ok = True
            break
        else:
            S += lnln[i][j]
    if ok == True:
        break

ans = int(f(str(a), d, n))

print(ans)
Problem p02727 (python)

Fixed submission:
X, Y, A, B, C = [int(x) for x in input().split()]
p = sorted([int(x) for x in input().split()], reverse=True)[:X]
q = sorted([int(x) for x in input().split()], reverse=True)[:Y]
r = sorted([int(x) for x in input().split()], reverse=True)[:X + Y]

s = sorted(p + q + r, reverse=True)

ans = sum(s[:X + Y])

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque

X, Y, A, B, C = [int(x) for x in input().split()]
p = deque(sorted([int(x) for x in input().split()]))
q = deque(sorted([int(x) for x in input().split()]))
r = deque(sorted([int(x) for x in input().split()]))

ans = 0
for i in range(X):
    if p[0] >= r[0]:
        ans += p.popleft()
    else:
        ans += r.popleft()

for i in range(Y):
    if q[0] >= r[0]:
        ans += q.popleft()
    else:
        ans += r.popleft()

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque

def merge(s, t):
    u = []

    while s + t:
        
        if s == [] or t == []:
            return u + s + t

        if s[0] >= t[0]:
            u.append(s[0])
            s = s[1:]
        else: # s0 > t0
            u.append(t[0])
            t = t[1:]

    return u

def merge_sort(A):
    while len(A) > 1:
        B = []
        for _ in range(len(A) // 2):
            B.append(merge(A[0], A[1]))
            A = A[2:]
        B += A
        A = B

    return(A[0])

X, Y, A, B, C = [int(x) for x in input().split()]
p = deque(merge_sort([[int(x)] for x in input().split()]))
q = deque(merge_sort([[int(x)] for x in input().split()]))
r = deque(merge_sort([[int(x)] for x in input().split()]))

ans = 0
for i in range(X):
    if p[0] >= r[0]:
        ans += p.popleft()
    else:
        ans += r.popleft()

for i in range(Y):
    if q[0] >= r[0]:
        ans += q.popleft()
    else:
        ans += r.popleft()

print(ans)
Problem p02761 (python)

Fixed submission:
N, M = [int(x) for x in input().split()]

cond = [None for _ in range(N + 1)]
ok = True
for i in range(M):
    s, c = [int(x) for x in input().split()]
    if cond[s] == None:
        cond[s] = c
    else:
        if cond[s] != c:
            ok = False
            break

if cond[1] == None:
    if N == 1:
        cond[1] = 0
    else:
        cond[1] = 1
else:
    if cond[1] == 0:
        if N != 1:
            ok = False

for i in range(2, N + 1):
    if cond[i] == None:
        cond[i] = 0

if ok == True:
    for i in range(1, N + 1):
        print(cond[i], end='')
    print('')
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
S = input()
Q = int(input())

c2 = 0
query = []
for i in range(Q):
    q = [x for x in input().split()]
    T = int(q[0])
    if T == 1:
        query.append([T])
    else: # T == 2
        F, C = int(q[1]), q[2]
        query.append([T, F, C])
        c2 += 1

while len(query) > c2 + 1:
    print(query)
    T1 = query[i][0]
    if T1 == 1:
        T2 = query[i + 1][0]
        if T2 == 1:
            query = query[:i] + query[i + 2:]
        if T2 == 2:
            F, C = query[i + 1][1], query[i + 1][2]
            if F == 1:
                query[i] = [2, 2, C]
                query[i + 1] = [1]
            else: # F == 2
                query[i] = [2, 1, C]
                query[i + 1] = [1]

M = c2 + 1
for i in range(M):
    T = query[i][0]
    if T == 1:
        L = len(S)
        S = S[L - 1::-1]
    else: # T == 2
        F, C = query[i][1], query[i][2]
        if F == 1:
            S = C + S
        else: # F == 2
            S = S + C

print(S)
Problem p02802 (python)

Fixed submission:
N, M = [int(x) for x in input().split()]

P = [0] * (N + 1)           #各問題のペナルティの回数を記録
ok = [False] * (N + 1)      #その問題でACが出たかどうか記録

correct = 0                 #正答数を記録
penalty = 0                 #ペナルティ数を記録
for i in range(M):
    query = input().split()
    p = int(query[0])
    S = query[1]
    if ok[p] == False:
        if S == 'AC':
            ok[p] = True
            correct += 1
            penalty += P[p]
        else: # S = 'WA'
            P[p] += 1

print(correct, end=' ')
print(penalty)

Buggy submission (verdict: Runtime Error):
N, M = [int(x) for x in input().split()]

P = [0] * (N + 1)
correct = 0
ok = [False] * (N + 1)
for i in range(M):
    query = input().split()
    p = int(query[0])
    S = query[1]
    if ok[p] == False:
        if S == 'AC':
            ok[p] = True
            correct += 1
        else: # S = 'WA'
            P[p] += 1

penalty = 0
for i in range(N):
    if ok[p] == True:
        penalty += P[p]

print(correct, end=' ')
print(penalty)
Problem p02803 (python)

Fixed submission:
from collections import deque

H, W = [int(x) for x in input().split()]

field = []
for i in range(H):
    field.append(input())

conn = [[[] for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if field[i][j] == '.':
            for e in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
                h, w = i + e[0], j + e[1]
                if 0 <= h < H and 0 <= w < W and field[h][w] == '.':
                    conn[i][j].append([h, w])
d = 0
for i in range(H):
    for j in range(W):
        l = 0
        q = deque([[i, j]])
        dist = [[-1 for _ in range(W)] for _ in range(H)]
        dist[i][j] = 0
        while q:
            v = q.popleft()
            for w in conn[v[0]][v[1]]:
                if dist[w[0]][w[1]] == -1:
                    q.append(w)
                    dist[w[0]][w[1]] = dist[v[0]][v[1]] + 1
                    l = dist[w[0]][w[1]]

        d = max(d, l)

print(d)

Buggy submission (verdict: Runtime Error):
from collections import deque
 
H, W = [int(x) for x in input().split()]
 
field = []
for i in range(H):
    field.append(input())
 
conn = [[[] for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if field[i][j] == '.':
            for e in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
                h, w = i + e[0], j + e[1]
                if 0 <= h < H and 0 <= w < W and field[h][w] == '.':
                    conn[i][j].append([h, w])
d = 0
for i in range(H):
    for j in range(W):
        l = 0
        q = deque([[i, j]])
        dist = [[-1 for _ in range(W)] for _ in range(H)]
        dist[i][j] = 0
        while q:
            v = q.popleft()
            for w in conn[v[0]][v[1]]:
                if dist[w[0]][w[1]] == -1:
                    q.append(w)
                    dist[w[0]][w[1]] = dist[v[0]][v[1]] + 1
                    l = dist[w[0]][w[1]]
 
    	d = max(d, l)
 
print(d)

Buggy submission (verdict: Runtime Error):
from collections import deque

H, W = [int(x) for x in input().split()]

field = []
for i in range(H):
    field.append(input())

conn = [[[] for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if field[i][j] == '.':
            for e in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
                h, w = i + e[0], j + e[1]
                if 0 <= h < H and 0 <= w < W and field[h][w] == '.':
                    conn[i][j].append([h, w])
d = 0
for i in range(H):
    for j in range(W):
        if field[i][j] == '.':
            l = 0
            q = deque([[i, j]])
            dist = [[-1 for _ in range(W)] for _ in range(H)]
            dist[i][j] = 0
            while q:
                v = q.popleft()
                for w in conn[v[0]][v[1]]:
                    if dist[w[0]][w[1]] == -1:
                        q.append(w)
                        dist[w[0]][w[1]] = dist[v[0]][v[1]] + 1
                        l = dist[w[0]][w[1]]

        d = max(d, l)

print(d)
Problem p03071 (python)

Fixed submission:
A,B=(int(x) for x in input().split())
if A > B:
    print(2 * A - 1)
elif A < B:
    print(2 * B - 1)
else:
    print(2 * A)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if A > B:
    print(2 * A - 1)
elif A < B:
    print(2 * B - 1)
else:
    print(2 * A)
Problem p02921 (python)

Fixed submission:
# -*- coding: utf-8 -*-
y = input()
t = input()
ylist = list(y)
tlist = list(t)
seikai = 0
for i in range(3):
  if ylist[i] == tlist[i]:
    seikai += 1
    
print(seikai)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n = int(input())
nt = []
for i in range(n):
  tmp = input().split()
  for j in range(n-1):
    tmp[j] = int(tmp[j])
  nt.append(tmp)

day = 0
j = []
for i in range(n):
  j.append(0)
  
while(True):
  #print(j)
  tmp = []
  for i in range(n):
    if j[i] < n-1 and nt[nt[i][j[i]]-1][j[nt[i][ j[i] ]-1]] == i+1:
      tmp.append(i)
  #print(tmp)
  if len(tmp) == 0:
    break
  for i in tmp:
    j[i] += 1
  day += 1
  
error = 0
for i in range(n):
  if j[i] != n-1:
    day = -1

print(day)
Problem p02922 (python)

Fixed submission:
a, b = map(int, input().split())
print(((b - 1) + (a - 2)) // (a - 1))

Buggy submission (verdict: Runtime Error):
a, b = int(input().split())
s = a - 1
t = b-1
asn = (s + t -1) // s

Buggy submission (verdict: Runtime Error):
S, T = input().split()
print(S + T -1) // S

Buggy submission (verdict: Runtime Error):
n = list(map(int, input().split(' '))
print(-(-n[1] + 1) // (n[0] -1))
Problem p02923 (python)

Fixed submission:
n=int(input())
h=[int(i) for i in input().split()]
c=0
d=c
for i in range(n-1):
    if h[i]>=h[i+1]:
        c+=1
    else:
        d=max([c,d])
        c=0

print(max([c,d]))

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = list(map(int, input.split('')))
count = 0
count2 = count
for i in range(n-1):
  if nums[i] >= nums[i+1]:
    count += 1
  else:
    count2 = max([count, count2])
    count = 0
print(max([count, count2]))

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = list(map(int, input.split('')))
count = 0
count2 = count
for i in range(n):
  if nums[i] >= nums[i+1]:
    count += 1
  else:
    count2 = max([count, count2])
    count = 0
print(max([count, count2]))

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = list(map(int, input().split(' ')))
count = []
for i in range(n):
  if num[i] > num[i+1]:
    count.append(1)
print(len(count))
Problem p02621 (python)

Fixed submission:
a = int(input())
print(a + a**2 + a**3)

Buggy submission (verdict: Runtime Error):
n = int(input())
print(a + a**2 + a**3)
Problem p02555 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000000)
S = int(input())

mod = 10**9+7

def dfs_memo(n):
    memo = [0]*(n+1)
    memo[3] = 1

    def dfs(n):
        if n < 3:
            return 0
        if memo[n] != 0:
            return memo[n]
        memo[n] = dfs(n-1)+dfs(n-3)
        return memo[n]
    return dfs(n)

if S <3:
    print(0)
else:
    print(dfs_memo(S)%mod)

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

mod = 10**9+7

def dfs_memo(n):
    memo = [0]*(n+1)
    memo[3] = 1

    def dfs(n):
        if n < 3:
            return 0
        elif memo[n] != 0:
            return memo[n]
        memo[n] = dfs(n-1)+dfs(n-3)
        return memo[n]
    return dfs(n)

if S <3:
    print(0)
else:
    print(dfs_memo(S)%mod)