Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
x = []
y = []
for i in input().split():
    n = int(i)
    if n < 0:
        x.append(-n)
    elif n == 0:
        K -= 1
    else:
        y.append(n)

x = x[::-1]

len_x = len(x)
len_y = len(y)
now = 10 ** 18

if len_x == 0:
    if len_y == 0:
        print(0)
    else:
        print(y[K-1])
elif len_y == 0:
    print(x[K-1])
else:
    for i in range(max(K - len_x, 0), K+1):
        if len_x < i:
            break
        if i == 0:
            now = min(x[K-1], now)
        elif i == K:
            now = min(y[K-1], now)
        else:
            now = min(min(x[i-1], y[K-i-1]) + x[i-1] + y[K-i-1], now)

    print(now)

Fixed submission:
N, K = map(int, input().split())
x = []
y = []
for i in input().split():
    n = int(i)
    if n < 0:
        x.append(-n)
    elif n == 0:
        K -= 1
    else:
        y.append(n)

x = x[::-1]

len_x = len(x)
len_y = len(y)
now = 10 ** 18

if len_x == 0:
    if len_y == 0:
        print(0)
    else:
        print(y[K-1])
elif len_y == 0:
    print(x[K-1])
else:
    for i in range(K+1):
        if K - i > len_y:
            continue
        if len_x < i:
            break
        if i == 0:
            now = min(y[K-1], now)
        elif i == K:
            now = min(x[K-1], now)
        else:
            now = min(min(x[i-1], y[K-i-1]) + x[i-1] + y[K-i-1], now)

    print(now)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
x = []
y = []
for i in input().split():
    n = int(i)
    if n < 0:
        x.append(-n)
    elif n == 0:
        K -= 1
    else:
        y.append(n)

x = x[::-1]

len_x = len(x)
len_y = len(y)
now = 10 ** 18

if len_x == 0:
    if len_y == 0:
        print(0)
    else:
        print(y[K-1])
elif len_y == 0:
    print(x[K-1])
else:
    for i in range(max(K - len_x, 0), K+1):
        if len_x < i:
            break
        print('x',i, K-i)
        if i == 0:
            now = min(x[K-1], now)
        elif i == K:
            now = min(y[K-1], now)
        else:
            now = min(min(x[i-1], y[K-i-1]) + x[i-1] + y[K-i-1], now)

    print(now)

Fixed submission:
N, K = map(int, input().split())
x = []
y = []
for i in input().split():
    n = int(i)
    if n < 0:
        x.append(-n)
    elif n == 0:
        K -= 1
    else:
        y.append(n)

x = x[::-1]

len_x = len(x)
len_y = len(y)
now = 10 ** 18

if len_x == 0:
    if len_y == 0:
        print(0)
    else:
        print(y[K-1])
elif len_y == 0:
    print(x[K-1])
else:
    for i in range(K+1):
        if K - i > len_y:
            continue
        if len_x < i:
            break
        if i == 0:
            now = min(y[K-1], now)
        elif i == K:
            now = min(x[K-1], now)
        else:
            now = min(min(x[i-1], y[K-i-1]) + x[i-1] + y[K-i-1], now)

    print(now)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
x = []
y = []
for i in input().split():
    n = int(i)
    if n < 0:
        x.append(-n)
    elif n == 0:
        K -= 1
    else:
        y.append(n)

x = x[::-1]

now = 10 ** 20
len_x = len(x)
len_y = len(y)

if len_x == 0:
    if len_y == 0:
        print(0)
    else:
        print(y[K-1])
elif len_y == 0:
    print(x[K-1])
else:
    for i in range(max(K - len_x, 0), K):
        if len_x < i:
            break
        now = min(min(x[i-1], y[K-i-1]) + x[i-1] + y[K-i-1], now)

    print(now)

Fixed submission:
N, K = map(int, input().split())
x = []
y = []
for i in input().split():
    n = int(i)
    if n < 0:
        x.append(-n)
    elif n == 0:
        K -= 1
    else:
        y.append(n)

x = x[::-1]

len_x = len(x)
len_y = len(y)
now = 10 ** 18

if len_x == 0:
    if len_y == 0:
        print(0)
    else:
        print(y[K-1])
elif len_y == 0:
    print(x[K-1])
else:
    for i in range(K+1):
        if K - i > len_y:
            continue
        if len_x < i:
            break
        if i == 0:
            now = min(y[K-1], now)
        elif i == K:
            now = min(x[K-1], now)
        else:
            now = min(min(x[i-1], y[K-i-1]) + x[i-1] + y[K-i-1], now)

    print(now)