Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split()))

def median(x, i):
    x = sorted(x)
        
    return(x[i])

def algo(x):
    l = len(x)
    t = (l + 1) // 2
    while True:
        p = x[len(x) // 2]
        a = []
        b = []
        for i in x:
            if i <= p:
                a.append(i)
            else:
                b.append(i)
        if len(a) == 0:
            return median(b, t - 1)
        elif len(b) == 0:
            return median(a, t - 1)
        elif len(a) >= t:
            x = a
        else:
            x = b
            t = t - len(a)


for i in range(n):
    a = x.pop(i)
    print(algo(x))
    x.insert(i, a)

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

y = sorted(x)

for i in x:
    if i < y[len(y) // 2]:
        print(y[len(y) // 2])
    else:
        print(y[len(y) // 2 - 1])

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

def median(x):
    x = sorted(x)

    return(x[(len(x) + 1) // 2 - 1])

for i in range(n):
    a = x.pop(i)
    print(median(x))
    x.insert(i, a)

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

y = sorted(x)

for i in x:
    if i < y[len(y) // 2]:
        print(y[len(y) // 2])
    else:
        print(y[len(y) // 2 - 1])

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy

n = int(input())
x = list(map(int, input().split()))

def median(x, i):
    y = deepcopy(x)
    y.pop(i)
    y = sorted(y)

    return(y[(len(y) + 1) // 2 - 1])

for i in range(n):
    print(median(x, i))

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

y = sorted(x)

for i in x:
    if i < y[len(y) // 2]:
        print(y[len(y) // 2])
    else:
        print(y[len(y) // 2 - 1])
Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy

n = int(input())
a = [0] + list(map(int, input().split())) + [0]

for i in range(1, n + 1):
    total = 0
    b = deepcopy(a)
    b.pop(i)
    for j in range(n):
        total += abs(b[j + 1] - b[j])
    print(total)

Fixed submission:
n = int(input())
a = [0] + list(map(int, input().split())) + [0]

costs = []
for i in range(n + 1):
    costs.append(abs(a[i + 1] - a[i]))

s = sum(costs)
for i in range(n):
    print(s - costs[i] - costs[i + 1] + abs(a[i] - a[i + 2]))
Buggy python submission (verdict: Runtime Error):
a = int(print())
if a%2 ==0:print(a)
else:print(2*a)


Fixed submission:
a = input()
a = int(a)
if a%2 ==0:print(a)
else:print(2*a)

Buggy python submission (verdict: Runtime Error):
a = print()
if a%2 ==0:print(a)
else:print(2*a)

Fixed submission:
a = input()
a = int(a)
if a%2 ==0:print(a)
else:print(2*a)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = for list(map(int,input().split()))
min = b[0]
max = b[0]
for i in range(a):
    if b[i] < min:min=b[i]
    if b[i] > max:max=b[i]
print(max-min)


Fixed submission:
a = int(input())
b = list(map(int,input().split()))
min = b[0]
max = b[0]
for i in range(a):
    if b[i] < min:min=b[i]
    if b[i] > max:max=b[i]
print(max-min)

Buggy python submission (verdict: Runtime Error):
a = int(input)
b = map(int,input().split())
min = b[0]
max = b[0]
for i in range(a):
    if b[i] < min:min=b[i]
    if b[i] > max:max=b[i]
print(max-min)

Fixed submission:
a = int(input())
b = list(map(int,input().split()))
min = b[0]
max = b[0]
for i in range(a):
    if b[i] < min:min=b[i]
    if b[i] > max:max=b[i]
print(max-min)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = list(map(int,input().split()))

table = [1,1]
while len(table) <= N:
    temp = table[0]
    for i in range(len(table)-1):
        table[i+1] += temp
        temp = table[i+1]- temp
        table[i+1] %= M
    table.append(1)


S = [1]

rev2 = pow(2, M-2, M)
base = pow(2, N, M)
ans = 0
S = [1]
for K in range(N+1):
    res = table[K] % M
    res = (res * pow(2, pow(2, N - K, M-1), M)) % M
    b = 1
    v = 0
    T = [0]*(K+2)
    for L in range(K):
        T[L+1] = s = (S[L] + (L+1)*S[L+1]) % M
        v += s * b
        b = (b * base) % M
    v += b
    T[K+1] = 1
    S = T
    res = (res * v) % M
    if K % 2:
        ans -= res
    else:
        ans += res
    ans %= M

    base = (base * rev2) % M
print(ans)


Fixed submission:
N, M = map(int, input().split())
fact = [1]*(N+1)
rfact = [1]*(N+1)
for i in range(1, N+1):
    fact[i] = r = (i * fact[i-1]) % M
    rfact[i] = pow(r, M-2, M)

S = [1]

rev2 = pow(2, M-2, M)
base = pow(2, N, M)
ans = 0
S = [1]
for K in range(N+1):
    res = (fact[N] * rfact[K] * rfact[N-K]) % M
    res = (res * pow(2, pow(2, N - K, M-1), M)) % M
    b = 1
    v = 0
    T = [0]*(K+2)
    for L in range(K):
        T[L+1] = s = (S[L] + (L+1)*S[L+1]) % M
        v += s * b
        b = (b * base) % M
    v += b
    T[K+1] = 1
    S = T
    res = (res * v) % M
    if K % 2:
        ans -= res
    else:
        ans += res
    ans %= M

    base = (base * rev2) % M
print(ans)

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

table = [1,1]
while len(table) <= N:
    temp = table[0]
    for i in range(len(table)-1):
        table[i+1] += temp
        temp = table[i+1]- temp
        table[i+1] %= M
    table.append(1)


S = [1]

rev2 = pow(2, M-2, M)
base = pow(2, N, M)
ans = 0
S = [1]
for K in range(N+1):
    res = table[K] % M
    res = (res * pow(2, pow(2, N - K, M-1), M)) % M
    b = 1
    v = 0
    T = [0]*(K+2)
    for L in range(K):
        T[L+1] = s = (S[L] + (L+1)*S[L+1]) % M
        v += s * b
        b = (b * base) % M
    v += b
    T[K+1] = 1
    S = T
    res = (res * v) % M
    if K % 2:
        ans -= res
    else:
        ans += res
    ans %= M

    base = (base * rev2) % M
print(ans)


Fixed submission:
N, M = map(int, input().split())
fact = [1]*(N+1)
rfact = [1]*(N+1)
for i in range(1, N+1):
    fact[i] = r = (i * fact[i-1]) % M
    rfact[i] = pow(r, M-2, M)

S = [1]

rev2 = pow(2, M-2, M)
base = pow(2, N, M)
ans = 0
S = [1]
for K in range(N+1):
    res = (fact[N] * rfact[K] * rfact[N-K]) % M
    res = (res * pow(2, pow(2, N - K, M-1), M)) % M
    b = 1
    v = 0
    T = [0]*(K+2)
    for L in range(K):
        T[L+1] = s = (S[L] + (L+1)*S[L+1]) % M
        v += s * b
        b = (b * base) % M
    v += b
    T[K+1] = 1
    S = T
    res = (res * v) % M
    if K % 2:
        ans -= res
    else:
        ans += res
    ans %= M

    base = (base * rev2) % M
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
l = y[n/2-2]
r = y[n/2-1]
for i in range(n):
    if x[i] <= l:print(r)
    else:print(l)


Fixed submission:
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
l = y[n//2-1]
r = y[n//2]
for i in range(n):
    if x[i] <= l:print(r)
    else:print(l)

Buggy python submission (verdict: Runtime Error):
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
l = y[n/2-2]
r = y[n/2-1]
for i in range(n):
    if x[I] <= l:print(r)
    else:print(l)


Fixed submission:
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
l = y[n//2-1]
r = y[n//2]
for i in range(n):
    if x[i] <= l:print(r)
    else:print(l)

Buggy python submission (verdict: Runtime Error):
n = list(map(int,input().split()))
x = list(map(int,input().split()))
y = sorted(x)
l = y[n/2-2]
r = y[n/2-1]
for i in range(n):
    if x[i] <= l:print(r)
    else:print(l)


Fixed submission:
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
l = y[n//2-1]
r = y[n//2]
for i in range(n):
    if x[i] <= l:print(r)
    else:print(l)

Buggy python submission (verdict: Runtime Error):
n = list(map(int,input().split()))
x = list(map(int,input().split()))
y = sorted(x)
l = y[n/2-2]
r = y[n/2-1]
for i in range(n):
    if x[I] <= l:print(r)
    else:print(l)

Fixed submission:
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
l = y[n//2-1]
r = y[n//2]
for i in range(n):
    if x[i] <= l:print(r)
    else:print(l)
Buggy python submission (verdict: Runtime Error):
import bisect
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
mid = bisect.bisect_left(y,y[-1]/2)
if y[-1]/2-x[mid]>=x[mid+1]-y[-1]/2:print(y[-1],x[mid+1])
else:print(y[-1],x[mid])

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

y = max(x)
sub = y
res = 0
for i in range(n):
    if abs(float(y/2-x[i])) < sub and x[i] != y:
        sub = abs(float(y/2-x[i]))
        res = x[i]

print(y,res)
Buggy python submission (verdict: Runtime Error):
h,w = list(map(int,input().split()))
s = []
for i in range(h):
    s.append(input())

con = []

for i in range(h):
    for j in range(i+1,h):
        ij = []
        ji = []
        for k in range(w):
            ij.append(s[i][k]+s[j][k])
            ji.append(s[j][k]+s[i][k])
        if sorted(ij) == sorted(ji):
            con.append([i,j])

rest = set()
for i in range(h):
    rest.add(i)
for x in con:
    if x[0] in rest and x[1] in rest:
        rest -= {x[0],x[1]}

if len(rest) == 0:print('YES')
elif len(rest) == 1 and [rest[0],rest[0]] in con:print('YES')
else:print('NO')


Fixed submission:
H, W = map(int, input().split())
S = [input() for i in range(H)]
 
def check(l):
    u = [0]*W
    mid = W % 2
    for i in range(W):
        if u[i]:
            continue
        for j in range(i+1, W):
            for p, q in l:
                sp = S[p]; sq = S[q]
                if sp[i] != sq[j] or sp[j] != sq[i]:
                    break
            else:
                u[j] = 1
                break
        else:
            if mid:
                for p, q in l:
                    sp = S[p]; sq = S[q]
                    if sp[i] != sq[i]:
                        break
                else:
                    mid = 0
                    continue
            break
    else:
        return 1
    return 0
 
def make(c, l, u, p):
    while c in u:
        c += 1
    if c == H:
        if check(l):
            print("YES")
            exit(0)
        return
    if p:
        l.append((c, c))
        make(c+1, l, u, 0)
        l.pop()
    for i in range(c+1, H):
        if i in u:
            continue
        u.add(i)
        l.append((c, i))
        make(c+1, l, u, p)
        l.pop()
        u.remove(i)
 
make(0, [], set(), H%2)
print("NO")
Buggy python submission (verdict: Runtime Error):
N = int(input())
c = -1
s = 0
for i in range(N):
    ai,bi = map(int,input().split())
    s += ai
    if ai > bi:
        if c == -1:
            c = bi
        if bi < c:
            c = bi
if c == -1:
    print(0)
else:
    print(s-c)


Fixed submission:
x = list(map(int,input().split()))
x.sort()
a = x[2]-x[0]
b = x[2]-x[1]

if a%2 == 0 and b%2 == 0:print(a//2+b//2)
if a%2 == 0 and b%2 == 1:print(a//2+(b+1)//2+1)
if a%2 == 1 and b%2 == 0:print((a+1)//2+b//2+1)
if a%2 == 1 and b%2 == 1:print((a-1)//2+(b-1)//2+1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
r = list(map(int,input().split()))
l1 = max(l)
r1 = max(r)
left = 1
if l[0] == l1:left = 0

right = n-2
if r[-1] == l1:right = n-1

res = 1
if l1 != r1:print(0)
else:
    while l[left] != l1:
        if l[left] == l[left-1]:
            res *= l[left]%1000000007
        left += 1
    while r[right] != r1:
        if r[right] == r[right+1]:
            res *= r[right]%1000000007
        right -=1

    if  left > right:print(0)
    else:
        if  left < right:
            res *= l1**(right-left-1)

        print(res%1000000007)




Fixed submission:
n = int(input())
l = list(map(int,input().split()))
r = list(map(int,input().split()))
l1 = max(l)
r1 = max(r)
left = 1
if l[0] == l1:left = 0

right = n-2
if r[-1] == l1:right = n-1

res = 1
if l1 != r1:print(0)
else:
    while l[left] != l1:
        if l[left] == l[left-1]:
            res = (res*l[left])%1000000007
        left += 1
    while r[right] != r1:
        if r[right] == r[right+1]:
            res = (res*r[right])%1000000007
        right -=1

    if  left > right:print(0)
    else:
        if  left < right:
            for i in range(right-left-1):
                res = (res*l1)%1000000007

        print(res%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
r = list(map(int,input().split()))
l1 = max(l)
r1 = max(r)
left = 1
if l[0] == l1:left = 0

right = n-2
if r[-1] == l1:right = n-1

res = 1
if l1 != r1:print(0)
else:
    while l[left] != l1:
        if l[left] == l[left-1]:
            res *= l[left]
        left += 1
    while r[right] != r1:
        if r[right] == r[right+1]:
            res *= r[right]
        right -=1

    if  left > right:print(0)
    else:
        if  left < right:
            res *= l1**(right-left-1)

        print(res%1000000007)




Fixed submission:
n = int(input())
l = list(map(int,input().split()))
r = list(map(int,input().split()))
l1 = max(l)
r1 = max(r)
left = 1
if l[0] == l1:left = 0

right = n-2
if r[-1] == l1:right = n-1

res = 1
if l1 != r1:print(0)
else:
    while l[left] != l1:
        if l[left] == l[left-1]:
            res = (res*l[left])%1000000007
        left += 1
    while r[right] != r1:
        if r[right] == r[right+1]:
            res = (res*r[right])%1000000007
        right -=1

    if  left > right:print(0)
    else:
        if  left < right:
            for i in range(right-left-1):
                res = (res*l1)%1000000007

        print(res%1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
s = [int(i=='#') for i in input()]

idx = [i for i, x in enumerate(s)
       if x==1]

if len(idx)==0 or len(idx)==n:
  print(0)
  
else:  
  s = np.array(s)

  ans = []

  for i in idx:
    s_ = np.array([0]*(i) + [1]*(n-i))
    ans.append((s!=s_).sum())

  print(np.min(ans))

Fixed submission:
import numpy as np

n = int(input())
s = [int(i=='#') for i in input()]

blacks = 0
whites = np.sum(np.array(s)==0)
ans = [blacks+whites]

for x in s:
  if x==1:
    blacks += 1
  else:
    whites -= 1

  ans.append(blacks + whites)

print(np.min(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, k = [int(i) for i in input().split()]
s = input()

ones = [len(x) for x in s.replace('0', ' ').split()]
zeros = [len(x) for x in s.replace('1', ' ').split()]

if s[0]=='0':
  ones = [0] + ones
if s[-1]=='0':
  ones = ones + [0]

if k >= len(zeros):
  result = n
else: 
  result = [
    np.sum(ones[i:i+k+1]) + np.sum(zeros[i:i+k])
    for i in range(len(zeros)-k+1)]
  result = max(result)

print(result)

Fixed submission:
import numpy as np

n, k = [int(i) for i in input().split()]
s = input()

ones = [len(x) for x in s.replace('0', ' ').split()]
zeros = [len(x) for x in s.replace('1', ' ').split()]

if s[0]=='0':
  ones = [0] + ones
if s[-1]=='0':
  ones = ones + [0]
  
ones = np.array(ones)
zeros = np.array(zeros)

if k >= len(zeros):
  result = n
else: 
  result = [
    np.sum(ones[i:i+k+1]) + np.sum(zeros[i:i+k])
    for i in range(len(zeros)-k+1)]
  result = max(result)

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, k = [int(i) for i in input().split()]
s = input()

ones = [len(x) for x in s.replace('0', ' ').split()]
zeros = [len(x) for x in s.replace('1', ' ').split()]

if s[0]=='0':
  ones = [0] + ones
if s[-1]=='0':
  ones = ones + [0]

if k >= len(zeros):
  result = n
else: 
  result = [
    np.sum(ones[i:i+k+1]) + np.sum(zeros[i:i+k])
    for i in range(len(zeros)) if i+k+1 <= len(ones)]
  result = max(result)

print(result)

Fixed submission:
import numpy as np

n, k = [int(i) for i in input().split()]
s = input()

ones = [len(x) for x in s.replace('0', ' ').split()]
zeros = [len(x) for x in s.replace('1', ' ').split()]

if s[0]=='0':
  ones = [0] + ones
if s[-1]=='0':
  ones = ones + [0]
  
ones = np.array(ones)
zeros = np.array(zeros)

if k >= len(zeros):
  result = n
else: 
  result = [
    np.sum(ones[i:i+k+1]) + np.sum(zeros[i:i+k])
    for i in range(len(zeros)-k+1)]
  result = max(result)

print(result)
Buggy python submission (verdict: Runtime Error):
N, Y = [int(i) for input().split()]

ans = None

for i in range(N+1):
    for j in range(i+1):
        y = (N-i)*10000 + (i-j)*5000 + j*1000
        if y == Y:
            ans=(i, j)
            break
    if y == Y:
        break
        
if ans:
    answer = ' '.join(
        [str(N-ans[0]), str(ans[0]-ans[1]), 
         str(ans[1])])
else:
    answer = '-1 -1 -1'
    
print(answer)

Fixed submission:
N, Y = [int(i) for i in input().split()]

ans = None

for i in range(N+1):
    for j in range(i+1):
        y = (N-i)*10000 + (i-j)*5000 + j*1000
        if y == Y:
            ans=(i, j)
            break
    if y == Y:
        break
        
if ans:
    answer = ' '.join(
        [str(N-ans[0]), str(ans[0]-ans[1]), 
         str(ans[1])])
else:
    answer = '-1 -1 -1'
    
print(answer)
Buggy python submission (verdict: Runtime Error):
sx = int(input())
sy = int(input())
tx = int(input())
ty = int(input())

dx = tx - sx
dy = ty - sy

p1 = dy * 'U' + dx * 'R'
p2 = dy * 'D' + dx * 'L'
p3 = 'D' + (dx + 1) * 'R' + \
	(dy + 1) * 'U' + 'L'
p4 = 'U' + (dx + 1) * 'L' + \
	(dy + 1) * 'D' + 'R'
  
print(p1 + p2 + p3 + p4)

Fixed submission:
sx, sy, tx, ty = [
  int(i) for i in input().split()]

dx = tx - sx
dy = ty - sy

p1 = dy * 'U' + dx * 'R'
p2 = dy * 'D' + dx * 'L'
p3 = 'D' + (dx + 1) * 'R' + \
	(dy + 1) * 'U' + 'L'
p4 = 'U' + (dx + 1) * 'L' + \
	(dy + 1) * 'D' + 'R'
  
print(p1 + p2 + p3 + p4)
Buggy python submission (verdict: Runtime Error):

def dp(i, h, c):
    if i == len(h)-1:
        return c
    elif i == len(h)-2:
        return dp(i+1, h, c + abs(h[i] - h[i+1]))
    return min(dp(i+1, h, c + abs(h[i] - h[i+1])), dp(i+2, h, c + abs(h[i] - h[i+2])))

if __name__ == '__main__':
    n = int(input())
    h = list(map(int, input().split()))
    c = 0

    print(dp(0, h, c))


Fixed submission:
if __name__ == '__main__':
    n = int(input())
    h = list(map(int, input().split()))
    c = [0] * n
    c[1] = abs(h[1] - h[0])

    for i in range(2, n):
        c[i] = min(c[i-1] + abs(h[i] - h[i-1]), c[i-2] + abs(h[i] - h[i-2]))

    print(c.pop())
Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [0]*n

for i in range(1, n):
    s = min(k, i)
    t = []
    for j in range(i-s, i):
        t.append(dp[j] + abs(h[i] - h[j]))
    dp[i] = min(t)

print(dp[-1])


Fixed submission:
import numpy as np

n, k = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))
dp = np.zeros(n)

for i in range(1, n):
    s = min(k, i)
    dp[i] = np.min(dp[i-s:i] + np.abs(h[i] - h[i-s:i]))

#    for j in range(i-s, i):
#        t.append(dp[j] + abs(h[i] - h[j]))

print(int(dp[-1]))
Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    print(max(A) - min(B))


Fixed submission:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    print(max(A) - min(A))
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = []
    ans = 10**9

    for i, a in enumerate(A):
        B.append(a - i - 1)

    for b in set(B):
        tmp = 0
        for i, a in enumerate(A):
            tmp += abs(a - i - b - 1)
        ans = min(ans, tmp)

    print(ans)


Fixed submission:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = []
    ans = 0
 
    for i, a in enumerate(A):
        B.append(a - i - 1)

    B.sort()

    b = B[len(B)//2]
    for i, a in enumerate(A):
        ans += abs(a - b - i - 1)

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = []
    ans = 10**9

    for i, a in enumerate(A):
        B.append(a - i - 1)

    for b in B:
        tmp = 0
        for i, a in enumerate(A):
            tmp += abs(a - i - b - 1)
        ans = min(ans, tmp)

    print(ans)


Fixed submission:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = []
    ans = 0
 
    for i, a in enumerate(A):
        B.append(a - i - 1)

    B.sort()

    b = B[len(B)//2]
    for i, a in enumerate(A):
        ans += abs(a - b - i - 1)

    print(ans)
Buggy python submission (verdict: Runtime Error):
#/usr/bin/env python3

import math

if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    print(max(1, math.ceil((len(A) - K) / (K-1)) + 1))


Fixed submission:
if __name__ == '__main__':
    S = list(input())
    n = 0
    for i in S:
        if i == '+':
            n = n + 1
        else:
            n = n - 1

    print(n)
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    xmin = min(a)
    xmax = max(a)

    ans = count = 0
    for x in range(xmin, xmax+1):
        for i in a:
            if i - 1 <= x <= i + 1:
                count += 1

        ans = max(ans, count)
        count = 0

    print(ans)




Fixed submission:
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    x = [0]*10**5

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

    ans = 0
    for i in range(len(x)):
        count = 0
        if i == 0:
            ans = max(x[0] + x[1], ans)
        elif i == len(x)-1:
            ans = max(x[len(x)-2] + x[len(x)-1], ans)
        else:
            ans = max(x[i-1] + x[i] + x[i+1], ans)

    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
S = input()

length = len(S)
i = length

while i > 0:
    if S[i-5:i] == 'dream':
        i -= 5
    elif S[i-7:i] == 'dreamer':
        i -= 7
    elif S[i-5:i] == 'erase':
        i -= 5
    elif S[i-6:i] == 'eraser':
        i -= 6
    else:
        print('NO')
    
print('YES')


Fixed submission:
import sys
S = input()[::-1]

length = len(S)
i = 0

while i < length:
    if S[i:i+5] == 'dream'[::-1]:
        i += 5
    elif S[i:i+7] == 'dreamer'[::-1]:
        i += 7
    elif S[i:i+5] == 'erase'[::-1]:
        i += 5
    elif S[i:i+6] == 'eraser'[::-1]:
        i += 6
    else:
        print('NO')
        sys.exit()
    
print('YES')
Buggy python submission (verdict: Runtime Error):
import re
s=input()
r=[0]
for i in re.finditer("[ACGT]+", s):
    r.append(len(i[0]))
print(max(r))


Fixed submission:
import re
s=input()
r=[0]
for i in re.finditer("[ACGT]+", s):
    r.append(len(i.group()))
print(max(r))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int, input().split())
A,B=[],[]
for i in range(N):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)

R,S=M,0
while R!=0:
    mloc=A.index(min(A))
    AA=A.pop(mloc)
    BB=B.pop(mloc)
    if BB>=R:
        S+=AA*R;R=0
    else:
        S+=AA*BB;R-=BB
print(S)



Fixed submission:
N,M=map(int, input().split())
A,B=[],[]
for i in range(N):
    A.append(list(map(int, input().split())))
A.sort(key=lambda x:x[0])
R,S=M,0
for a in A:
    if a[1]>=R:
        S+=a[0]*R;R=0
    else:
        S+=a[0]*a[1];R-=a[1]
    if R==0: break
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
import re
import copy
s=input()
sr,ss=copy.deepcopy(s),""
while ss!=sr:
    sr,ss=ss,re.sub("01|10","",ss if sr!=s else s)
print(len(s)-len(ss))


Fixed submission:
s=input();print(min(s.count("1"),s.count("0"))*2)