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

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

if (a + b + c == 17) and (a * b * c == 5 * 5 * 7):
    print("YES")
else:
    print("NO")

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

if (a + b + c == 17) && (a * b * c == 5 * 5 * 7):
    print("YES")
else:
    print("NO")

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

if a + b + c == 17 && a * b * c == 5 * 5 * 7:
    print("YES")
else:
    print("NO")

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

if a + b + c == 17 && a * b * c == 5 * 5 * 7:
    print("YES")
else:
    print("NO")
Problem p02772 (python)

Fixed submission:
n = int(input())
A = [int(x) for x in input().split()]
flag = True
for i in range(0, n) :
	if A[i] % 2 != 0 :
		continue
	elif A[i] % 2 == 0 and (A[i]%3 == 0 or A[i]%5 == 0) :
		continue
	else :
		flag = False
		break
if flag :
	print ("APPROVED")
else :
	print ("DENIED")

Buggy submission (verdict: Runtime Error):
n = int(input())
A = []
for i in range(0, n) :
	temp = int(input())
	A.append(temp)
flag = True
for i in range(0, n) :
	if A[i] % 2 != 0 :
		continue
	elif A[i] % 2 == 0 and (A[i]%3 == 0 or A[i]%5 == 0) :
		continue
	else :
		flag = False
		break
if flag :
	print ("APPROVED")
else :
	print ("DENIED")
Problem p03494 (python)

Fixed submission:
def checkCanHalf(ary):
  for item in ary:
    if(item % 2 != 0):
      return False
  return True

n = range(int(input()))
ary = list(map(int, input().split()))
cnt = 0

while checkCanHalf(ary) == True:
  for i in range(len(ary)):
    ary[i] = ary[i]/2
  cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
def checkCanHalf(ary):
  for item in ary:
    if(item % 2 != 0):
      return False
  return True

n = range(int(input()))
ary = map(int, input().split())
cnt = 0

while checkCanHalf(ary) == True:
  for i in range(len(ary)):
    ary[i] = ary[i]/2
  cnt += 1

print(cnt)
Problem p02612 (python)

Fixed submission:
n = int(input())

if n%1000 == 0:
  print(0)
else:
  print(1000 - n%1000)

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

if n%1000 == 0:
  return n//1000
else:
  return 1000 - n%1000
Problem p02641 (python)

Fixed submission:
import sys

X, N = map(int, input().split())
p = list(map(int, input().split()))

if N == 0:
    print(X)
    sys.exit()

comp = 101
for i in range(102):
    x = abs(X - i)
    if comp > x and i not in p:
        comp = x
        result = i

print(result)

Buggy submission (verdict: Runtime Error):
import sys

X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

comp = 101
for i in range(100):
    i += 1    
    x = abs(X - i)
    if comp > x and i not in p:
        comp = x
        result = i

print(result)

Buggy submission (verdict: Runtime Error):
import sys

X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

comp = 101
for i in range(1, 101):
    x = abs(X - i)
    if comp == x:
        break
    if comp > x and i not in p:
        comp = x
        result = i

print(result)

Buggy submission (verdict: Runtime Error):
import sys

X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

comp = 101
for i in range(1, 101):
    x = abs(X - i)
    if comp > x and i not in p:
        comp = x
        result = i

print(result)

Buggy submission (verdict: Runtime Error):
import sys

X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

comp = 101

for i in range(1, 101):
    x = abs(X - i)
    if x == comp:
        break
    if comp > x and i not in p and:
        comp = x
        result = i

print(result)

Buggy submission (verdict: Runtime Error):
import sys

X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

comp = 101

for i in range(1, 101):
    x = abs(X - i)
    if x == comp:
        sys.exit()
    if comp > x and i not in p and:
        comp = x
        result = i

print(result)

Buggy submission (verdict: Runtime Error):
import sys

X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

comp = 101
for i in range(1, 101):
    x = abs(X - i)
    if comp > x and i not in p:
        comp = x
        result = i

print(result)
Problem p02658 (python)

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

total = 1
li.sort()
for a in li:
    if a == 0:
        total = 0
        break
    total *= a
    if 10 ** 18 < total:
        total = -1
        break
print(total)

Buggy submission (verdict: Runtime Error):
n = input()

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

total = 1

if a in 0:
	total = 0
else:
	for i in a:
		total *= i

if total > 10**18:
	total = -1

print(total)
Problem p02843 (python)

Fixed submission:
x = int(input())

nokori = x%100
max_n = x//100

if max_n < nokori//5 + nokori%5//4 + nokori%5%4//3 + nokori%5%4%3//2 + nokori%5%4%3%2:
    print(0)
else:
    print(1)

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

nokori = x%100
max_n = x//100
print(int(nokori/5) + int(nokori%5/4) + int(nokori%5%4/3) + int(nokori%5%4%3/2) + int(nokori%5%4%3%2)
if max_n < int(nokori/5) + int(nokori%5/4) + int(nokori%5%4/3) + int(nokori%5%4%3/2) + nokori%5%4%3%2:
    print(0)
else:
    print(1)
Problem p02909 (python)

Fixed submission:
s = input()

if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')

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


n,m = map(int,input().split())
a = np.array(list(map(int,input().split())))
for i in range(m):
    a[a.argmax()] = a[a.argmax()]//2 
print(np.sum(a))

Buggy submission (verdict: Runtime Error):
import numpy as np
n = list(map(int,input().split()))
a = np.array(list(map(int,input().split())))
print(a)
for i in range(n[1]):
    a[a.argmax()] = a[a.argmax()]//2 
print(np.sum(a))

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

a = [int(input()) for i in range(n[2])]

for i in range(n[0]):
    if n[1]-(n[2]-a.count(i+1)) <= 0:
        print('No')
    else:
        print('Yes')
Problem p02995 (python)

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

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

num = 0

import fractions
lcm = c*d//int(fractions.gcd(c, d))

num = b-b//c-b//d+b//lcm-((a-1)-(a-1)//c-(a-1)//d+(a-1)//lcm)





print(str(num))

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

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

num = 0

import math

lcm = c*d//int(math.gcd(c, d))

num = b-b//c-b//d+b//lcm-((a-1)-(a-1)//c-(a-1)//d+(a-1)//lcm)





print(str(num))
Problem p02999 (python)

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

x,a = map(int, input().split())
if x<a:
  print("0")
else:
  print("10")

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

n,k = map(int, input().split())

a = input().split()
num = 0

for i,s in enumerate(a):
  for j,g in enumerate(a):
    sum = 0
    for l,e in enumerate(a):
      if l >= i and l <= j:
        sum += int(e)
    if sum >= int(k):
       num += 1

print(str(num))
Problem p03324 (python)

Fixed submission:
d,n = map(int,input().split())
 
if d == 0:
    if n == 100:
        print(101)
    else: 
        print(n)
else:
    if n == 100:
        print(pow(100,d)*(n+1)) 
    else:
        print(pow(100,d)*n)

Buggy submission (verdict: Runtime Error):
d,n = map(int,input().split())
 
if d == 0:
    if n == 100:
        print(101)
  print(n)
else:
    if d == 1 and n == 100:
        print(10001)
  print(100*d*n)

Buggy submission (verdict: Runtime Error):
d,n = map(int,input())

if d == 0:
  print(n)
else:
  print(100*d*n)
Problem p03565 (python)

Fixed submission:
s = input()
t = input()

ans = []
for i in range(len(s)-(len(t)-1)):
    f = True
    for j in range(len(t)):
        if s[j+i] != t[j] and s[j+i] != '?':
            f = False
    if f == True:
        s2 = s[:i] + t + s[i+len(t):]
        s2 = s2.replace('?','a')
        ans.append(s2)



if len(ans) > 0:
    print(min(ans))
else:
    print('UNRESTORABLE')

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

ans = []
for i in range(len(s)-(len(t)-1)):
    f = True
    for j in range(len(t)):
        if s[-(j+i+1)] != t[-(j+1)] and s[-(j+i+1)] != '?':
            f = False
    if f == True:
        s = s[:-(len(t)+i)] + t + s[len(s)-1-i:0]
        s = s.replace('?','a')
        ans.append(s)



if len(ans) > 0:
    print(sorted(ans)[0])
else:
    print('UNRESTORABLE')
Problem p04045 (python)

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

while 1:
    if all(dd not in str(n) for dd in d):
        print(n)
        break
    n = n+1

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

ans = ''

for i in range(10):
    if not str(i) in d:
        sm = str(i)
        break

for i in range(len(str(n))):
    if n[i] in d:
        co = str(int(n[i])+1)
        while(1):
            if not co in d:
                break
            co = co + 1
        ans = ans + co + sm*(len(n)-i-1)
        break
    else:
        ans = ans + n[i]
print(ans)
Problem p02630 (python)

Fixed submission:

  
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    bc =[list(map(int, input().split())) for _ in range(q)]
    temp = [0] * (10**5 + 1)
    
    for i in a:
        temp[i] += 1
    ans = sum(a)
    for i in range(q):
        b,c = bc[i][0],bc[i][1]
        ans = ans - temp[b] * b + temp[b] * c 
        print(ans)
        temp[c] += temp[b]
        temp[b] = 0
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc =[list(map(int, input().split())) for _ in range(q)]
temp = [0] * (10**5 + 1)

for i in a:
    temp[i] += 1
ans = sum(a)
for i in range(q):
    b,c = bc[i][0],bc[i][1]
    ans = ans - temp[b] * b + temp[b] * c 
    print(sum(temp))
    temp[c] += tremp[b]

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc =[list(map(int, input().split())) for _ in range(q)]
temp = [0] * (max(a)+1)

for i in a:
    temp[i] += i

for i in range(q):
    b,c = bc[i][0],bc[i][1]
    temp[c] += (temp[b]//b) * c
    temp[b] = 0
    print(sum(temp))
Problem p02675 (python)

Fixed submission:

a = int(input())
x = str(a)
aa = int(x[len(x)-1])

if aa in (2,4,5,7,9):
    print('hon')
    exit()
if aa in (0,1,6,8):
    print('pon')
    exit()
if aa == 3:
    print('bon')
    exit()

Buggy submission (verdict: Runtime Error):
if aa in (2,4,5,7,9):
    print('hon')
    exit()
if aa in (0,1,6,8):
    print('pon')
    exit()
if aa == 3:
    print('bon')
    exit()
Problem p02683 (python)

Fixed submission:
def main():
    n,m,x = map(int,input().split())
    a = [[] for _ in range(n)]
    c = [0] * n

    INF = 10 ** 9
    ans = INF

    for i in range(n):
        ca = list(map(int,input().split()))
        c[i],a[i] = ca[0],ca[1:]

    for s in range(0,1<<n):
        smart = [0] * m
        cost = 0
        for i in range(n):
            if(s>>i) % 2 == 0:continue
            cost += c[i]
            for j in range(m):
                smart[j] += a[i][j]
        ok = True
        for i in range(m):
            if smart[i] < x:
                ok = False
        if ok:
            ans = min(ans,cost)
    if ans == INF:
        ans = -1
    
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):

import itertools

def main():
    n,m,x = map(int,input().split())
    ans = 0
    tmp = 10 ** 7
    ca = [[0]*m for i in range(n)]
    nn = [i for i in range(n)]

    for _ in range(n):
        ca[_] = list(map(int, input().split()))

    xx = list(itertools.combinations(nn))

    for ii in xx:
        ans = 0
        a = [0 for i in range(m)]

        for _ in ii:
            cost = ca[_][0]
            chk = 0
            for i in range(m):
                a[i] += ca[_][i+1]
                if a[i] < x:
                    chk = 1

            ans += cost
            if chk == 0:
                if tmp > ans:
                    tmp = ans
                break
            
        if tmp == 10 ** 7:
            print(-1)
            exit()

    print(tmp)

 
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import itertools

n,m,x = map(int,input().split())
ans = 0
tmp = 10 ** 7
ca = [[0]*m for i in range(n)]
nn = [i for i in range(n)]

for _ in range(n):
    ca[_] = list(map(int, input().split()))

xx = list(itertools.combinations(nn))

for ii in xx:
    ans = 0
    a = [0 for i in range(m)]

    for _ in ii:
        cost = ca[_][0]
        chk = 0
        for i in range(m):
            a[i] += ca[_][i+1]
            if a[i] < x:
                chk = 1

        ans += cost
        if chk == 0:
            if tmp > ans:
                tmp = ans
            break
    
    if tmp == 10 ** 7:
        print(-1)
        exit()

print(tmp)
Problem p02684 (python)

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

    num = 1
    l = []
    s = [1]*n

    while s[num-1]:
        l.append(num)
        s[num-1] = 0
        num = a[num-1]

    if l.index(num) <= k:
        l2 = l[l.index(num):]
        kk = (k-len(set(l)-set(l2)))%len(l2)
        print(l2[kk])
    else:
        print(l[k])

main()

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int, input().split()))
ns = [0] * (n+1)
tree = []

ns = [0] * n
ns[0] = 1
# max 2*10**5
# どこかでループしてる
nexti = 0
starti = 0
endi = 0
tree.append(nexti)

while  k > 0 :
    nexti = a[nexti] - 1
    if ns[nexti] == 1:
        starti = nexti
        break
    ns[nexti] = 1
    endi = nexti
    tree.append(nexti)

x = tree.index(starti) 
# y = tree[starti:]
y = len(tree[x:])

if k - x <= 0:
    print(tree[k-1])
else:
    k = k - x
    z = k % y
    if starti == 0:
        starti = -1
    temp = tree[starti+1:]

    print(temp[z]+1)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int, input().split()))
ns = [0] * (n+1)
tree = []

ns = [0] * n
ns[0] = 1
# max 2*10**5
# どこかでループしてる
nexti = 0
starti = 0
endi = 0
tree.append(nexti)

while  k > 0 :
    nexti = a[nexti] - 1
    if ns[nexti] == 1:
        starti = nexti
        break
    ns[nexti] = 1
    endi = nexti
    tree.append(nexti)

x = tree.index(starti) 
# y = tree[starti:]
y = len(tree[x:])

if k - x <= 0:
    print(tree[k-1])
else:
    k = k - x
    z = k % y
    if starti == 0:
        starti = -1
    temp = tree[starti+1:]

    print(temp[z] + 1,temp,z)
Problem p02714 (python)

Fixed submission:

def main():
    n = int(input())
    s = str(input())
    cnt = 0
    r = s.count('R')
    g = s.count('G')
    b = s.count('B')

    for i in range(n):
        for j in range(i,n):
            if i == j:
                continue
            k = 2 * j - i
            if k > len(s) - 1:
                continue
            if s[i] == s[j] or s[j] == s[k] or s[k] == s[i]:
                continue

            cnt +=1

    all = r * g * b
    print(all - cnt) 
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
n = int(input())
s = str(input())
r = [i + 1 for i in range(n) if s[i] == 'R']
g = [i + 1 for i in range(n) if s[i] == 'G']
b = [i + 1 for i in range(n) if s[i] == 'B']

def count(x,y,z):
    c = 0
    for i in x:
        for j in y:
            if i > j: continue 
            for k in z:
                if j > k: continue 
                if j - i != k - j:
                    c += 1
    return c

ans = 0
ans += count(r,g,b)
ans += count(r,b,g)
ans += count(b,r,g)
ans += count(b,g,r)
ans += count(g,r,b)
ans += count(g,b,r)

print(ans)n = int(input())
s = str(input())
r = [i + 1 for i in range(n) if s[i] == 'R']
g = [i + 1 for i in range(n) if s[i] == 'G']
b = [i + 1 for i in range(n) if s[i] == 'B']

def count(x,y,z):
    c = 0
    for i in x:
        for j in y:
            if i > j: continue 
            for k in z:
                if j > k: continue 
                if j - i != k - j:
                    c += 1
    return c

ans = 0
ans += count(r,g,b)
ans += count(r,b,g)
ans += count(b,r,g)
ans += count(b,g,r)
ans += count(g,r,b)
ans += count(g,b,r)

print(ans)
Problem p02760 (python)

Fixed submission:
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input() )for _ in range(n)]

for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j] = 0

for i in range(3):
    if a[i][0] == 0 and a[i][1] == 0 and a[i][2] == 0:
        print('Yes')
        exit()
for i in range(3):
    if a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0:
        print('Yes')
        exit()
if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
    print('Yes')
    exit()
if a[2][0] == 0 and a[1][1] == 0 and a[0][2] == 0:
    print('Yes')
    exit()
print('No')

Buggy submission (verdict: Runtime Error):
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input() )for _ in range(n)]

print(a,n,b)
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j] = 0

for i in range(3):
    if a[i] == [0,0,0]:
        print('Yes')
        exit()
for i in range(3):
    if a[j0][i] == 0 and a[1][i] == 0 and a[2][i] == 0:
        print('Yes')
        exit()
if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
    print('Yes')
    exit()
if a[2][0] == 0 and a[1][1] == 0 and a[0][2] == 0:
    print('Yes')
    exit()
print('No')
Problem p02923 (python)

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
ans = 0
b = 0
temp = 0

for i in h:
    if i <= b:
        temp += 1
    else:
        temp = 0
    b = i
    ans = max(ans,temp)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split())))
ans = 0
b = 10 ** 9
temp = 0

for i in h:
    if i <= b
        temp += 1
    else:
        temp = 0
    b = i
    ans = max(ans,temp)
print(ans)
Problem p02971 (python)

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]

maxa = max(a)
maxb = max(a)
cntmax = a.count(maxa)
if cntmax >= 2:
    for i in range(n):
        print(maxa)
    exit()
else:
    maxi = a.index(maxa)
    x = 0
    y = 0
    if maxi >= 1:
        x = max(a[:maxi])
    if maxi < n - 1 :
        y = max(a[maxi+1:])
    maxb = max(x,y)

for i in a:
    if i == maxa:
        print(maxb)
    else:
        print(maxa)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]

maxa = max(a)
maxb = max(a)
cntmax = a.count(maxa)
if cntmax >= 2:
    for i in range(n):
        print(maxa)
    exit()
else:
    maxi = a.index(maxa)
    if maxi >= 1:
        x = max(a[:maxi])
    if maxi < n - 1 :
        y = max(a[maxi+1:])
    maxb = max(x,y)

for i in a:
    if i == maxa:
        print(maxb)
    else:
        print(maxa)
Problem p02995 (python)

Fixed submission:
from fractions import gcd
import math

def lcm(x, y):
    return (x * y) // gcd(x, y)
a,b,c,d = map(int,input().split())
all = b - a + 1
if c == 1 or d == 1:
    print(0)
    exit()

cd = lcm(c, d)

cs = b//c - math.ceil(a/c) + 1
ds = b//d - math.ceil(a/d) + 1
cds = b//cd - math.ceil(a/cd) + 1

print(all - cs - ds + cds)

Buggy submission (verdict: Runtime Error):

import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a,b,c,d = map(int,input().split())
all = b - a + 1
if c == 1 or d == 1:
    print(0)
    exit()

cd = lcm(a, b)

cs = b//c - a//c + 1
ds = b//d - a//d + 1
cds = b//cd - a//cd + 1

print(all - cs - ds + cds)
Problem p03161 (python)

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

# 無限大の値
INF = 10**10

# DP テーブル
# DP テーブル全体を初期化 (最小化問題なので INF に初期化)
dp = [INF] * n

# 初期条件
dp[0] = 0
dp[1] = abs(h[0] - h[1])

# ループ
for i in range(2,n):
    # ...
    for j in range(1,min(k,i)+1):
        hk = dp[i-j] + abs(h[i-j] - h[i])
        dp[i] = min(hk,dp[i])
    
# 解を得て出力
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
from numba import njit
@njit #処理の並列化
def main():
    n,k = map(int,input().split())
    h = list(map(int, input().split()))

    # 無限大の値
    INF = 10**10

    # DP テーブル
    # DP テーブル全体を初期化 (最小化問題なので INF に初期化)
    dp = [INF] * n

    # 初期条件
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])

    # ループ
    for i in range(2,n):
        # ...
        # for j in range(1,min(k,i)+1):
        #     hk = dp[i-j] + abs(h[i-j] - h[i])
        #     dp[i] = min(hk,dp[i])
        dp[i] = min(dp[i-j] + abs(h[i-j] - h[i]) for j in range(1,min(k,i)+1))

    # 解を得て出力
    print(dp[n-1])

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from numba import njit
@njit #処理の並列化
def main():
    n,k = map(int,input().split())
    h = list(map(int, input().split()))

    # 無限大の値
    INF = 10**10

    # DP テーブル
    # DP テーブル全体を初期化 (最小化問題なので INF に初期化)
    dp = [INF] * n

    # 初期条件
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])

    # ループ
    for i in range(2,n):
        # ...
        for j in range(1,min(k,i)+1):
            hk = dp[i-j] + abs(h[i-j] - h[i])
            dp[i] = min(hk,dp[i])

    # 解を得て出力
    print(dp[n-1])

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

Fixed submission:
MX = 100005
n = int(input())
cnt = [0] * MX
a = list(map(int, input().split()))

for i in a:
    cnt[i] += 1

total = 0

for i in range(MX):
    total += i*cnt[i]

q = int(input())
b = []
c = []
 
for i in range(q):
    B, C = [int(i) for i in input().split()]
    b.append(B)
    c.append(C)

for i in range(q):
    total -= b[i]*cnt[b[i]]
    total -= c[i]*cnt[c[i]]
    cnt[c[i]] += cnt[b[i]]
    cnt[b[i]] = 0
    total += c[i]*cnt[c[i]]
    print(total)

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

q = int(input())
b = []
c = []

for i in range(q):
    B, C = [int(i) for i in input().split()]
    b.append(B)
    c.append(C)

int_list = {}

for i in a:
    int_list[i] = 0

for i in a:
    int_list[i] += 1

ans = 0
for k, v in int_list.items():
    ans += k*v # 3


for i in range(q):
    ans = 0
    p = int_list[b[i]] # 1 1
    ans = 0
    int_list[b[i]] = 0
    try:
        int_list[c[i]] += p
    except KeyError:
        int_list[c[i]] = p
    for k, v in int_list.items():
        ans += k*v
    
    print(ans)