Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy
n,k = map(int,input().split())
s = input()
tmp = s[0]
cnt = 1
ans = 0
ss = []
res = [0]
sum = 0
if s[0] == '0':
    ss.append(0)

for i in range(1,n):
    if s[i] == tmp:
        cnt += 1
    else:
        tmp = s[i]
        ss.append(cnt)
        cnt = 1
ss.append(cnt)
if s[-1] == '0':
    ss.append(0)
ll = len(ss)
for i in range(ll):
    sum += ss[i]
    res.append(sum)

if ll//2 <= k:
    print(n)
else:
    for i in range(ll-k*2)[::2]:
        ans = max(ans, res[i+k*2+1]-res[i])
    print(ans)


Fixed submission:
n,k = map(int,input().split())
s = input()
tmp = s[0]
cnt = 1
ans = 0
ss = []
res = [0]
sum = 0
if s[0] == '0':
    ss.append(0)

for i in range(1,n):
    if s[i] == tmp:
        cnt += 1
    else:
        tmp = s[i]
        ss.append(cnt)
        cnt = 1
ss.append(cnt)
if s[-1] == '0':
    ss.append(0)
ll = len(ss)
for i in range(ll):
    sum += ss[i]
    res.append(sum)

if ll//2 <= k:
    print(n)
else:
    for i in range(ll-k*2)[::2]:
        ans = max(ans, res[i+k*2+1]-res[i])
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
s = input()
tmp = s[0]
cnt = 1
ans = 0
ss = []
if s[0] == '0':
    ss.append(0)

for i in range(1,n):
    if s[i] == tmp:
        cnt += 1
    else:
        tmp = s[i]
        ss.append(cnt)
        cnt = 1
ss.append(cnt)
if s[-1] == '0':
    ss.append(0)
ll = len(ss)

if k >= ll//2:
    print(n)
else:
    for i in range(ll-k*2)[::2]:
        ans = max(ans, sum(ss[i:i+k*2+1]))
    print(ans)

Fixed submission:
n,k = map(int,input().split())
s = input()
tmp = s[0]
cnt = 1
ans = 0
ss = []
res = [0]
sum = 0
if s[0] == '0':
    ss.append(0)

for i in range(1,n):
    if s[i] == tmp:
        cnt += 1
    else:
        tmp = s[i]
        ss.append(cnt)
        cnt = 1
ss.append(cnt)
if s[-1] == '0':
    ss.append(0)
ll = len(ss)
for i in range(ll):
    sum += ss[i]
    res.append(sum)

if ll//2 <= k:
    print(n)
else:
    for i in range(ll-k*2)[::2]:
        ans = max(ans, res[i+k*2+1]-res[i])
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x,y,z,k = inpl()
a = inpl()
b = inpl()
c = inpl()
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
q = [[-(a[0] + b[0] + c[0]), 0, 0, 0]]
heapify(q)
old = [(0,0,0)]
for i in range(k):
    k,l,m,n = heappop(q)
    print(-k)
    if l + 1 < x and not (l+1,m,n) in old:
        heappush(q,[-(a[l+1] + b[m] + c[n]), l+1, m, n])
        old.append((l+1,m,n))
    if m + 1 < y and not(l,m+1,n) in old:
        heappush(q,[-(a[l] + b[m+1] + c[n]), l, m+1, n])
        old.append((l,m+1,n))
    if n + 1 < z and not (l,m,n+1)  in old:
        heappush(q,[-(a[l] + b[m] + c[n+1]), l, m, n+1])
        old.append((l,m,n+1))
    # print(q)

Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x,y,z,k = inpl()
a = inpl()
b = inpl()
c = inpl()
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
q = [[-(a[0] + b[0] + c[0]), 0, 0, 0]]
heapify(q)
old = set((0,0,0))
for i in range(k):
    k,l,m,n = heappop(q)
    print(-k)
    if l + 1 < x and not (l+1,m,n) in old:
        heappush(q,[-(a[l+1] + b[m] + c[n]), l+1, m, n])
        old.add((l+1,m,n))
    if m + 1 < y and not(l,m+1,n) in old:
        heappush(q,[-(a[l] + b[m+1] + c[n]), l, m+1, n])
        old.add((l,m+1,n))
    if n + 1 < z and not (l,m,n+1)  in old:
        heappush(q,[-(a[l] + b[m] + c[n+1]), l, m, n+1])
        old.add((l,m,n+1))
    # print(q)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
ans = []
rl = []
for i in range(Q):
    a,b = map(int,input().split())
    rl += [[a,b]]

for i in range(Q):
    count = 0
    for j in range(rl[i][0]-1,rl[i][-1]-1):
        if S[j] == "A" and S[j+1] == "C":
            count += 1
    ans.append(count)
    
for i in range(Q):
    print(ans[i])


Fixed submission:
N,Q = map(int,input().split())
S = input()
lr = []
S_temp = []
S_temp.append(0)
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C":
        S_temp.append(S_temp[i-1] + 1)
    else:
        S_temp.append(S_temp[i-1])
for i in range(Q):
    a,b = map(int,input().split())
    lr.append([a-1,b-1])

for i in range(Q):
    print(S_temp[lr[i][-1]] - S_temp[lr[i][0]])
Buggy python submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,k = inpl()
c = math.gcd(a,b)
res = []
for i in range(1,c+1):
    if a%i == 0 and b%i == 0:
        res.append(i)
res.sort(reverse = True)
print(res[k-1])


Fixed submission:
a,b,k = map(int,input().split())
cnt = 0
tmp = []
for i in range(1,min(a,b)+1):
    if a % i == 0 and b % i == 0:
        cnt += 1
        tmp.append(i)
print(tmp[cnt - k])
Buggy python submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
res = a[0]
for i in range(n-1):
    res = math.gcd(res,a[i+1])
print(res)


Fixed submission:
def gcd(a,b):
    while b:
        a,b = b,a % b
    return a
def monsters(li,n):
    t = temp
    for i in range(n-1):
        t = gcd(li[i+1],t)
    return t

n = int(input())
li_a = list(map(int,input().split()))
temp = li_a[0]
print(monsters(li_a,n))

Buggy python submission (verdict: Runtime Error):
import fraction
def monsters(li,n):
    t = temp
    for i in range(1,n-1):
        t = fraction.gcd(t,li[i+1])
    return t

n = int(input())
li_a = list(map(int,input().split()))
temp = li_a[0]
print(monsters(li_a,n))

Fixed submission:
def gcd(a,b):
    while b:
        a,b = b,a % b
    return a
def monsters(li,n):
    t = temp
    for i in range(n-1):
        t = gcd(li[i+1],t)
    return t

n = int(input())
li_a = list(map(int,input().split()))
temp = li_a[0]
print(monsters(li_a,n))

Buggy python submission (verdict: Runtime Error):
import math 
def monsters(li,n):
    t = temp
    for i in range(1,n-1):
        t = math.gcd(t,li[i+1])
    return t

n = int(input())
li_a = list(map(int,input().split()))
temp = li_a[0]
print(monsters(li_a,n))

Fixed submission:
def gcd(a,b):
    while b:
        a,b = b,a % b
    return a
def monsters(li,n):
    t = temp
    for i in range(n-1):
        t = gcd(li[i+1],t)
    return t

n = int(input())
li_a = list(map(int,input().split()))
temp = li_a[0]
print(monsters(li_a,n))

Buggy python submission (verdict: Runtime Error):
import math 
def monsters(li,n):
    t = temp
    for i in range(1,n-1):
        t = math.gcd(t,li[i+1])
    return t

n = int(input())
li_a = list(map(int,input().split()))
temp = li_a[0]
print(monsters(li_a,n))

Fixed submission:
def gcd(a,b):
    while b:
        a,b = b,a % b
    return a
def monsters(li,n):
    t = temp
    for i in range(n-1):
        t = gcd(li[i+1],t)
    return t

n = int(input())
li_a = list(map(int,input().split()))
temp = li_a[0]
print(monsters(li_a,n))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = sorted(inpl(), reverse = True)
b = [0,2,5,5,4,5,6,3,7,6]
dp = [[0]*(n+1) for _ in range(m+1)]

for i,x in enumerate(a):
    for c in range(b[x],n+1,b[x]):
        va = x * (c//b[x])
        # print(c,va)
        for j in range(n+1):
            if j != 0 and (j % c == 0 or (j >= c and dp[i+1][j-c] != 0)):
                dp[i+1][j] = max(dp[i][j],dp[i+1][j], dp[i+1][j-c]*10 + va)
                continue
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
print(dp[-1][-1])

Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = sorted(inpl(), reverse = True)
b = [0,2,5,5,4,5,6,3,7,6]
dp = [0] * (n+1)

for i in a:
    w,v = b[i],i
    for j in range(n+1):
        if j < w:
            continue
        if j%w == 0 or dp[j-w]:
            dp[j] = max(dp[j], dp[j-w]*10 + v)
    # print(dp)
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = sorted(inpl(), reverse = True)
b = [0,2,5,5,4,5,6,3,7,6]
dp = [['0']*(n+1) for _ in range(m+1)]

for i,x in enumerate(a):
    for c in range(b[x],n+1,b[x]):
        va = str(x) * (c//b[x])
        # print(c,va)
        for j in range(n+1):
            if j != 0 and (j % c == 0 or (j >= c and dp[i+1][j-c] != '0')):
                dp[i+1][j] = max(int(dp[i][j]),int(dp[i+1][j]), int(dp[i+1][j-c] + va))
                dp[i+1][j] = str(dp[i+1][j])
                continue
            dp[i+1][j] = max(int(dp[i+1][j]), int(dp[i][j]))
            dp[i+1][j] = str(dp[i+1][j])
print(dp[-1][-1])

Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = sorted(inpl(), reverse = True)
b = [0,2,5,5,4,5,6,3,7,6]
dp = [0] * (n+1)

for i in a:
    w,v = b[i],i
    for j in range(n+1):
        if j < w:
            continue
        if j%w == 0 or dp[j-w]:
            dp[j] = max(dp[j], dp[j-w]*10 + v)
    # print(dp)
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = [int(i) for i in input().split()]
inf = 10**9
dp = [inf] * n
dp[0] = 0

for i in range(n-1):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j])) 

print(dp[n-1])


Fixed submission:
n,k = map(int,input().split())
h = [int(i) for i in input().split()]
inf = 10**9
dp = [inf] * n
dp[0] = 0

for i in range(n-1):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j])) 

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = [int(i) for i in input().split()]
inf = 10**9
dp = [inf] * n
dp[0] = 0

for i in range(n-1):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j])) 

print(dp[n-1])


Fixed submission:
n,k = map(int,input().split())
h = [int(i) for i in input().split()]
inf = 10**9
dp = [inf] * n
dp[0] = 0

for i in range(n-1):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j])) 

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict
import sys,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n,w = inpl()
ww = [0] * n
vv = [0] * n
for i in range(n):
    ww[i],vv[i] = inpl()
dp = [[0 for i in range(w+1)] for j in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j >= ww[i]:
            dp[i+1][j] = max(dp[i][j], dp[i][j-ww[i]]+vv[i])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[n][w])


            


Fixed submission:
from collections import Counter,defaultdict
import sys,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n,w = inpl()
ww = [0] * n
vv = [0] * n
for i in range(n):
    ww[i],vv[i] = inpl()
dp = [[0 for i in range(w+1)] for j in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j >= ww[i]:
            dp[i+1][j] = max(dp[i][j], dp[i][j-ww[i]]+vv[i])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[n][w])
Buggy python submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,W = inpl()
value = []
weight = []
for i in range(n):
    a,b = inpl()
    value.append(a)
    weight.append(b)
dp = [[0 for i in range(n+5)] for j in range(W+5)]
for i in range(n):
    for w in range(W+1):
        if w >= weight[i]:
            dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]
print(dp[n][w])

# n=6
# (weight,value)=(2,3),(1,2),(3,6),(2,1),(1,3),(5,85)
# W=8

# >> 91

Fixed submission:
from collections import Counter,defaultdict
import sys,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n,w = inpl()
ww = [0] * n
vv = [0] * n
for i in range(n):
    ww[i],vv[i] = inpl()
dp = [[mod for i in range(sum(vv)+1)] for j in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(sum(vv)+1):
        if j >= vv[i]:
            dp[i+1][j] = min(dp[i][j], dp[i][j-vv[i]]+ww[i])
        else:
            dp[i+1][j] = dp[i][j]
for i in range(sum(vv)+1)[::-1]:
    if dp[n][i] <= w:
        print(i)
        break
Buggy python submission (verdict: Runtime Error):
import sympy
n,p = map(int,input().split())
cnt = sympy.factorint(p)
ans = 1

for i in cnt:
    while cnt[i] >= n:
        ans *= i
        cnt[i] -= n
print(ans)

Fixed submission:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
#素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n,p = inpl()
soin = prime_factorize(p)
cnt = Counter(soin)
res = 1
for key in cnt.keys():
    if cnt[key] >= n:
        res *= key ** (cnt[key]//n)
print(res)
Buggy python submission (verdict: Runtime Error):
import math,fractions
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
a = Counter(v[1::2]).most_common()
b = Counter(v[0::2]).most_common()
a.append(0,0)
b.append(0,0)

if a[0][0] != b[0][0]:
    print(n//2 - a[0][1] + n//2 - b[0][1])
else:
    tmp_x = n//2 - a[1][1] + n//2 - b[0][1]
    tmp_y = n//2 - a[0][1] + n//2 - b[1][1]
    print(min(tmp_x, tmp_y))


Fixed submission:
import math,fractions
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
a = [v[i] for i in range(n) if i%2]
b = [v[i] for i in range(n) if i%2==0]
cnt_a = Counter(a)
cnt_b = Counter(b)
max_a = cnt_a.most_common()[0][1]
max_b = cnt_b.most_common()[0][1]

str_a = cnt_a.most_common()[0][0]
str_b = cnt_b.most_common()[0][0]

max_2a = 0
max_2b = 0

for i in cnt_a:
    if str_a != i  and cnt_a[i] > max_2a:
        max_2a = cnt_a[i]

for i in cnt_b:
    if str_b != i  and cnt_b[i] > max_2b:
        max_2b = cnt_b[i]

if str_a != str_b:
    print(n//2 - max_a + n//2 - max_b)
else:
    tmp_a = n//2 - max_2a + n//2 - max_b
    tmp_b = n//2 - max_a + n//2 - max_2b
    print(min(tmp_a,tmp_b))

Buggy python submission (verdict: Runtime Error):
import math,fractions
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
a = Counter(v[1::2]).most_common()
b = Counter(v[0::2]).most_common()

if a[0][0] != b[0][0]:
    print(n//2 - a[0][1] + n//2 - b[0][1])
else:
    tmp_x = n//2 - a[1][1] + n//2 - b[0][1]
    tmp_y = n//2 - a[0][1] + n//2 - b[1][1]
    print(min(tmp_x, tmp_y))


Fixed submission:
import math,fractions
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
a = [v[i] for i in range(n) if i%2]
b = [v[i] for i in range(n) if i%2==0]
cnt_a = Counter(a)
cnt_b = Counter(b)
max_a = cnt_a.most_common()[0][1]
max_b = cnt_b.most_common()[0][1]

str_a = cnt_a.most_common()[0][0]
str_b = cnt_b.most_common()[0][0]

max_2a = 0
max_2b = 0

for i in cnt_a:
    if str_a != i  and cnt_a[i] > max_2a:
        max_2a = cnt_a[i]

for i in cnt_b:
    if str_b != i  and cnt_b[i] > max_2b:
        max_2b = cnt_b[i]

if str_a != str_b:
    print(n//2 - max_a + n//2 - max_b)
else:
    tmp_a = n//2 - max_2a + n//2 - max_b
    tmp_b = n//2 - max_a + n//2 - max_2b
    print(min(tmp_a,tmp_b))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,q = inpl()
g = [[0]*n for _ in range(n)]
for _ in range(m):
    l,r = inpl()
    l,r = l-1, r-1
    g[l][r] += 1
for _ in range(q):
    a,b = inpl()
    a,b = a-1,b-1
    cnt = 0
    for i in range(a,b+1):
        for j in range(i,b+1):
            cnt += g[i][j] 
    print(cnt)

Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m,q = inpl()
lr = [inpl() for i in range(m)]
st = [inpl() for i in range(q)]
cnt = [[0 for j in range(n)] for i in range(n)]

for i in lr:
    a,b = i
    cnt[a-1][b-1] += 1
for i in range(n):
    for j in range(i,n-1):
        cnt[i][j+1] += cnt[i][j]
# pprint.pprint(cnt)
for i in st:
    cc = 0
    a,b = i
    for _ in range(a-1,b):
        cc += cnt[_][b-1]
    print(cc)
Buggy python submission (verdict: Runtime Error):
from statistics import mean
import math
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
    a[i] -= i+1
a_fl = math.floor(median(a))
a_ce = math.ceil(median(a))
ans_fl=ans_ce=0

for i in range(n):
    ans_fl += abs(a[i]-a_fl)
    ans_ce += abs(a[i]-a_ce)
print(int(min(ans_fl,ans_ce)))

Fixed submission:
from statistics import median
import math
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
    a[i] -= i+1
a_fl = math.floor(median(a))
a_ce = math.ceil(median(a))
ans_fl=ans_ce=0

for i in range(n):
    ans_fl += abs(a[i]-a_fl)
    ans_ce += abs(a[i]-a_ce)
print(int(min(ans_fl,ans_ce)))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
k = inp()
n = len(s)
t = []
for i in s:
    t.append(ord(i) - ord('a'))
se = set()
for i in range(26):
    for j in range(n):
        if t[j] == i:
            for l in range(j,n):
                tmp = s[j:l+1]
                if tmp == '':
                    continue
                se.add(tmp)
    if len(se) >= k:
        break
res = sorted(list(se))
print(res[k-1])

Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
k = inp()
n = len(s)
t = []
for i in s:
    t.append(ord(i) - ord('a'))
se = set()
for i in range(26):
    for j in range(n):
        if t[j] == i:
            for l in range(j,min(j+k,n)):
                tmp = s[j:l+1]
                if tmp == '':
                    continue
                se.add(tmp)
    if len(se) >= k:
        break
res = sorted(list(se))
print(res[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
n = len(s)
se = set()
k = inp()
for i in range(n):
    for j in range(n):
        if s[i:j+1] == '':
            continue
        se.add(s[i:j+1])
res = sorted(list(se))
# print(res)
print(res[k-1])

Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
k = inp()
n = len(s)
t = []
for i in s:
    t.append(ord(i) - ord('a'))
se = set()
for i in range(26):
    for j in range(n):
        if t[j] == i:
            for l in range(j,min(j+k,n)):
                tmp = s[j:l+1]
                if tmp == '':
                    continue
                se.add(tmp)
    if len(se) >= k:
        break
res = sorted(list(se))
print(res[k-1])