Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc107/tasks/arc101_a
# C - Candles

n, k = list(map(int, input().split()))
x_list = list(map(int, input().split()))
x_list = sorted(x_list)
min_l = float('inf')

minus_list = [x for x in x_list if x < 0]
plus_index = len(minus_list)
# print('plus_index: {}'.format(plus_index))
# plus_list = [x for x in work_list if x >= 0]

for i, x in enumerate(x_list):
    l = 0
    minus_list = []
    plus_list = []
    if i + k < plus_index:
        # 全部負の数
        minus_list = x_list[i:i+k]
        plus_list = []
    elif i > plus_index:
        # 全部正の数
        plus_list = x_list[i:i+k]
        minus_list = []
    else:
        minus_list = x_list[i:plus_index]
        diff = k - len(minus_list)
        plus_list = x_list[plus_index: plus_index + (k - len(minus_list))]

    # print(minus_list)
    # print(plus_list)

    minus_l = -minus_list[0] if minus_list else 0
    plus_l = plus_list[-1] if plus_list else 0
    # print('{}, {}'.format(minus_l, plus_l))

    if plus_l > minus_l:
        l = minus_l * 2 + plus_l
    else:
        l = plus_l * 2 +  minus_l

    if l < min_l:
        min_l = l

    if i + k > n - 1:
        break

print(min_l)

Fixed submission:
# https://atcoder.jp/contests/abc107/tasks/arc101_a
# C - Candles

n, k = list(map(int, input().split()))
x_list = list(map(int, input().split()))
x_list = sorted(x_list)
min_l = float('inf')

minus_list = [x for x in x_list if x < 0]
plus_index = len(minus_list)

for i, x in enumerate(x_list):
    left, right = x_list[i], x_list[i+k-1]
    # 最左端に行ってから、最右端に行く
    a = abs(left) + abs(left-right)
    # 最右端に行ってから、最左端に行く
    b = abs(right) + abs(right - left)
    l = min(a, b)

    if l < min_l:
        min_l = l

    if i + k > n - 1:
        break

print(min_l)

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc107/tasks/arc101_a
# C - Candles

n, k = list(map(int, input().split()))
x_list = list(map(int, input().split()))
x_list = sorted(x_list)
min_l = float('inf')
# 0の場所は

for i, x in enumerate(x_list):
    l = 0
    work_list = x_list[i:i+k]
    minus_list = [x for x in work_list if x < 0]
    plus_list = [x for x in work_list if x >= 0]

    minus_l = -minus_list[0] if minus_list else 0
    plus_l = plus_list[-1] if plus_list else 0

    if plus_l > minus_l:
        l = minus_l * 2 + plus_l
    else:
        l = plus_l * 2 +  minus_l

    if l < min_l:
        min_l = l

    if i + k > n - 1:
        break

print(min_l)

Fixed submission:
# https://atcoder.jp/contests/abc107/tasks/arc101_a
# C - Candles

n, k = list(map(int, input().split()))
x_list = list(map(int, input().split()))
x_list = sorted(x_list)
min_l = float('inf')

minus_list = [x for x in x_list if x < 0]
plus_index = len(minus_list)

for i, x in enumerate(x_list):
    left, right = x_list[i], x_list[i+k-1]
    # 最左端に行ってから、最右端に行く
    a = abs(left) + abs(left-right)
    # 最右端に行ってから、最左端に行く
    b = abs(right) + abs(right - left)
    l = min(a, b)

    if l < min_l:
        min_l = l

    if i + k > n - 1:
        break

print(min_l)

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc107/tasks/arc101_a
# C - Candles

n, k = list(map(int, input().split()))
x_list = list(map(int, input().split()))
x_list = sorted(x_list)
min_l = float('inf')
# 0の場所は

for i, x in enumerate(x_list):
    l = 0
    work_list = x_list[i:i+k]
    minus_list = [x for x in work_list if x < 0]
    plus_list = [x for x in work_list if x >= 0]

    if not plus_list:
        l = abs(min(minus_list))
    elif not minus_list:
        l = max(plus_list)
    elif max(plus_list) > max(minus_list):
        l = abs(min(minus_list)) * 2 + max(plus_list)
    else:
        l = max(plus_list) * 2 + abs(min(minus_list))

    if l < min_l:
        min_l = l

    if i + k > n - 1:
        break

print(min_l)

Fixed submission:
# https://atcoder.jp/contests/abc107/tasks/arc101_a
# C - Candles

n, k = list(map(int, input().split()))
x_list = list(map(int, input().split()))
x_list = sorted(x_list)
min_l = float('inf')

minus_list = [x for x in x_list if x < 0]
plus_index = len(minus_list)

for i, x in enumerate(x_list):
    left, right = x_list[i], x_list[i+k-1]
    # 最左端に行ってから、最右端に行く
    a = abs(left) + abs(left-right)
    # 最右端に行ってから、最左端に行く
    b = abs(right) + abs(right - left)
    l = min(a, b)

    if l < min_l:
        min_l = l

    if i + k > n - 1:
        break

print(min_l)