Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,l = map(int,input().split())
apple = [l + i -1 for i in range(1, n+1)]
org = sum(apple)
dif = org
for i in range(n):
    if abs(sum(apple[:i]+apple[i+1:]) - org) < dif:
        dif = abs(sum(apple[:i]+apple[i+1:]) - org)
        ans = sum(apple[:i]+apple[i+1:])
print(ans)

Fixed submission:
n,l = map(int,input().split())
apple = [l + i -1 for i in range(1, n+1)]
org = sum(apple)

for i in range(n):
    if i == 0:
        dif = abs(sum(apple[:i]+apple[i+1:]) - org)
        ans = sum(apple[i+1:])
    elif abs(sum(apple[:i]+apple[i+1:]) - org) < dif:
        dif = abs(sum(apple[:i]+apple[i+1:]) - org)
        ans = sum(apple[:i]+apple[i+1:])
print(ans)

Buggy python submission (verdict: Runtime Error):
n,l = map(int,input().split())
apple = [l + i -1 for i in range(1, n+1)]
org = sum(apple)
dif = org
for i in range(n):
    if abs(sum(apple[:i]+apple[i+1:]) - org) < dif:
        dif = abs(sum(apple[:i]+apple[i+1:]) - org)
        ans = sum(apple[:i]+apple[i+1:])
print(ans)

Fixed submission:
n,l = map(int,input().split())
apple = [l + i -1 for i in range(1, n+1)]
org = sum(apple)

for i in range(n):
    if i == 0:
        dif = abs(sum(apple[:i]+apple[i+1:]) - org)
        ans = sum(apple[i+1:])
    elif abs(sum(apple[:i]+apple[i+1:]) - org) < dif:
        dif = abs(sum(apple[:i]+apple[i+1:]) - org)
        ans = sum(apple[:i]+apple[i+1:])
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
div_c = set()
div_d = set()
for i in range(1,int(math.sqrt(c))+):
    if c % i == 0:
        div_c.add(i)
for i in range(1,int(math.sqrt(d))+1):
    if d % i == 0:
        div_d.add(i)
gcd = max(list(div_c & div_d))
cd = c*d/gcd    
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//(cd) - (a-1)//(cd)
print(int(u - n_c - n_d + n_cd))

Fixed submission:
a,b,c,d = map(int,input().split())
u = b - a + 1
from fractions import gcd
cd = c*d//gcd(c,d)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd =b//cd - (a-1)//cd
print(int(u - n_c - n_d + n_cd))

Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
cd = c * d / math.gcd(c, d)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//(cd) - (a-1)//(cd)
print(int(u - n_c - n_d + n_cd))

Fixed submission:
a,b,c,d = map(int,input().split())
u = b - a + 1
from fractions import gcd
cd = c*d//gcd(c,d)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd =b//cd - (a-1)//cd
print(int(u - n_c - n_d + n_cd))

Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
cd = c * d / math.gcd(c, d)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//(cd) - (a-1)//(cd)
print(int(u - n_c - n_d + n_cd))

Fixed submission:
a,b,c,d = map(int,input().split())
u = b - a + 1
from fractions import gcd
cd = c*d//gcd(c,d)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd =b//cd - (a-1)//cd
print(int(u - n_c - n_d + n_cd))

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d = map(int,input().split())
u = b - a + 1
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
for i in range(1, c*d+1):
    if i % c == 0 and i % d == 0:
        cd = i
        break
n_cd = b//(cd) - (a-1)//(cd)
print(u - n_c - n_d + n_cd)

Fixed submission:
a,b,c,d = map(int,input().split())
u = b - a + 1
from fractions import gcd
cd = c*d//gcd(c,d)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd =b//cd - (a-1)//cd
print(int(u - n_c - n_d + n_cd))

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d = map(int,input().split())
count = 0
for i in range(a,b+1):
    if i % c != 0 and i % d != 0:
        count += 1
print(count)

Fixed submission:
a,b,c,d = map(int,input().split())
u = b - a + 1
from fractions import gcd
cd = c*d//gcd(c,d)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd =b//cd - (a-1)//cd
print(int(u - n_c - n_d + n_cd))
Buggy python submission (verdict: Runtime Error):
p,q,r = map(int,input().split)
print(min(p+q, q+r, r+p))

Fixed submission:
p,q,r = map(int,input().split())
print(min(p+q, q+r, r+p))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
a = [int(input()) for i in range(m)]
p = [0 for i in range(n+1)]
for i in range(1,n+1):
    if i in a:
        p[i] = 0
    elif i == 1:
        p[i] = 1
    elif i == 2:
        p[i] = p[1] + 1
    else:
        p[i] = p[i-1] + p[i-2]
print(p[n] % (10**9 + 7))

Fixed submission:
n, m = map(int,input().split())
p = [0 for i in range(n+1)]
a = [0 for i in range(n+1)]
for i in range(m):
    a[int(input())] = 1
for i in range(1,n+1):
    if a[i] == 1:
        p[i] = 0
    elif i == 1:
        p[i] = 1
    elif i == 2:
        p[i] = p[1] + 1
    else:
        p[i] = p[i-1] + p[i-2]
print(p[n] % (10**9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
a = []
for i in range(m):
    a.append(int(input()))
p = [0 for i in range(n+1)]
for i in range(1,n+1):
    if i in a:
        p[i] = 0
    elif i == 1:
        p[i] = 1
    elif i == 2:
        p[i] = p[1] + 1
    else:
        p[i] = p[i-1] + p[i-2]
print(p[n] % (10**9 + 7))

Fixed submission:
n, m = map(int,input().split())
p = [0 for i in range(n+1)]
a = [0 for i in range(n+1)]
for i in range(m):
    a[int(input())] = 1
for i in range(1,n+1):
    if a[i] == 1:
        p[i] = 0
    elif i == 1:
        p[i] = 1
    elif i == 2:
        p[i] = p[1] + 1
    else:
        p[i] = p[i-1] + p[i-2]
print(p[n] % (10**9 + 7))

Buggy python submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = []
import sys
sys.setrecursionlimit(10000)
for i in range(m):
    a.append(int(input()))
memo = [0 for i in range(n)]
done = [0 for i in range(n)]
def p(i):
    if done[i-1] == 1:
        return memo[i-1]
    if i in a:
        return 0
    elif i == 1:
        return 1
    elif i == 2:
        return p(1) + 1
    else:
        done[i-1] = 1
        memo[i-1] = p(i-1) + p(i-2)
        return memo[i-1]
print(p(n) % (10**9 + 7))

Fixed submission:
n, m = map(int,input().split())
p = [0 for i in range(n+1)]
a = [0 for i in range(n+1)]
for i in range(m):
    a[int(input())] = 1
for i in range(1,n+1):
    if a[i] == 1:
        p[i] = 0
    elif i == 1:
        p[i] = 1
    elif i == 2:
        p[i] = p[1] + 1
    else:
        p[i] = p[i-1] + p[i-2]
print(p[n] % (10**9 + 7))

Buggy python submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = []
for i in range(m):
    a.append(int(input()))
memo = [0 for i in range(n)]
done = [0 for i in range(n)]
def p(i):
    if done[i-1] == 1:
        return memo[i-1]
    if i in a:
        return 0
    elif i == 1:
        return 1
    elif i == 2:
        return p(1) + 1
    else:
        done[i-1] = 1
        memo[i-1] = p(i-1) + p(i-2)
        return memo[i-1]
print(p(n) % (10**9 + 7))

Fixed submission:
n, m = map(int,input().split())
p = [0 for i in range(n+1)]
a = [0 for i in range(n+1)]
for i in range(m):
    a[int(input())] = 1
for i in range(1,n+1):
    if a[i] == 1:
        p[i] = 0
    elif i == 1:
        p[i] = 1
    elif i == 2:
        p[i] = p[1] + 1
    else:
        p[i] = p[i-1] + p[i-2]
print(p[n] % (10**9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
l, r = map(int,input().split())
set1 = set([i for i in range(l,r+1)])
for i in range(m-1):
    l, r = map(int,input().split())
    set2 = set([i for i in range(l,r+1)])
    set1 = set1 & set2
print(len(set1))

Fixed submission:
n,m = map(int,input().split())
L0, R0 = map(int,input().split())
for i in range(m-1):
    l, r = map(int,input().split())
    L0 = max(L0,l)
    R0 = min(R0,r)

if L0 <= R0:
    print(R0-L0+1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
import numpy as np
n = int(input())
a = list(map(int, input().split()))
l = np.zeros(n)
r = np.zeros(n+1)
r[n] = 0
for i in range(n):
    if i == 0:
        l[0] = 0
    else:
        l[i] = gcd(l[i-1],a[i-1])
for j in range(n-1, -1, -1):
        r[j] = gcd(r[j+1],a[j])
m = 0
for i in range(n):
    m = max(gcd(l[i],r[i+1]),m)
print(int(m))

Fixed submission:
from fractions import gcd
import numpy as np
n = int(input())
a = list(map(int, input().split()))
l = np.zeros(n)
r = np.zeros(n+1)
r[n] = 0
for i in range(n):
    if i == 0:
        l[0] = 0
    else:
        l[i] = gcd(l[i-1],a[i-1])
for j in range(n-1, -1, -1):
        r[j] = gcd(r[j+1],a[j])
m = 0
for i in range(n):
    m = max(gcd(l[i],r[i+1]),m)
print(int(m))

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
max_gcd = 0
for i in range(n):
    if i == 0:
        Gcd = reduce(gcd,a[1:])
    elif i == n-1:
        Gcd = reduce(gcd,a[:n-1])
    else:
        Gcd = reduce(gcd,a[:i] + a[i+1:])
    max_gcd = max(max_gcd,Gcd)
print(max_gcd)

Fixed submission:
from fractions import gcd
import numpy as np
n = int(input())
a = list(map(int, input().split()))
l = np.zeros(n)
r = np.zeros(n+1)
r[n] = 0
for i in range(n):
    if i == 0:
        l[0] = 0
    else:
        l[i] = gcd(l[i-1],a[i-1])
for j in range(n-1, -1, -1):
        r[j] = gcd(r[j+1],a[j])
m = 0
for i in range(n):
    m = max(gcd(l[i],r[i+1]),m)
print(int(m))

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
max_gcd = 0
for i in range(n):
    if i == 0:
        Gcd = reduce(gcd,a[1:])
    elif i == n-1:
        Gcd = reduce(gcd,a[:n-1])
    else:
        Gcd = reduce(gcd,a[:i] + a[i+1:])
    max_gcd = max(max_gcd,Gcd)
print(max_gcd)

Fixed submission:
from fractions import gcd
import numpy as np
n = int(input())
a = list(map(int, input().split()))
l = np.zeros(n)
r = np.zeros(n+1)
r[n] = 0
for i in range(n):
    if i == 0:
        l[0] = 0
    else:
        l[i] = gcd(l[i-1],a[i-1])
for j in range(n-1, -1, -1):
        r[j] = gcd(r[j+1],a[j])
m = 0
for i in range(n):
    m = max(gcd(l[i],r[i+1]),m)
print(int(m))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
cap = [a,b,c,d,e]
p0 = [n,0,0,0,0,0]
time = 0
import copy
while p0[5] != n:
    p1 = copy.copy(p0)
    for i in range(5):
        p1[i+1] += min(p0[i],cap[i])
    for i in range(5):
        p1[i] -= min(p0[i],cap[i])
    time += 1
    p0 = copy.copy(p1)

print(time)

Fixed submission:
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
import math
print(math.ceil(n/min(a,b,c,d,e))+4)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
cap = [a,b,c,d,e]
p0 = [n,0,0,0,0,0]
time = 0
import copy
while p0[5] != n:
    p1 = copy.copy(p0)
    for i in range(5):
        p1[i+1] += min(p0[i],cap[i])
    for i in range(5):
        p1[i] -= min(p0[i],cap[i])
    time += 1
    p0 = copy.copy(p1)

print(time)

Fixed submission:
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
import math
print(math.ceil(n/min(a,b,c,d,e))+4)
Buggy python submission (verdict: Runtime Error):
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
    a = list(map(int,input().split()))
    eq = c
    for j in range(m):
        eq += a[i] * b[i]
    if eq > 0:
        count += 1
print(count)

Fixed submission:
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
    a = list(map(int,input().split()))
    eq = c
    for j in range(m):
        eq += a[j] * b[j]
    if eq > 0:
        count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
n,A,B,C = map(int,input().split(()))
l = [int(input()) for i in range(n)]
inf = 10 ** 9

def dfs(i,a,b,c):
    if i == n:
        if min(a,b,c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return inf
    ret0 = dfs(i+1, a, b, c)
    ret1 = dfs(i+1, a + l[i], b, c) + 10
    ret2 = dfs(i+1, a, b + l[i], c) + 10
    ret3 = dfs(i+1, a, b, c + l[i]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0,0,0,0))


Fixed submission:
n,A,B,C = map(int,input().split())
l = [int(input()) for i in range(n)]
inf = 10 ** 9

def dfs(i,a,b,c):
    if i == n:
        if min(a,b,c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return inf
    ret0 = dfs(i+1, a, b, c)
    ret1 = dfs(i+1, a + l[i], b, c) + 10
    ret2 = dfs(i+1, a, b + l[i], c) + 10
    ret3 = dfs(i+1, a, b, c + l[i]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0,0,0,0))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(1,n+1):
    seven = 0
    five = 0
    three = 0
    while i > 0:
        if i % 10 == 7:
            seven = 1
        elif i % 10 == 3:
            three = 1
        elif i % 10 == 5:
            five = 1
        else:
            break
        i = i // 10
    if i == 0 and seven == 1 and five == 1 and three == 1:
        ans += 1
print(ans)


Fixed submission:
n = int(input())
ans = 0
def dfs(s):
    global ans
    if int(s) > n:
        return
    seven = 0
    five = 0
    three = 0
    for i in range(len(s)):
        if s[i] == "7":
            seven = 1
        elif s[i] == "5":
            five = 1
        elif s[i] == "3":
            three = 1
    if seven == 1 and five == 1 and three == 1:
        ans += 1

    dfs(s + "7")
    dfs(s + "5")
    dfs(s + "3")
    return
dfs("7")
dfs("5")
dfs("3")
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(1,n+1):
    seven = 0
    five = 0
    three = 0
    while i > 0:
        if i % 10 == 7:
            seven = 1
        elif i % 10 == 3:
            three = 1
        elif i % 10 == 5:
            five = 1
        else:
            break
        i = i // 10
    if i == 0 and seven == 1 and five == 1 and three == 1:
        ans += 1
print(ans)

Fixed submission:
n = int(input())
ans = 0
def dfs(s):
    global ans
    if int(s) > n:
        return
    seven = 0
    five = 0
    three = 0
    for i in range(len(s)):
        if s[i] == "7":
            seven = 1
        elif s[i] == "5":
            five = 1
        elif s[i] == "3":
            three = 1
    if seven == 1 and five == 1 and three == 1:
        ans += 1

    dfs(s + "7")
    dfs(s + "5")
    dfs(s + "3")
    return
dfs("7")
dfs("5")
dfs("3")
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split))
ans = 0
temp1 = t - h[0] * 0.006
for i in range(1,n):
    temp2 = t - h[i] * 0.006
    if abs(temp1-a) > abs(temp2-a):
        ans = i
        temp1 = temp2
print(ans)

Fixed submission:
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
ans = 1
temp1 = t - h[0] * 0.006
for i in range(1,n):
    temp2 = t - h[i] * 0.006
    if abs(temp1-a) > abs(temp2-a):
        ans = i + 1
        temp1 = temp2
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split))
ans = 0
temp1 = t - h[0] * 0.006
for i in range(a,n):
    temp2 = t - h[i] * 0.006
    if abs(temp1-a) > abs(temp2-a):
        ans = i
        temp1 = temp2
print(ans)

Fixed submission:
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
ans = 1
temp1 = t - h[0] * 0.006
for i in range(1,n):
    temp2 = t - h[i] * 0.006
    if abs(temp1-a) > abs(temp2-a):
        ans = i + 1
        temp1 = temp2
print(ans)
Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
min_cost = 10**3 + 1
for i in range(n):
    c, t = map(int,input().split())
    if t <= T and c < min_cost:
        min_cost = c
if c != 10**3 + 1:
    print(min_cost)
else:
    print("TLE")

Fixed submission:
N,T = map(int,input().split())
min_cost = 10**3 + 1
for i in range(N):
    c, t = map(int,input().split())
    if t <= T and c < min_cost:
        min_cost = c
if min_cost != 10**3 + 1:
    print(min_cost)
else:
    print("TLE")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
v = list(map(int,input().split()))
even = [[v[i], 0] for i in range(n) if (i+1)%2 == 0]
odd = [[v[i], 0] for i in range(n) if (i+1)%2 == 1]
for i in range(n):
    for j in range(n):
        if (i+1) % 2 == 0 and (j+1) % 2 == 0:
            if even[i//2][0] == even[j//2][0]:
                even[i//2][1] += 1
        elif (i+1) % 2 == 1 and (j+1) % 2 == 1:
            if odd[i//2][0] == odd[j//2][0]:
                odd[i//2][1] += 1
even = sorted(even, key = lambda x: x[1],reverse = True)
odd = sorted(odd, key = lambda x: x[1],reverse = True)
#print(even)
#print(odd)
if even == odd:
    print(n//2)
elif even[0][0] != odd[0][0]:
    print(n - even[0][1] - odd[0][1])
elif even[0][1] >= odd[0][1]:
    for i in range(n//2):
        if odd[i][0] != even[0][0]:
            print(n - even[0][1] - odd[i][1])
            break
else:
    for i in range(n//2):
        if even[i][0] != odd[0][0]:
            print(n - even[i][1] - odd[0][1])
            break
        

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

vo = [0] * (10**5 + 1)
ve = [0] * (10**5 + 1)

for i in range(n):
    if (i+1) % 2 == 0:
        ve[v[i]] += 1
    else:
        vo[v[i]] += 1
ve1 = sorted(ve, reverse = True)
vo1 = sorted(vo, reverse = True)
if vo.index(max(vo)) != ve.index(max(ve)):
    print(n - max(vo) - max(ve))
    
elif max(vo) > max(ve):    
    print(n - max(vo) - ve1[1])
elif max(vo) < max(ve):
    print(n - max(ve) - vo1[1])
else:
    print(n - max(vo) - max(ve1[1], vo1[1]))
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
ans = 1
if k =< len(s):
    if s[:k] == "1" * k:
        ans = 1
    else:
        ans = int(s[k-1])
else:
    for i in range(len(s)):
        if s[i] != "1":
            ans = int(s[i])
            break
print(ans)

Fixed submission:
s = input()
k = int(input())
ans = 1
if k <= len(s):
    if s[:k] == "1" * k:
        ans = 1
    else:
        for i in range(len(s)):
            if s[i] != "1":
                ans = int(s[i])
                break
else:
    for i in range(len(s)):
        if s[i] != "1":
            ans = int(s[i])
            break
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
for i in range(len(s)):
    if s[i] != "1":
        ans = int(s[i])
        break
print(ans)

Fixed submission:
s = input()
k = int(input())
ans = 1
if k <= len(s):
    if s[:k] == "1" * k:
        ans = 1
    else:
        for i in range(len(s)):
            if s[i] != "1":
                ans = int(s[i])
                break
else:
    for i in range(len(s)):
        if s[i] != "1":
            ans = int(s[i])
            break
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
for i in (len(s)):
    if s[i] != "1":
        ans = int(s[i])
        break
print(ans)

Fixed submission:
s = input()
k = int(input())
ans = 1
if k <= len(s):
    if s[:k] == "1" * k:
        ans = 1
    else:
        for i in range(len(s)):
            if s[i] != "1":
                ans = int(s[i])
                break
else:
    for i in range(len(s)):
        if s[i] != "1":
            ans = int(s[i])
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = []
div = -2
i = 0
while n!=0:
    r = n % div
    if r == 0:
        s.append(0)
    else:
        s.append(1)
        n -= (-2) ** i
    div *= 2
    i += 1
ans = ""
for i in range(len(s)):
    ans =  str(s[i]) + ans
if n != 0
    print(ans)
else:
    print(0)

Fixed submission:
n = int(input())
s = []
div = -2
i = 0
while n!=0:
    r = n % div
    if r == 0:
        s.append(0)
    else:
        s.append(1)
        n -= (-2) ** i
    div *= 2
    i += 1
ans = ""
for i in range(len(s)):
    ans =  str(s[i]) + ans
if ans != "":
    print(ans)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 10 ** 9
for i in range(n):
    b = a[i] - (i+1)
    f = 0
    for j in range(n):
        f += abs(a[j] - (b + j + 1))
    ans = min(f,ans)
print(ans)


Fixed submission:
n = int(input())
A = list(map(int, input().split()))
B = [A[i] - (i+1) for i in range(n)]
B.sort()
b = B[n//2]
f = 0
for i in range(n):
    f += abs(B[i] - b)
print(f)
Buggy python submission (verdict: Runtime Error):
n = int(input())
memo = [-1] * (n+1)
import sys
sys.setrecursionlimit(10000)
def f(n):
    if n == 0:
        return 0
    if memo[n] != -1:
        return memo[n]
    res = n
    pow6 = 1
    pow9 = 1
    res = min(res, f(n - 1) + 1)
    while pow6*6 <= n:
        pow6 *= 6
        res = min(res, f(n - pow6) + 1)
        
    while pow9*9 <= n:
        pow9 *= 9
        res = min(res, f(n - pow9) + 1)
        
    memo[n] = res
    return res
print(f(n))


Fixed submission:
n = int(input())
memo = [-1] * (n+1)
import sys
sys.setrecursionlimit(1000000)
def f(n):
    if n == 0:
        return 0
    if memo[n] != -1:
        return memo[n]
    res = n
    pow6 = 1
    pow9 = 1
    res = min(res, f(n - 1) + 1)
    while pow6*6 <= n:
        pow6 *= 6
        res = min(res, f(n - pow6) + 1)
        
    while pow9*9 <= n:
        pow9 *= 9
        res = min(res, f(n - pow9) + 1)
        
    memo[n] = res
    return res
print(f(n))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = n

for i in range(n):
    if i>0 and i< n-1:
        m = s[:i+1].count("W") + s[i+1:].count("E")
    elif i == 0:
        m = s[1:].count("E")
    elif i == n-1:
        m = s[:n-2].count("W")
    ans = min(ans,m)
    
print(ans)
         

Fixed submission:
n = int(input())
s = input()
ans = n
w = [0 for i in range(n)]
e = [0 for i in range(n)]
m = [0 for i in range(n)]
for i in range(1,n):
    if s[i-1] == "W":
        w[i] = w[i-1] + 1
    else:
        w[i] = w[i-1]
for i in range(n-2,-1,-1):
    if s[i+1] == "E":
        e[i] = e[i+1] + 1
    else:
        e[i] = e[i+1]
for i in range(n):
    m[i] = e[i] + w[i]
print(min(m))