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

Fixed submission:
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c,x=map(int,input().split())
ans=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                ans+=1
print(ans)
Problem p03478 (python)

Fixed submission:
n,a,b=map(int,input().split())
ans=0
for i in range (1,n+1):
    result=sum(list(map(int,str(i))))
    if result>=a and result<=b:
        ans+=i
print(ans)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
n=0
for i in range (1,n+1):
    result=sum(list(map(int,str(i))))
    if result>=a and result<=b:
        ans+=i
print(ans)
Problem p03493 (python)

Fixed submission:
print(input().count('1'))

Buggy submission (verdict: Runtime Error):
N=int(input())
an=list(map(int,input().split()))
n=0
for i in range(N):
    if an[i]%2==0:
        an[i]//2
        n+=1
print(n)
Problem p03494 (python)

Fixed submission:
N=int(input())
an=list(map(int,input().split()))
n=0
while(all(a%2==0 for a in an)):
    an=[a//2 for a in an]
    n+=1
print(n)

Buggy submission (verdict: Runtime Error):
N=int(input())
an=list(map(int,input().split()))
n=0
for i in range(N):
    if an%2==0:
        n+=1
print(an/2)
Problem p02742 (python)

Fixed submission:
a,b = map(int,input().split())
num1 = (a//2)*(b//2)

if a == 1 or b==1:
    print(1)
else:
    
    # print(num1)
    p = b//2
    q = a//2
    num2 = (b - p )*(a - q)
    ans = num1+num2
    print(num1+num2)

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
num1 = (a//2)*(b//2)

if a == 1 :
    print(b)
else if b==1:
  	print(a)
else:
    
    # print(num1)
    p = b//2
    q = a//2
    num2 = (b - p )*(a - q)
    ans = num1+num2
    print(num1+num2)
Problem p02606 (python)

Fixed submission:
import math

L, R, d = map(int,input().split())

ans = 0

for i in range(L,R+1):
    if i % d == 0:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import math

def main():
    N = int(input())
    ans = [0]*(N+1)

    end = math.ceil(math.sqrt(N))

    for i in range(3,end+1):
        sn = i
        x = 1
        y = 1
        z = sn - 2
        zt = z
        if(cal(x,y,z) < N):
            ans[cal(x,y,z)] += func(x,y,z)
        while True:
            x = 1
            z = zt
            y += 1
            z -= 1
            zt = z
            if x > z or y > z:
                break
            if(cal(x,y,z) < N):
                ans[cal(x,y,z)] += func(x,y,z)
            for j in range(y - 1):
                if y < x + 1:
                    break
                x += 1
                z -= 1
                if x > z or y > z:
                    break
                if(cal(x,y,z) < N):
                    ans[cal(x,y,z)] += func(x,y,z)
    
    for i in range(1,N+1):
        print(ans[i])
        

def func(x,y,z):
    # print(x,y,z)
    if x == y and y == z and z == x:
        return 1
    elif x != y and y != z and z != x:
        return 6
    else:
        return 3

def cal(x,y,z):
    return x**2+y**2+z**2+x*y+y*z+z*x

main()

Buggy submission (verdict: Runtime Error):
import math

def main():
    N = int(input())
    ans = [0]*(N+1)

    end = N

    for i in range(3,end+1):
        sn = i
        x = 1
        y = 1
        z = sn - 2
        ans[cal(x,y,z)] += func(i,x,y,z)
        while z >= math.ceil(sn / 2):
            y += 1
            z -= 1
            if x > z or y > z:
                break
            ans[cal(x,y,z)] += func(i,x,y,z)
            for j in range(y):
                x += 1
                z -= 1
                if x > z or y > z:
                    break
                ans[cal(x,y,z)] += func(i,x,y,z)
    
    for i in range(1,N+1):
        print(ans[i])
        

def func(n,x,y,z):
    if x == y and y == z and z == x:
        return 1
    elif x != y and y != z and z != x:
        return 6
    else:
        return 3

def cal(x,y,z):
    return x**2+y**2+z**2+x*y+y*z+z*x

main()

Buggy submission (verdict: Runtime Error):
import math

def main():
    N = int(input())
    ans = [0]*(N+1)

    end = math.ceil(math.sqrt(N))

    for i in range(3,end+1):
        sn = i
        x = 1
        y = 1
        z = sn - 2
        ans[cal(x,y,z)] += func(i,x,y,z)
        while z >= math.ceil(sn / 2):
            y += 1
            z -= 1
            if x > z or y > z:
                break
            ans[cal(x,y,z)] += func(i,x,y,z)
            for j in range(y):
                x += 1
                z -= 1
                if x > z or y > z:
                    break
                ans[cal(x,y,z)] += func(i,x,y,z)
    
    for i in range(1,N+1):
        print(ans[i])
        

def func(n,x,y,z):
    if x == y and y == z and z == x:
        return 1
    elif x != y and y != z and z != x:
        return 6
    else:
        return 3

def cal(x,y,z):
    return x**2+y**2+z**2+x*y+y*z+z*x

main()
Problem p02608 (python)

Fixed submission:
import math

def main():
    N = int(input())
    ans = [0]*(N+1)

    rn = math.ceil(math.sqrt(N))

    for x in range(1,rn):
        for y in range(1,rn):
            for z in range(1,rn):
                k = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if k <= N:
                    ans[k-1] += 1
    
    for i in range(len(ans) - 1):
        print(ans[i])
    
main()

Buggy submission (verdict: Runtime Error):
import math

def main():
    N = int(input())
    ans = [0]*(N+1)

    end = N

    for i in range(3,end+1):
        sn = i
        x = 1
        y = 1
        z = sn - 2
        ans[cal(x,y,z)] += func(i,x,y,z)
        while z >= math.ceil(sn / 2):
            y += 1
            z -= 1
            if x > z or y > z:
                break
            ans[cal(x,y,z)] += func(i,x,y,z)
            for j in range(y):
                x += 1
                z -= 1
                if x > z or y > z:
                    break
                ans[cal(x,y,z)] += func(i,x,y,z)
    
    for i in range(1,N+1):
        print(ans[i])
        

def func(n,x,y,z):
    if x == y and y == z and z == x:
        return 1
    elif x != y and y != z and z != x:
        return 6
    else:
        return 3

def cal(x,y,z):
    return x**2+y**2+z**2+x*y+y*z+z*x

main()
Problem p02621 (python)

Fixed submission:

a = int(input())

print(a+a**2+a**3)

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

def solve():
    N, M, K = map(int, input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    sumA = 0
    sumB = 0

    tmp = 0

    dA = deque(A)
    dB = deque(B)

    dsA = deque()
    dsB = deque()

    while dA:
        tmp = dA.popleft()
        if sumA + tmp <= K:
            dsA.append(tmp)
            sumA += tmp
        else:
            break
    
    while dB:
        tmp = dB.popleft()
        if sumB + tmp <= K:
            dsB.append(tmp)
            sumB += tmp
        else:
            break

    sumall = sumA + sumB
    lenall = len(dsA) + len(dsB)
    Atmp = 0
    Btmp = 0

    while sumall > K:
        if Atmp == 0:
            Atmp = dsA.pop()
        if Btmp == 0:
            Btmp = dsB.pop()
        if Atmp >= Btmp:
            sumall -= Atmp
            lenall -= 1
            Atmp = 0
        else:
            sumall -= Btmp
            lenall -= 1
            Btmp = 0

    print(lenall)
                 
solve()
Problem p02630 (python)

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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    Q = int(input())
    BC = [list(map(int, input().split())) for _ in range(Q)]

    d = dict()

    # dictに格納 O(1)
    for a in A:
        try:
            d[a] += 1
        except KeyError:
            d[a] = 1
    
    ans = 100000000000000000000000000
    ans = 0

    # 一旦ans出す
    for dat in d.items():
        ans += dat[0]*dat[1]

    # B,Cの操作
    # for bc in BC:
    #     try:
    #         d[bc[1]] += d[bc[0]]
    #     except KeyError:
    #         try:
    #             d[bc[1]] = d[bc[0]]
    #         except KeyError:
    #             d[bc[0]] = 0
    #             d[bc[1]] = 0
    #     finally:
    #     # 増減分だけ変更
    #         ans += bc[1]*d[bc[0]] - bc[0]*d[bc[0]]
    #         d[bc[0]] = 0
    #     print(ans)

    # B,Cの操作
    for bc in BC:
        if bc[0] in d:
            if bc[1] in d:
                d[bc[1]] += d[bc[0]]
                ans += bc[1]*d[bc[0]] - bc[0]*d[bc[0]]
                d[bc[0]] = 0
            else:
                d[bc[1]] = d[bc[0]]
                ans += bc[1]*d[bc[0]] - bc[0]*d[bc[0]]
                d[bc[0]] = 0
        else:
            pass
        print(ans)



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline

def main():
    N = int(input())
    A = list(map(int,input().split()))
    Q = int(input())
    BC = [list(map(int, input().split())) for _ in range(Q)]

    d = dict()

    # dictに格納 O(1)
    for a in A:
        try:
            d[a] += 1
        except KeyError:
            d[a] = 1
    
    ans = 0

    # 一旦ans出す
    for dat in d.items():
        ans += dat[0]*dat[1]

    # B,Cの操作
    for bc in BC:
        try:
            d[bc[1]] += d[bc[0]]
        except KeyError:
            try:
                d[bc[1]] = d[bc[0]]
            except KeyError:
                d[bc[1]] = 0
        finally:
        # 増減分だけ変更
            ans += bc[1]*d[bc[0]] - bc[0]*d[bc[0]]
            d[bc[0]] = 0
        print(ans)

main()
Problem p02658 (python)

Fixed submission:
import math
import numpy as np

N = int(input())
A = list(map(int,input().split()))
ans = 1
A_log = A
try:
    A_log = list(map(math.log10,A))
except ValueError:
    print(0)
else:
    if sum(A_log) > 18:
        print(-1)
    else:
        for i in A:
            ans *= i
        if ans <= 1e18:
            print(ans)
        else:
            print(-1)

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

N = int(input())
A = list(map(int,input().split()))
ans = 1
A_log = list(map(math.log10,A))

if sum(A_log) >= 18:
    print(-1)
else:
    for i in A:
        ans *= i
    print(ans)
Problem p02663 (python)

Fixed submission:
import datetime

def main():
    H1, M1, H2, M2, K = map(int, input().split())

    start = H1*60 + M1
    sleep = H2*60 + M2

    print(abs(sleep - start - K))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    H1, M1, H2, M2, K = map(int, input().split())
    print( K * ( abs((sleep - 1)-start) // K) )


if __name__ == "__main__":
    main()
Problem p02684 (python)

Fixed submission:
import math

def solve():
    N, K = map(int,input().split())
    A = list(map(int, input().split()))

    state = 1
    chklist = [0] * (N + 1)
    chklist_flag = [False] * (N + 1)
 
    chkmod = 0
    chkrem = K

    chklist_flag[0] = True

    for i in range(1, K + 1):
        state = A[state - 1]
        if chklist_flag[state - 1]:
            chkmod = (K - chklist[state - 1]) % (i - chklist[state - 1]) 
            chkrem = chklist[state - 1]
            break
        chklist[state - 1] = i 
        chklist_flag[state - 1] = True
    
    state = 1

    for i in range(chkrem + chkmod):
        state = A[state - 1]
    
    print(state)

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import math

def solve():
    N, K = map(int,input().split())
    A = list(map(int, input().split()))

    state = 1
    chklist = [0] * (N + 1)
    chklist_flag = [False] * (N + 1)
    chkmod = 0

    chklist_flag[0] = True

    for i in range(1, K + 1):
        state = A[state - 1]
        if chklist_flag[state - 1]:
            chkmod = (K - chklist[state - 1]) % (i - chklist[state - 1]) 
            chkrem = chklist[state - 1]
            break
        chklist[state - 1] = i 
        chklist_flag[state - 1] = True
    
    state = 1

    for i in range(chkrem + chkmod):
        state = A[state - 1]
    
    print(state)

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import math

def solve():
    N, K = map(int,input().split())
    A = list(map(int, input().split()))

    state = 0
    chklist = [0] * N
    chklist_flag = [False] * N
    chkmod = 0

    chklist_flag[0] = True

    for i in range(1, K + 1):
        if chklist_flag[state - 1]:
            chkmod = (K - chklist[state - 1]) % (i - chklist[state - 1]) 
            break
        chklist[state - 1] = i 
        chklist_flag[state - 1] = True
        state = A[state]
        print(chklist_flag)

    for i in range(chklist[state - 1] + chkmod):
        chklist[state - 1] = i 
        state = A[state- 1]

    print(state)

if __name__ == "__main__":
    solve()
Problem p02553 (python)

Fixed submission:
a,b,c,d = map(int, input().split())

print( max( [a*c,a*d,b*c,b*d] ))

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int, input().split()

print(max( [a*c,a*d,b*c,b*d]  ))
Problem p02573 (python)

Fixed submission:
from collections import deque
N,M=map(int,input().strip().split())
l=list()
dp=[list() for _ in range(N)]
id=[-1 for _ in range(N)] #友人グループid 友人のいない者に-1をつける
for _ in range(M):
    a,b=map(int,input().strip().split())
    l.append((a,b))
    dp[a-1].append(b)
    dp[b-1].append(a)
    id[a-1]=0
    id[b-1]=0

i=1
c=[]
for n in range(1,N+1):
    cnt=0
    if id[n-1]==0:
        q=deque([n])
        while q:
            tmp=q.popleft()
            cnt+=1
            id[tmp-1]=i
            for e in dp[tmp-1]:
                if id[e-1]==0:
                    id[e-1]=i
                    q.append(e)
                else:
                    continue
        i+=1
        c.append(cnt)
    else:
        continue
if c:
    print(max(c))
else:
    print(1)

Buggy submission (verdict: Runtime Error):
from collections import deque
N,M=map(int,input().strip().split())
l=list()
dp=[list() for _ in range(N)]
id=[-1 for _ in range(N)] #友人グループid 友人のいない者に-1をつける
for _ in range(M):
    a,b=map(int,input().strip().split())
    l.append((a,b))
    dp[a-1].append(b)
    dp[b-1].append(a)
    id[a-1]=0
    id[b-1]=0

i=1
c=[]
for n in range(1,N+1):
    cnt=0
    if id[n-1]==0:
        q=deque([n])
        cnt+=1
        while q:
            tmp=q.popleft()
            id[tmp-1]=i
            for e in dp[tmp-1]:
                if id[e-1]==0:
                    id[e-1]=i
                    q.append(e)
                    cnt+=1
                else:
                    continue
        i+=1
        c.append(cnt)
    else:
        continue
print(max(c))
Problem p02642 (python)

Fixed submission:
def main():
    #input
    N=int(input())
    A=list(map(int,input().strip().split()))

    A.sort()

    l=[True for _ in range(A[-1]+1)]
    
    cnt=0
    for n in range(N-1):
        if l[A[n]]==True:
            if A[n]==A[n+1]:
                l[A[n]]=False
            else:
                l[A[n]]=False
                cnt+=1
            i=1
            while i*A[n]<=A[-1]:
                l[A[n]*i]=False
                i+=1
    if l[A[N-1]]==True:
        cnt+=1
        l[A[N-1]]=False
    return cnt

if __name__=="__main__":
    print(main())

Buggy submission (verdict: Runtime Error):
def main():
    #input
    N=int(input())
    A=list(map(int,input().strip().split()))

    A.sort()

    l=[True for _ in range(A[-1]+1)]
    
    cnt=0
    for n in range(N):
        if l[A[n]]==True:
            cnt+=1
            l[A[n]]=False
            i=2
            while i*A[n]<=A[-1]:
                l[A[n]*i]=False
                i+=1
    if A[0]==A[1]:
        cnt-=1
    return cnt
if __name__=="__main__":
    print(main())

Buggy submission (verdict: Runtime Error):
def main():
    #input
    N=int(input())
    A=list(map(int,input().strip().split()))

    A.sort()

    l=[True for _ in range(A[-1])]
    
    cnt=0
    for n in range(N):
        if l[A[n]-1]==True:
            cnt+=1
            l[A[n]-1]=False
            i=1
            while i*A[n]-1<=len(l)-1:
                l[A[n]*i-1]=False
                i+=1
    if A[0]==A[1]:
        cnt-=1
    return cnt
if __name__=="__main__":
    print(main())

Buggy submission (verdict: Runtime Error):
import math

def prime(x):
    if x==1:
        prime=True
        #この問題に合わせて１でもTrueとする
    else:
        prime=True
        for i in range(2,int(math.sqrt(x)+1)):
            if x%i==0:
                prime=False
                break
    return prime

def main():
    #input
    N=int(input())
    A=list(map(int,input().strip().split()))

    A.sort(reverse=True)
    
    #割り切れた場合+1
    cnt=0
    for i in range(N-1):
        #A[i]が素数または1の場合
        if prime(A[i]):
            #前後に同じ数がない場合、割り切れない
            if i<N-1:
                if A[i]==A[i+1]:
                    cnt+=1
            elif i>0:
                if A[i]==A[i-1]:
                    cnt+=1
        #A[i]が素数ではない場合
        else:
            for j in reversed(range(i+1,N)):
                if A[i]%A[j]==0:
                    cnt+=1
                    break
    if A[-1]%A[-2]==0:
        cnt+=1
    print(N-cnt)

if __name__=="__main__":
    main()

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

A.sort(reverse=True)

cnt=0
for i in range(N-1):
    for j in reversed(range(i+1,N)):
        if A[i]%A[j]==0:
            cnt+=1
            break
if A[-1]%A[-2]==0:
    cnt+=1
print(N-cnt)
Problem p02684 (python)

Fixed submission:
N,K=map(int,input().strip().split())
A=list(map(int,input().strip().split()))

l=[1]
x=1
cnt=[0 for n in range(N)]
cnt[0]=1
for n in range(N):
    y=A[x-1]
    l.append(y)
    cnt[y-1]+=1
    x=y
    if cnt[y-1]==2:
        value=y
        temp=n
        break

for m in range(len(l)):
    if l[m]==value:
        bias=m
        mul=temp-bias+1
        break
    
if bias>K:
    print(l[K])
else:
    print(l[bias+(K-bias)%mul])

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

l=[1]
x=1
for n in range(N):
    y=A[x-1]
    l.append(y)
    x=y

cnt=[0 for n in range(N)]
for n in range(N):
    cnt[l[n]-1]+=1
    if cnt[l[n]-1]==2:
        temp=n
        break
for m in range(len(l)):
    if l[m]==temp:
        bias=m
        mul=temp-bias+1
        break

if bias>K:
    print(l[K])
else:
    print(l[bias+(K-bias)%mul])

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

l=[1]
x=1
for n in range(N):
    y=A[x-1]
    l.append(y)
    x=y

x=[0 for n in range(N)]
for n in range(N):
    x[l[n]-1]+=1
    if x[l[n]-1]==2:
        temp=n
        break
for m in range(len(l)):
    if l[m]==temp:
        bias=m
        mul=temp-bias+1
        break

if bias>K:
    print(l[K])
else:
    print(l[bias+(K-bias)%mul])

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

l=[1]
x=1
for n in range(N):
    y=A[x-1]
    l.append(y)
    x=y

x=[0 for n in range(N)]
for n in range(N):
    x[l[n]-1]+=1
    if x[l[n]-1]==2:
        temp=n
        break
for m in range(len(l)):
    if l[m]==temp:
        bias=m
        mul=temp-bias+1
        break

if bias>K:
    print(l[K])
else:
    print(l[bias+(K-bias)%mul])
Problem p02714 (python)

Fixed submission:
N=int(input())
S=input()
R=[]
G=[]
B=[]

for n in range(N):
    if S[n]=="R":
        R.append(n)
    elif S[n]=="G":
        G.append(n)
    else:
        B.append(n)

ANS=len(R)*len(G)*len(B)

for i in range(N-2):
    for j in range(i+1,N-1):
        k=2*j-i
        if k<N and 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=input()
R=[]
G=[]
B=[]

def binary_search(A,n):
    find=False
    start=0
    end=len(A)
    if len(A)==1 and A[0]==n:
        find=True
    elif A[0]==n:
        find=True
    else:
        while find==False and start<end-1:
            middle=(start+end)//2
            if n>A[middle]:
                start=middle
            elif n<A[middle]:
                end=middle
            else:
                find=True
    return find

for n in range(N):
    if S[n]=="R":
        R.append(n)
    elif S[n]=="G":
        G.append(n)
    else:
        B.append(n)

EVERY=len(R)*len(G)*len(B)

REMOVE=0
for r in R:
    for g in G:
        if (r+g)%2==0:
            candidate=[2*r-g,(r+g)//2,2*g-r]
        else:
            candidate=[2*r-g,2*g-r]
        
        for e in candidate:
            if binary_search(B,e)==True:
                REMOVE+=1

print(EVERY-REMOVE)
Problem p03160 (python)

Fixed submission:
import sys
sys.setrecursionlimit(200000)

def dp_func(n,dp,h):
    if n==0:
        return 0
    elif n==1:
        return dp[1]
    
    else:
        if dp[n-1]==-1:
            dp[n-1]=dp_func(n-1,dp,h)

        c1=dp[n-1]+abs(h[n]-h[n-1])

        if dp[n-2]==-1:
            dp[n-2]=dp_func(n-2,dp,h)
            
        c2=dp[n-2]+abs(h[n]-h[n-2])
        
        dp[n]=min(c1,c2)
        return dp[n]

def main():
    #input
    N=int(input())
    h=list(map(int,input().strip().split()))
    # N=10000
    # h=[n**2 for n in range(N)]

    dp=[-1 for n in range(N)]
    dp[0]=0
    dp[1]=abs(h[1]-h[0])

    return dp_func(N-1,dp,h)

if __name__=="__main__":
    print(main())

Buggy submission (verdict: Runtime Error):
def dp_func(n,dp,h):
    dp[0]=0
    dp[1]=abs(h[1]-h[0])

    if n==0:
        return 0
    elif n==1:
        return dp[1]
    
    else:
        if dp[n-1]==-1:
            dp[n-1]=dp_func(n-1,dp,h)

        c1=dp[n-1]+abs(h[n]-h[n-1])

        if dp[n-2]==-1:
            dp[n-2]=dp_func(n-2,dp,h)
            
        c2=dp[n-2]+abs(h[n]-h[n-2])
        
        dp[n]=min(c1,c2)
        return dp[n]

def main():
    #input
    N=int(input())
    h=list(map(int,input().strip().split()))

    dp=[-1 for n in range(N)]

    return dp_func(N-1,dp,h)

if __name__=="__main__":
    print(main())

Buggy submission (verdict: Runtime Error):
def dp_func(n,dp,h):
    dp[0]=0
    dp[1]=abs(h[1]-h[0])

    if n==0:
        return 0
    elif n==1:
        return dp[1]
    
    else:
        if dp[n-1]==-1:
            dp[n-1]=dp_func(n-1,dp,h)

        c1=dp[n-1]+abs(h[n]-h[n-1])

        if dp[n-2]==-1:
            dp[n-2]=dp_func(n-2,dp,h)
            
        c2=dp[n-2]+abs(h[n]-h[n-2])
        return min(c1,c2)

def main():
    #input
    N=int(input())
    h=list(map(int,input().strip().split()))

    dp=[-1 for n in range(N)]

    return dp_func(N-1,dp,h)

if __name__=="__main__":
    print(main())

Buggy submission (verdict: Runtime Error):
def dp_func(n,dp,h):
    dp[0]=0
    dp[1]=abs(h[1]-h[0])

    if dp[n-1]==-1:
        dp[n-1]=dp_func(n-1,dp,h)

    c1=dp[n-1]+abs(h[n]-h[n-1])

    if dp[n-2]==-1:
        dp[n-2]=dp_func(n-2,dp,h)
        
    c2=dp[n-2]+abs(h[n]-h[n-2])

    return min(c1,c2)

def main():
    #input
    N=int(input())
    h=list(map(int,input().strip().split()))

    dp=[-1 for n in range(N)]

    return dp_func(N-1,dp,h)

if __name__=="__main__":
    print(main())
Problem p03262 (python)

Fixed submission:
N,X=map(int,input().strip().split())
x=list(map(int,input().strip().split()))
x.append(X)
x.sort()
    
d=[]
for n in range(1,N+1):
    d.append(x[n]-x[n-1])
    
def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    tmp=x%y
    if tmp==0:
        return y
    else:
        return gcd(y,tmp)
    
if len(d)<=1:
    print(d[0])
else:
    D=d[0]
    for i in range(1,len(d)):
        D=gcd(D,d[i])
    print(D)

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

x.sort()

d=[]
for n in range(1,N):
    d.append(x[n]-x[n-1])

def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    tmp=x%y
    if tmp==0:
        return y
    else:
        gcd(y,tmp)

if len(d)==0:
    print(abs(x[0]-X))
else:
    D=d[0]
    for i in range(1,len(d)):
        D=gcd(D,d[i])
    print(D)