Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a = []
b = []
min = 10
minutes = 0

for i in range(5):
    a.append(int(input()))
    amari = a[i] % 10
    if amari < min and 0 < amari:
        min = amari
        min_index = i

a[4], a[min_index] = a[min_index], a[4]

for i in range(4):
    if a[i] % 10 != 0:
        minutes += (a[i] // 10 + 1) * 10
    else:
        minutes += a[i]

minutes += a[4]

print(minutes)

Fixed submission:
a = []
b = []
min = 10
minutes = 0
min_index = 0

for i in range(5):
    a.append(int(input()))
    if 0 < a[i] % 10 < min:
        min = a[i] % 10
        min_index = i

a[4], a[min_index] = a[min_index], a[4]

for i in range(4):
    if a[i] % 10 != 0:
        minutes += (a[i] // 10 + 1) * 10
    else:
        minutes += a[i]

minutes += a[4]

print(minutes)
Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = list(input())

l = [0]
ll = []
count = 0

for i in range(n):
    if s[i] == 'A' and s[i+1] == 'C':
        count += 1
    l.append(count)


for i in range(q):
    array = list(map(int, input().split()))
    ll.append(array)

for i in range(q):
    print(l[ll[i][1]-1] - l[ll[i][0]-1])



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

l = [0]
ll = []
count = 0

for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        count += 1
    l.append(count)


for i in range(q):
    array = list(map(int, input().split()))
    ll.append(array)

for i in range(q):
    print(l[ll[i][1]-1] - l[ll[i][0]-1])

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = list(input())

l = [0]
ll = []
count = 0

for i in range(n):
    if s[i] == 'A' and s[i+1] == 'C':
        count += 1
    l.append(count)


for i in range(q):
    array = list(map(int, input().split()))
    ll.append(array)

for i in range(q):
    print(l[ll[i][1]-1] - l[ll[i][0]-1])

print(l)


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

l = [0]
ll = []
count = 0

for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        count += 1
    l.append(count)


for i in range(q):
    array = list(map(int, input().split()))
    ll.append(array)

for i in range(q):
    print(l[ll[i][1]-1] - l[ll[i][0]-1])

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

l = []

num_list = []
for i in range(len(s)-1):
    if s[i] == 'A' and s[i+1] == 'C':
        num_list.append(i)

for i in range(q):
    array = list(map(int, input().split()))
    l.append(array)

for i in range(q):
    count = 0
    for j in num_list:
        if l[i][0]-1 <= j < l[i][1]-1:
            count += 1
    print(count)

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

l = [0]
ll = []
count = 0

for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        count += 1
    l.append(count)


for i in range(q):
    array = list(map(int, input().split()))
    ll.append(array)

for i in range(q):
    print(l[ll[i][1]-1] - l[ll[i][0]-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

ans = 0
stack = [s[0]]
flg = False
for i in range(1,len(s)):
        if len(stack) > 0:
            if stack[0] != s[i]:
                ans += 2
                stack.pop(0)
            else:
                stack.insert(0, s[i])
        else:
            stack.insert(0, s[i])

print(ans)


Fixed submission:
s = list(input())
count_zero = 0
count_one = 0
for i in range(len(s)):
    if s[i] == '1':
        count_one += 1
    else:
        count_zero += 1

print(len(s) - abs(count_zero - count_one))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
bridges = []
island_connection = [[i] for i in range(n)]
unconfortable = (n * (n - 1)) // 2
unconfortable_list = [unconfortable]

for i in range(m):
    array = list(map(int, input().split()))
    array[0] -= 1
    array[1] -= 1
    bridges.append(array)

bridges = bridges[::-1]

for i, j in bridges:
    if unconfortable != 0:
        if len(island_connection[i]) == 1 and len(island_connection[j]) == 1:
            unconfortable -= 1
            island_connection[i].append(j)
            island_connection[j].append(i)
        else:
            unconfortable -= (len(island_connection[i]) * len(island_connection[j]))
            plus_list_1 = island_connection[i].copy()
            plus_list_2 = island_connection[j].copy()
            for island in plus_list_1:
                island_connection[island].extend(plus_list_2)
            for island in plus_list_2:
                island_connection[island].extend(plus_list_1)

    unconfortable_list.append(unconfortable)

for i in range(1, m+1):
    print(unconfortable_list[-1-i])



Fixed submission:
n, m = map(int, input().split())
bridges = []
island_connection = [1] * n
unconfortable = (n * (n - 1)) // 2
unconfortable_list = [unconfortable]


class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]
        # 正==子: 根の頂点番号 / 負==根: 連結頂点数

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        else:
            if self.size(x) < self.size(y):
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x

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

    def size(self, x):
        x = self.find(x)
        return -self.parent[x]

    def is_root(self, x):
        return self.parent[x] < 0


connection = UnionFind(n)

for i in range(m):
    array = list(map(int, input().split()))
    array[0] -= 1
    array[1] -= 1
    bridges.append(array)

bridges = bridges[::-1]

for i, j in bridges:
    if connection.same(i,j) == 0:
        p = connection.size(i)
        q = connection.size(j)
        if p == 1 and q == 1:
            unconfortable -= 1
            connection.unite(i, j)
        else:
            unconfortable -= (p * q)
            connection.unite(i, j)
    unconfortable_list.append(unconfortable)

for i in range(1, m+1):
    print(unconfortable_list[-1-i])
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

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

print(gcd_list(x))

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

hp = max(l)

l.sort()

while hp > 1 and len(l) != 1:
    a = l[0]
    for i in range(1, len(l)):
        l[i] %= a
    l.sort()
    while l[0] == 0:
        l.remove(0)
    if l[0] < hp:
        hp = l[0]

print(hp)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

x = list(map(int, input().split()))
x = sorted(x)
diff = [x[i+1] - x[i] for i in range(0, m-1)]

sort_diff = sorted(diff, reverse=True)

sum = 0

if len(sort_diff) == 0:
    print(0)
    exit()

for i in range(n-1):
    sort_diff.pop(0)

for i in range(len(sort_diff)):
    sum += sort_diff[i]
print(sum)

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

if n >= m:
    print(0)
    exit()

x = list(map(int, input().split()))
x = sorted(x)
diff = [x[i+1] - x[i] for i in range(0, m-1)]

sort_diff = sorted(diff, reverse=True)

sum = 0

if len(sort_diff) == 0:
    print(0)
    exit()

for i in range(n-1):
    sort_diff.pop(0)

for i in range(len(sort_diff)):
    sum += sort_diff[i]
print(sum)

Buggy python submission (verdict: Runtime Error):

n, m = map(int, input().split())

x = list(map(int, input().split()))
x = sorted(x)
diff = [x[i+1] - x[i] for i in range(0, m-1)]

sort_diff = sorted(diff, reverse=True)

sum = 0
for i in range(n-1):
    sort_diff.pop(0)

for i in range(len(sort_diff)):
    sum += sort_diff[i]
print(sum)

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

if n >= m:
    print(0)
    exit()

x = list(map(int, input().split()))
x = sorted(x)
diff = [x[i+1] - x[i] for i in range(0, m-1)]

sort_diff = sorted(diff, reverse=True)

sum = 0

if len(sort_diff) == 0:
    print(0)
    exit()

for i in range(n-1):
    sort_diff.pop(0)

for i in range(len(sort_diff)):
    sum += sort_diff[i]
print(sum)

Buggy python submission (verdict: Runtime Error):
import itertools

n, m = map(int, input().split())

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

x = sorted(x)
sum = 0
min = 1000000
flag = False
if m == 1:
    flag = True
    min = 0

l = list(range(1, m))

for i in itertools.combinations(l, n-1): # Change the conbination mCn
    if flag == True:
        break
    sum = 0
    for j in range(0, n):
        if j == 0:
            sum += x[i[0]-1] - x[0]
        elif j == n-1:
            sum += x[-1] - x[i[-1]]
        else:
            sum += x[i[j]-1] - x[i[j-1]]
    if sum < min:
        min = sum

print(min)

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

if n >= m:
    print(0)
    exit()

x = list(map(int, input().split()))
x = sorted(x)
diff = [x[i+1] - x[i] for i in range(0, m-1)]

sort_diff = sorted(diff, reverse=True)

sum = 0

if len(sort_diff) == 0:
    print(0)
    exit()

for i in range(n-1):
    sort_diff.pop(0)

for i in range(len(sort_diff)):
    sum += sort_diff[i]
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

excess = []
shortage = []

ans = 0

for i in range(n):
    if a[i] >= b[i]:
        excess.append(a[i] - b[i])
    else:
        shortage.append(b[i] - a[i])

ans = len(shortage)

if sum(excess) < sum(shortage):
    print(-1)
elif len(shortage) == 0:
    print(0)
else:
    excess.sort(reverse=True)
    excess_num = 0
    for i in range(n):
        excess_num += excess[i]
        ans += 1
        if excess_num >= sum(shortage):
            print(ans)
            exit()

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

excess = []
shortage = []

ans = 0

for i in range(n):
    if a[i] >= b[i]:
        excess.append(a[i] - b[i])
    else:
        shortage.append(b[i] - a[i])

ans = len(shortage)

if sum(excess) < sum(shortage):
    print(-1)
elif len(shortage) == 0:
    print(0)
else:
    excess.sort(reverse=True)
    excess_num = 0
    shortage_num = sum(shortage)
    for i in range(n):
        excess_num += excess[i]
        ans += 1
        if excess_num >= shortage_num:
            print(ans)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, w = map(int ,input().split())
items = []
for i in range(n):
    array = list(map(int, input().split()))
    items.append(array)
dp = np.zeros((n+1, w+1))

for i in range(1, n+1):
    weight = items[i-1][0]
    for j in range(0, w+1):
        if j >= weight:
            dp[i][j] = max((dp[i - 1][j - weight] + items[i - 1][1]), dp[i - 1][j])
        else:
            dp[i][j] = dp[i-1][j]


print(int(dp[i][j]))



Fixed submission:
n, w = map(int ,input().split())
items = []
for i in range(n):
    array = list(map(int, input().split()))
    items.append(array)
# dp = np.zeros((n+1, w+1))
dp = [[0 for _ in range(w+1)] for _ in range(n+1)]

for i in range(1, n+1):
    weight = items[i-1][0]
    for j in range(0, w+1):
        if j >= weight:
            dp[i][j] = max((dp[i - 1][j - weight] + items[i - 1][1]), dp[i - 1][j])
        else:
            dp[i][j] = dp[i-1][j]


print(int(dp[i][j]))

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

n, w = map(int ,input().split())
items = []
for i in range(n):
    array = list(map(int, input().split()))
    items.append(array)
dp = np.zeros((n+1, w+1))


for i in range(1, n+1):
    weight = items[i-1][0]
    for j in range(0, w+1):
        if j >= weight:
            dp[i][j] = max((dp[i - 1][j - weight] + items[i - 1][1]), dp[i - 1][j])
        else:
            dp[i][j] = dp[i-1][j]

print(int(dp[-1][-1]))

Fixed submission:
n, w = map(int ,input().split())
items = []
for i in range(n):
    array = list(map(int, input().split()))
    items.append(array)
# dp = np.zeros((n+1, w+1))
dp = [[0 for _ in range(w+1)] for _ in range(n+1)]

for i in range(1, n+1):
    weight = items[i-1][0]
    for j in range(0, w+1):
        if j >= weight:
            dp[i][j] = max((dp[i - 1][j - weight] + items[i - 1][1]), dp[i - 1][j])
        else:
            dp[i][j] = dp[i-1][j]


print(int(dp[i][j]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

weight = []

N, W = map(int, input().split())
for i in range(N):
    array = list(map(int, input().split()))
    weight.append(array)

dp = [[0 for i in range(W+1)] for i in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j >= weight[i][0]:
            dp[i+1][j] = max(dp[i][j-weight[i][0]] + weight[i][1], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[N][W])

Fixed submission:
n, w = map(int ,input().split())
items = []
for i in range(n):
    array = list(map(int, input().split()))
    items.append(array)
# dp = np.zeros((n+1, w+1))
dp = [[0 for _ in range(w+1)] for _ in range(n+1)]

for i in range(1, n+1):
    weight = items[i-1][0]
    for j in range(0, w+1):
        if j >= weight:
            dp[i][j] = max((dp[i - 1][j - weight] + items[i - 1][1]), dp[i - 1][j])
        else:
            dp[i][j] = dp[i-1][j]


print(int(dp[i][j]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
sitigosan_list = [3, 5, 7]
count = 0

if n < 357:
    print(0)
    exit()

def make_753(num):
    b = str(num) + '3'
    c = str(num) + '5'
    d = str(num) + '7'
    sitigosan_list.append(int(b))
    sitigosan_list.append(int(c))
    sitigosan_list.append(int(d))


for i in sitigosan_list:
    make_753(i)
    if max(sitigosan_list) > n:
        break

for j in sitigosan_list:
    if '3' in str(j) and '5' in str(j) and '7' in str(j) and j <= n:
        count += 1

print(count)


Fixed submission:
n = int(input())

sitigosan_list = [3, 5, 7]
count = 0

if n < 357:
    print(0)
    exit()

def make_753(num):
    global count
    b = str(num) + '3'
    c = str(num) + '5'
    d = str(num) + '7'
    if int(b) > n:
        return
    elif '3' in str(b) and '5' in str(b) and '7' in str(b):
        count += 1
        make_753(b)
    else:
        make_753(b)
    if int(c) > n:
        return
    elif '3' in str(c) and '5' in str(c) and '7' in str(c):
        count += 1
        make_753(c)
    else:
        make_753(c)
    if int(d) > n:
        return
    elif '3' in str(d) and '5' in str(d) and '7' in str(d):
        count += 1
        make_753(d)
    else:
        make_753(d)


make_753('')

print(count)
Buggy python submission (verdict: Runtime Error):
n, t = map(int,input().split())

routes = []

for i in range(n):
    array = list(map(int, input().split()))
    if array[1] <= t:
        routes.append(array)

if not routes:
    print('TLE')
    exit()

print(min(routes[1]))




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

routes = []
cost = 1000

for i in range(n):
    array = list(map(int, input().split()))
    if array[1] <= t:
        routes.append(array)
        cost = min(array[0], cost)

if not routes:
    print('TLE')
    exit()

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

lis = []

for i in range(n):
    array = list(map(int, input().split()))
    lis.append(array)

ans_list = []

for i in range(101):
    for j in range(101):
        h = abs(i-lis[0][0]) + abs(j-lis[0][1]) + lis[0][2]
        flag = True
        for k in range(1, n):
            dist = abs(i - lis[k][0]) + abs(j - lis[k][1])
            if h - dist == lis[k][2]:
                continue
            else:
                flag = False
                break
        if flag is True:
            ans_list.append([i, j, h])

ans_list.sort(reverse=True, key=lambda x:x[2])

for i in ans_list[0]:
    print(i, end=' ')



Fixed submission:
n = int(input())

lis = []

for i in range(n):
    array = list(map(int, input().split()))
    lis.append(array)

lis.sort(reverse=True, key=lambda x:x[2])
ans_list = []

for i in range(101):
    for j in range(101):
        h = abs(i-lis[0][0]) + abs(j-lis[0][1]) + lis[0][2]
        flag = True
        for k in range(1, n):
            dist = abs(i - lis[k][0]) + abs(j - lis[k][1])
            if h - dist == lis[k][2]:
                continue
            elif h - dist <= 0 and lis[k][2] == 0:
                continue
            else:
                flag = False
                break
        if flag is True:
            print(i, j, h)
Buggy python submission (verdict: Time Limit Exceeded):
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

prime_list = primes(10**7)
p_list = set(prime_list)

n, m = map(int, input().split())

ans = 1

for i in prime_list:
    if n * i > m:
        break
    if m % i == 0:
        num = m // i
        if num in p_list:
            ans = i
        elif num < n:
            continue
        elif num >= i * n:
            a = num // n
            ans = i * a
    else:
        continue

print(ans)

Fixed submission:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n, m = map(int, input().split())

ans = 1

div = make_divisors(m)

for i in div:
    if i * n <= m:
        ans = i
    else:
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

x = input()
y = input()

c = collections.Counter(x)
d = collections.Counter(y)

chars = []
for i in c.items():
    if i[1] >= 2:
        chars.append(i[0])
for j in d.items():
    if j[1] >= 2:
        chars.append(j[0])

chars = list(set(chars))



for i in chars:
    li = []
    li_2 = []
    for j in range(len(x)):
        if i == x[j]:
            li.append(y[j])
        elif i == y[j]:
            li_2.append(x[j])
        if len(li) >= 2:
            if len(list(set(li))) == 1:
                continue
            else:
                print('No')
                exit()
        elif len(li_2) >= 2:
            if len(list(set(li_2))) == 1:
                continue
            else:
                print('No')
                exit()

print('Yes')


Fixed submission:
s = input()
t = input()

alphabet_1 = [[] for _ in range(26)]
alphabet_2 = [[] for _ in range(26)]

for i in range(len(s)):
    if alphabet_1[ord(s[i])-97] == []:
        alphabet_1[ord(s[i])-97] = t[i]
    else:
        if alphabet_1[ord(s[i])-97] == t[i]:
            continue
        else:
            print('No')
            exit()

    if alphabet_2[ord(t[i])-97] == []:
        alphabet_2[ord(t[i])-97] = s[i]
    else:
        if alphabet_2[ord(t[i])-97] == s[i]:
            continue
        else:
            print('No')
            exit()

print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
x = input()
y = input()


for i in range(97,123):
    li = []
    li_2 = []
    for j in range(len(x)):
        if chr(i) == x[j]:
            li.append(y[j])
        elif chr(i) == y[j]:
            li_2.append(x[j])
        if len(li) >= 2:
            if len(list(set(li))) == 1:
                continue
            else:
                print('No')
                exit()
        elif len(li_2) >= 2:
            if len(list(set(li_2))) == 1:
                continue
            else:
                print('No')
                exit()

print('Yes')


Fixed submission:
s = input()
t = input()

alphabet_1 = [[] for _ in range(26)]
alphabet_2 = [[] for _ in range(26)]

for i in range(len(s)):
    if alphabet_1[ord(s[i])-97] == []:
        alphabet_1[ord(s[i])-97] = t[i]
    else:
        if alphabet_1[ord(s[i])-97] == t[i]:
            continue
        else:
            print('No')
            exit()

    if alphabet_2[ord(t[i])-97] == []:
        alphabet_2[ord(t[i])-97] = s[i]
    else:
        if alphabet_2[ord(t[i])-97] == s[i]:
            continue
        else:
            print('No')
            exit()

print('Yes')
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

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

if n == 1:
    print(abs(x-l[0]))
    exit()

diff = []
for i in range(len(l)-1):
    diff.append(abs(l[i] - l[i+1]))

for i in range(len(l)):
    diff.append(abs(l[i] - x))

gcd = gcd(diff[0], diff[1])
if n == 2:
    print(gcd)
    exit()

for i in range(2, len(diff)-1):
    gcd = gcd(gcd, diff[i])

print(gcd)

Fixed submission:
from fractions import gcd

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

if n == 1:
    print(abs(x-l[0]))
    exit()

diff = []
for i in range(len(l)-1):
    diff.append(abs(l[i] - l[i+1]))

for i in range(len(l)):
    diff.append(abs(l[i] - x))

gcd_1 = gcd(diff[0], diff[1])
if n == 2:
    print(gcd_1)
    exit()

for i in range(2, len(diff)-1):
    gcd_1 = gcd(gcd_1, diff[i])

print(gcd_1)

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

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

if n == 1:
    print(abs(x-l[0]))
    exit()

diff = []
for i in range(len(l)-1):
    diff.append(abs(l[i] - l[i+1]))

for i in range(len(l)):
    diff.append(abs(l[i] - x))

gcd = math.gcd(diff[0], diff[1])
if n == 2:
    print(gcd)
    exit()

for i in range(2, len(diff)-1):
    gcd = math.gcd(gcd, diff[i])

print(gcd)

Fixed submission:
from fractions import gcd

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

if n == 1:
    print(abs(x-l[0]))
    exit()

diff = []
for i in range(len(l)-1):
    diff.append(abs(l[i] - l[i+1]))

for i in range(len(l)):
    diff.append(abs(l[i] - x))

gcd_1 = gcd(diff[0], diff[1])
if n == 2:
    print(gcd_1)
    exit()

for i in range(2, len(diff)-1):
    gcd_1 = gcd(gcd_1, diff[i])

print(gcd_1)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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


for distance in range(100000000):
    a = bisect.bisect_left(x, -distance)
    b = bisect.bisect_right(x, distance)
    near_k = b- a
    if near_k == k:
        break
    elif near_k > k:
        if x[a]+1 in x:
            a += 1
            break
        elif x[b-1] - 1 in x:
            b -= 1
            break

if x[b-1] * x[a] < 0:
    semi_final_distance = max(x[b-1], x[a])+ (-2 * min(x[b-1], x[a]))
else:
    semi_final_distance = max(x[b-1], x[a])

a_2 = bisect.bisect_left(x, -semi_final_distance)
b_2 = bisect.bisect_right(x, semi_final_distance)
c = bisect.bisect_left(x, 0)
if b_2 - c > k:
    for distance in range(semi_final_distance):
        b_3 = bisect.bisect_right(x, distance)
        if b_3 - c == k:
            print(distance)
            exit()
elif c - a_2 > k:
    for distance in range(semi_final_distance):
        a_3 = bisect.bisect_left(x, -distance)
        if c - a_3 == k:
            print(distance)
            exit()
else:
    print(semi_final_distance)



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


def cal_num(a, b):
    if x[a] * x[b] < 0:
        return min(abs(x[a]), abs(x[b])) * 2 + max(abs(x[a]), abs(x[b]))
    else:
        return max(abs(x[a]), abs(x[b]))

for i in range(n-k+1):
    c = cal_num(i, i+k-1)
    if num >= c:
        num = c

print(num)