Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

ans = 0
def gcd(x,y):
    while y:
        x, y = y, x % y
    return x

for i in range(1,k+1):
    for j in range(1,k+1):
        for s in range(1,k+1):
            ans += gcd(gcd(i,j),s)

print(ans)


Fixed submission:
k = int(input())

ans = 0
def gcd(x,y):
    while y:
        x, y = y, x % y
    return x

for i in range(1,k+1):
    for j in range(1,k+1):
        for s in range(1,k+1):
            ans += gcd(gcd(i,j),s)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())

ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for s in range(1,k+1):
            ans += math.gcd(math.gcd(i,j),s)

print(ans)


Fixed submission:
k = int(input())

ans = 0
def gcd(x,y):
    while y:
        x, y = y, x % y
    return x

for i in range(1,k+1):
    for j in range(1,k+1):
        for s in range(1,k+1):
            ans += gcd(gcd(i,j),s)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())

ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for s in range(1,k+1):
            ans += math.gcd(math.gcd(i,j),s)

print(ans)

Fixed submission:
k = int(input())

ans = 0
def gcd(x,y):
    while y:
        x, y = y, x % y
    return x

for i in range(1,k+1):
    for j in range(1,k+1):
        for s in range(1,k+1):
            ans += gcd(gcd(i,j),s)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k, n = map(int,input().split())
a = list(map(int,input().split()))

cost = 10**9
y = min(a)
for i in range(n):
    cost_r = 0
    cost_l = 0
    r = a[i:] + a[:i]
    l = list(reversed(a[:i+1])) + list(reversed(a[i+1:]))
    for j in range(n-1):
        if r[j+1] < r[j]:
            cost_r += k - r[j]
            if l[j+1] < l[j]:
                cost_l += k - l[j]
                continue
            cost_l += l[j+1] - l[j]
            continue
        if l[j+1] < l[j]:
            cost_l += k - l[j]
            cost_r += r[j+1] - r[j]
            continue
        cost_r += r[j+1] - r[j]
        cost_l += l[j+1] - l[j]
    #print(cost_r,cost_l)
    #print(r,l)
    cost = min(cost,cost_l,cost_r)
print(cost)

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

cost = max(a[0]+k-a[-1],a[-1]-a[-2])
for i in range(1,n-1):
    cost = max(a[i]-a[i-1],a[i+1]-a[i],cost)
print(k-cost)
Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int,input().split())

ans = []
for i in range(1,n+1):
    for j in range(i+1,n+1):
        ans.append(min(j-i,abs(x-i)+1+abs(y-j)))
for k in range(1,n):
    print(ans.count(k))


Fixed submission:
n, x, y = map(int,input().split())

ans = [0]*(n-1)
for i in range(1,n+1):
    for j in range(i+1,n+1):
        ans[min(j-i,abs(x-i)+1+abs(y-j))-1] += 1
        #ans.append(min(j-i,abs(x-i)+1+abs(y-j)))
for k in range(n-1):
    print(ans[k])

Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int,input().split())

ans = []
for i in range(1,n+1):
    for j in range(i+1,n+1):
        ans.append(min(j-i,abs(x-i)+1+abs(y-j)))
for k in range(1,n):
    print(ans.count(k))

Fixed submission:
n, x, y = map(int,input().split())

ans = [0]*(n-1)
for i in range(1,n+1):
    for j in range(i+1,n+1):
        ans[min(j-i,abs(x-i)+1+abs(y-j))-1] += 1
        #ans.append(min(j-i,abs(x-i)+1+abs(y-j)))
for k in range(n-1):
    print(ans[k])
Buggy python submission (verdict: Runtime Error):
x, y, a, b, c = map(int,input().split())
p = [list(map(int,input().split())) for _ in range(3)]

for i, e in enumerate(p):
    p[i] = list(sorted(e,reverse=True))

g, h = 0, 0
ans = 0
for i in range(x):
    if p[0][i] >= p[2][g]:
        ans += p[0][i]
    else:
        if p[1][h] < p[0][i]:
            ans += p[0][i]
            h += 1
        else:
            ans += p[2][g]
            g += 1
            p[2][g] = 0

for i, e in enumerate(p):
    p[i] = list(sorted(e,reverse=True))

g = 0
for i in range(y):
    if p[1][i] >= p[2][g]:
        ans += p[1][i]
    else:
        if g >= c:
            ans += p[1][i]
        else:
            ans += p[2][g]
            g += 1
print(ans)

Fixed submission:
x, y, a, b, c = map(int,input().split())
p = (list(map(int,input().split())))
q = (list(map(int,input().split())))
r = (list(map(int,input().split())))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p = p[:x]
q = q[:y]
apple = p + q + r
apple.sort(reverse=True)
ans = sum(apple[:x+y])
print(ans)

Buggy python submission (verdict: Runtime Error):
x, y, a, b, c = map(int,input().split())
p = [list(map(int,input().split())) for _ in range(3)]

for i, e in enumerate(p):
    p[i] = list(sorted(e,reverse=True))

g, h = 0, 0
ans = 0
for i in range(x):
    if p[0][i] >= p[2][g]:
        ans += p[0][i]
    else:
        if p[1][h] < p[0][i]:
            ans += p[0][i]
            h += 1
        else:
            ans += p[2][g]
            g += 1
            p[2][g] = 0

for i, e in enumerate(p):
    p[i] = list(sorted(e,reverse=True))

g = 0
for i in range(y):
    print(p[1][i],p[2][g])
    if p[1][i] >= p[2][g]:
        ans += p[1][i]
    else:
        ans += p[2][g]
        g += 1
print(ans)

Fixed submission:
x, y, a, b, c = map(int,input().split())
p = (list(map(int,input().split())))
q = (list(map(int,input().split())))
r = (list(map(int,input().split())))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p = p[:x]
q = q[:y]
apple = p + q + r
apple.sort(reverse=True)
ans = sum(apple[:x+y])
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())
query = [list(input().replace(' ','')) for _ in range(q)]

r = False
for i in range(q):
    if r:
        if len(query[i]) == 1:
            r = False
        elif query[i][1] == '1':
            s = s + query[i][2]
        else:
            s = query[i][2] + s
    else:
        if len(query[i]) == 1:
            r = True
        elif query[i][1] == '1':
            s = query[i][2] + s
        else:
            s = s + query[i][2]

if r:
    print(s[::-1])
else:
    print(s)

Fixed submission:
s = str(input())
station_a = s.count('A')
station_b = s.count('B')
if station_a != 3 and station_b != 3:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []
for i in range(n):
    s.append(input())

c = []
for j in s:
    if j not in c:
        c.append(j)

g = []
for t in c:
    g.append([s.count(t),t])
g.sort(reverse=True)
h = max(g)[0]
hh = []
for ii in range(len(g)):
    if g[ii][0] == h:
        hh.append(g[ii])
    else:
        break
hh.sort(key=lambda x: x[1])
ans = []
for k in range(len(hh)):
    print(hh[k][1])

Fixed submission:
import collections

n = int(input())
s = []
for i in range(n):
    s.append(input())

c = collections.Counter(s)
c_s = c.most_common()
m = c.most_common()[0][1]
ans = []
for j in range(len(c_s)):
    if c_s[j][1] != m:
        break
    else:
        ans.append(c_s[j][0])
ans.sort()
for t in ans:
    print(t)
Buggy python submission (verdict: Runtime Error):
n, k = map(int,input().split())
p = list(map(int,input().split()))

ans = 0
for i in range(n-k+1):
    e = 0
    for j in range(0,k):
        e += (0.5*(p[i+j]+1))
    ans = max(ans,e)
print(ans)


Fixed submission:
s, t = map(str,input().split())
a, b = map(int,input().split())
u = str(input())

if u == s:
    print(a-1,b)
else:
    print(a,b-1)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
p = list(map(int,input().split()))

ans = 0
for i in range(n-k+1):
    e = 0
    for j in range(0,k):
        e += (0.5*(p[i+j]+1))
    ans = max(ans,e)
print(ans)


Fixed submission:
import numpy as np
n, k = map(int,input().split())
p = list(map(int,input().split()))

e = [(i+1)/2 for i in p]
e = np.cumsum(e)
e = np.append(0,e)
ans = 0
for i in range(n-k+1):
    ans = max(e[i+k]-e[i],ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
p = list(map(int,input().split()))

ans = 0
for i in range(n-k+1):
    e = 0
    for j in range(0,k):
        e += (0.5*(p[i+j]+1))
    ans = max(ans,e)
print(ans)

Fixed submission:
import numpy as np
n, k = map(int,input().split())
p = list(map(int,input().split()))

e = [(i+1)/2 for i in p]
e = np.cumsum(e)
e = np.append(0,e)
ans = 0
for i in range(n-k+1):
    ans = max(e[i+k]-e[i],ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int,input().split()))

ans = 0
for i in range(n):
    if i == 0:
        ans += 1
        m = p[0]
        continue
    if p[i] <= m:
        ans += 1
        m = p[i]

print(ans)

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

if n == m:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int,input().split()))

ans = 0
for i in range(n):
    count = -1
    for j in range(i+1):
        if p[i] <= p[j]:
            count += 1
    if count == i:
        ans += 1

print(ans)

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

ans = 0
n_min = 0
for i in range(0,n):
    if i == 0:
        ans += 1
        n_min = p[i]
        continue
    if p[i] <= n_min:
        ans += 1
        n_min = p[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int,input().split()))

ans = 0
for i in range(0,n):
    for j in range(0,i+1):
        if p[i] > p[j]:
            break
        elif j == i:
            ans += 1
print(ans)

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

ans = 0
n_min = 0
for i in range(0,n):
    if i == 0:
        ans += 1
        n_min = p[i]
        continue
    if p[i] <= n_min:
        ans += 1
        n_min = p[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n, m =map(int,input().split())
p = []
for i in range(m):
    p.append(input().split())

del_l = []
for j in range(m):
    if p[j][1] == 'AC':
        del_l.append(p[j][0])
        p[j][0] = 'pass'
        p[j][1] = 'pass'
    if p[j][1] =='WA' and p[j][0] in del_l:
        p[j][0] = 'pass'
        p[j][1] = 'pass'
pen = 0
for s in range(m):
    if p[s][1] == 'WA' and p[s][0] in del_l:
        pen += 1
print(len(collections.Counter(del_l)),pen)

Fixed submission:
n, m = map(int,input().split())
a = [input().split() for i in range(m)]
p = [int(i[0]) for i in a]
q = [j[1] for j in a]

ac = 0
wa = 0
wa_c = [0] * n
ac_c = [False] * n

for t in range(m):
    if ac_c[p[t]-1]:
        continue
    if q[t] == 'AC':
        ac += 1
        ac_c[p[t]-1] = True
        wa += wa_c[p[t]-1]
    else:
        wa_c[p[t]-1] += 1
print(ac,wa)

Buggy python submission (verdict: Time Limit Exceeded):
n, m =map(int,input().split())
p = []
for i in range(m):
    p.append(input().split())

del_l = []
for j in range(m):
    if p[j][1] == 'AC' and p[j][0] not in del_l:
        del_l.append(p[j][0])
    if p[j][1] =='WA' and p[j][0] in del_l:
        p[j][0] = 'pass'
        p[j][1] = 'pass'
pen = 0
for s in range(m):
    if p[s][1] == 'WA' and p[s][0] in del_l:
        pen += 1
print(len(del_l),pen)

Fixed submission:
n, m = map(int,input().split())
a = [input().split() for i in range(m)]
p = [int(i[0]) for i in a]
q = [j[1] for j in a]

ac = 0
wa = 0
wa_c = [0] * n
ac_c = [False] * n

for t in range(m):
    if ac_c[p[t]-1]:
        continue
    if q[t] == 'AC':
        ac += 1
        ac_c[p[t]-1] = True
        wa += wa_c[p[t]-1]
    else:
        wa_c[p[t]-1] += 1
print(ac,wa)

Buggy python submission (verdict: Time Limit Exceeded):
n, m =map(int,input().split())
p = []
for i in range(m):
    p.append(input().split())

l_1 = []
l_2 = []
for x in p:
    l_1.append(x[0])
for y in p:
    l_2.append(y[1])
del_l = []
for j in range(m):
    if l_2[j] == 'AC' and l_1[j] not in del_l:
        del_l.append(l_1[j])
    if l_2[j] =='WA' and l_1[j] in del_l:
        l_1[j] = 'pass'
        l_2[j] = 'pass'
pen = 0
for s in range(m):
    if l_2[s] == 'WA' and l_1[s] in del_l:
        pen += 1
print(len(del_l),pen)

Fixed submission:
n, m = map(int,input().split())
a = [input().split() for i in range(m)]
p = [int(i[0]) for i in a]
q = [j[1] for j in a]

ac = 0
wa = 0
wa_c = [0] * n
ac_c = [False] * n

for t in range(m):
    if ac_c[p[t]-1]:
        continue
    if q[t] == 'AC':
        ac += 1
        ac_c[p[t]-1] = True
        wa += wa_c[p[t]-1]
    else:
        wa_c[p[t]-1] += 1
print(ac,wa)
Buggy python submission (verdict: Runtime Error):
s = str(input())
t = str(input())

print(t+s)

Fixed submission:
s,t = map(str,input().split())
print(t+s)
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int,input().split())
lim = a * b +1
for i in range(min(a,b),lim):
    if i % a == 0 and i % b == 0:
        print(i)
        quit()

Fixed submission:
import math
a ,b = map(int,input().split())

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
ans = a * b / gcd(a,b)
print(int(ans))

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

ans = a * b / math.gcd(a,b)
print(int(ans))

Fixed submission:
import math
a ,b = map(int,input().split())

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
ans = a * b / gcd(a,b)
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

pins = []
for i in range(1000):
    i = str(i)
    if len(i) == 1:
        pins.append(str('00')+i)
    elif len(i) == 2:
        pins.append(str('0')+i)
    else:
        pins.append(i)

ans = 0
for pin in pins:
    c = 0
    for i in s:
        if pin[c] == i:
            c += 1
        if c == 3:
            ans += 1
            break

print(ans)

Fixed submission:
n = int(input())
s = input()

pin = []
for i in range(1000):
    i = str(i)
    if len(i) == 1:
        i = '00' + i
    elif len(i) == 2:
        i = '0' + i
    pin.append(i)

ans = 0
for i in pin:
    c = 0
    for j in s:
        if j == i[c]:
            c += 1
        if c == 3:
            ans += 1
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

pin = []
for i in range(1000):
    i = str(i)
    if len(i) == 1:
        i = '00' + i
    elif len(i) == 2:
        i = '0' + i
    pin.append(i)

ans = 0
for i in pin:
    c = 0
    for j in s:
        if j == i[c]:
            c += 1
        if c == 3:
            ans += 1
            break
print(ans)

Fixed submission:
n = int(input())
s = input()

pin = []
for i in range(1000):
    i = str(i)
    if len(i) == 1:
        i = '00' + i
    elif len(i) == 2:
        i = '0' + i
    pin.append(i)

ans = 0
for i in pin:
    c = 0
    for j in s:
        if j == i[c]:
            c += 1
        if c == 3:
            ans += 1
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
a , b, x = map(int,input().split())

if x >= 1000000000:
    print(10**9)
else:
    for n in range(1,10**9):
        l = len(str(n))
        if x <= a * n + b * l:
            ans = n - 1
            break
    print(ans)

Fixed submission:
s = str(input())

if s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
elif s == 'SAT':
    print(1)
Buggy python submission (verdict: Runtime Error):
N =int(input())
d = list(map(int,input().split()))

r  = 0
for i in range(N-1):
    for f in range(i + 1,N):
        r += d[i] * d[j]
print(r)

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

r  = 0
for i in range(N-1):
    for j in range(i + 1,N):
        r += d[i] * d[j]
print(r)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from math import factorial
n = int(input())
s = [list(input()) for _ in range(n)]

ss = []
for i in range(n):
    a = sorted(s[i])
    a = ''.join(a)
    ss.append(a)

ss = Counter(ss)
ans = 0
n = len(ss)
k = ss.keys()
for i in k:
    if ss[i] == 1:
        continue
    if ss[i] > 2:
        ans += factorial(ss[i]) / 2 / factorial(ss[i]-2)
    else:
        ans += 1
print(int(ans))

Fixed submission:
from collections import Counter
from scipy import misc
n = int(input())
s = [list(input()) for _ in range(n)]

ss = []
for i in range(n):
    a = sorted(s[i])
    a = ''.join(a)
    ss.append(a)

ss = Counter(ss)
ans = 0
n = len(ss)
k = ss.keys()
for i in k:
    if ss[i] == 1:
        continue
    if ss[i] >= 2:
        ans += round(float(misc.comb(ss[i],2)))
print(int(ans))

Buggy python submission (verdict: Runtime Error):
from collections import Counter
from math import factorial
n = int(input())
s = [list(input()) for _ in range(n)]

ss = []
for i in range(n):
    a = sorted(s[i])
    a = ''.join(a)
    ss.append(a)

ss = Counter(ss)
ans = 0
n = len(ss)
k = ss.keys()
for i in k:
    if ss[i] == 1:
        continue
    if ss[i] > 2:
        ans += factorial(ss[i]) / 2 / factorial(ss[i]-2)
    else:
        ans += 1
print(int(ans))

Fixed submission:
from collections import Counter
from scipy import misc
n = int(input())
s = [list(input()) for _ in range(n)]

ss = []
for i in range(n):
    a = sorted(s[i])
    a = ''.join(a)
    ss.append(a)

ss = Counter(ss)
ans = 0
n = len(ss)
k = ss.keys()
for i in k:
    if ss[i] == 1:
        continue
    if ss[i] >= 2:
        ans += round(float(misc.comb(ss[i],2)))
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
s = [Counter(input()) for _ in range(n)]

c = 0
for i in range(n):
    for j in range(n):
        if s[i] == s[j] and i != j:
            c += 1
print(c//2)

Fixed submission:
from collections import Counter
from scipy import misc
n = int(input())
s = [list(input()) for _ in range(n)]

ss = []
for i in range(n):
    a = sorted(s[i])
    a = ''.join(a)
    ss.append(a)

ss = Counter(ss)
ans = 0
n = len(ss)
k = ss.keys()
for i in k:
    if ss[i] == 1:
        continue
    if ss[i] >= 2:
        ans += round(float(misc.comb(ss[i],2)))
print(int(ans))
Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = map(int,input().split())

l = int(math.gcd(c,d) * c / math.gcd(c,d) * d / math.gcd(c,d))
#print(l)
x = b // c - a // c
y = b // d - a // d
z = b // l - a // l
if a % c == 0 or a % d == 0:
    print(int(b-a-(x+y-z)))
else:
    print(int(b-a-(x+y-z))+1)
#print(x,y,z)

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

l = int(fractions.gcd(c,d) * c / fractions.gcd(c,d) * d / fractions.gcd(c,d))
#print(l)
x = b // c - a // c
y = b // d - a // d
z = b // l - a // l
if a % c == 0 or a % d == 0:
    print(int(b-a-(x+y-z)))
else:
    print(int(b-a-(x+y-z))+1)
#print(x,y,z)
Buggy python submission (verdict: Time Limit Exceeded):
from decimal import *
n, k = map(int,input().split())

ans = Decimal(0)
for i in range(1,n+1):
    count = 0
    if i < k-1:
        while i < k:
            i *= 2
            count += 1
    ans += Decimal(1/n) * Decimal((1/2)**count)
print(ans)

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

ans = 0
for i in range(1,n+1):
    count = 0
    if i < k:
        while i < k:
            i *= 2
            count += 1
    ans += 1/n * (1/2)**count
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = map(int,input().split())

ans = 0
for i in range(n//r+1):
    for j in range(n//g+1):
        bule_ball = (n - (r * i + g * j)) // b
        sum_ball = bule_ball * b + i * r + j * g
        #print(i,j,bule_ball)
        if bule_ball >= 0 and sum_ball == n:
            ans += 1

print(ans)

Fixed submission:
r, g, b, n = map(int,input().split())

ans = 0
for i in range(n//r+1):
    for j in range(n//g+1):
        bule_ball = (n - (r * i + g * j)) // b
        sum_ball = bule_ball * b + i * r + j * g
        #print(i,j,bule_ball)
        if bule_ball >= 0 and sum_ball == n:
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))

ans = math.gcd(a[0],a[1])
for i in range(2,n):
    ans = math.gcd(ans,a[i])
print(ans)

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

ans = fractions.gcd(a[0],a[1])
for i in range(2,n):
    ans = fractions.gcd(ans,a[i])
print(ans)

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

ans = math.gcd(a[0],a[1])
for i in range(2,n):
    ans = math.gcd(ans,a[i])
print(ans)

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

ans = fractions.gcd(a[0],a[1])
for i in range(2,n):
    ans = fractions.gcd(ans,a[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
h = list(map(int,input().split()))

dp = [math.inf] * n
dp[0] = 0

for i in range(1,n):
    if i == 1:
        dp[i] = abs(h[i]-h[0])
        continue
    #print(dp)
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

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

dp = [0] * n

for i in range(1,n):
    if i == 1:
        dp[i] = abs(h[i]-h[0])
        continue
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
v

Fixed submission:
n, w = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(n)]

def knapsack(n,w,wv):
    inf = float('inf')
    dp = [[-inf for _ in range(w+1)] for _ in range(n+1)]
    for i in range(w+1): dp[0][i] = 0

    for i in range(n):
        for w in range(w+1):
            if wv[i][0]<=w:
                dp[i+1][w] = max(dp[i][w-wv[i][0]]+wv[i][1],dp[i][w])
            else:
                dp[i+1][w] = dp[i][w]
    return dp[n][w]

print(knapsack(n,w,wv))
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(n)]

v = 0
for i in range(n):
    v += wv[i][1]


dp = [[float('inf') for _ in range(v+1)] for _ in range(n+1)]

dp[0][0] = 0

for i in range(n):
    for j in range(v+1):
        if j >= wv[i][1]:
            dp[i+1][j] = min(dp[i+1][j],dp[i][j-wv[i][1]]+wv[i][0])
        dp[i+1][j] = min(dp[i+1][j],dp[i][j])
ans = 0
for i in range(v+1):
    if dp[n][i] <= w:
        ans = i
print(ans)

Fixed submission:
from pprint import pprint

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

lim = 1
for i in range(n):
    lim += wv[i][1]

dp = [[float('inf')] * lim for _ in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(lim):
        if j - wv[i][1] >= 0:
            dp[i+1][j] = min(dp[i][j - wv[i][1]] + wv[i][0], dp[i][j])
        else:
            dp[i+1][j] = min((dp[i][j], dp[i+1][j]))

ans = float('inf')

for i in reversed(range(lim)):
    if dp[-1][i] <= w:
        ans = min(i, ans)
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())

ans = 0
n = len(s)
for i in range(n):
    if s[i] == 'W':
        ans += s[:i].count('B')

print(ans)

Fixed submission:
s = list(input())

ans = 0
count_b = 0
n = len(s)
for i in range(n):
    if s[i] == 'B':
        count_b += 1
    if s[i] == 'W':
        ans += count_b

print(ans)