Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
x = list(map(int, input().split()))

dist = []
for i in range(N-K+1): 
    l, r = x[i], x[i+k-1]
    t = min(abs(l)+abs(l-r), abs(r)+abs(r-l))
    dist.append(t)

print(min(dist))

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

dist = []
for i in range(N-K+1): 
    l, r = x[i], x[i+K-1]
    t = min(abs(l)+abs(l-r), abs(r)+abs(r-l))
    dist.append(t)

print(min(dist))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
x = list(map(int, input().split()))

dist = []
for i in range(N-K+1):
    t = 0
    tmp = x[i:i+K]
    l, r = tmp[0], tmp[-1]
    
    t = min(abs(l)+abs(l-r), abs(r)+abs(r-l))

    dist.append(t)

print(min(dist))

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

dist = []
for i in range(N-K+1): 
    l, r = x[i], x[i+K-1]
    t = min(abs(l)+abs(l-r), abs(r)+abs(r-l))
    dist.append(t)

print(min(dist))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
x = list(map(int, input().split()))

dist = []
for i in range(N-K+1):
    a = 0
    tmp = x[i:i+K]
    mini, maxi = tmp[0], tmp[-1]
    if (mini >= 0 and maxi >= 0):
        a = maxi
    elif (mini < 0 and maxi < 0):
        a = abs(mini)
    if mini < 0 and maxi >= 0:
        a = abs(mini) + maxi + min(abs(mini), maxi)
    dist.append(a)

print(min(dist))

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

dist = []
for i in range(N-K+1): 
    l, r = x[i], x[i+K-1]
    t = min(abs(l)+abs(l-r), abs(r)+abs(r-l))
    dist.append(t)

print(min(dist))

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
x = list(map(int, input().split()))

dist = []
for i in range(N-K+1):
    a = 0
    tmp = x[i:i+K]
    mini, maxi = tmp[0], tmp[-1]
    if (mini >= 0 and maxi >= 0):
        a = maxi
    elif (mini < 0 and maxi < 0):
        a = abs(mixi)
    if mini < 0 and maxi >= 0:
        a = abs(mixi) + maxi + min(abs(mixi), maxi)
    dist.append(a)

print(min(dist))

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

dist = []
for i in range(N-K+1): 
    l, r = x[i], x[i+K-1]
    t = min(abs(l)+abs(l-r), abs(r)+abs(r-l))
    dist.append(t)

print(min(dist))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
x = list(map(int, input().split()))

dist = []
for i in range(N-K+1):
    a = 0
    tmp = x[i:i+K]
    mini, maxi = tmp[0], tmp[-1]
    if (mini >= 0 and maxi >= 0):
        a = tmp[-1]
    elif (mini < 0 and maxi < 0):
        a = abs(tmp[0])
    if mini < 0 and maxi >= 0:
        a = abs(tmp[0]) + tmp[-1] + min(abs(tmp[0]), tmp[-1])
    dist.append(a)

print(min(dist))

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

dist = []
for i in range(N-K+1): 
    l, r = x[i], x[i+K-1]
    t = min(abs(l)+abs(l-r), abs(r)+abs(r-l))
    dist.append(t)

print(min(dist))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
x = list(map(int, input().split()))

dist = []
for i in range(N-K+1):
    max_pos = 0
    min_neg = 0
    tmp = x[i:i+K]
    pos = []
    neg = []
    pos = [tmp[j] for j in range(K) if tmp[j] >= 0]
    neg = [tmp[j] for j in range(K) if tmp[j] < 0]
    if pos:
        max_pos = max(pos)
    if neg:
        min_neg = abs(min(neg))
    dist.append((max_pos + min_neg + min(max_pos, min_neg)))

print(min(dist))

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

dist = []
for i in range(N-K+1): 
    l, r = x[i], x[i+K-1]
    t = min(abs(l)+abs(l-r), abs(r)+abs(r-l))
    dist.append(t)

print(min(dist))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
x = list(map(int, input().split()))

dist = []
for i in range(N-K+1):
    pos_exist = False
    neg_exist = False
    max_pos = 0
    min_neg = 0
    tmp = x[i:i+K]
    pos = []
    neg = []
    for j in range(K):
        if tmp[j] >= 0:
            pos.append(tmp[j])
            pos_exist = True
        else:
            neg.append(tmp[j])
            neg_exist = True
    if pos_exist:
        max_pos = max(pos)
    if neg_exist:
        min_neg = abs(min(neg))
    dist.append((max_pos + min_neg + min(max_pos, min_neg)))

print(min(dist))

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

dist = []
for i in range(N-K+1): 
    l, r = x[i], x[i+K-1]
    t = min(abs(l)+abs(l-r), abs(r)+abs(r-l))
    dist.append(t)

print(min(dist))