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

Fixed submission:
a = int(input())
if a==1:
  print("Hello World")
else:
  A = int(input())
  B = int(input())
  print(A+B)

Buggy submission (verdict: Runtime Error):
N = int(input())
A,B = map(int,input().split())
if N % 2 == 0:
  print(A+B)
else:
  print("Hello World")
Problem p03239 (python)

Fixed submission:
n,t=map(int,input().split())
l=[]
for i in range(n):
    c,time=map(int,input().split())
    if time<=t:
        l.append(c)
print(min(l) if l!=[] else "TLE")

Buggy submission (verdict: Runtime Error):
n,t=map(int,input().split())
l=[]
for i in range(n):
    c,time=map(int,input().split())
    if time>=t:
        l.append(c)
print(min(l))
Problem p03261 (python)

Fixed submission:
import sys
n=int(input())
w=input()
l=[]
l.append(w)
for i in range(1,n):
    w=input()
    if w[0]!=l[-1][-1] or w in l:
        print("No")
        sys.exit()
    else:
        l.append(w)
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
n=input()
w=input()
l=[]
l.append(w)
for i in range(1,n):
    w=input()
    if w[0]!=l[-1][-1] or w in l:
        print("No")
        sys.exit()
    else:
        l.append(w)
print("Yes")
Problem p03264 (python)

Fixed submission:
k=int(input())
print((k//2)**2 if k%2==0 else(k//2)*(k+1)//2)

Buggy submission (verdict: Runtime Error):
k=int(input())
print(k//2*//2 if k%2==0 else k//2*(k+1)//2)
Problem p03282 (python)

Fixed submission:
s=input()
k=int(input())-1
if s.count("1")==len(s):
    t=k
    print(1)
else:
    i=0
    while s[i]=="1":
        i+=1
    if k<i:
        print(1)
    else:
        print(s[i])

Buggy submission (verdict: Runtime Error):
s=input()
input()
if s.count("1")==len(s):
    print(1)
else:
    i=0
    while s[i]!="1":
        i+=1
    print(s[i])

Buggy submission (verdict: Runtime Error):
s=input()
if s.count("1")==len(s):
    print(1)
else:
    i=0
    while s[i]!="1":
        i+=1
    print(s[i])

Buggy submission (verdict: Runtime Error):
s=input()
input()
i=0
while s[i]=="1":
    i+=1
    if i==len(s)-1:
        break
print(s[i])

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
i=0
while s[i]=="1":
    i+=1
print(s[i])
Problem p03323 (python)

Fixed submission:
a,b=map(int,input().split())
if a<=8 and b<=8:
  print("Yay!")
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
a,b=map(int,input(),split())
if a<=8 and b<=8:
  print("Yay!")
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
a,b =map(int,input(),split())
if a<=8 or b<=8:
  print("Yay!")
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
a,b =int(input(),split())
if a<=8 or b<=8:
  print("Yay!")
else:
  print(":(")
Problem p03379 (python)

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
l=sorted(x)
m1=l[n//2-1]
m2=l[n//2]
for i in range(n):
    if x[i]<=m1:
        print(m2)
    else:
        print(m1)

Buggy submission (verdict: Runtime Error):
n=int(input())
p=n//2
l=list(map(int,input().split()))
for i in range(n):
    m=l
    m.pop(i)
    m.sort()
    print(m[p-1])
Problem p03555 (python)

Fixed submission:
a = input()
b = input()
if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
a,b,c=map(str,input().split())
d,e,f=map(str,input().split())
if (a==f and b==e and c==d):
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
if a[0]=b[2] and a[1]=b[1] and a[2]=b[0]:
  print("YES")
else:
  print("NO")
Problem p03731 (python)

Fixed submission:
n,t=map(int,input().split())
l=list(map(int,input().split()))
ans=0
for i in range(1,n):
    ans+=min(t,l[i]-l[i-1])
print(ans+t)

Buggy submission (verdict: Runtime Error):
n,t=map(int,input().split())
l=list(map(int,input().split()))
time=t
m=[0]
i=1
if len(l)==1:
    print(t)
else:
    while True:
        if l[i]-(time-m[-1])<0:
            time=time-(l[i]-(time-m[1]))+t
        else:
            m.append(time)
            time=t
        if i==n-1:
            break
        i+=1
    print(time if len(m)==1 else sum(m)+time)
Problem p03998 (python)

Fixed submission:
import sys
a=input()
b=input()
c=input()
turn=0
ap=0
bp=0
cp=0
while True:
    if turn==0:
        ap+=1
        if ap==len(a)+1:
            print("A")
            sys.exit()
        if a[ap-1]=="a":
            turn=0
        elif a[ap-1]=="b":
            turn=1
        else:
            turn=2
    if turn==1:
        bp+=1
        if bp==len(b)+1:
            print("B")
            sys.exit()
        if b[bp-1]=="a":
            turn=0
        elif b[bp-1]=="b":
            turn=1
        else:
            turn=2
    if turn==2:
        cp+=1
        if cp==len(c)+1:
            print("C")
            sys.exit()
        if c[cp-1]=="a":
            turn=0
        elif c[cp-1]=="b":
            turn=1
        else:
            turn=2

Buggy submission (verdict: Runtime Error):
l=[]
for i in range(3):
    l.append(input())
turn=0
next_turn=0
while True:
    s=l[turn][0]
    l[turn]=l[turn][1:]
    if s=="a":
        turn=0
    elif s=="b":
        turn=1
    else:
        turn=2
    if l[0]=="":
        print("A")
        break
    elif l[1]=="":
        print("B")
    elif l[2]=="":
        print("C")
Problem p04019 (python)

Fixed submission:
s=input()
if "N" in s and "S" in s and "W" in s and "E" in s:
    print("Yes")
elif "N" in s and "S" in s:
    print("No" if "W" in s or "E" in s else "Yes")
elif "W" in s and "E" in s:
    print("No" if "N" in s or "S" in s else "Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s=input()s=input()
if "N" in s and "S" in s and "W" in s and "E" in s:
    print("Yes")
elif "N" in s and "S" in s:
    print("Yes" if "W" in s or "E" in s else "No")
else:
    print("Yes" if "N" in s or "S" in s else "No")
Problem p04030 (python)

Fixed submission:
s=""
for c in input():
    s=s[:-1] if c=="B" else s+c
print(s)

Buggy submission (verdict: Runtime Error):
s=input()
ans=[]
for c in s:
    if c=="0" or c=="1":
        ans.append(c)
    else:
        ans.pop(-1)
print("".join(ans))s=input()
ans=[]
for c in s:
    if c=="0" or c=="1":
        ans.append(c)
    else:
        if len(ans)>0:
            ans.pop(-1)
print("".join(ans))

Buggy submission (verdict: Runtime Error):
s=input()
ans=[]
for c in s:
    if c=="0" or c=="1":
        ans.append(c)
    else:
        ans.pop(-1)
print("".join(ans))
Problem p04047 (python)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
i=0
while i<n*2-1:
    ans+=l[i]
    i+=2
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(0,n/2,2):
    ans+=l[i]
print(ans)n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range([0,]n[,2]):
    ans+=l[i]
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(0,n/2,2):
    ans+=l[i]
print(ans)
Problem p02602 (python)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))

#hyouten = []


for i in range(n-k+1):

    
    if i>0:
        score_old = a[i-1]
        score = a[i+k-1]
#        print(score_old,score)
        if score >score_old:
            print("Yes")
        else:
            print("No")

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))

hyouten = []


for i in range(n-k+1):

    
    if i>0:
        score_old = a[i-1]
        score = a[i+k-1]
#        print(score_old,score)
        if score >score_old:
            print("Yes")
        else:
            print("No")
    hyouten.append(score)
Problem p02603 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))

yen = 1000

kabu = 0

for i in range(n-1):
    if a[i] < a[i+1]:
        kabu_today = yen // a[i]
        kabu += kabu_today
        yen = yen % a[i]
        
    else:
        yen += kabu * a[i]
        kabu = 0
    
#    print(yen, kabu,a[i], a[i] < a[i+1])

yen += kabu * a[n-1]
kabu = 0

print(yen)

Buggy submission (verdict: Runtime Error):
n = int(input(n))
a = list(map(int,input().split()))

yen = 1000

kabu = 0

for i in range(n-1):
    if a[i] < a[i+1]:
        kabu_today = yen // a[i]
        kabu += kabu_today
        yen = yen % a[i]
        
    else:
        yen += kabu * a[i]
        kabu = 0
    
#    print(yen, kabu,a[i], a[i] < a[i+1])

yen += kabu * a[n-1]
kabu = 0

print(yen)
Problem p02585 (python)

Fixed submission:
N, K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = -float("inf")
for i in range(N):
    hoge = []
    p = i
    s = 0
    for j in range(K):
        p = P[p]-1
        s += C[p]
        hoge.append(s)
        ans = max(ans,s)
        if p == i:
            s *= (K-1)//len(hoge)
            s += max(hoge[0:(K-1)%len(hoge)+1])
            ans = max(ans,s)
            break
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = -float("inf")
for i in range(N):
    hoge = []
    p = i
    s = 0
    for j in range(K):
        p = P[p]-1
        s += C[p]
        hoge.append(s)
        ans = max(ans,s)
        if p == i:
            S = s*((K-1)//len(hoge)) + max(hoge[:(K-1)%len(hoge)])
            if (K-1)//len(hoge) > 0:
                S = max(S,s*((K-1)//len(hoge))-1) + max(hoge)
            ans = max(ans,S)
            break
print(ans)
Problem p02586 (python)

Fixed submission:
R, C, K = map(int,input().split())
V = [[]for i in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    V[r-1].append([c,v])
cost = [0]*(C+1)
for r in range(R):
    V[r].sort()
    hoge = [0,0,0,0]
    for c,v in V[r]:
        for i in range(3,0,-1):
            hoge[i] = max(cost[c]+v,hoge[i-1]+v,hoge[i])
        hoge[0] = cost[c]
        cost[c] = max(hoge)
    for i in range(1,C+1):
        cost[i] = max(cost[i],cost[i-1])

print(cost[-1])

Buggy submission (verdict: Runtime Error):
R, C, K = map(int,input().split())
V = [[]for i in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    V[r-1].append([c,v])
cost = [0]*C
for r in range(R):
    V[r].sort()
    hoge = [0,0,0,0]
    for c,v in V[r]:
        for i in range(3,-1,-1):
            hoge[i] = max(cost[c],hoge[i-1])
            hoge[i] += v
        hoge[0] -= v
        cost[c] = max(hoge)
    for i in range(1,C):
        cost[i] = max(cost[i],cost[i-1])

print(cost[-1][-1])
Problem p02609 (python)

Fixed submission:
def func(N):
    return N%bin(N).count("1")

N = int(input())
X = input()

popcount = X.count("1")
X_num = int(X,2)

O = X_num%(popcount+1)
if popcount==1:
    I = 0
else:
    I = X_num%(popcount-1)

bO = 1
bI = 1

ans= []
for i in range(N):
    if X[-1-i]=="0":
        hoge = (O + bO)%(popcount+1)
    else:
        if popcount==1:
            ans.append(0)
            continue
        hoge = (I - bI)%(popcount-1)
    count = 1
    while hoge:
        hoge = func(hoge)
        count += 1
    ans.append(count)
    bO = (bO*2)%(popcount+1)
    if popcount != 1:
        bI = (bI*2)%(popcount-1)

for i in range(N):
    print(ans[-1-i])

Buggy submission (verdict: Runtime Error):
def func(N):
    return N%bin(N).count("1")

N = int(input())
X = input()

popcount = X.count("1")
X_num = int(X,2)
bi = 2**(N-1)


for i in range(N):
    if(X[i] == "0"):
        hoge = X_num+bi
        I_count = popcount + 1
    else:
        hoge = X_num-bi
        I_count = popcount - 1
    count = 1
    hoge = hoge%I_count
    while hoge != 0:
        hoge = func(hoge)
        count += 1
    print(count)
    bi >>= 1
Problem p02686 (python)

Fixed submission:
N = int(input())
S = list(input() for _ in range(N))
X = []
for s in S:
    l,r = 0,0
    for c in s:
        if c == ")":
            if r > 0:
                r -= 1
            else:
                l += 1
        else:
            r += 1
    X.append([l,r])
X.sort(key = lambda x:x[0])
Y = []
L = 0
for p,q in X:
    if p > L:
        print("No")
        quit()
    if q >= p:
        L -= p
        L += q
    else:
        Y.append([p,q])
Y.sort(key = lambda x:-x[1])
for a,b in Y:
    if a > L:
        print("No")
        quit()
    L -= a
    L += b
if L:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(input() for _ in range(N))
X = []
for s in S:
    l,r = 0,0
    for c in s:
        if c == ")":
            if r > 0:
                r -= 1
            else:
                l += 1
        else:
            r += 1
    X.append([l,r])
X.sort(key = lambda x:(x[0],-x[1]))
Y = 0
for a,b in X:
    if a > Y:
        print(1/0)
        quit()
    Y -= a
    Y += b

if Y:
    print(1/0)
else:
    print("Yes")
Problem p02782 (python)

Fixed submission:
MOD = 10**9+7
r1,c1,r2,c2 = map(int,input().split())

size = 1010000*2
f_list = [1]*(size)
for i in range(1,size):
    f_list[i] = (f_list[i-1]*i)%MOD

def func(r,c):
    return (f_list[r+c]*pow(f_list[r],MOD-2,MOD)*pow(f_list[c],MOD-2,MOD))

ans = func(r2+1,c2+1)-1
ans += func(r1,c1)-1
ans -= func(r2+1,c1)-1
ans -= func(r1,c2+1)-1
print(ans%MOD)

Buggy submission (verdict: Runtime Error):
MOD = 10**9+7
r1,c1,r2,c2 = map(int,input().split())

size = 101000*2
f_list = [1]*(size)
for i in range(1,size):
    f_list[i] = (f_list[i-1]*i)%MOD

def func(r,c):
    return (f_list[r+c]*pow(f_list[r],MOD-2,MOD)*pow(f_list[c],MOD-2,MOD))

ans = func(r2+1,c2+1)-1
ans += func(r1,c1)-1
ans -= func(r2+1,c1)-1
ans -= func(r1,c2+1)-1
print(ans%MOD)
Problem p02787 (python)

Fixed submission:
H,N = map(int,input().split())
magic = list(list(map(int,input().split()))for i in range(N))

DP = [10**9]*(H+1)
DP[0] = 0
for a,b in magic:
    for i in range(min(a,H+1)):
        DP[i] = min(DP[i],b)
    for i in range(a,H+1):
        DP[i] = min(DP[i],DP[i-a]+b)
print(DP[-1])

Buggy submission (verdict: Runtime Error):
H,N = map(int,input().split())
magic = list(list(map(int,input().split()))for i in range(N))

DP = [10**9]*(H+1)
DP[0] = 0
for a,b in magic:
    for i in range(a):
        DP[i] = min(DP[i],b)
    for i in range(a,H+1):
        DP[i] = min(DP[i],DP[i-a]+b)
print(DP[-1])

Buggy submission (verdict: Runtime Error):
H,N = map(int,input().split())
magic = list(list(map(int,input().split()))for i in range(N))

DP = [10**9]*(H+1)
DP[0] = 0
for a,b in magic:
    for i in range(a):
        DP[i] = min(DP[i],b)
    for i in range(b,H+1):
        DP[i] = min(DP[i],DP[i-a]+b)
print(DP[-1])
Problem p02798 (python)

Fixed submission:
import bisect
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 10**9+7
for i in range(2**N):
    card = [[],[]]
    num = []
    iii = i
    for j in range(N):
        if i&1:
            num.append(B[j])
            card[(j+1)%2].append(j)
        else:
            num.append(A[j])
            card[(j)%2].append(j)
        i >>= 1
    if len(card[1]) != N//2:
        continue
    card[0].sort(key=lambda x:[num[x],x])
    card[1].sort(key=lambda x:[num[x],x])
    hoge = []
    for i in range(N):
        hoge.append(card[i%2][i//2])
    flag = True
    for i in range(N-1):
        if num[hoge[i]] > num[hoge[i+1]]:
            flag = False
    if flag:
        huga = []
        count = 0
        for i in range(N):
            l = bisect.bisect_left(huga,hoge[i])
            huga.insert(l,hoge[i])
            count += i-l
        if count < ans:
            ans = count
if ans >= 10**9:
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 10**9+7
for i in range(2**N):
    card = [[],[]]
    num = []
    x = i
    for j in range(N):
        if i&1:
            num.append(B[j])
            card[(j+1)%2].append(j)
        else:
            num.append(A[j])
            card[(j)%2].append(j)
        i >>= 1
    if len(card[1]) != N//2:
        continue
    card[0].sort(key=lambda x:[num[x],x]);card[1].sort(key=lambda x:[num[x],x])
    hoge = []
    for i in range(N):
        hoge.append(card[i%2][i//2])
    flag = True
    for i in range(N-1):
        if num[hoge[i]] > num[hoge[i+1]]:
            flag = False
    if flag:
        huga = sum(abs(hoge[i]-i)for i in range(N))
        if huga % 2:
            print(1/0)
        else:
            huge //= 2
        if huga < ans:
            ans = huga
if ans >= 10**9:
    print(-1)
else:
    print(ans)
Problem p02814 (python)

Fixed submission:
def GCD(x,y):
    if y==0:
        return x
    return GCD(y,x%y)
def LCM(x,y):
    return x*y // GCD(x,y)
N, M = map(int,input().split())
A = list(map(int,input().split()))
ans = 1
for i in A:
    i //= 2
    ans = LCM(ans,i)
    if (ans//i)%2 == 0:
        print(0)
        exit()
    if ans > M:
        print(0)
        exit()
print(M//ans-M//(ans*2))

Buggy submission (verdict: Runtime Error):
_,A = input(),list(map(int,input().split()))
for i in A:
  if i%2 == 1:
    print(2/0)
print("unrated")

Buggy submission (verdict: Runtime Error):
def GCD(x,y):
    if y==0:
        return x
    return GCD(y,x%y)


N, M = map(int,input().split())
A = list(map(int,input().split()))
ans = 1
for i in A:
    ans = (ans*(i//2))//GCD(ans,i)
    if ans%2 == 0:
        ans = 0
print(M//ans-M//(ans*2))
Problem p02825 (python)

Fixed submission:
def GCD(x,y):
    if y == 0:
        return x
    else:
        return GCD(y,x%y)


N = int(input())
if N == 2:
    print(-1)
    exit()
if N == 7:
    ans = [".aaggcc",
           "c..ddee",
           "c..ffgg",
           "hij....",
           "hij....",
           "klm....",
           "klm...."]
    for i in ans:
        print("".join(i))
    exit()
if N == 3:
    print(".aa")
    print("a..")
    print("a..")
    exit()

four = ["aacd",
        "bbcd",
        "efgg",
        "efhh"]
five = ["aabbc",
        "h.iic",
        "hj..d",
        "gj..d",
        "gffee"]
six = ["aacd..",
       "bbcd..",
       "ef..gg",
       "ef..hh",
       "..iikl",
       "..jjkl"]
ans = [list("."*N) for i in range(N)]
a,b,c = [[0,N//5,0],[0,N//5-1,1],[0,N//5-2,2],[2,N//5-1,0],[1,N//5,0]][N%5]
p = 0
for i in range(a):
    for x in range(4):
        for y in range(4):
            ans[p+x][p+y] = four[x][y]
    p += 4

for i in range(b):
    for x in range(5):
        for y in range(5):
            ans[p+x][p+y] = five[x][y]
    p += 5

for i in range(c):
    for x in range(6):
        for y in range(6):
            ans[p+x][p+y] = six[x][y]
    p += 6
for i in ans:
    print("".join(i))

Buggy submission (verdict: Runtime Error):
def GCD(x,y):
    if y == 0:
        return x
    else:
        return GCD(y,x%y)


N = int(input())
if N == 2:
    print(-1)
    exit()
if N == 7:
    print(1/0)
if N == 3:
    print(".aa")
    print("a..")
    print("a..")
    exit()

four = ["aacd",
        "bbcd",
        "efgg",
        "efhh"]
five = ["aabbc",
        "h.iic",
        "hj..d",
        "gj..d",
        "gffee"]
six = ["aacd..",
       "bbcd..",
       "ef..gg",
       "ef..hh",
       "..iikl",
       "..jjkl"]
ans = [list("."*N) for i in range(N)]
a,b,c = [[0,N//5,0],[0,N//5-1,1],[0,N//5-2,2],[2,N//5-1,0],[1,N//5,0]][N%5]
p = 0
for i in range(a):
    for x in range(4):
        for y in range(4):
            ans[p+x][p+y] = four[x][y]
    p += 4

for i in range(b):
    for x in range(5):
        for y in range(5):
            ans[p+x][p+y] = five[x][y]
    p += 5

for i in range(c):
    for x in range(6):
        for y in range(6):
            ans[p+x][p+y] = six[x][y]
    p += 6
for i in ans:
    print("".join(i))

Buggy submission (verdict: Runtime Error):
def GCD(x,y):
    if y == 0:
        return x
    else:
        return GCD(y,x%y)



N = int(input())
if N == 2:
    print(-1)
    exit()
if N%3 != 0:
    print(1/0)
    exit()
ans = [list("."*N) for i in range(N)]
for i in range((2*N*3//GCD(2*N,3))//6):
    ans[i][N-i*2-1] = 'a'
    ans[i][N-i*2-2] = 'a'
    ans[N-i*2-1][i] = 'a'
    ans[N-i*2-2][i] = 'a'

for i in ans:
    print("".join(i))

Buggy submission (verdict: Runtime Error):
N = int(input())
if N == 7:
  print(-1)
else:
  print(1/0)
Problem p02839 (python)

Fixed submission:
H,W = map(int,input().split())
A = [list(map(int,input().split()))for _ in range(H)]
for i in range(H):
    b = list(map(int,input().split()))
    for j in range(W):
        A[i][j] = abs(A[i][j]-b[j])
NUM = 6400
DP = [[[0]*NUM for i in range(W)]for j in range(H)]
DP[0][0][A[0][0]] = 1
i = 0
for j in range(W-1):
    a = A[i][j+1]
    for k in range(NUM):
        if DP[i][j][k] == 1:
            if 0 <= a-k < NUM:
                DP[i][j+1][a-k] = 1
            if 0 <= k-a < NUM:
                DP[i][j+1][k-a] = 1
            if 0 <= k+a < NUM:
                DP[i][j+1][k+a] = 1
j = 0
for i in range(H-1):
    a = A[i+1][j]
    for k in range(NUM):
        if DP[i][j][k] == 1:
            if 0 <= a-k < NUM:
                DP[i+1][j][a-k] = 1
            if 0 <= k-a < NUM:
                DP[i+1][j][k-a] = 1
            if 0 <= k+a < NUM:
                DP[i+1][j][k+a] = 1
for i in range(H-1):
    for j in range(W-1):
        a = A[i+1][j+1]
        for k in range(NUM):
            if DP[i+1][j][k] == 1:
                if 0 <= a-k < NUM:
                    DP[i+1][j+1][a-k] = 1
                if 0 <= k-a < NUM:
                    DP[i+1][j+1][k-a] = 1
                if 0 <= k+a < NUM:
                    DP[i+1][j+1][k+a] = 1
            if DP[i][j+1][k] == 1:
                if 0 <= a-k < NUM:
                    DP[i+1][j+1][a-k] = 1
                if 0 <= k-a < NUM:
                    DP[i+1][j+1][k-a] = 1
                if 0 <= k+a < NUM:
                    DP[i+1][j+1][k+a] = 1

print(DP[-1][-1].index(1))

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
A = [list(map(int,input().split()))for _ in range(H)]
for i in range(H):
    b = list(map(int,input().split()))
    for j in range(W):
        A[i][j] = abs(A[i][j]-b[j])
NUM = 10
DP = [[[0]*NUM for i in range(W)]for j in range(H)]
DP[0][0][A[0][0]] = 1
i = 0
for j in range(W-1):
    a = A[i][j+1]
    for k in range(NUM):
        if DP[i][j][k] == 1:
            if 0 <= a-k < NUM:
                DP[i][j+1][a-k] = 1
            if 0 <= k-a < NUM:
                DP[i][j+1][k-a] = 1
            if 0 <= k+a < NUM:
                DP[i][j+1][k+a] = 1
j = 0
for i in range(H-1):
    a = A[i+1][j]
    for k in range(NUM):
        if DP[i][j][k] == 1:
            if 0 <= a-k < NUM:
                DP[i+1][j][a-k] = 1
            if 0 <= k-a < NUM:
                DP[i+1][j][k-a] = 1
            if 0 <= k+a < NUM:
                DP[i+1][j][k+a] = 1
for i in range(H-1):
    for j in range(W-1):
        a = A[i+1][j+1]
        for k in range(NUM):
            if DP[i+1][j][k] == 1:
                if 0 <= a-k < NUM:
                    DP[i+1][j+1][a-k] = 1
                if 0 <= k-a < NUM:
                    DP[i+1][j+1][k-a] = 1
                if 0 <= k+a < NUM:
                    DP[i+1][j+1][k+a] = 1
            if DP[i][j+1][k] == 1:
                if 0 <= a-k < NUM:
                    DP[i+1][j+1][a-k] = 1
                if 0 <= k-a < NUM:
                    DP[i+1][j+1][k-a] = 1
                if 0 <= k+a < NUM:
                    DP[i+1][j+1][k+a] = 1

print(DP[-1][-1].index(1))
Problem p02845 (python)

Fixed submission:
MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7
RGB = [0]*3
ans = 1
for i in A:
    count = 0
    for j in RGB:
        if i == j:
            count += 1
    if count == 0:
        print(0)
        exit()
    RGB[RGB.index(i)] += 1
    ans = (ans * count)% MOD

print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7
RGB = [0]*3
ans = 1
for i in A:
    count = 0
    for j in RGB:
        if i == j:
            count += 1
    RGB[RGB.index(i)] += 1
    ans = (ans * count)% MOD

print(ans)