Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
arr = [int(x) for x in input().split()]

def my_index(arr, x, default = -1):
    if x in arr:
        return arr.index(x)
    else:
        return default

idx = my_index(arr, 1)

if idx == -1:
    print(-1)
else:
    search = 2
    while idx < n:
        s_arr = arr[idx:]
        n_idx = my_index(s_arr, search)
        if n_idx == -1:
            break
        idx += n_idx
        search += 1
    
    print(n - search + 1)

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

ans = 0
current = 1
flag = False

for a in a_list:
    if a != current:
        ans += 1
    else:
        current += 1
        flag = True

if flag:
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
import numpy as np

A = int(input())

candidates = np.arange(A // 2) + 1
candidates = candidates[A % candidates == 0]

distances = (A // candidates) - 1 + candidates - 1

print(np.min(distances))

Fixed submission:
import numpy as np

A = int(input())

tmp = int(np.floor(np.sqrt(A)))
for i in range(tmp):
    if A % (tmp - i) == 0:
        base1 = tmp - i
        break
base2 = A // base1

print(base1 + base2 - 2)
Buggy python submission (verdict: Runtime Error):
n = input()
digit = len(str(n))

count = 0
for i in range(digit - 1):
  if (i + 1) % 2 == 1:
    count += 10 ** (i + 1) - (10 ** i)

if digit % 2 == 1:
  count += n - 10 ** (digit - 1) + 1

print(count)

Fixed submission:
n = int(input())
digit = len(str(n))

count = 0
for i in range(digit - 1):
  if (i + 1) % 2 == 1:
    count += 10 ** (i + 1) - (10 ** i)

if digit % 2 == 1:
  count += n - 10 ** (digit - 1) + 1

print(count)

Buggy python submission (verdict: Runtime Error):
n = input()
digit = len(str(n))

count = -1
for i in range(digit - 1):
  if (i + 1) % 2 == 1:
    count += 10 ** (i + 1)

if digit % 2 == 1:
  count += n - 10 ** (digit - 1) + 1

print(count)

Fixed submission:
n = int(input())
digit = len(str(n))

count = 0
for i in range(digit - 1):
  if (i + 1) % 2 == 1:
    count += 10 ** (i + 1) - (10 ** i)

if digit % 2 == 1:
  count += n - 10 ** (digit - 1) + 1

print(count)

Buggy python submission (verdict: Runtime Error):
n = input()
digit = len(str(n))

count = -1
for i in range(digit - 1):
  if (i + 1) % 2 == 1:
    count += 10 ** (i + 1)

if digit % 2 == 1:
  count += n - 10 ** (digit - 1)

print(count)

Fixed submission:
n = int(input())
digit = len(str(n))

count = 0
for i in range(digit - 1):
  if (i + 1) % 2 == 1:
    count += 10 ** (i + 1) - (10 ** i)

if digit % 2 == 1:
  count += n - 10 ** (digit - 1) + 1

print(count)

Buggy python submission (verdict: Runtime Error):
n = input()
digit = len(str(n))

count = -1
for i in range(digit - 1):
  if (i + 1) % 2 == 1:
    count += 10 ** i

if digit % 2 == 1:
  count += n - 10 ** (digit - 1)

print(count)

Fixed submission:
n = int(input())
digit = len(str(n))

count = 0
for i in range(digit - 1):
  if (i + 1) % 2 == 1:
    count += 10 ** (i + 1) - (10 ** i)

if digit % 2 == 1:
  count += n - 10 ** (digit - 1) + 1

print(count)
Buggy python submission (verdict: Runtime Error):
w, h, x, y = [int(i) for i in input().split(' ')]

m_x, m_y = w / 2, h / 2

a = (x - m_x) / (y - m_y)

print(w * h / 2, 1 if x == m_x and y == m_y else 0)

Fixed submission:
w, h, x, y = [int(i) for i in input().split(' ')]

m_x, m_y = w / 2, h / 2

print(w * h / 2, 1 if x == m_x and y == m_y else 0)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
Judge = True
remain_initial = 7 % K
remain = 0
i = 0

while Judge == True:
    i += 1
    remain_str = str(remain) + '7'
    number = int(remain_str)
    remain = number % K

    if number % K == 0:
        Judge = False
        answer = i

    elif i == 1:
        continue

    elif number % K == remain_initial:
        Judge = False
        answer = -1

print(answer)

Fixed submission:
K = int(input())
remain = 0
i = 0

answer = -1

for i in range(1, K+5):
    number = remain*10 + 7

    remain = number % K

    if remain == 0:
        answer = i
        break

print(answer)
Buggy python submission (verdict: Runtime Error):
import math

N, K = map(int, input().split())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

answer = 0

for i in range(1, K+1):
    answer = combinations_count(K-1, i-1)
    answer *= combinations_count(N-K+1, i)
    answer %= 10**(9) + 7
    print(answer)

Fixed submission:
import math

N, K = map(int, input().split())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

answer = 0

for i in range(1, K+1):
    if N-K+1 < i:
        print(0)
        continue
    answer = combinations_count(K-1, i-1)
    answer *= combinations_count(N-K+1, i)
    answer %= 10**(9) + 7
    print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
Slist = [0 for x in range(0,N)]
L = list()
R = list()

for x in range(0,N-1):
    if S[x] is 'A' and S[x+1] is 'C':
        Slist[x] = 1

for x in range(0,Q):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)

for x in range(0,Q):
    Sumple = Slist[L[x]-1:R[x]]
    answer = sum(Sumple) - Sumple[-1]
    print(answer)

Fixed submission:
N,Q = map(int,input().split())
S = input()
Slist = [0 for x in range(0,N)]
L = list()
R = list()
number = 0

for x in range(0,N-1):
    if S[x] is 'A' and S[x+1] is 'C':
        number += 1
    Slist[x+1] = number

for x in range(0,Q):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)

for x in range(0,Q):
    answer = Slist[R[x]-1] - Slist[L[x]-1]
    print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
Slist = [0 for x in range(0,N)]
Answer = []

for x in range(0,N-1):
    if S[x] is 'A' and S[x+1] is 'C':
        Slist[x] = 1

for x in range(0,Q):
    l,r = map(int,input().split())
    Sumple = Slist[l-1:r]
    answer = sum(Sumple) - Sumple[-1]
    Answer.append(answer)

for x in range(0,len(Answer)):
        print(Answer[x])

Fixed submission:
N,Q = map(int,input().split())
S = input()
Slist = [0 for x in range(0,N)]
L = list()
R = list()
number = 0

for x in range(0,N-1):
    if S[x] is 'A' and S[x+1] is 'C':
        number += 1
    Slist[x+1] = number

for x in range(0,Q):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)

for x in range(0,Q):
    answer = Slist[R[x]-1] - Slist[L[x]-1]
    print(answer)
Buggy python submission (verdict: Runtime Error):
import fraction

N = int(input())
A = list(map(int,input().split()))

sortedA = sorted(A)
answer = A[0]

for x in range(0,N):
        answer = gcd(answer,A[x])
        if answer == 1:
            break

print(answer)

Fixed submission:
from fractions import gcd

N = int(input())
A = list(map(int,input().split()))

sortedA = sorted(A)
answer = A[0]

for x in range(0,N):
        answer = gcd(answer,A[x])
        if answer == 1:
            break

print(answer)

Buggy python submission (verdict: Runtime Error):
from fraction import gcd

N = int(input())
A = list(map(int,input().split()))

sortedA = sorted(A)
answer = A[0]

for x in range(0,N):
        answer = gcd(answer,A[x])
        if answer == 1:
            break

print(answer)

Fixed submission:
from fractions import gcd

N = int(input())
A = list(map(int,input().split()))

sortedA = sorted(A)
answer = A[0]

for x in range(0,N):
        answer = gcd(answer,A[x])
        if answer == 1:
            break

print(answer)
Buggy python submission (verdict: Runtime Error):
N,K = list(map(int,input().split()))
TDlist = []

for x in range(0,N):
    TDlist.append(list(map(int,input().split())))

TDlist.reverse(key = lambda x: x[1])
kinds = []
seconds = []
answer = 0

for x in TDlist[:K]:
    if not x[0] in kinds:
        kinds.append(x[0])
    else:
        seconds.append(x[1])
    answer += x[1]

answer += len(kinds)**2
score = answer
max_score = answer

for x in TDlist[K:]:
    if seconds == []:
        break
    if x[0] in kinds:
        continue
    kinds.append(x[0])
    y = seconds.pop()
    score += (x[1] - y) + (len(kinds)*2 -1)
    max_score = max(score,answer)
    

answer = max(answer,max_score)

print(answer)

Fixed submission:
S = list(map(int,input().split()))
AB = S[0]
BC = S[1]
CA = S[2]

answer = AB * BC // 2

print(answer)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(map(int,input().split()))
H = list(map(int,input().split()))
T = S[0]
A = S[1]
sub = abs(A - (T - H[0]*0.006))
for x in range(0,N):
    H_sub = abs(A -(T - H[x]*0.006))
    if H_sub < sub:
        sub = H_sub
        X = x
print(X+1)

Fixed submission:
N = int(input())
S = list(map(int,input().split()))
H = list(map(int,input().split()))
T = S[0]
A = S[1]
sub = abs(A - (T - H[0]*0.006))
for x in range(0,N):
    H_sub = abs(A -(T - H[x]*0.006))
    if H_sub <= sub:
        sub = H_sub
        X = x
print(X+1)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect
L = list(map(int,input().split()))
N = L[0]
M = L[1]
P = list()
Y = list()
S = list()
for x in range(0,N):
    S.append(list())
for x in range(0,M):
    X = list(map(int,input().split()))
    P.append(X[0])
    Y.append(X[1])
    S[X[0]-1].append(X[1])
    S[X[0]-1] = sorted(S[X[0]-1])
for y in range(0,M):
    n = 0
    n = bisect(S[P[y]-1],Y[y])
    nstr = str(n)
    Pstr = str(P[y])
    while len(nstr) < 6:
        nstr = '0' + nstr
    while len(Pstr) < 6:
        Pstr = '0' + Pstr
    number = Pstr + nstr
    print(number)

Fixed submission:
L = list(map(int,input().split()))
N = L[0]
M = L[1]
PY = list()

for x in range(0,M):
    X = list(map(int,input().split()))
    PY.append((X[0],X[1],x))

sortedPY = sorted(PY, key=lambda x:x[1])
ID = [0 for i in range(N)]

for y in range(0,M):
    n = sortedPY[y][0]
    n = n-1
    ID[n] = ID[n] + 1
    nstr = str(ID[n])
    Pstr = str(sortedPY[y][0])
    while len(nstr) < 6:
        nstr = '0' + nstr
    while len(Pstr) < 6:
        Pstr = '0' + Pstr
    PY[sortedPY[y][2]] = Pstr + nstr
    number = Pstr + nstr

for x in range(0,M):
    print(PY[x])
Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int,input().split()))
H = S[0]
W = S[1]
K = S[2]

def f(h,w,k):
    fib = [1,2,3,5,8,13,21,34,55,1]
    if h == 0 and k == 1:
        return 1
    elif h == 0 and not k == 1:
        return 0
    else:
        if not(k == 1 or k == w):
            return (fib[w-k-1]*fib[k-3]*f(h-1,w,k-1) + fib[k-1]*fib[w-k-1]*f(h-1,w,k) + fib[k-1]*fib[w-k-2]*f(h-1,w,k))
        elif k==1:
            return (fib[w-2]*f(h-1,w,k) + fib[w-3]*f(h-1,w,k+1))
        elif k == w:
            return (fib[w-3]*f(h-1,w,k-1) + fib[w-2]*f(h-1,w,k))

if W == 1:
    answer = 1
else:
    answer = f(H,W,K) % 1000000007
print(answer)

Fixed submission:
S = list(map(int,input().split()))
H = S[0]
W = S[1]
K = S[2]
fib = [1,2,3,5,8,13,21,0,1]
List = [1]
for x in range(0,W):
    List.append(0)

for x in range(0,H):
    X = tuple(List)
    for y in range(0,W):
        List[y] = fib[y-2]*fib[W-y-2]*X[y-1] + fib[y-1]*fib[W-y-2]*X[y] + fib[y-1]*fib[W-y-3]*X[y+1] 

ans = List[K-1] % 1000000007
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int,input().split()))
N = S[0]
M = S[1]
ans = 1
for x in range(N,M//2+1):
    if M % x == 0:
        ans = M // x
        break

print(ans) 

Fixed submission:
import math

S = list(map(int,input().split()))
N = S[0]
M = S[1]
div = list()
z = math.sqrt(M)
z = math.ceil(z)

for x in range(1,z):
    if M % x == 0:
        div.append(x)
        div.append(M//x)
div.append(M)
div.append(N)

sorted_div = sorted(div)
n = sorted_div.index(N)

y =sorted_div[n+1]

ans = M // y

print(ans)

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

for x in range(N,M+1):
    if M % x == 0:
        ans = M // x
        break

print(ans) 

Fixed submission:
import math

S = list(map(int,input().split()))
N = S[0]
M = S[1]
div = list()
z = math.sqrt(M)
z = math.ceil(z)

for x in range(1,z):
    if M % x == 0:
        div.append(x)
        div.append(M//x)
div.append(M)
div.append(N)

sorted_div = sorted(div)
n = sorted_div.index(N)

y =sorted_div[n+1]

ans = M // y

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
T = input()
for x in range(0,len(S)):
    S = S.replace(S[x],'A').replace(T[x],S[x]).replace('A',T[x])
if S == T:
    print('Yes')
else:
    print('No')

Fixed submission:
S = input()
T = input()
for x in set(T):
    S = S.replace(S[T.index(x)],'A').replace(x,S[T.index(x)]).replace('A',x)
if S == T:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import fracion
from functools import reduce

S = list(map(int,input().split()))
N = S[0]
X = S[1]
x = list(map(int,input().split()))
x.append(X)
xmin = min(x)
xlist = list(map(lambda y: y-xmin ,x))
xlist.remove(0)

answer = reduce(fraction.gcd, xlist)
print(answer)

Fixed submission:
import fractions
from functools import reduce

S = list(map(int,input().split()))
N = S[0]
X = S[1]
x = list(map(int,input().split()))
x.append(X)
xmin = min(x)
xlist = list(map(lambda y: y-xmin ,x))
xlist.remove(0)

answer = reduce(fractions.gcd, xlist)
print(answer)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

S = list(map(int,input().split()))
N = S[0]
X = S[1]
x = list(map(int,input().split()))
x.append(X)
xmin = min(x)
xlist = list(map(lambda y: y-xmin ,x))
xlist.remove(0)

answer = reduce(math.gcd, xlist)
print(answer)

Fixed submission:
import fractions
from functools import reduce

S = list(map(int,input().split()))
N = S[0]
X = S[1]
x = list(map(int,input().split()))
x.append(X)
xmin = min(x)
xlist = list(map(lambda y: y-xmin ,x))
xlist.remove(0)

answer = reduce(fractions.gcd, xlist)
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int,input().split()))
N = S[0]
X = S[1]
x = list(map(int,input().split()))
n = max(max(x),X)//N 
x.append(X)
for i in range(n,0,-1):
    xmod = list(map(lambda y:y % i,x))
    if xmod.count(xmod[0]) == len(xmod):
        print(i)
        break

Fixed submission:
import fractions
from functools import reduce

S = list(map(int,input().split()))
N = S[0]
X = S[1]
x = list(map(int,input().split()))
x.append(X)
xmin = min(x)
xlist = list(map(lambda y: y-xmin ,x))
xlist.remove(0)

answer = reduce(fractions.gcd, xlist)
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int,input().split()))
N = S[0]
X = S[1]
x = list(map(int,input().split()))
n = max(max(x),X)//N 

for i in range(n,0,-1):
    xmod = list()
    xmod.append(X % i)
    for y in range(0,N):
        xmod.append(x[y] % i)
    if xmod.count(xmod[0]) == len(xmod):
        print(i)
        break

Fixed submission:
import fractions
from functools import reduce

S = list(map(int,input().split()))
N = S[0]
X = S[1]
x = list(map(int,input().split()))
x.append(X)
xmin = min(x)
xlist = list(map(lambda y: y-xmin ,x))
xlist.remove(0)

answer = reduce(fractions.gcd, xlist)
print(answer)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
Sdash = [x for x in S if not x == '1']  
n = S.index(Sdash[0])
if n >= K:
    print(1)
else:
    print(Sdash[0])

Fixed submission:
S = input()
K = int(input())
Sdash = [x for x in S if not x == '1'] 

if len(Sdash) == 0:
    n = len(S) 
else:
    n = S.index(Sdash[0])

if n >= K:
    print(1)
else:
    print(Sdash[0])

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
Sdash = [x for x in S if not x == '1']  
print(Sdash[0])

Fixed submission:
S = input()
K = int(input())
Sdash = [x for x in S if not x == '1'] 

if len(Sdash) == 0:
    n = len(S) 
else:
    n = S.index(Sdash[0])

if n >= K:
    print(1)
else:
    print(Sdash[0])
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input())

if N % K == 0:
    print(0)
else:
    print(1)

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

if N % K == 0:
    print(0)
else:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
for x in range(N):
    A[x] -= (x+1)

sorted_A = sorted(A)

if len(A) == 1:
    ans = 0
elif N % 2 == 1 and not len(A) == 1 :
    ans = sum(map(lambda x: abs(x-sorted_A[N//2+2]),A))
    for x in range(sorted_A[N//2],sorted_A[N//2+2]):
        y = sum(map(lambda z: abs(z -x),A))
        if ans > y :
            ans = y
else:
    ans = sum(map(lambda x: abs(x-sorted_A[N//2+1]),A))
    for x in range(sorted_A[N//2],sorted_A[N//2+1]):
        y = sum(map(lambda z: abs(z -x),A))
        if ans > y :
            ans = y
    
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
for x in range(N):
    A[x] -= (x+1)

sorted_A = sorted(A)

if len(A) == 1:
    ans = 0
else:
    ans = sum(map(lambda x: abs(x-sorted_A[N//2]),A))

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
for x in range(N):
    A[x] -= (x+1)

sorted_A = sorted(A)

if N % 2 == 1:
    ans = sum(map(lambda x: abs(x-sorted_A[N//2+2]),A))
    for x in range(sorted_A[N//2],sorted_A[N//2+2]):
        y = sum(map(lambda z: abs(z -x),A))
        if ans > y :
            ans = y
else:
    ans = sum(map(lambda x: abs(x-sorted_A[N//2+1]),A))
    for x in range(sorted_A[N//2],sorted_A[N//2+1]):
        y = sum(map(lambda z: abs(z -x),A))
        if ans > y :
            ans = y
    
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
for x in range(N):
    A[x] -= (x+1)

sorted_A = sorted(A)

if len(A) == 1:
    ans = 0
else:
    ans = sum(map(lambda x: abs(x-sorted_A[N//2]),A))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
list6 = [6**x for x in range(0,7) ]
list9 = [9**x for x in range(0,6) ]

def f(x):
    if x < 6:
        return x
    else:
        max6 = max(y for y in list6 if y <= x)
        max9 = max(y for y in list9 if y <= x)
        x6 = x - max6
        x9 = x - max9
        return min(f(x6)+ 1,f(x9)+ 1)

print(f(N))

Fixed submission:
N = int(input())
list6 = [6**x for x in range(0,7) ]
list9 = [9**x for x in range(0,6) ]
result = {}

def f(x):
    if x < 6:
        return x
    elif x in result:
        return result[x] 
    else:
        max6 = max(y for y in list6 if y <= x)
        max9 = max(y for y in list9 if y <= x)
        x6 = x - max6
        x9 = x - max9
        result[x] = min(f(x6)+ 1,f(x9)+ 1)
        return result[x]

print(f(N))

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

def f(x,n):
    if x == 0:
        return n
    else:
        i = 0
        j = 0
        while 6**i <= x:
            i += 1
        while 9**j <= x:
            j += 1
        n6 = n + 1
        n9 = n + 1
        x6 = x - (6**(i-1))
        x9 = x - (9**(j-1))
        return min(f(x6,n6),f(x9,n9))

print(f(N,0))

Fixed submission:
N = int(input())
list6 = [6**x for x in range(0,7) ]
list9 = [9**x for x in range(0,6) ]
result = {}

def f(x):
    if x < 6:
        return x
    elif x in result:
        return result[x] 
    else:
        max6 = max(y for y in list6 if y <= x)
        max9 = max(y for y in list9 if y <= x)
        x6 = x - max6
        x9 = x - max9
        result[x] = min(f(x6)+ 1,f(x9)+ 1)
        return result[x]

print(f(N))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
answer = N

for x in range(0,N):
    a = S[:x]
    if not x == N-1:
        b = S[x+1:]
    anum = a.count('W')
    bnum = b.count('E')
    num = anum + bnum
    answer = min(answer,num)

print(answer)

Fixed submission:
N = int(input())
S = input()
answer = S.count('E')
if S[0] =='E':
    test = S.count('E') - 1
else:
    test = S.count('E')

for x in range(0,N-1):
    if S[x] == 'W':
        test += 1
    if S[x+1] =='E':
        test -= 1
    answer = min (answer,test)

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
List = [0 for x in range(0,N)]
answer = N

for x in range(0,N):
    a = S[:x]
    if not x == N-1:
        b = S[x+1:]
    anum = a.count('W')
    bnum = b.count('E')
    num = anum + bnum
    answer = min(answer,num)

print(answer)

Fixed submission:
N = int(input())
S = input()
answer = S.count('E')
if S[0] =='E':
    test = S.count('E') - 1
else:
    test = S.count('E')

for x in range(0,N-1):
    if S[x] == 'W':
        test += 1
    if S[x+1] =='E':
        test -= 1
    answer = min (answer,test)

print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int,input().split()))
sortedX = sorted(X)

for x in X:
    if sortedX.index(x) <= N//2 -1:
        print(sortedX[N//2])
    else:
        print(sortedX[N//2 -1])

Fixed submission:
N = int(input())
X = list(map(int,input().split()))
sortedX = sorted(X)

for x in X:
    if sortedX[N//2 -1] >= x:
        print(sortedX[N//2])
    else:
        print(sortedX[N//2 -1])
Buggy python submission (verdict: Runtime Error):
def generate_block(s):
    table = []
    j = 0
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            table.append(s[j:i+1])
            j = i + 1
    return table

def happy(s):
    count = 0
    ll = len(s)
    for i in range(ll):
        if i != ll-1 and s[i] == 'R' and s[i+1] == 'R': count += 1
        if i != 0 and s[i] == 'L' and s[i-1] == 'L': count += 1
    return count

n, k = map(int, input().split())
s = input() + '.'
x = 0
table = generate_block(s)[::-1]
while k > 0:
    pos = 2 * x + 1
    if pos > len(table): break
    if 'L' in table[pos]: table[pos] = table[pos].replace('L', 'R')
    else: table[pos] = table[pos].replace('R', 'L')
    k -= 1
    x += 1
print(happy(''.join(table)))

Fixed submission:
def generate_block(s):
    table = []
    j = 0
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            table.append(s[j:i+1])
            j = i + 1
    return table

def happy(s):
    count = 0
    ll = len(s)
    for i in range(ll):
        if i != ll-1 and s[i] == 'R' and s[i+1] == 'R': count += 1
        if i != 0 and s[i] == 'L' and s[i-1] == 'L': count += 1
    return count

n, k = map(int, input().split())
s = input() + '.'
x = 0
table = generate_block(s)[::-1]
while k > 0:
    pos = 2 * x + 1
    if pos >= len(table): break
    if 'L' in table[pos]: table[pos] = table[pos].replace('L', 'R')
    else: table[pos] = table[pos].replace('R', 'L')
    k -= 1
    x += 1
print(happy(''.join(table)))
Buggy python submission (verdict: Runtime Error):
s, t = list(input().split()), list(input().split())
print(len([s[i] == t[i] for i in range(len(s))

Fixed submission:
s, t = list(input()), list(input())
print(len([1 for i in range(len(s)) if s[i] == t[i]]))
Buggy python submission (verdict: Runtime Error):
from math import factorial
n = int(input())
c = {}
for x in range(n):
    k = ''.join(sorted(input()))
    if k in c: c[k] += 1
    else: c[k] = 1
print(sum([int(factorial(n) / factorial(2) / factorial(n - 2)) for n in c.values() if n != 1]))

Fixed submission:
n = int(input())
c = {}
for x in range(n):
    k = ''.join(sorted(input()))
    if k in c: c[k] += 1
    else: c[k] = 1
print(sum([n*(n-1)//2 for n in c.values() if n != 1]))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a, b = [], []
hp = [[] for _ in range(m+1)]
ignore = [0] * (n+1)
ans = 0
for _ in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
for x in range(1, m+1):
    candidate = []
    for i, e in enumerate(a):
        if e <= x and not ignore[i]: candidate.append(b[i])
    if candidate:
        m = max(candidate)
        ans += m
        ignore[b.index(m)] = 1
print(ans)

Fixed submission:
import heapq
import collections

n, m = map(int, input().split())
work = collections.defaultdict(list)
hp = [[] for _ in range(m+1)]
ignore = []
ans = 0
for _ in range(n):
    x, y = map(int, input().split())
    work[x].append(-y)
candidate = []
for x in range(1, m+1):
    if work[x]:
        for e in work[x]:
            heapq.heappush(candidate, e)
    if candidate:
        ans += heapq.heappop(candidate)
print(abs(ans))