CodeEff/ECCO huggingface dataset:
# Original solution
import bisect
N, K = list(map(int, input().split()))
x = list(map(int, input().split()))
t = 2 * (x[-1] - x[0])
i = bisect.bisect_right(x, 0)
for j in range(0, N):
    if N <= j + K -1 :
        break
    if (j - (i - 0.1)) * (j + K- 1 - (i - 0.1)) >= 0:
        t = min(t, max(abs(x[j]), abs(x[j+K-1])))
    else:
        t = min(t, abs(2 * x[j]) + x[j+K-1])
        t = min(t, abs(x[j]) + 2 * x[j+K-1])
print(t)

# Optimized solution
N, K = list(map(int, input().split()))
x = list(map(int, input().split()))
dist = 2 * (x[-1] - x[0])
for i in range(N):
    if i + K -1 >= N:
        break
    dist = min(dist, abs(x[i]) + abs(x[i + K - 1] - x[i]),abs(x[i + K -1]) + abs(x[i + K - 1] - x[i]))
print(dist)
# Original solution
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = inf 
count = 0; pro = 1

n, k = list(map(int, input().split()))
A=[]; B=[]
x=list(map(int,input().split()))
for i in range(n-(k-1)):
    candi = max(abs(x[i+k-1]),abs(x[i]))
    if x[i+k-1]*x[i]<0:
        candi += 2*min(abs(x[i+k-1]), abs(x[i]))

    ans = min(ans, candi)
print(ans)


# Optimized solution
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,k = list(map(int,input().split()))
X = list(map(int,input().split()))
for i in range(n-k+1):
  fi = X[i]
  en = X[i+k-1]
  if fi <= 0 and en >= 0:
    mans = min(mans,min(-fi,en)-fi+en)
  else:
    mans=min(mans,max(abs(fi),abs(en)))
print(mans)
# Original solution
N, K = list(map(int, input().split()))
x = list(map(int,input().split()))

candidate = []
for i in range(N - K + 1):
    tmp = []
    for j in range(i, i + K):
        tmp.append(x[j])
    candidate.append(tmp)

ans = 1000000000
for i in candidate:
    tmp = 0
    #最初の要素がマイナスだとマイナスとプラスの混合の可能性がある
    if i[0] < 0:
        #混合の場合
        if i[-1] > 0:
            #マイナスに最後に行く場合
            if abs(i[0]) > abs(i[-1]):
                tmp += abs(i[-1]) * 2
                tmp += abs(i[0])
            #プラスに最後に行く場合
            else:
                tmp += abs(i[0]) * 2
                tmp += abs(i[-1])
        #混合じゃない
        else:
            tmp += abs(i[0])
    else:
        #単純にすべて足す。
        tmp += i[-1]
    ans = min(ans, tmp)
print(ans)


# Optimized solution
N, K = list(map(int, input().split()))
x = list(map(int,input().split()))

ans = 100000000000
#最初と最後だけ調べればOK
for i in range(N - K + 1):
    tmp_min = x[i]
    tmp_max = x[i + K - 1]
    tmp = 0
    if tmp_min < 0:
        #混合の場合
        if tmp_max > 0:
            #+に先に行く場合
            if abs(tmp_min) > tmp_max:
                tmp = tmp_max * 2
                tmp += abs(tmp_min)
            #-に先に行く場合
            else:
                tmp = abs(tmp_min) * 2
                tmp += tmp_max
        #すべてマイナスの場合
        else:
            tmp = abs(tmp_min)
    else:
        tmp = tmp_max
    ans = min(ans, tmp)
print(ans)
# Original solution
N, K = list(map(int, input().split()))
x = list(map(int,input().split()))

ans = 100000000000
#最初と最後だけ調べればOK
for i in range(N - K + 1):
    tmp_min = x[i]
    tmp_max = x[i + K - 1]
    tmp = abs(tmp_min) + abs(tmp_min - tmp_max)
    tmp2 = abs(tmp_max) + abs(tmp_min - tmp_max)
    ans = min(ans, min(tmp, tmp2))
print(ans)





# Optimized solution
N, K = list(map(int, input().split()))
x = list(map(int,input().split()))

ans = 100000000000
#最初と最後だけ調べればOK
for i in range(N - K + 1):
    tmp_min = x[i]
    tmp_max = x[i + K - 1]
    ans = min(ans, min(abs(tmp_min), abs(tmp_max)) + abs(tmp_min - tmp_max))
print(ans)
# Original solution
#-*-coding:utf-8-*-

def main():
    n, k = list(map(int, input().split()))
    x_list = list(map(int, input().split()))

    ans = float('inf')
    for i in range(n - k + 1):
        arry = x_list[i:i+k]
        if arry[0] >= 0 and arry[-1] >= 0:
            ans = min(ans, arry[-1])
        elif arry[0] < 0 and arry[-1] < 0:
            ans = min(ans, -arry[0])
        else:
            ans = min(ans, -arry[0] * 2 + arry[-1])
    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
#-*-coding:utf-8-*-

def main():
    n, k = list(map(int, input().split()))
    x_list = list(map(int, input().split()))
    ans = float('inf')

    for i in range(n - k + 1):
        if x_list[i] >= 0 and x_list[i+k-1] >= 0:
            ans = min(ans, x_list[i+k-1])
        elif x_list[i] <= 0 and x_list[i+k-1] <= 0:
            ans = min(ans, -x_list[i])
        else:
            ans = min(ans, min(-x_list[i] * 2 + x_list[i+k-1] , -x_list[i] + x_list[i+k-1] * 2))
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
import bisect

n, k = list(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)



# Optimized solution
n, k = list(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)
# Original solution
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))

ans = 10 ** 9

for i in range(n-k+1):
    temp = x[i:i+k]
    dif = temp[-1] - temp[0]
    from_s = min(abs(temp[-1]), abs(temp[0]))

    ans = min(dif + from_s, ans)

print(ans)

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

ans = 10 ** 9

for i in range(n-k+1):

    l = abs(x[i]) + abs(x[i+k-1] - x[i])
    r = abs(x[i+k-1]) + abs(x[i+k-1] - x[i])

    if l < r:
        ans = min(ans, l)
    else:
        ans = min(ans, r)

print(ans)
# Original solution
# vim: set fileencoding=utf-8:
import bisect


def main():
    N, K = list(map(int, input().split()))
    x = [int(ele) for ele in input().split()]
    o = bisect.bisect_right(x, 0)
    top = min(o + K, N)
    bottom = max(o - K, 0)
    x = x[bottom:top]

    best = 999999999999
    u = len(x)
    for i in range(u):
        if u < i + K:
            break

        hani = x[i:i + K]
        if hani[0] < 0 and hani[-1] < 0:
            best = min(best, abs(hani[0]))
        elif hani[0] < 0 <= hani[-1]:
            best = min(best, 2 * abs(hani[0]) + hani[-1])
        elif 0 <= hani[0] and 0 <= hani[-1]:
            best = min(best, hani[-1])

    print(best)


if __name__ == "__main__":
    main()


# Optimized solution
# vim: set fileencoding=utf-8:
import bisect


def main():
    N, K = list(map(int, input().split()))
    x = [int(ele) for ele in input().split()]
    o = bisect.bisect_right(x, 0)
    top = min(o + K, N)
    bottom = max(o - K, 0)
    best = 999999999999
    for i in range(K):
        if top < bottom + i + K:
            break

        if x[bottom + i + K - 1] < 0:
            best = min(best, abs(x[bottom + i]))
        elif x[bottom + i] < 0 <= x[bottom + i + K - 1]:
            ans1 = 2 * min(abs(x[bottom + i]), x[bottom + i + K - 1])
            ans2 = max(abs(x[bottom + i]), x[bottom + i + K - 1])
            ans = min(best, ans1 + ans2)
            best = min(best, ans)
        elif 0 <= x[bottom + i]:
            best = min(best, x[bottom + i + K - 1])

    print(best)


if __name__ == "__main__":
    main()
# Original solution
MAX = 300000001

N, K = list(map(int, input().split()))
xn = [int(i) for i in input().split()]


def main():
    if 0 <= xn[0]:
        print((xn[K - 1]))
        return

    if xn[N - 1] < 0:
        print((abs(xn[N - K])))
        return

    ans = MAX

    for i in range(N):
        if N - 1 < i + K - 1:
            break

        if xn[i] < 0:
            if xn[i + K - 1] < 0 and i + K <= N - 1 and 0 < xn[i + K]:
                ans = min(ans, abs(xn[i]))

            elif 0 <= xn[i + K - 1]:
                ans = min(ans,
                          2 * abs(xn[i]) + abs(xn[i + K - 1]),
                          abs(xn[i]) + 2 * abs(xn[i + K - 1]))

        elif 0 == xn[i]:
            ans = min(ans, xn[i + K - 1])

    print(ans)
    return


main()


# Optimized solution
MAX = 300000001

N, K = list(map(int, input().split()))
xn = [int(i) for i in input().split()]


def main():
    if 0 <= xn[0]:
        print((xn[K - 1]))
        return

    if xn[N - 1] < 0:
        print((abs(xn[N - K])))
        return

    ans = MAX

    for i in range(N - K + 1):
        if xn[i + K - 1] < 0 and i + K <= N - 1 and 0 < xn[i + K]:
            ans = min(ans, abs(xn[i]))

        elif 0 <= xn[i + K - 1]:
            ans = min(ans,
                      2 * abs(xn[i]) + abs(xn[i + K - 1]),
                      abs(xn[i]) + 2 * abs(xn[i + K - 1]))

    print(ans)
    return


main()
# Original solution
MAX = 300000001

N, K = list(map(int, input().split()))
xn = [int(i) for i in input().split()]


def main():
    if 0 <= xn[0]:
        print((xn[K - 1]))
        return

    if xn[N - 1] < 0:
        print((abs(xn[N - K])))
        return

    ans = MAX

    for i in range(N - K + 1):
        if xn[i + K - 1] < 0 and i + K <= N - 1 and 0 < xn[i + K]:
            ans = min(ans, abs(xn[i]))

        elif 0 <= xn[i + K - 1]:
            ans = min(ans,
                      2 * abs(xn[i]) + abs(xn[i + K - 1]),
                      abs(xn[i]) + 2 * abs(xn[i + K - 1]))

    print(ans)
    return


main()


# Optimized solution
MAX = 300000001

N, K = list(map(int, input().split()))
xn = [int(i) for i in input().split()]


def main():
    if 0 <= xn[0]:
        print((xn[K - 1]))
        return

    if xn[N - 1] < 0:
        print((abs(xn[N - K])))
        return

    ans = MAX

    for i in range(N - K + 1):
        ans = min(ans,
                  2 * abs(xn[i]) + abs(xn[i + K - 1]),
                  abs(xn[i]) + 2 * abs(xn[i + K - 1]))

    print(ans)
    return


main()
# Original solution
MAX = 300000001

N, K = list(map(int, input().split()))
xn = [int(i) for i in input().split()]


def main():
    if 0 <= xn[0]:
        print((xn[K - 1]))
        return

    if xn[N - 1] < 0:
        print((abs(xn[N - K])))
        return

    ans = MAX

    for i in range(N - K + 1):
        ans = min(ans,
                  2 * abs(xn[i]) + abs(xn[i + K - 1]),
                  abs(xn[i]) + 2 * abs(xn[i + K - 1]))

    print(ans)
    return


main()


# Optimized solution
MAX = 300000001

N, K = list(map(int, input().split()))
xn = [int(i) for i in input().split()]


def main():
    if 0 < xn[0]:
        print((xn[K - 1]))
        return

    if xn[N - 1] < 0:
        print((abs(xn[N - K])))
        return

    ans = MAX

    for i in range(N - K + 1):
        ans = min(ans,
                  2 * abs(xn[i]) + abs(xn[i + K - 1]),
                  abs(xn[i]) + 2 * abs(xn[i + K - 1]))

    print(ans)
    return


main()
# Original solution
MAX = 300000001

N, K = list(map(int, input().split()))
xn = [int(i) for i in input().split()]


def main():
    if 0 < xn[0]:
        print((xn[K - 1]))
        return

    if xn[N - 1] < 0:
        print((abs(xn[N - K])))
        return

    ans = MAX

    for i in range(N - K + 1):
        if xn[i + K - 1] < 0 and i + K <= N - 1 and 0 < xn[i + K]:
            ans = min(ans, abs(xn[i]))

        elif 0 < xn[i]:
            if 0 != i:
                if xn[i - 1] < 0:
                    ans = min(ans, abs(xn[i + K - 1]))
                else:
                    break

        elif 0 <= xn[i + K - 1]:
            ans = min(ans,
                      2 * abs(xn[i]) + abs(xn[i + K - 1]),
                      abs(xn[i]) + 2 * abs(xn[i + K - 1]))

    print(ans)
    return


main()


# Optimized solution
MAX_D = 300000001


def main():
    N, K, *xn = list(map(int, open(0).read().split()))
    if 0 < xn[0]:
        print((xn[K - 1]))
        return
    if xn[N - 1] < 0:
        print((abs(xn[N - K])))
        return
    ans = MAX_D
    for i in range(N - K + 1):
        if xn[i + K - 1] < 0 and i + K <= N - 1 and 0 < xn[i + K]:
            ans = min(ans, abs(xn[i]))
        elif 0 < xn[i]:
            if 0 != i:
                if xn[i - 1] < 0:
                    ans = min(ans, abs(xn[i + K - 1]))
                else:
                    break
        elif 0 <= xn[i + K - 1]:
            ans = min(ans,
                      2 * abs(xn[i]) + abs(xn[i + K - 1]),
                      abs(xn[i]) + 2 * abs(xn[i + K - 1]))
    print(ans)
    return


main()
# Original solution
# coding: utf-8
# Your code here!
import bisect

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

zero=bisect.bisect_left(X,0)

ans=10**18
start=max(0,zero-K)
for i in range(start,start+N-K+1):
    temp=X[i:i+K]
    m=min(0,min(temp))
    M=max(0,max(temp))
    ans=min((abs(m)+abs(M)*2),(abs(m)*2+abs(M)),ans)
    
print(ans)



# Optimized solution
# coding: utf-8
# Your code here!
import bisect

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

zero=bisect.bisect_left(X,0)

ans=10**18
start=max(0,zero-K)
for i in range(start,start+N-K+1):
    #print(i)
    m=min(0,X[i])
    M=max(0,X[i+K-1])
    ans=min((abs(m)+abs(M)*2),(abs(m)*2+abs(M)),ans)
    if i+K==N:
        break
    
print(ans)
# Original solution
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))

ans = 10 ** 10
for i in range(n - k + 1):
    temp = x[i:i + k]
    left = temp[0]
    right = temp[-1]
    ans = min(ans, abs(left) + abs(right - left), abs(right) + abs(right - left))

print(ans)


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

ans = 10 ** 10
for i in range(n - k + 1):
    left = x[i]
    right = x[i + k - 1]
    ans = min(ans, abs(left) + abs(right - left), abs(right) + abs(right - left))

print(ans)
# Original solution
N, K = list(map(int,input().split()))
A = list(map(int,input().split()))
P = [0] + [abs(i) for i in A if i> 0 ]
M = [abs(i) for i in A if i< 0 ] +[0]
M = sorted(M,reverse =False)


cnt = 10000000000

if len(P) == len(M) == 1:
    cnt = 0
elif len(P) == 1:
    cnt = M[K]
elif len(M) == 1:
    cnt = P[K]
else:
    #リストがK以下の場合不具合が起きる
    #for i in range(1,K):   
    #len(P)=4 len(M)=3 K=5の場合、IndexErrorとなる。rangeをうまく設定する必要があるが実装できない。
    #正の方向でi個ろうそくを通って、負の方向にK-i個ろうそくを通る
    s = max(0,K-len(M)+1)
    e = min(K+1, len(P))
    for i in range(s, e):
        cnt =min(cnt,P[i]*2 + M[K-i])
    #負の方向でi個ろうそくを通って、正の方向にK-i個ろうそくを通る
    s1 = max(0,K-len(P)+1)
    e1 = min(K+1, len(M))
    for i in range(s1, e1):
        cnt =min(cnt,M[i]*2 + P[K-i])

print(cnt)

# Optimized solution
N,K = list(map(int,input().split()))
X = list(map(int,input().split()))
ans = 10**10

for i in range(N-K+1):
    #S = X[i:i+K]
    #print(S,S[0],S[-1])
    mi = X[i]
    ma = X[i+K-1]
    #print(mi,ma)
    if ma<=0:
        ans = min(ans ,abs(mi))
    elif  mi>0:
        ans = min(ans ,ma)
    elif  mi<0 and ma>0:
        if abs(mi) > ma :
            ans = min(ans,abs(mi) + 2*ma)
        else :
            ans = min(ans,abs(mi)*2 + ma)

print(ans)
# Original solution
n, k = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = float('Inf')
for i in range(n-k+1):
  temp = c[i:i+k]
  l, r = abs(temp[0]), abs(temp[-1])
  if temp[0] < 0 and temp[-1] > 0:
    ans = min(ans, min(l, r) * 2 + max(l, r))
  else:
    ans = min(ans, max(list(map(abs, temp))))
print(ans)

# Optimized solution
n, k = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = float('Inf')
for i in range(n-k+1):
  l, r = c[i], c[i+k-1]
  ans = min(abs(l) + abs(r-l), abs(r) + abs(r-l), ans)

print(ans)
# Original solution
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def solve(X, K):
    N = len(X)

    cumsum = [0 for _ in range(N)]
    for i in range(1, N):
        cumsum[i] = abs(X[i] - X[i - 1]) + cumsum[i - 1]

    idx_zero = bisect.bisect_left(X, 0)

    ret = 1000000005
    for i in range(0, N):
        if X[i] >= 0:
            break
        res = -X[i]
        k = idx_zero - i
        if (k < K) and (idx_zero + K - k - 1 < N):
            res += cumsum[idx_zero + K - k - 1] - cumsum[i]
            ret = min(ret, res)

    return ret


if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    X = list(map(int, input().split()))

    res = 1000000005
    if min(X) >= 0:
        print((X[K - 1]))
    elif max(X) <= 0:
        X = X[::-1]
        print((-X[K - 1]))
    else:
        res = min(res, solve(X, K))
        X = [-x for x in X]
        res = min(res, solve(X[::-1], K))
        print(res)


# Optimized solution
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
minus = []
plus = []
ans = 10**100
for x in a:
    if x <0:minus.append(-x)
    else:plus.append(x)
minus = minus[::-1]
for i in range(min(k+1,len(minus)+1)):#負のものをi個通る
    if k-i > len(plus):continue
    res = 0
    if i-1 >=0:res += minus[i-1]
    res*=2
    if k-i-1 >=0 and k-i <= len(plus):res += plus[k-i-1]
    ans = min(ans,res)
    res = 0
    if k-i-1 >=0 and  k-i <= len(plus):res += plus[k-i-1]
    res *=2
    if i-1 >=0:res += minus[i-1]
    ans = min(ans,res)
print(ans)
# Original solution
import itertools

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

pos = [0]
neg = []
for i in x:
    if i<0:
        neg.append(-i)
    else:
        pos.append(i)
neg = [0] + neg[::-1]

# negを往復する場合
neg_twice = []
for i in range(min(len(neg),k)):
    neg_twice.append(neg[i]*2)
for i in range(len(neg_twice)):
    if k-i<len(pos):
        neg_twice[i] += pos[k-i]
    else:
        neg_twice[i] = float('inf')
# posを往復する場合
pos_twice = []
for i in range(min(len(pos),k)):
    pos_twice.append(pos[i]*2)
for i in range(len(pos_twice)):
    if k-i<len(neg):
        pos_twice[i] += neg[k-i]
    else:
        pos_twice[i] = float('inf')
print((min(pos_twice+neg_twice)))


# Optimized solution
n,k = list(map(int,input().split()))
x = list(map(int,input().split()))
pos = []
neg = []
for i in x:
    if i < 0:
        neg.append(-i)
    else:
        pos.append(i)
neg = neg[::-1]

pos = [0] + pos
neg = [0] + neg

#print(pos)
#print(neg)

# posにいってからneg
res = float('inf')
for i in range(min(len(pos),k)):
    # posからi本灯して, negからK-i本灯す
    j = k - i
    if j >= len(neg):
        continue
    tmp = pos[i] * 2 + neg[j]
    res = min(res, tmp)

# negにいってからpos
for i in range(min(len(neg),k)):
    j = k - i
    if j >= len(pos):
        continue
    tmp = neg[i] * 2 + pos[j]
    res = min(res, tmp)

print(res)
# Original solution
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))

min_t = 10 ** 9

import bisect

snuke = bisect.bisect_left(x, 0)
if snuke < n and x[snuke] == 0:
    k -= 1
    n -= 1
    del x[snuke]

for i in range(k+1):
    if i == 0:
        left = 0
    elif snuke - i >= 0:
        left = abs(x[snuke - i])
    else:
        left = 10 ** 9

    if k - i == 0:
        right = 0
    elif snuke + k - i - 1 <= n - 1:
        right = abs(x[snuke + k - i - 1])
    else:
        right = 10 ** 9

    min_t = min(min_t, min(left, right) * 2 + max(left, right))

print(min_t)

# Optimized solution
n,k=list(map(int,input().split()))
x=sorted(list(map(int,input().split())))
a=[]
for i in range(n-k+1):
    l=x[i]
    r=x[i+k-1]
    a.append(min(abs(l)+abs(r-l),abs(r)+abs(l-r)))
print((min(a)))
# Original solution
N, K = list(map(int, input().split()))
candles = list(map(int, input().split()))
abs_c = [abs(c) for c in candles]
result = []
for n in range(N-K+1):
    route = candles[n:n+K]
    r1 = abs(route[0]) + abs(route[-1]-route[0])
    r2 = abs(route[-1]) + abs(route[0]-route[-1])
    result.append(min(r1, r2))

print((min(result)))

# Optimized solution
N, K = list(map(int, input().split()))
candles = list(map(int, input().split()))
abs_c = [abs(c) for c in candles]
result = []
for n in range(N-K+1):
    r1 = abs(candles[n]) + abs(candles[n+K-1]-candles[n])
    r2 = abs(candles[n+K-1]) + abs(candles[n]-candles[n+K-1])
    result.append(min(r1, r2))

print((min(result)))
# Original solution
N, K = list(map(int, input().split()))
x = list(map(int, input().split()))
left = []
right = []
cnt = 0
for i in range(N):
    if x[i] < 0:
        left += [-x[i]]
    elif x[i] > 0:
        right += [x[i]]
    else:
        cnt += 1
rest = K - cnt
left = left[::-1]
if rest != 0:
    ans = float('inf')
else:
    ans = 0
    print(ans)
    exit()

for i in range(rest+1):
    if i == 0 and len(right) >= rest:
        ans = min(ans, right[rest-1])
    elif rest-i == 0 and len(left) >= i:
        ans = min(ans, left[rest-1])
    elif len(left) >= i and len(right) >= rest-i:
        ans = min(ans, left[i-1]+right[rest-i-1]+min(left[i-1], right[rest-i-1]))

print(ans)

# Optimized solution
N, K = list(map(int, input().split()))
x = list(map(int, input().split()))
ans = float('inf')
for i in range(N-K+1):
    ans = min(ans, abs(x[i]) + abs(x[i]-x[i+K-1]))
    ans = min(ans, abs(x[i+K-1]) + abs(x[i]-x[i+K-1]))
print(ans)
# Original solution
R=[]
N,K=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]
for i in range(N-K+1):
    a=abs(x[i])+abs(x[i+K-1]-x[i])
    b=abs(x[i+K-1])+abs(x[i+K-1]-x[i])
    c=min(a,b)
    R.append(c)
print((min(R)))

# Optimized solution
ANS=[]
N,K=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]
for i in range(N-K+1):
    a=x[i]
    b=x[i+K-1]
    A=abs(a)+abs(a-b)
    B=abs(b)+abs(b-a)
    c=min(A,B)
    ANS.append(c)
print((min(ANS)))
# Original solution
n,k = list(map(int,input().split()))

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


for i in range(n-k+1):
	a = x[i:i+k]
	b = 0
	if a[-1] <= 0:
		b = -a[0]
	elif a[0] >= 0:
		b = a[-1]
	else:
		b = min(abs(a[0])*2+a[-1],a[-1]*2-a[0])
	ans = min(ans,b)
print(ans)

# Optimized solution
n,k = list(map(int,input().split()))

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

a = 0
while a != n:
	if x[a] >= 0:
		break
	a += 1
for i in range(max(0,a-k),n-k+1):
	if x[i+k-1] <= 0:
		ans = min(ans,-x[i])
	elif x[i] >= 0:
		ans = min(x[i+k-1],ans)
	else:
		ans = min(x[i+k-1]-x[i]+min(-x[i],x[i+k-1]),ans)
print(ans)
# Original solution
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))

ans = []
for i in range(n - k + 1):
    left = x[i]
    right = x[i + k - 1]
    ans.append(min(abs(left) + abs(right - left),
                   abs(right) + abs(left - right)))

print((min(ans)))

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

ans = []
for i in range(n - k + 1):
    left = x[i]
    right = x[i + k - 1]
    if abs(left) > abs(right):
        ans.append(abs(right) + abs(left - right))
    else:
        ans.append(abs(left) + abs(right - left))

print((min(ans)))