Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
a = [int(n) for n in input().split()]
sum = [0]*n
sum[0] = a[0]
ans = 0
for i in range(1,n):
    sum[i] = sum[i-1]
    while((sum[i]+a[i])*sum[i-1] >= 0):
        if(sum[i-1] > 0):
            ans+=sum[i-1] + a[i]+1
            a[i]-=sum[i-1] + a[i]+1
        else:
            ans+=1 - sum[i-1] - a[i]
            a[i]+=1 - sum[i-1] - a[i]
        print(a)
    sum[i] += a[i]
print(ans)
# print(a)
# print(sum)


Fixed submission:
import sys
N = int(input())
a = [int(_) for _ in input().split()]

#+,-,+,-
asum = [0]*(N)
ansp = 0
if(a[0] <= 0):
    ansp+=1-a[0]
    asum[0]=1
else:
    asum[0] = a[0]
for i in range(1,N):
    asum[i] = asum[i-1] + a[i]
    if(asum[i-1]*asum[i] >= 0):
        if(asum[i-1]>0):
            ansp+=1+asum[i]
            asum[i]=-1
        else:
            ansp+=1-asum[i]
            asum[i]=1
# print(asum)
# print(ansp)
#-,+,-,+,,,
ansn = 0
if(a[0] >= 0 ):
    ansn+=1+a[0]
    asum[0]=-1
else:
    asum[0] = a[0]
for i in range(1,N):
    asum[i] = asum[i-1] + a[i]
    if(asum[i-1]*asum[i] >= 0):
        if(asum[i-1]>0):
            ansn+=1+asum[i]
            asum[i]=-1
        else:
            ansn+=1-asum[i]
            asum[i]=1
# print(asum)
# print(ansn)
print(min(ansp,ansn))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(input())
a = [int(n) for n in input().split()]
sum = [0]*n
sum[0] = a[0]
ans = 0
for i in range(1,n):
    sum[i] = sum[i-1]
    while((sum[i]+a[i])*sum[i-1] >= 0):
        if(sum[i-1] > 0):
            a[i]-=1
            ans+=1
        else:
            a[i]+=1
            ans+=1
        # print(a)
    sum[i] += a[i]
print(ans)
# print(a)
# print(sum)


Fixed submission:
import sys
N = int(input())
a = [int(_) for _ in input().split()]

#+,-,+,-
asum = [0]*(N)
ansp = 0
if(a[0] <= 0):
    ansp+=1-a[0]
    asum[0]=1
else:
    asum[0] = a[0]
for i in range(1,N):
    asum[i] = asum[i-1] + a[i]
    if(asum[i-1]*asum[i] >= 0):
        if(asum[i-1]>0):
            ansp+=1+asum[i]
            asum[i]=-1
        else:
            ansp+=1-asum[i]
            asum[i]=1
# print(asum)
# print(ansp)
#-,+,-,+,,,
ansn = 0
if(a[0] >= 0 ):
    ansn+=1+a[0]
    asum[0]=-1
else:
    asum[0] = a[0]
for i in range(1,N):
    asum[i] = asum[i-1] + a[i]
    if(asum[i-1]*asum[i] >= 0):
        if(asum[i-1]>0):
            ansn+=1+asum[i]
            asum[i]=-1
        else:
            ansn+=1-asum[i]
            asum[i]=1
# print(asum)
# print(ansn)
print(min(ansp,ansn))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

count = -1

for i in range(int(n/2)):
    for j in range(n-1):
        if (i+1)*(j+1) < n:
            count += 1
        else:
            break
count += n - int(n/2)
print(count)


Fixed submission:
n = int(input())

count = 0

if n%2==0:
    for i in range(int(n/2)-1):
        count += int((n-1)/(i+1))
    count += int(n/2)

else:
    for i in range(int(n/2)):
        count += int((n-1)/(i+1))
    count += int(n/2)

print(count)
Buggy python submission (verdict: Runtime Error):
S = input()
count = 0

if len(S)<=200000:
    for i in range(len(S)-4):
        for j in range(i+5, len(S)+1):
            tmp = int(S[i:j])
            if tmp%2019==0:
                count += 1

print(count)

Fixed submission:
S, W = map(int, input().split())

if S>W:
    print('safe')
else:
    print('unsafe')

Buggy python submission (verdict: Runtime Error):
S = input()
count = 0

for i in range(len(S)-3):
    for j in range(i+3, len(S)+1):
        tmp = int(S[i:j])
        if tmp%2019==0:
            print(i, j)
            count += 1

print(count)

Fixed submission:
S, W = map(int, input().split())

if S>W:
    print('safe')
else:
    print('unsafe')
Buggy python submission (verdict: Runtime Error):
from scipy.special import comb
x, y = map(int, input().split())

n = ((x + y) / 3)
r = min(x, y) - n

a = comb(n, r, exact=True)
print(a)

Fixed submission:
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

x, y = map(int, input().split())

n = int(((x + y) / 3))
r = min(x, y) - n

if (min(x, y)<n)or((x + y)%3!=0):   
    print(0)
else:
    a = cmb(n, r)%(10**9 + 7)
    print(int(a))
Buggy python submission (verdict: Runtime Error):
n = int(input())
min = n+1
kaisu = int((n/4)-1)

for i in range(kaisu):
    if n%(i+1)==0:
        tmp = i+(n/(i+1))-1
        if min > tmp:
            min = tmp
    if (i+1)**2>n:
        break

print(int(min))

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

if a>9 or b>9:
    print("-1")
else:
    print(a * b)
Buggy python submission (verdict: Runtime Error):
n = int(input())
min = n+1
kaisu = int(n-1)
if 
for i in range(kaisu):
    if n%(i+1)==0:
        tmp = i+(n/(i+1))-1
        if min > tmp:
            min = tmp
    if (i+1)**2>n:
        break

print(int(min))

Fixed submission:
n = int(input())
min = n+1
kaisu = int(n-1)

for i in range(kaisu):
    if n%(i+1)==0:
        tmp = i+(n/(i+1))-1
        if min > tmp:
            min = tmp
    if (i+1)**2>n:
        break

print(int(min))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

common = 0
for i in range(1,len(s)+):
    common = min(common, len(set(s[:i]).intersection(set(s[i:])))

print(common)

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

common = 0
for i in range(1,len(s)+1):
    common = max(common, len(set(s[:i]).intersection(set(s[i:]))))

print(common)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

common = 0
for i in range(1,len(s)+):
    common = min(common, len(set(s[:i]).intersection(set[i:])))

print(common)

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

common = 0
for i in range(1,len(s)+1):
    common = max(common, len(set(s[:i]).intersection(set(s[i:]))))

print(common)
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const* argv[])
{
  int m;
  cin >> m;
  cout << 48 - m << endl;

  return 0;
}

Fixed submission:
m = int(input())
print(48-m)
Buggy python submission (verdict: Runtime Error):
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]

if x in a and y in a:
	print("Yes")
elif x in b and y in b:
	print("Yes")      
elif x in c and y in c:
	print("Yes")
else:
	print("No")
      

Fixed submission:
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]

x,y = map(int, input().split())

if x in a and y in a:
	print("Yes")
elif x in b and y in b:
	print("Yes")      
elif x in c and y in c:
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = []
t = 1
for _ in range(n):
  x = list(map(int,input().split())
  l.append(x)
count = 0
for i, j in l:
  if i == j:
    count += 1
  if i!=j:
    count = 0
  if count == 3:
  	t = 0
    print("Yes")
    break
if t:
  print("No")
  

Fixed submission:
n = int(input())
count = 0
t = 1
for _ in range(n):
  a, b = map(int,input().split())
  if a==b:
    count += 1
  if a!=b:
    count = 0
  if count == 3:
    t = 0
if t:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
def binexp(b):
  res = 1
  while b>0:
    if b&1:
      res *= a
      res%=mod
    a *= a
    a%=mod
    b>>=1
  return res
mod = 1000000007
n = int(input())
if n==1:
  print(0)
elif n==2:
  print(1)
else:
  count = 1
  n -= 2
  ans = binexp(n)
  print(ans)

Fixed submission:
def binexp(a,b):
  res = 1
  while b>0:
    if b&1:
      res *= a
      res%=mod
    a *= a
    a%=mod
    b>>=1
  return res
mod = 1000000007
n = int(input())
if n==1:
  print(0)
elif n==2:
  print(2)
else:
  ans = binexp(10,n)
  ans1 = binexp(9,n)
  ans2 = binexp(8,n)
  print((ans-2*ans1+ans2)%mod)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(1,n):
  l[i] += l[i-1]
i = 0
while i<n-1:
  ans += l[i]*(l[n] - l[i])
  i += 1
print(ans)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
x = [*l]
ans = 0
mod = 1000000007
for i in range(1,n):
  l[i] += l[i-1]
i = 0
while i<n-1:
  ans += (x[i])*(l[n-1] - l[i])
  i += 1
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
from collections import deque
def good(x,y):
    if (x>=0 and x<h) and (y>=0 and y<w):
        return (mat[x][y] != "#")
h, w = map(int,input().split())
sh, sw = map(int,input().split())
eh, ew = map(int,input().split())
mat = []
for _ in range(h):
    s = input()
    mat.append(s)
x = [1,-1,0,0]
y = [0,0,-1,1]
dist = [[float('inf') for i in range(w)]for j in range(h)]
sh -= 1
sw -= 1
eh -= 1
ew -= 1
dist[sh][sw] = 0
queue = deque()
queue.appendleft((sh,sw))
while queue:
    m = queue.popleft()
    for d in range(4):
        nx = m[0] + x[d]
        ny = m[1] + y[d]
        if good(nx,ny):
            if dist[nx][ny] > dist[m[0]][m[1]]:
                dist[nx][ny] =  dist[m[0]][m[1]]
                queue.appendleft((nx,ny))
    for i in range(m[0]-2,m[1]+3):
        for j in range(m[1]-2,m[1]+3):
            if good(i,j):
                if dist[i][j] > dist[m[0]][m[1]] + 1:
                    dist[i][j] = dist[m[0]][m[1]] + 1
                    queue.append((i,j))
if dist[eh][ew] == float('inf'):
    print(-1)
else:
    print(dist[eh][ew])


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

if n%x==0:
  print((n//x)*t)
else:
  n = n//x +1
  print(n*t)
Buggy python submission (verdict: Runtime Error):
from collections import deque
def good(x,y):
    if (x>=0 and x<h) and (y>=0 and y<w):
        return (mat[x][y] != "#")
h, w = map(int,input().split())
sh, sw = map(int,input().split())
eh, ew = map(int,input().split())
mat = []
for _ in range(h):
    s = input()
    mat.append(s)
x = [1,-1,0,0]
y = [0,0,-1,1]
dist = [[float('inf') for i in range(w)]for j in range(h)]
sh -= 1
sw -= 1
eh -= 1
ew -= 1
dist[sh][sw] = 0
queue = deque()
queue.appendleft((sh,sw))
while queue:
    m = queue.popleft()
    for d in range(4):
        nx = m[0] + x[d]
        ny = m[1] + y[d]
        if not good(nx,ny):
            continue
        if dist[nx][ny] > dist[m[0]][m[1]]:
            dist[nx][ny] =  dist[m[0]][m[1]]
            queue.appendleft((nx,ny))
    for i in range(m[0]-2,m[1]+3):
        for j in range(m[1]-2,m[1]+3):
            if not good(nx,ny):
                continue
            if dist[i][j] > dist[m[0]][m[1]] + 1:
                dist[i][j] = dist[m[0]][m[1]] + 1
                queue.append((i,j))
if dist[eh][ew] == float('inf'):
    print(-1)
else:
    print(dist[eh][ew])


Fixed submission:
from collections import deque
def good(x,y):
    if (x>=0 and x<h) and (y>=0 and y<w):
        return (mat[x][y] != "#")
h, w = map(int,input().split())
sh, sw = map(int,input().split())
eh, ew = map(int,input().split())
mat = []
for _ in range(h):
    s = input()
    mat.append(s)
x = [1,-1,0,0]
y = [0,0,-1,1]
dist = [[float('inf') for i in range(w)]for j in range(h)]
sh -= 1
sw -= 1
eh -= 1
ew -= 1
dist[sh][sw] = 0
queue = deque()
queue.appendleft((sh,sw))
while queue:
    m = queue.popleft()
    for d in range(4):
        nx = m[0] + x[d]
        ny = m[1] + y[d]
        if good(nx,ny):
            if dist[nx][ny] > dist[m[0]][m[1]]:
                dist[nx][ny] =  dist[m[0]][m[1]]
                queue.appendleft((nx,ny))
    for i in range(m[0]-2,m[0]+3):
        for j in range(m[1]-2,m[1]+3):
            if good(i,j):
                if dist[i][j] > dist[m[0]][m[1]] + 1:
                    dist[i][j] = dist[m[0]][m[1]] + 1
                    queue.append((i,j))
if dist[eh][ew] == float('inf'):
    print(-1)
else:
    print(dist[eh][ew])
Buggy python submission (verdict: Runtime Error):
from scipy.special import comb
n, m = [int(x) for x in input().split()]



print(int(comb(n, 2, exact=True) + comb(m, 2, exact=True)))

Fixed submission:
from scipy.misc import comb
n, m = [int(x) for x in input().split()]



print(int(comb(n, 2, exact=True) + comb(m, 2, exact=True)))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s = deque(input())
q = int(input())

for _ in range(q):
  Q = [x for x in input().split()]
  if Q[0] == '1':
    s.reverse()
  else:
    if Q[1] == '1':
      s.appendleft(Q[2])
    else:
      s.append(Q[2])

print('' . join(s))

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
flg = 0

for _ in range(q):
  Q = [x for x in input().split()]
  if Q[0] == '1':
    flg += 1
  else:
    if (Q[1] == '1' and flg%2==0) or (Q[1] == '2' and flg%2==1):
      s.appendleft(Q[2])
    else:
      s.append(Q[2])
if flg%2==1:
  s.reverse()

print('' . join(s))

Buggy python submission (verdict: Time Limit Exceeded):
#n, m = [int(x) for x in input().split()]

s = list(input())
q = int(input())

for _ in range(q):
  Q = [x for x in input().split()]
  if Q[0] == '1':
    s.reverse()
  else:
    if Q[1] == '1':
      s.insert(0, Q[2])
    else:
      s.append(Q[2])

print('' . join(s))

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
flg = 0

for _ in range(q):
  Q = [x for x in input().split()]
  if Q[0] == '1':
    flg += 1
  else:
    if (Q[1] == '1' and flg%2==0) or (Q[1] == '2' and flg%2==1):
      s.appendleft(Q[2])
    else:
      s.append(Q[2])
if flg%2==1:
  s.reverse()

print('' . join(s))

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

for _ in range(q):
  Q = [x for x in input().split()]
  if Q[0] == '1':
    s = s[::-1]
  else:
    if Q[1] == '1':
      s.insert(0, Q[2])
    else:
      s.append(Q[2])

for i in s:
  print(i, end ="")

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
flg = 0

for _ in range(q):
  Q = [x for x in input().split()]
  if Q[0] == '1':
    flg += 1
  else:
    if (Q[1] == '1' and flg%2==0) or (Q[1] == '2' and flg%2==1):
      s.appendleft(Q[2])
    else:
      s.append(Q[2])
if flg%2==1:
  s.reverse()

print('' . join(s))
Buggy python submission (verdict: Runtime Error):
n = int(input())

# i = format(n, 'b')[::-1].find('1')
ans = 0
k = 1
while True:
  n //=2
  ans += k
  k *= 2
  if n =< 1:
    break

print(ans+k)

Fixed submission:
n = int(input())

# i = format(n, 'b')[::-1].find('1')
ans = 0
k = 1
while True:
  n //=2
  ans += k
  k *= 2
  if n == 1:
    print(ans+k)
    break
  elif n < 1:
    print(ans)
    break

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

# i = format(n, 'b')[::-1].find('1')
ans = 0
k = 1
while True:
  n //=2
  ans += k
  k *= 2
  if n == 1:
    break

print(ans+k)

Fixed submission:
n = int(input())

# i = format(n, 'b')[::-1].find('1')
ans = 0
k = 1
while True:
  n //=2
  ans += k
  k *= 2
  if n == 1:
    print(ans+k)
    break
  elif n < 1:
    print(ans)
    break

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

# i = format(n, 'b')[::-1].find('1')
i = 0
ans = 0
while True:
  n //=2
  ans += 2**i
  i += 1
  if n == 1:
    break

print(ans+2**i)

Fixed submission:
n = int(input())

# i = format(n, 'b')[::-1].find('1')
ans = 0
k = 1
while True:
  n //=2
  ans += k
  k *= 2
  if n == 1:
    print(ans+k)
    break
  elif n < 1:
    print(ans)
    break

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

# i = format(n, 'b')[::-1].find('1')
i = 0
while True:
  n //=2
  i += 1
  if n == 1:
    break


ans = 0
for j in range(i+1):
  ans += 2**j

print(ans)

Fixed submission:
n = int(input())

# i = format(n, 'b')[::-1].find('1')
ans = 0
k = 1
while True:
  n //=2
  ans += k
  k *= 2
  if n == 1:
    print(ans+k)
    break
  elif n < 1:
    print(ans)
    break

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
i=0
while True:
  n = n//2
  i += 1
  if n == 1:
    break

ans = 0
for j in range(i+1):
  ans += 2**j

print(ans)

Fixed submission:
n = int(input())

# i = format(n, 'b')[::-1].find('1')
ans = 0
k = 1
while True:
  n //=2
  ans += k
  k *= 2
  if n == 1:
    print(ans+k)
    break
  elif n < 1:
    print(ans)
    break
Buggy python submission (verdict: Runtime Error):
s = [input() for i in range(2)]
N = int(s[0])
S = list(s[1])
eng = list('ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ')
idx = np.array([eng.index(S[i]) for i in range(len(S))])
N_l = np.array([N]*len(S))
new_idx = idx + N_l
ans = [eng[i] for i in new_idx]
fin_ans = ''
for x in ans:
    fin_ans += x
print(fin_ans)

Fixed submission:
import numpy as np
s = [input() for i in range(2)]
N = int(s[0])
S = list(s[1])
eng = list('ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ')
idx = np.array([eng.index(S[i]) for i in range(len(S))])
N_l = np.array([N]*len(S))
new_idx = idx + N_l
ans = [eng[i] for i in new_idx]
fin_ans = ''
for x in ans:
    fin_ans += x
print(fin_ans)

Buggy python submission (verdict: Runtime Error):
s = [input() for i in range(2)]
N = int(s[0])
S = list(s[1])
eng = list('ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ')
idx = np.array([eng.index(S[i]) for i in range(len(S))])
N_l = np.array([N]*len(S))
new_idx = idx + N_l
ans = [eng[i] for i in new_idx]
fin_ans = ''
for x in ans:
    fin_ans += x
print(fin_ans)

Fixed submission:
import numpy as np
s = [input() for i in range(2)]
N = int(s[0])
S = list(s[1])
eng = list('ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ')
idx = np.array([eng.index(S[i]) for i in range(len(S))])
N_l = np.array([N]*len(S))
new_idx = idx + N_l
ans = [eng[i] for i in new_idx]
fin_ans = ''
for x in ans:
    fin_ans += x
print(fin_ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

if n == 1:
  print(1)

elif n == 2:
  print(0.5)
  
elif n%2 == 0:
  print(0.5)
  
else:
  print((n+1)/2n)

Fixed submission:
n = int(input())
 
if n == 1:
  print(1)
 
elif n == 2:
  print(0.5)
  
elif n%2 == 0:
  print(0.5)
  
else:
  print((n+1)/2/n)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(x) for x in input().split()]
a = [int(input()) for _ in range(m)]
# a = [int(x) for x in input().split()]

memo = [0]*(n + 1)

for i in range(n+1):
  if i in a:
    continue
  else:
    if i == 0 or i == 1:
      memo[i] = 1
    else:
      memo[i] = (memo[i-1] + memo[i-2])%((10**9)+7)

print(memo[n])

Fixed submission:
n, m = [int(x) for x in input().split()]
a = set([int(input()) for _ in range(m)])
# a = [int(x) for x in input().split()]
 
memo = [0]*(n + 1)
 
for i in range(n+1):
  if i in a:
    continue
  else:
    if i == 0 or i == 1:
      memo[i] = 1
    else:
      memo[i] = (memo[i-1] + memo[i-2])%((10**9)+7)
 
print(memo[n])

Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(x) for x in input().split()]
a = [int(input()) for _ in range(m)]
# a = [int(x) for x in input().split()]

memo = [0]*(n + 1)

for i in range(n+1):
  if i in a:
    continue
  else:
    if i == 0 or i == 1:
      memo[i] = 1
    else:
      memo[i] = memo[i-1] + memo[i-2]

print(memo[n]%((10**9)+7))


Fixed submission:
n, m = [int(x) for x in input().split()]
a = set([int(input()) for _ in range(m)])
# a = [int(x) for x in input().split()]
 
memo = [0]*(n + 1)
 
for i in range(n+1):
  if i in a:
    continue
  else:
    if i == 0 or i == 1:
      memo[i] = 1
    else:
      memo[i] = (memo[i-1] + memo[i-2])%((10**9)+7)
 
print(memo[n])
Buggy python submission (verdict: Runtime Error):
# B - Guidebook
import numpy as np
import pandas as pd 

N = int(input())
A, B = [[], []]

for _ in range(N):
  a, b = [i for i in input().split()]
  A.append(a)
  B.append(int(b))


A = np.array(A)[:, np.newaxis]
B = np.array(B)[:, np.newaxis]
C = np.concatenate([A, B], axis=1)
df = pd.DataFrame(C, index=[i+1 for i in range(N)])
df = df.sort_values([0, 1], ascending=[True, False])

for i in df.index:
  print(i)


Fixed submission:
# B - Guidebook
import numpy as np
# import pandas as pd 

N = int(input())
A, B = [[], []]

for _ in range(N):
  a, b = [i for i in input().split()]
  A.append(a)
  B.append(int(b))


A = np.array(A)[:, np.newaxis]
B = np.array(B)[:, np.newaxis].astype('int')
C = np.concatenate([A, B], axis=1)
C = C.tolist()

ans = sorted(C, key=lambda x:(x[0],-int(x[1])))

for i in ans:
  print(C.index(i)+1)


"""
df = pd.DataFrame(C, index=[i+1 for i in range(N)])
df = df.sort_values([0, 1], ascending=[True, False])
"""
# for i in df.index:
#  print(i)

Buggy python submission (verdict: Runtime Error):
# B - Guidebook
import numpy as np
import pandas as pd 

N = int(input())
A, B = [[], []]

for _ in range(N):
  a, b = [i for i in input().split()]
  A.append(a)
  B.append(int(b))


A = np.array(A)[:, np.newaxis]
B = np.array(B)[:, np.newaxis]
C = np.concatenate([A, B], axis=1)
df = pd.DataFrame(C, index=[i+1 for i in range(N)])
df = df.sort_values([0, 1])

for i in df.index:
  print(i)


Fixed submission:
# B - Guidebook
import numpy as np
# import pandas as pd 

N = int(input())
A, B = [[], []]

for _ in range(N):
  a, b = [i for i in input().split()]
  A.append(a)
  B.append(int(b))


A = np.array(A)[:, np.newaxis]
B = np.array(B)[:, np.newaxis].astype('int')
C = np.concatenate([A, B], axis=1)
C = C.tolist()

ans = sorted(C, key=lambda x:(x[0],-int(x[1])))

for i in ans:
  print(C.index(i)+1)


"""
df = pd.DataFrame(C, index=[i+1 for i in range(N)])
df = df.sort_values([0, 1], ascending=[True, False])
"""
# for i in df.index:
#  print(i)

Buggy python submission (verdict: Runtime Error):
# B - Guidebook
import numpy as np
import pandas as pd 

N = int(input())
A, B = [[], []]

for _ in range(N):
  a, b = [i for i in input().split()]
  A.append(a)
  B.append(int(b))


A = np.array(A)[:, np.newaxis]
B = np.array(B)[:, np.newaxis]
C = np.concatenate([A, B], axis=1)

print(C)
df = pd.DataFrame(C, index=[i+1 for i in range(N)])
df = df.sort_values([0, 1])
for i in df.index:
  print(i)


Fixed submission:
# B - Guidebook
import numpy as np
# import pandas as pd 

N = int(input())
A, B = [[], []]

for _ in range(N):
  a, b = [i for i in input().split()]
  A.append(a)
  B.append(int(b))


A = np.array(A)[:, np.newaxis]
B = np.array(B)[:, np.newaxis].astype('int')
C = np.concatenate([A, B], axis=1)
C = C.tolist()

ans = sorted(C, key=lambda x:(x[0],-int(x[1])))

for i in ans:
  print(C.index(i)+1)


"""
df = pd.DataFrame(C, index=[i+1 for i in range(N)])
df = df.sort_values([0, 1], ascending=[True, False])
"""
# for i in df.index:
#  print(i)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [int(input()) for _ in [0]*N]

h = sorted(h)
ans = []

for i in range(len(h)-K+1):
  a = h[i:i+K]
  ans.append(max(a)-min(a))
  if ans[-1] == 0:
    print(0)
    exit()

print(min(ans))

Fixed submission:
N, K = map(int, input().split())
h = [int(input()) for _ in [0]*N]

h = sorted(h)
ans = []

for i in range(len(h)-K+1):
  ans.append(h[i+K-1]-h[i])
  if ans[-1] == 0:
    print(0)
    exit()

print(min(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [int(input()) for _ in [0]*N]

h = sorted(h)
ans = []

for i in range(len(h)-K+1):
  a = h[i:i+K]
  ans.append(max(a)-min(a))

print(min(ans))

Fixed submission:
N, K = map(int, input().split())
h = [int(input()) for _ in [0]*N]

h = sorted(h)
ans = []

for i in range(len(h)-K+1):
  ans.append(h[i+K-1]-h[i])
  if ans[-1] == 0:
    print(0)
    exit()

print(min(ans))