Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02793 (python)

Fixed submission:
N=int(input())
A=[int(i) for i in input().split(" ")]
mod=10**9+7

def GCD(a,b):
    if min(a,b)==0:
        return max(a,b)
    else:
        return GCD(min(a,b),max(a,b)%min(a,b))

def LCM(a,b):
    return int(a*b//GCD(a,b))





lcm=1
for a in A:
    lcm=LCM(lcm,a)


retval=0
for a in A:
    retval+=lcm//a

print(int(retval%mod))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(i) for i in input().split(" ")]
mod=10**9+7

def GCD(a,b):
    if min(a,b)==0:
        return max(a,b)
    else:
        return GCD(min(a,b),max(a,b)%min(a,b))

def LCM(a,b):
    return int(a*b/GCD(a,b))


lcm=1
for a in A:
    lcm=LCM(lcm,a)

retval=0
for a in A:
    retval+=lcm/a
    retval=retval%mod

print(int(retval%mod))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(i) for i in input().split(" ")]
mod=10**9+7

def GCD(a,b):
    if min(a,b)==0:
        return max(a,b)
    else:
        return GCD(min(a,b),max(a,b)%min(a,b))

def LCM(a,b):
    return (a*b/GCD(a,b))


lcm=1
for a in A:
    lcm=LCM(lcm,a)

retval=0
for a in A:
    retval+=lcm/a

print(int(retval%mod))
Problem p02833 (python)

Fixed submission:
import sys
N=int(input())

if N%2==1:
    print(0)
    sys.exit()


N=N//2
retval=0
i=1
while 5**i<=N:
    retval+= N//(5**i)
    i+=1

print(retval)

Buggy submission (verdict: Runtime Error):
N=int(input())

if N%2==1:
    print(0)
    sys.exit()


N=N//2
retval=0
i=1
while 5**i<=N:
    retval+= N//(5**i)
    i+=1

print(retval)
Problem p02570 (python)

Fixed submission:
D,T,S=map(int,input().split())
print('Yes' if S*T>=D else 'No')

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
V=[]
for _ in range(M):
    a,b=map(int,input().split())
    f=True
    for t in V:
        if a in t and b not in t:
            f=False
            t.append(a)
            break
        if a in t and b not in t:
            f=False
            t.append(b)
            break
    if f:
        V.append((a,b))
if M == 0:
    print(1)
else:
    print(max(map(len,V)))
Problem p03127 (python)

Fixed submission:
def get_int(): return int(input())
def get_float(): return float(input())
def get_line(): return input().split()
def get_lines(v): return [get_line() for _ in range(v)]
def get_int_line(): return list(map(int, get_line()))
def get_int_lines(v): return [get_int_line() for _ in range(v)]
def get_float_line(): return list(map(float, get_line()))
def get_float_lines(v): return [get_float_line() for _ in range(v)]

import functools
import math

def gcd(a, b):
  if (b == 0): return a
  else: return gcd(b, a % b)


N = get_int()
A = get_int_line()

print(functools.reduce(gcd, A))

Buggy submission (verdict: Runtime Error):
def get_int(): return int(input())
def get_float(): return float(input())
def get_line(): return input().split()
def get_lines(v): return [get_line() for _ in range(v)]
def get_int_line(): return list(map(int, get_line()))
def get_int_lines(v): return [get_int_line() for _ in range(v)]
def get_float_line(): return list(map(float, get_line()))
def get_float_lines(v): return [get_float_line() for _ in range(v)]
  
import functools
import math

N = get_int()
A = get_int_line()

print(functools.reduce(math.gcd, A))
Problem p03221 (python)

Fixed submission:
def get_line():
  return input().split(' ')

class element:
  def __init__(self, P, Y, idx):
    self.P = P
    self.Y = Y
    self.idx = idx
  def __lt__(self, other):
    return self.Y < other.Y

N, M = map(int, get_line())
els = [0] * M
for i in range(M):
  p, y = map(int, get_line())
  els[i] = element(p, y, i)

p_map = [[] for _ in range(N)]

for e in els:
  p_map[e.P - 1].append(e)

ans = [0] * M

for mp in p_map:
  cnt = 1
  for e in sorted(mp):
    ans[e.idx] = "{:06d}{:06d}".format(e.P, cnt)
    cnt = cnt + 1

for e in ans:
  print(e)

Buggy submission (verdict: Runtime Error):
def get_line():
  return input().split(' ')

class element:
  def __init__(self, P, Y, idx):
    self.P = P
    self.Y = Y
    self.idx = idx
  def __lt__(self, other):
    return self.Y < other.Y

N, M = map(int, get_line())
els = [0] * M
for i in range(M):
  p, y = map(int, get_line())
  els[i] = Element(p, y, i)

p_map = [[] for _ in range(N)]

for e in els:
  p_map[e.P - 1].append(e)

ans = [0] * M

for mp in p_map:
  cnt = 1
  for e in sorted(mp):
    ans[e.idx] = "{:06d}{:06d}".format(e.P, cnt)
    cnt = cnt + 1

for e in ans:
  print(e)
Problem p02729 (python)

Fixed submission:
n,m=map(int,input().split())
print((n*(n-1)+m*(m-1))//2)

Buggy submission (verdict: Runtime Error):
n=int(input())
m=int(input())
print((n*(n-1)+m*(m-1))//2)

Buggy submission (verdict: Runtime Error):
n=int(input())
m=int(input())
c=int((n*(n-1))//2)
d=int((m*(m-1))//2)
print(c+d)

Buggy submission (verdict: Runtime Error):
n=int(input())
m=int(input())
if n>1:
    c=int((n*(n-1))/2)
else:
    c=int(input(0))
if m>1:
    d=int((m*(m-1))/2)
else:
    d=int(input(0))
print(c+d)

Buggy submission (verdict: Runtime Error):
n=int(input())
m=int(input())
if n>1:
    c=int((n*(n-1))/2)
else:
    c=int(0)
if m>1:
    d=int((m*(m-1))/2)
else:
    d=int(0)
print(c+d)
return 0

Buggy submission (verdict: Runtime Error):
n=int(input())
m=int(input())
if n>1:
    c=int((n*(n-1))/2)
else:
    c=int(0)
if m>1:
    d=int((m*(m-1))/2)
else:
    d=int(0)
print(c+d)

Buggy submission (verdict: Runtime Error):
n=int(input())
m=int(input())
if n>1:
    c=int((n*(n-1))/2)
else:
    c=0
if m>1:
    d=int((m*(m-1))/2)
else:
    d=0
print(c+d)

Buggy submission (verdict: Runtime Error):
n=int(input())
m=int(input())
c=0
d=0
if n>1:
    c=int((n*(n-1))/2)
if m>1:
    d=int((m*(m-1))/2)
print(c+d)
Problem p02661 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A, B = ZIP(N)
A = sorted(A)
B = sorted(B)
if N%2 == 0:
	l = (A[N//2]+A[N//2-1])
	r = (B[N//2]+B[N//2-1])
	print(r-l+1)
else:
	print(B[N//2]-A[N//2]+1)

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A, B = ZIP(N)
A.sort()
B.sort()
if N%2 == 0:
	l = (A[N//2]+A[N//2-1])
	r = (B[N//2]+B[N//2-1])
	print(r-l+1)
else:
	print(B[N//2]-A[N//2]+1)
Problem p02851 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
import heapq
import numpy as np

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
A = LIST()

A_acc = list(accumulate(A))
S = [0] + A_acc
S = [(S[i]-i)%K for i in range(N+1)]

ans = 0
dic = defaultdict(int)

for i, x in enumerate(S):
	ans += dic[x]  # 範囲内かつ今まで出てきたxの個数を探す
	dic[x] += 1
	if i >= K-1:  # 範囲外のものを捨てる
		dic[S[i-K+1]] -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
import heapq
import numpy as np

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
A = LIST()

A_acc = list(accumulate(A))
S = [0] + A_acc
S = [(S[i]-i)%K for i in range(N+1)]

ans = 0
dic = [0]*K

for i, x in enumerate(S):
	ans += dic[x]  # 範囲内かつ今まで出てきたxの個数を探す
	dic[x] += 1
	if i >= K-1:  # 範囲外のものを捨てる
		dic[S[i-K+1]] -= 1

print(ans)
Problem p02863 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
import bisect
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, T = MAP()
wv = [LIST() for _ in range(N)]
dp1 = [[0]*T for _ in range(N+1)]
dp2 = [[0]*T for _ in range(N+1)]


for i in range(N):
	for j in range(T):
		if j < wv[i][0]:
			dp1[i+1][j] = dp1[i][j]
		else:
			dp1[i+1][j] = max(dp1[i][j], dp1[i][j-wv[i][0]]+wv[i][1])

wv = wv[::-1]

for i in range(N):
	for j in range(T):
		if j < wv[i][0]:
			dp2[i+1][j] = dp2[i][j]
		else:
			dp2[i+1][j] = max(dp2[i][j], dp2[i][j-wv[i][0]]+wv[i][1])

wv = wv[::-1]
ans = 0
for i in range(1, N+1):
	tmp = 0
	for j in range(T):
		tmp = max(tmp, dp1[i-1][j] + dp2[N-i][T-1-j])
	ans = max(ans, tmp+wv[i-1][1])

print(ans)

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
import bisect
from heapq import heappush, heappop
from scipy.sparse.csgraph import floyd_warshall

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, T = MAP()
wv = [LIST() for _ in range(N)]
dp1 = [[0]*T for _ in range(N+1)]
dp2 = [[0]*T for _ in range(N+1)]


for i in range(N):
	for j in range(T):
		if j < wv[i][0]:
			dp1[i+1][j] = dp1[i][j]
		else:
			dp1[i+1][j] = max(dp1[i][j], dp1[i][j-wv[i][0]]+wv[i][1])

wv = wv[::-1]

for i in range(N):
	for j in range(T):
		if j < wv[i][0]:
			dp2[i+1][j] = dp2[i][j]
		else:
			dp2[i+1][j] = max(dp2[i][j], dp2[i][j-wv[i][0]]+wv[i][1])

wv = wv[::-1]
ans = 0
for i in range(1, N+1):
	tmp = 0
	for j in range(T):
		tmp = max(tmp, dp1[i-1][j] + dp2[N-i][T-1-j])
	ans = max(ans, tmp+wv[i-1][1])

print(ans)
Problem p02897 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
if N % 2 == 0:
	print(0.5)
else:
	print(((N+1)*1/2)/N)

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
dp = [INF]*(1<<N)
dp[0] = 0

for _ in range(M):
	a, b = MAP()
	c = LIST()
	d = 0
	for x in c:
		d += 1<<(x-1)

	for j in range(1<<N):
		tmp = j|d
		dp[tmp] = min(dp[tmp], dp[j]+a)

if dp[-1] == INF:
	print(-1)
else:
	print(dp[-1])
Problem p02912 (python)

Fixed submission:
from heapq import heappush, heappop, heapify
import math

N, M = map(int, input().strip().split())
A = list(map(int, input().strip().split()))
A = [-x for x in A]
A.sort()
for i in range(M):
  heappush(A, math.ceil(heappop(A)/2))

print(-sum(A))

Buggy submission (verdict: Runtime Error):
from heapq import heappush, heappop, heapify

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

A.sort()
heap = heapify(A)
for i in range(M):
  heappush(heap, heappop()//2)
print(sum(heap))
Problem p02990 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

factorial = [1]
for i in range(1, N+1):
	factorial.append(factorial[i-1] * i % mod)

def power(x, y):
	if y == 0:
		return 1
	elif y == 1:
		return x % mod
	elif y % 2 == 0:
		return power(x, int(y/2)) ** 2 % mod
	else:
		return power(x, int((y-1)/2)) ** 2 * x % mod

def C(n, r):
	return (((factorial[n] * x_inv[r]) % mod) * x_inv[n-r]) % mod

x_inv = [0] * (N+1)
x_inv[-1] = power(factorial[-1], mod-2)
for i in range(N-1, -1, -1):
	x_inv[i] = x_inv[i+1] * (i+1) % mod

for i in range(1, K+1):
	if N-K >= i-1:
		print((C(K-1, i-1)*C(N-K+1, i))%mod)
	else:
		print(0)

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

factorial = [1]
for i in range(1, N):
	factorial.append(factorial[i-1] * i % mod)

def power(x, y):
	if y == 0:
		return 1
	elif y == 1:
		return x % mod
	elif y % 2 == 0:
		return power(x, int(y/2)) ** 2 % mod
	else:
		return power(x, int((y-1)/2)) ** 2 * x % mod

def C(n, r):
	return (((factorial[n] * x_inv[r]) % mod) * x_inv[n-r]) % mod

x_inv = [0] * (N)
x_inv[-1] = power(factorial[-1], mod-2)
for i in range(N-2, -1, -1):
	x_inv[i] = x_inv[i+1] * (i+1) % mod

for i in range(1, K+1):
	print((C(K-1, i-1)*C(N-K+1, i))%mod)
Problem p03033 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()

event = [None]*(2*N+Q)
Xl = [0]*N
for i in range(N):
    S, T, X = MAP()
    event[2*i] = (S-X, 1, X)
    event[2*i+1] = (T-X, 0, X)
    Xl[i] = X

t = 2*N
for i in range(Q):
    D = INT()
    event[t+i] = (D, 2, 0)


event.sort()
p = []
q = []
for t, c, x in event:
    if c == 0:
        heappush(q, x)
    elif c == 1:
        heappush(p, x)
    else:
        while q and p[0] == q[0]:
            heappop(p)
            heappop(q)
        print(-1 if not p else p[0])

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()

event = [None]*(2*N+Q)
Xl = [0]*N
for i in range(N):
	S, T, X = MAP()
	event[2*i] = (S-X, 1, X)
	event[2*i+1] = (T-X, 0, X)
	Xl[i] = X

t = 2*N
for i in range(Q):
	D = INT()
	event[t+i] = (D, 2, 0)

event.sort()
p = []
q = []
for t, c, x in event:
	if c == 0:
		heappush(p, x)
	elif c == 1:
		heappush(q, x)
	else:
        while q and p[0] == q[0]:
            heappop(p)
            heappop(q)
		print(-1 if not p else p[0])
Problem p03127 (python)

Fixed submission:
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z
    
N = int(input())
A = [int(x) for x in input().split()]

for i in range(N):
    if i == 0:
        tmp = A[i]
    if i == N:
        break
    else:
        tmp = gcd(tmp, A[i])

print(tmp)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
A = [int(x) for x in input().split()]

for i in range(N):
    if i == 0:
        tmp = A[i]
    if i == N:
        break
    else:
        tmp = math.gcd(tmp, A[i])

print(tmp)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
A = [int(x) for x in input().split()]

for i in range(N):
    if i == 0:
        tmp = A[i]
    if i == N:
        break
    else:
        tmp = math.gcd(tmp, A[i])

print(tmp)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
A = [int(x) for x in input().split()]

for i in range(N):
    if i == 0:
        tmp = A[i]
    if i == N:
        break
    else:
        tmp = math.gcd(tmp, A[i])

print(tmp)
Problem p03208 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
h = [INT() for _ in range(N)]

h.sort()

ans = INF
for i in range(N-K+1):
	ans = min(ans, h[i+K-1]-h[i])

print(ans)

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
h = [INT() for _ in range(N)]

h.sort()

ans = INF
for i in range(K):
	ans = min(ans, h[i+K-1]-h[i])

print(ans)
Problem p03745 (python)

Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import groupby, accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
A = [k for k, g in groupby(A)]
N = len(A)
i = 1
ans = 0

while i < N-1:
	if A[i-1] < A[i] > A[i+1] or A[i-1] > A[i] < A[i+1]:
		ans += 1
		i += 1
	i += 1

print(ans+1)

Buggy submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import groupby, accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
A = [k for k, g in groupby(A)]
i = 1
ans = 0

while i < N-1:
	if A[i-1] < A[i] > A[i+1] or A[i-1] > A[i] < A[i+1]:
		ans += 1
		i += 1
	i += 1

print(ans+1)