Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)])
ans = 10**9
for i in range(n-k+1):
  tmp = max(h[i:i+k])-min(h[i:i+k])
  if ans > tmp:
    ans = tmp
print(ans)

Fixed submission:
n, k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)])
ans = 10**9
for i in range(k-1, n):
  ans = min(ans, h[i]-h[i-k+1])
print(ans)
Buggy python submission (verdict: Runtime Error):
print('YES' if input() in '753' else 'NO')i

Fixed submission:
x = input()
print('YES' if x in '753' else 'NO')
Buggy python submission (verdict: Runtime Error):
n = int(input())

def abc(s):
  t = all('3' in s, '5' in s, '7' in s)
  if len(s) < len(n):
    return abc(s+'3') + abc(s+'5') + abc(s+'7') + t
  elif s <= n:
    return t
  else:
    return 0
print(abc(''))

Fixed submission:
n = input()

def abc(s):
  t = all(('3' in s, '5' in s, '7' in s))
  if len(s) < len(n):
    return abc(s+'3') + abc(s+'5') + abc(s+'7') + t
  elif s <= n:
    return t
  else:
    return 0

print(abc(''))
Buggy python submission (verdict: Runtime Error):
print(int(input()) + (int(input())//2))

Fixed submission:
x, y = map(int, input().split())
print(x + (y//2))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = float("inf")
for i in range(len(s)):
  ans = min(ans, s[:i].count('W')+s[i:].count('E'))
print(ans)

Fixed submission:
n = int(input())
s = input()
ans = float("inf")
E = s.count('E')
W = 0
for i in s:
  if i == 'E':
    E -= 1
    ans = min(ans, E+W)
  else:
    W += 1
    ans = min(ans, E+W-1)
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
for i in range(a, min(b,a+k)):
  print(i)
for j in range(max(i,b-k)+1, b+1):
  print(j)

Fixed submission:
a, b, k = map(int, input().split())
if a != b:
  if k == 0:
    print(a, b, sep='\n')
    exit()
else:
  print(a)
  exit()
for i in range(a, min(b,a+k)):
  print(i)
for j in range(max(i,b-k)+1,b+1):
  print(j)
Buggy python submission (verdict: Time Limit Exceeded):
import math
A,B = map(int,input().split())
N = max(A,B)
prime = []

tA = A
tB = B
for i in range(2, math.ceil(N**0.5)+1):
    if tA%i==0 and tB%i==0:
        while tA%i==0:
            tA //= i
        while tB%i==0:
            tB //= i
        prime.append(i)

if tA!=1 or tB != 1:
    N = max(tA,tB)
    for i in range(2, N+1):
        if tA%i==0 and tB%i==0:
            while tA%i==0:
                tA //= i
            while tB%i==0:
                tB //= i
            prime.append(i)

# print(prime)
print(len(prime)+1)

Fixed submission:
import math
A,B = map(int,input().split())
N = max(A,B)
prime = []

tA = A
tB = B
for i in range(2, math.ceil(N**0.5)+1):
    Aflag = False
    Bflag = False
    if tA%i==0:
        Aflag = True
        while tA%i==0:
            tA //= i
    if tB%i==0:
        Bflag = True
        while tB%i==0:
            tB //= i
    if Aflag == True and Bflag == True:
        prime.append(i)

if tA!=1 and tA == tB:
    prime.append(tA)

# print(prime)
print(len(prime)+1)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
A,B = map(int,input().split())

L = range(2,fractions.gcd(A,B)+1)
# print(list(L))
prime = []

for i in L:
    if (A%i != 0) or (B%i != 0):
        continue

    primecheck = True
    for j in prime:
        if i%j == 0:
            primecheck = False

    if primecheck == True:
        prime.append(i)
prime.append(1)

# print(prime)
print(len(prime))

Fixed submission:
import math
A,B = map(int,input().split())
N = max(A,B)
prime = []

tA = A
tB = B
for i in range(2, math.ceil(N**0.5)+1):
    Aflag = False
    Bflag = False
    if tA%i==0:
        Aflag = True
        while tA%i==0:
            tA //= i
    if tB%i==0:
        Bflag = True
        while tB%i==0:
            tB //= i
    if Aflag == True and Bflag == True:
        prime.append(i)

if tA!=1 and tA == tB:
    prime.append(tA)

# print(prime)
print(len(prime)+1)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))


diff = []
npA = np.array(A)
lenA = len(A)
for a in A:
    temp = list(np.array([a for i in range(lenA)]) - npA)
    diff.append(temp)

D = np.array(diff)

upD = np.triu(D,k=1)

upC = np.count_nonzero(upD>0)

ans = int(K*(2*upC) - dwC)
print(ans%(1000000007))

Fixed submission:
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))


diff = []
npA = np.array(A)
lenA = len(A)
for a in A:
    temp = list(np.array([a for i in range(lenA)]) - npA)
    diff.append(temp)

D = np.array(diff)

upD = np.triu(D,k=1)

upC = np.count_nonzero(upD>0)
dwC = np.count_nonzero(upD<0)

ans = (K*(K+1)//2)*upC + ((K-1)*K//2)*dwC
print(ans%(1000000007))
Buggy python submission (verdict: Time Limit Exceeded):
import string

N = int(input())

CountList = []

atoz = string.ascii_lowercase
for i in range(N):
    temp = ''
    s=input()
    CountList.append(''.join(sorted(s)))

lis = set(CountList)

count = 0

for str in lis:
    strcount = CountList.count(str)
    count += sum(range(strcount))

print(count)

Fixed submission:
import string
import collections

N = int(input())

CountList = []

atoz = string.ascii_lowercase
for i in range(N):
    temp = ''
    s=input()
    CountList.append(''.join(sorted(s)))

str = collections.Counter(CountList)

count = 0
for s in str:
    count += sum(range(str[s]))

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import string

N = int(input())

CountList = []

atoz = string.ascii_lowercase
for i in range(N):
    temp = ''
    s=input()
    CountList.append(''.join(sorted(s)))

count = 0
for i,str1 in enumerate(CountList[:-1]):
    for str2 in CountList[i+1:]:
        if str1==str2:
            count+=1

print(count)

Fixed submission:
import string
import collections

N = int(input())

CountList = []

atoz = string.ascii_lowercase
for i in range(N):
    temp = ''
    s=input()
    CountList.append(''.join(sorted(s)))

str = collections.Counter(CountList)

count = 0
for s in str:
    count += sum(range(str[s]))

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import string

N = int(input())

CountList = []

atoz = string.ascii_lowercase
for i in range(N):
    temp = ''
    s=input()
    for c in atoz:
        temp+=str(s.count(c))
    CountList.append(temp)

count = 0
for i,str1 in enumerate(CountList[:-1]):
    for str2 in CountList[i+1:]:
        if str1==str2:
            count+=1

print(count)

Fixed submission:
import string
import collections

N = int(input())

CountList = []

atoz = string.ascii_lowercase
for i in range(N):
    temp = ''
    s=input()
    CountList.append(''.join(sorted(s)))

str = collections.Counter(CountList)

count = 0
for s in str:
    count += sum(range(str[s]))

print(count)
Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split(' ')]
frei = [int(x) for x in input().split(' ')]

ans = 0
for x int frie:
  if x >= k:
    ans += 1
print(ans)
     

Fixed submission:
n, k = [int(x) for x in input().split(' ')]
frei = [int(x) for x in input().split(' ')]

ans = 0
for x in frei:
    if x >= k:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()

l = -1
r = A[0] * F[-1]
while l+1 < r:
    c = (l + r) // 2
    practice = 0
    for i in range(N):
        practice += max(math.ceil(A[i] - c / F[i]), 0)
    if practice <= K:
        r = c
    else:
        l = c
print(r)

Fixed submission:
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()

l = -1
r = A[0] * F[-1]
while l+1 < r:
    c = (l + r) // 2
    practice = 0
    for i in range(N):
        practice += max(math.ceil(A[i] - c / F[i]), 0)
    if practice <= K:
        r = c
    else:
        l = c
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, L = map(int, input().split())
INF = 1001001001

class Graph():
    def __init__(self, N):
        self.graph = [[INF for _ in range(N)] for _ in range(N)]
        for i in range(N):
            self.graph[i][i] = 0

    def add_path(self, a, b, c):
        self.graph[a][b] = c
        self.graph[b][a] = c

    def get(self, a, b):
        return self.graph[a][b]

    def warshall_floyd(self):
        N = len(self.graph)
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    self.graph[i][j] = min(self.graph[i][j], self.graph[i][k]+self.graph[k][j])

path = Graph(N)
for _ in range(M):
    A, B, C = map(int, input().split())
    path.add_path(A-1, B-1, C)
path.warshall_floyd()
aid = Graph(N)
for i in range(N):
    for j in range(i+1, N):
        if path.get(i, j) <= L:
            aid.add_path(i, j, 1)
aid.warshall_floyd()
Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    ans = aid.get(s-1, t-1)
    if ans == INF:
        print(-1)
    else:
        print(ans-1)

Fixed submission:
N, M, L = map(int, input().split())
INF = 1001001001

class Graph():
    def __init__(self, N):
        self.graph = [[INF for _ in range(N)] for _ in range(N)]
        for i in range(N):
            self.graph[i][i] = 0

    def add_path(self, a, b, c):
        self.graph[a][b] = c
        self.graph[b][a] = c

    def get(self, a, b):
        return self.graph[a][b]

    def warshall_floyd(self):
        N = len(self.graph)
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    self.graph[i][j] = min(self.graph[i][j], self.graph[i][k]+self.graph[k][j])

path = Graph(N)
for _ in range(M):
    A, B, C = map(int, input().split())
    path.add_path(A-1, B-1, C)
path.warshall_floyd()
aid = Graph(N)
for i in range(N):
    for j in range(i+1, N):
        if path.get(i, j) <= L:
            aid.add_path(i, j, 1)
aid.warshall_floyd()
Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    ans = aid.get(s-1, t-1)
    if ans == INF:
        print(-1)
    else:
        print(ans-1)
Buggy python submission (verdict: Time Limit Exceeded):
Q = int(input())
a = []
b = 0

for _ in range(Q):
    q = list(map(int, input().split()))
    if q[0] == 1:
        a.append(q[1])
        b += q[2]
    else:
        a.sort()
        idx = len(a) // 2
        if len(a) % 2 == 0:
            ans_x = a[idx-1]
        else:
            ans_x = a[idx]
        ans = b
        if len(a) == 0:
            print("0 0")
        else:
            for v in a:
                if v < ans_x:
                    ans += ans_x - v
                else:
                    ans += v - ans_x
            print("{0} {1}".format(ans_x, ans))


Fixed submission:
import heapq

Q = int(input())
ans = 0

L = []
R = []

for _ in range(Q):
    q = list(map(int, input().split()))
    if q[0] == 1:
        l = heapq.heappushpop(L, -q[1])
        r = heapq.heappushpop(R, q[1])
        heapq.heappush(L, -r)
        heapq.heappush(R, -l)
        ans += abs(l + r) + q[2]
    else:
        print(-L[0], ans)

Buggy python submission (verdict: Time Limit Exceeded):
Q = int(input())
a = []
b = 0

for _ in range(Q):
    q = list(map(int, input().split()))
    if q[0] == 1:
        a.append(q[1])
        b += q[2]
    else:
        a.sort()
        idx = len(a) // 2
        if len(a) % 2 == 0:
            ans_x = a[idx-1]
        else:
            ans_x = a[idx]
        ans = b
        if len(a) == 0:
            print("0 0")
        else:
            for v in a:
                if v < ans_x:
                    ans += ans_x - v
                else:
                    ans += v - ans_x
            print("{0} {1}".format(ans_x, ans))


Fixed submission:
import heapq

Q = int(input())
ans = 0

L = []
R = []

for _ in range(Q):
    q = list(map(int, input().split()))
    if q[0] == 1:
        l = heapq.heappushpop(L, -q[1])
        r = heapq.heappushpop(R, q[1])
        heapq.heappush(L, -r)
        heapq.heappush(R, -l)
        ans += abs(l + r) + q[2]
    else:
        print(-L[0], ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

class UnionFind():
    def __init__(self, N):
        self.nodes = [i for i in range(N)]

    def root(self, x):
        if self.nodes[x] != x:
            self.nodes[x] = self.root(self.nodes[x])
        return self.nodes[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        if self.same(x, y):
            return
        self.nodes[self.root(x)] = self.root(y)

uf = UnionFind(N)
anti_list = [[] for _ in range(N)]

for _ in range(M):
    x, y, z = map(int, input().split())
    uf.unite(x-1, y-1)

group = set()
for node in uf.nodes:
    group.add(uf.root(node))

print(len(group))


Fixed submission:
import sys
sys.setrecursionlimit(10**5)

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

class UnionFind():
    def __init__(self, N):
        self.nodes = [i for i in range(N)]

    def root(self, x):
        if self.nodes[x] != x:
            self.nodes[x] = self.root(self.nodes[x])
        return self.nodes[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        if self.same(x, y):
            return
        self.nodes[self.root(x)] = self.root(y)

uf = UnionFind(N)

for _ in range(M):
    x, y, z = map(int, input().split())
    uf.unite(x-1, y-1)

group = set()
for node in uf.nodes:
    group.add(uf.root(node))

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

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

not_replaced_max = A[0]

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

# def divisor(n):
#     limit = int(math.sqrt(n))
#     for i in range(2, limit):
#         if n % i == 0:
#             result.append(i)
#     return result

# def merge(A, B):

# divisor_list = divisor(A[1])
# for i in range(1, N):
#     not_replaced_max = gcd(not_replaced_max, A[i])
# print(replaced_max)
#
A.sort()

def func(n):
    limit = int(math.sqrt(n))
    divisor = []
    for i in range(1, limit):
        if n % i == 0:
            divisor.append(i)
    return divisor

def merge(A, B):
    divisor_list = [a for a in A]
    for b in B:
        if b not in A:
            divisor_list.append(b)
    return divisor_list

divisor_list = merge(func(A[0], A[1]))
divisor_list.sort(reverse=True)
is_end = False
for d in divisor_list:
    count = 0
    for a in A:
        if a % d != 0:
            count += 1
            if count > 1:
                break
    if count == 0 or is_end:
        print(d)
    else:
        is_end = True


Fixed submission:
import math

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

gcd_list = [0 for _ in range(N)]

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

for i in range(1, N):
    gcd_list[i] = gcd(gcd_list[i-1], A[i-1])
last_gcd = 0
for i in range(N-2, -1, -1):
    last_gcd = gcd(last_gcd, A[i+1])
    gcd_list[i] = gcd(last_gcd, gcd_list[i])

print(max(gcd_list))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())
K = int(input())

target = S[K]
ans = ""
for s in S:
    ans += s if s == target else "*"
print(ans)


Fixed submission:
N = int(input())
S = list(input())
K = int(input())

target = S[K-1]
ans = ""
for s in S:
    ans += s if s == target else "*"
print(ans)
Buggy python submission (verdict: Runtime Error):
    def get_input_row():
      return [int(i) for i in input().split(" ")]
     
    inp = get_input_row()
    N = inp[0]
    M = inp[1]
    item_dict = {}
    num = 0
    for i in range(N):
      a, b = get_input_row()
      if a in item_dict:
        item_dict[a] += b
      else:
      	item_dict[a] = b
    sorted_list = [k for k in item_dict.keys()]
    sorted_list.sort()
    money = 0
    for price in sorted_list:
      if M > item_dict[price]:
        M -= item_dict[price]
        money += price * item_dict[price]
      else:
        money += price * M
        break
    print(money)

Fixed submission:
def get_input_row():
  return [int(i) for i in input().split(" ")]
     
inp = get_input_row()
N = inp[0]
M = inp[1]
item_dict = {}
num = 0
for i in range(N):
  a, b = get_input_row()
  if a in item_dict:
    item_dict[a] += b
  else:
    item_dict[a] = b

sorted_list = [k for k in item_dict.keys()]
sorted_list.sort()
money = 0
for price in sorted_list:
  if M > item_dict[price]:
    M -= item_dict[price]
    money += price * item_dict[price]
  else:
    money += price * M
    break
print(money)
Buggy python submission (verdict: Runtime Error):
N = int(input())

money = 0
for _ in range(N):
    x, u = map(int, input().split())
    if u == "JPY":
        money += x
    else:
        money += x * 380000
print(money)


Fixed submission:
N = int(input())

money = 0
for _ in range(N):
    x, u = input().split()
    if u == "JPY":
        money += float(x)
    else:
        money += float(x) * 380000
print(money)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
useful_num_list = list(map(int, input().split()))

need_matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [-1] * (N+1)
dp[0] = 0
for i in range(1, N+1):
    max_scale = -1
    for num in useful_num_list:
        if need_matches[num] <= i:
            scale = dp[i-need_matches[num]] + 1
            if max_scale < scale:
                max_scale = scale
    dp[i] = max_scale

useful_num_list.sort(reverse=True)
ans =""
n = N
while n > 0:
    ans_scale = ""
    for num in useful_num_list:
        if dp[n] - 1 == dp[n - need_matches[num]]:
            ans_scale = str(num)
            n -= need_matches[num]
            break
    ans += ans_scale
print(ans)


Fixed submission:
A, B = map(int, input().split())

if B % A == 0:
    print(A+B)
else:
    print(B-A)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
loved_by_everyone = [0] * M
for _ in range(N):
    like_list = list(map(int, input().split()))
    for like in like_list[1:]:
        loved_by_everyone[like] += 1

kinds = 0
for food in loved_by_everyone:
    kinds += 1 if food == N else 0
print(kinds)


Fixed submission:
N, M = map(int, input().split())
loved_by_everyone = [0] * M
for _ in range(N):
    like_list = list(map(int, input().split()))
    for like in like_list[1:]:
        loved_by_everyone[like-1] += 1

kinds = 0
for food in loved_by_everyone:
    kinds += 1 if food == N else 0
print(kinds)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

scale = 1
while scale <= K:
    scale *= 2
scale /= 2

X = 0
while scale >= 1:
    count = 0
    for i in range(N):
        if A[i] >= scale:
            A[i] -= scale
            count += 1
        else:
            count -= 1
    if count > 0:
        X += scale

ans = 0
for a in A:
    ans += X^a
print(ans)


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

X = 0
ans = 0
for i in range(40, -1, -1):
    bit = 1 << i
    count = 0
    for a in A:
        if bit & a:
            count += 1
    if N >= count * 2 and (X^bit) <= K:
        X ^= bit
        count = N - count
    ans += count * bit

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

elem = [0 for _ in range(N+1)]

for i in range(1, N+1):
    cur = i
    for j in range(1, i+1):
        while cur % j == 0:
            elem[j] += 1
            cur //= j

def num(m):
    return len(list(filter(lambda x: x >= m-1, elem)))

print(num(75)  + num(25)*(num(3)-1) + num(15)*(num(3)-1) + num(5)*(num(5)-1)*(num(3)-2) // 2)


Fixed submission:
N = int(input())

elem = [0 for _ in range(N+1)]

for i in range(1, N+1):
    cur = i
    for j in range(2, i+1):
        while cur % j == 0:
            elem[j] += 1
            cur //= j

def num(m):
    return len(list(filter(lambda x: x >= m-1, elem)))

print(num(75)  + num(25)*(num(3)-1) + num(15)*(num(5)-1) + num(5)*(num(5)-1)*(num(3)-2) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

start = M // N
for i in range(start, 0, -1):
    if M % i == 0:
        print(i)
        break


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

start = M // N
for i in range(start, 0, -1):
    if M % i == 0:
        print(i)
        break
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

odd_cells = []
for y in range(H):
    for x in range(W):
        x = x if y % 2 == 0 else W-x-1
        if A[y][x] % 2 == 1:
            odd_cells.append([x+1, y+1])

ans_operation = []
for i in range(0, len(odd_cells), 2):
    source = odd_cells[i]
    dist = odd_cells[i+1]
    while not (source[0] == dist[0] and source[1] == dist[1]):
        if dist[1] - source[1] > 1:
            ans_operation.append(source+[source[0], source[1]+1])
            source[1] += 1
        else:
            if (source[0] == W and source[1] % 2 == 1) or\
                    (source[0] == 0 and source[1] % 2 == 0):
                ans_operation.append(source+[source[0], source[1]+1])
                source[1] += 1
            else:
                direction = 1 if source[1] % 2 == 1 else -1
                ans_operation.append(source+[source[0]+direction, source[1]])
                source[0] += direction

print(len(ans_operation))
for ans in ans_operation:
    # x と y が逆
    print(ans[1], ans[0], ans[3], ans[2])


Fixed submission:
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

odd_cells = []
for y in range(H):
    for x in range(W):
        x = x if y % 2 == 0 else W-x-1
        if A[y][x] % 2 == 1:
            odd_cells.append([x+1, y+1])

ans_operation = []
for i in range(0, len(odd_cells)-1, 2):
    source = odd_cells[i]
    dist = odd_cells[i+1]
    while not (source[0] == dist[0] and source[1] == dist[1]):
        if (source[0] == W and source[1] % 2 == 1) or\
                (source[0] == 1 and source[1] % 2 == 0):
            ans_operation.append(source+[source[0], source[1]+1])
            source[1] += 1
        else:
            direction = 1 if source[1] % 2 == 1 else -1
            ans_operation.append(source+[source[0]+direction, source[1]])
            source[0] += direction

print(len(ans_operation))
for ans in ans_operation:
    # x と y が逆
    print(ans[1], ans[0], ans[3], ans[2])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
X = list(map(int, input().split()))

distance = max([X[-1] - X[0], -X[i], X[-1]])
for i in range(N-K+1):
    if X[i+K-1] < 0:
        distance = min(distance, -X[i])
    elif X[i] > 0:
        distance = min(distance, X[i+K-1])
    else:
        tmp_distance = X[i+K-1]-X[i]
        tmp_distance += min(X[i+K-1], -X[i])
        distance = min(distance, tmp_distance)
print(distance)


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

distance = float('inf')
for i in range(N-K+1):
    tmp_distance = abs(X[i]) + abs(X[i+K-1]-X[i])
    distance = min(distance, tmp_distance)
    tmp_distance = abs(X[i+K-1]) + abs(X[i+K-1]-X[i])
    distance = min(distance, tmp_distance)
print(distance)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().split())

# cum_sum[L][R]
cum_sum = [[0 for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
    L, R = map(int, input().split())
    cum_sum[L][R] += 1

for l in range(1, N+1):
    for r in range(1, N+1):
        cum_sum[l][r] += cum_sum[l][r-1]

for _ in range(Q):
    p, q = map(int, input().split())
    ans = 0
    for l in range(p, q+1):
        ans += cum_sum[l][q] - cum_sum[l][p-1]
    print(ans)


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

# cum_sum[L][R]
cum_sum = [[0 for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
    L, R = map(int, input().split())
    cum_sum[L][R] += 1

for l in range(1, N+1):
    for r in range(1, N+1):
        cum_sum[l][r] += cum_sum[l][r-1] + cum_sum[l-1][r] - cum_sum[l-1][r-1]

for _ in range(Q):
    p, q = map(int, input().split())
    print(cum_sum[q][q]-cum_sum[q][p-1]-cum_sum[p-1][q]+cum_sum[p-1][p-1])