CodeEff/ECCO huggingface dataset:
# Original solution
# -*- coding: utf-8 -*-

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

kouho = []
ans_list = []
for i in range(N-K+1):
    li = xi[i:i+K]
    if li[0]*li[-1] < 0:
        a = abs(li[0])*2 + abs(li[-1])
        b = abs(li[-1])*2 + abs(li[0])
        if a > b :
            ans_list.append(b)
        else:
            ans_list.append(a)
    elif li[0] < 0:
        ans_list.append(abs(li[0]))
    else: #if li[-1] > 0:
        ans_list.append(abs(li[-1]))

print((min(ans_list)))


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

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

ans_list = []
for i in range(N-K+1):
    l = xi[i]
    r = xi[i+K-1]
    if l*r < 0:
        a = abs(l)*2 + abs(r)
        b = abs(r)*2 + abs(l)
        if a > b :
            ans_list.append(b)
        else:
            ans_list.append(a)
    elif l < 0:
        ans_list.append(abs(l))
    else: #if li[-1] > 0:
        ans_list.append(abs(r))

print((min(ans_list)))
# Original solution
N, K = list(map(int, input().split()))
X = list(map(int, input().split()))

if N == 1:
    print((abs(X[0])))
    exit()


flg = False

for x in X:
    if x < 0:
        flg = True

if flg is False:
    print((X[K - 1]))
    exit()

flag2 = False

for x in X:
    if x > 0:
        flag2 = True

if flag2 is False:
    X.reverse()
    print((abs(X[K - 1])))
    exit()


def sol(lft, rgt):
    if X[lft] < 0 and X[rgt] < 0:
        return float('inf')
    elif X[lft] <= 0:
        return min(2 * abs(X[lft]) + X[rgt], abs(X[lft]) + 2 * X[rgt])
    else:
        return float('inf')


lft, rgt = 0, 0
ans = float('inf')
while True:

    if rgt == N - 1:
        break

    if rgt - lft + 1 < K:
        rgt += 1
        if rgt - lft + 1 == K:
            ans = min(ans, sol(lft, rgt))
            lft += 1
print(ans)


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

lft, rgt = 0, K - 1
ans = float('inf')

while True:
    if rgt == N:
        break
    ans = min(ans, min(abs(X[lft]) + abs(X[lft] - X[rgt]),
                       abs(X[rgt]) + abs(X[rgt] - X[lft])))
    lft += 1
    rgt += 1
print(ans)
# Original solution
N, K   = list(map(int, input().split()))
x = list(map(int, input().split()))
assert len(x) == N

m = min(x[i] - x[i-K+1] + min(abs(x[i]), abs(x[i-K+1])) for i in range(K-1, N))
print(m)

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

m = min(b - a + min(abs(a), abs(b)) for a, b in zip(x, x[K-1:]))
print(m)
# Original solution
N, K = list(map(int, input().split()))
cans = list(map(int, input().split()))

d = []
for n in range(N-K+1):
  l = abs(cans[n]) + abs(cans[n  + (K-1)] - cans[n])
  r = abs(cans[n  + (K-1)]) + abs(cans[n  + (K-1)] - cans[n])
  d.append(min(l,r))

print((min(d)))

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

print((min([min(abs(cans[n]), abs(cans[n  + (K-1)]))  + abs(cans[n  + (K-1)] - cans[n]) for n in range(N-K+1)])))
# Original solution
n, k, *a = list(map(int, open(0).read().split()))
ans = 1e11
for i in range(n-k+1):
    ans = min(ans, a[i+k-1]-a[i]+min(abs(a[i+k-1]),abs(a[i])))
print(ans)

# Optimized solution
n,k,*a=list(map(int,open(0).read().split()));print((min([a[i+k-1]-a[i]+min(abs(a[i+k-1]),abs(a[i]))for i in range(n-k+1)])))
# Original solution
import sys
def input(): return sys.stdin.readline().rstrip()

def solve(l, m):
    if l < m:
        return l * 2 + m
    else:
        return l + m * 2

def main():
    N, K = list(map(int, input().split()))
    x = tuple(map(int, input().split()))
    right_x = [i for i in x if i >= 0][:K]
    left_x = [-i for i in x if i < 0][-K:]

    left_len = len(left_x)
    right_len = len(right_x)
    if right_len < K:
        right_x += [10 ** 9 + 1] * (K - right_len)
    if left_len < K:
        left_x = [10 ** 9 + 1] * (K - left_len) + left_x

    right_x = [0] + right_x
    left_x += [0]

    ans = 10 ** 9
    for i in range(K + 1):
        tmp_ans = solve(left_x[i], right_x[i])
        if tmp_ans < ans:
            ans = tmp_ans
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
import sys
def input(): return sys.stdin.readline().rstrip()

def solve(l, r):
    lv = abs(l)
    rv = abs(r)
    if (l < 0) ^ (r < 0):
        return lv + rv + min(lv, rv)
    else:
        return max(lv, rv)

def main():
    N, K = list(map(int, input().split()))
    x = tuple(map(int, input().split()))

    ans = 10 ** 9
    for i in range(N - K + 1):
        tmp_ans = solve(x[i], x[i + K - 1])
        if tmp_ans < ans:
            ans = tmp_ans

    print(ans)

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

n, k, *x = list(map(int, sys.stdin.read().split()))

def main():
    l = 0; r = k - 1
    ans = float('inf')
    while r < n:
        if x[r] <= 0:
            res = abs(x[l])
        elif x[l] < 0:
            res = min(abs(x[l]), x[r]) * 2 + max(abs(x[l]), x[r])
        else:
            res = x[r]
        ans = min(ans, res)
        l += 1; r += 1
    
    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

# Optimized solution
import sys

n, k, *x = list(map(int, sys.stdin.read().split()))

def main():
    res = float('inf')
    for i in range(n - k + 1):
        j = i + k - 1
        if x[i] < 0:
            d = -x[i] if x[j] <= 0 else min(-x[i], x[j]) * 2 + max(-x[i], x[j])
        else:
            d = x[j]
        res = min(res, d)
    print(res)
    
if __name__ ==  '__main__':
    main()
# Original solution
N, K = list(map(int, input().split()))
X = list(map(int, input().split()))
cost = []
for i in range(0, N-K+1):
    window = X[i:i+K]
    cost.append(window[-1]-window[0] + min(abs(window[-1]), abs(window[0])))
print((min(cost)))

# Optimized solution
N, K = list(map(int, input().split()))
X = list(map(int, input().split()))
cost = []
for i in range(0, N-K+1):
    #window = X[i:i+K]
    #cost.append(window[-1]-window[0] + min(abs(window[-1]), abs(window[0])))
    cost.append(X[i+K-1]-X[i] + min(abs(X[i+K-1]), abs(X[i])))
print((min(cost)))
# Original solution
n,k=list(map(int,input().split()))
x=list(map(int,input().split()))

ans=float('inf')
for i in range(n-k+1):
    nowx=x[i:i+k]
    if nowx[0]>=0 and nowx[-1]>=0:
        ans=min(ans, nowx[-1])
    elif nowx[0]<=0 and nowx[-1]<=0:
        ans=min(ans, abs(nowx[0]))
    elif nowx[0]<0 and nowx[-1]>=0:
        ans=min(ans, 2*abs(nowx[0])+nowx[-1], abs(nowx[0])+2*nowx[-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):
    nowx=(x[i],x[i+k-1])
    if nowx[0]>=0 and nowx[-1]>=0:
        ans=min(ans, nowx[-1])
    elif nowx[0]<=0 and nowx[-1]<=0:
        ans=min(ans, abs(nowx[0]))
    elif nowx[0]<0 and nowx[-1]>=0:
        ans=min(ans, 2*abs(nowx[0])+nowx[-1], abs(nowx[0])+2*nowx[-1])
print(ans)
# Original solution
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))

for i in range(n-k+1):
    xtmp = x[i:i+k]
    if i==0:
        MIN = abs(xtmp[0]-xtmp[-1]) + abs(xtmp[0])

    MIN = min(MIN, abs(xtmp[0]-xtmp[-1]) + abs(xtmp[0]))
    MIN = min(MIN, abs(xtmp[0]-xtmp[-1]) + abs(xtmp[-1]))

print(MIN)

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

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(left-right), abs(right)+abs(right-left))
print(ans)
# Original solution
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))

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

print((min(arr)))


# Optimized solution
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N, K = i_l()
x = i_l()

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

print(ans)
# Original solution
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
x = LIST()


ans = INF
idx = bisect(x, 0)
for i in range(idx-K, idx+1):
	if 0 <= i <= N-K:
		l = x[i:i+K]
		if i == idx-K:
			ans = min(ans, abs(x[i]))
		elif i == idx:
			ans = min(ans, x[i+K-1])
		else:
			ans = min(ans, 2*abs(x[i])+x[i+K-1], abs(x[i])+2*x[i+K-1])
print(ans)


# Optimized solution
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
x = LIST()


ans = INF
idx = bisect(x, 0)
for i in range(idx-K, idx+1):
	if 0 <= i <= N-K:
		if i == idx-K:
			ans = min(ans, abs(x[i]))
		elif i == idx:
			ans = min(ans, x[i+K-1])
		else:
			ans = min(ans, 2*abs(x[i])+x[i+K-1], abs(x[i])+2*x[i+K-1])
print(ans)
# Original solution
import bisect

N, K = list(map(int, input().split()))
x = list(map(int, input().split()))
ans, tmp = 10**9, 10**9

#print(bisect.bisect(x, 0))

for i in range(len(x) - K + 1):
  if x[i] <= 0 and x[i+K-1] >= 0:
    tmp = abs(x[i]) + x[i+K-1] + min(abs(x[i]), x[i+K-1])
  elif x[i] < 0 and x[i+K-1] <= 0:
    tmp = abs(x[i])
  elif x[i] >= 0 and x[i+K-1] > 0:
    tmp = x[i+K-1]
#  elif i == bisect.bisect(x, 0)-1:
#    tmp = x[i+K-1]
#  elif i+K-1 == bisect.bisect(x, 0)-1:
#    tmp = abs[x[i]]
#  print("i:{}, i+K-1:{}, tmp:{}".format(i, i+K-1, tmp))
  ans = min(tmp, ans)
print(ans)

# Optimized solution
N, K = list(map(int, input().split()))
x = [int(i) for i in input().split()]
ans = 10**9
for l in range(N-K+1):
  r = l + K - 1
  tmp = x[r]-x[l]
  if x[r] < 0:
    tmp += abs(x[r])
  elif x[l] < 0 and 0 <= x[r]:
    tmp += min(abs(x[l]), x[r])
  else:
    tmp += x[l]
  ans = min(ans, tmp)
print(ans)
# Original solution
N, K = list(map(int, input().split()))
X = list(map(int, input().split()))

answer = []
for i in range(N):
  if i + K > N:
    break
  Y = X[i:i+K]
  if Y[0] > 0:
    answer.append(Y[-1])
  elif Y[-1] < 0:
    answer.append(-Y[0])
  else:
    answer.append(min(Y[0]*(-2)+Y[-1], Y[-1]*2-Y[0]))

print((min(answer)))

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

answer = []
for i in range(N):
  if i + K > N:
    break
  Ys, Yt = X[i], X[i+K-1]
  if Ys > 0:
    answer.append(Yt)
  elif Yt < 0:
    answer.append(-Ys)
  else:
    answer.append(min(Ys*(-2)+Yt, Yt*2-Ys))

print((min(answer)))
# Original solution
def solve(N, K, Xs):
    plus = sorted([x for x in Xs if x >= 0])
    minus = sorted([abs(x) for x in Xs if x < 0])
    ans = 10 ** 9
    for i in range(0, max(K, len(plus)) + 1):
        ps = plus[:i]
        ms = minus[:K - i]
        if len(ps) == K:
            ans = min(ans, ps[-1])
            continue
        if len(ms) == K:
            ans = min(ans, ms[-1])
            continue
        if len(ps) + len(ms) == K:
            p, m = ps[-1], ms[-1]
            ans = min(ans, p * 2 + m, m * 2 + p)

    return ans
  
if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    Xs = list(map(int, input().split(" ")))
    print((solve(N, K, Xs)))


# Optimized solution
def solve(N, K, Xs):
    plus = sorted([x for x in Xs if x >= 0])
    minus = sorted([abs(x) for x in Xs if x < 0])
    ans = 10 ** 9
    for i in range(0, K + 1):
        j = K - i
        if i <= len(plus) and i == K:
            p = plus[i-1]
            ans = min(ans, p)
        elif j <= len(minus) and j == K:
            m = minus[j-1]
            ans = min(ans, m)
        elif i <= len(plus) and j <= len(minus):
            p = plus[i - 1]
            m = minus[j - 1]
            ans = min(ans, p * 2 + m, m * 2 + p)

    return ans
  
if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    Xs = list(map(int, input().split(" ")))
    print((solve(N, K, Xs)))
# Original solution
N,K = list(map(int, input().split()))

X = []
idx = 0
for i,x in enumerate(input().split()):
    x = int(x)
    X.append(x)
    if x < 0:
        idx = i + 1
if idx == N:
    idx = N-1
ans = 10**9
for i in range(max(0,idx-K), min(N-K+1,idx+K)):
    tmp = 0
    if i <= idx <= i+K-1 or i >= idx or i+K-1 <= idx:
        tmp = min(abs(X[i]), abs(X[i+K-1]))
    # print(i,tmp)
    ans = min(ans, X[i+K-1] - X[i] + tmp)
print(ans)

# Optimized solution
N,K = list(map(int, input().split()))
X = []
idx = 0
for i,x in enumerate(input().split()):
    x = int(x)
    X.append(x)
    if x < 0:
        idx = i + 1
if idx == N:
    idx = N-1
ans = 10**9
for i in range(max(0,idx-K), min(N-K+1,idx+K)):
    ans = min(ans, X[i+K-1] - X[i] + min(abs(X[i]), abs(X[i+K-1])))
print(ans)
# Original solution
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))
first = True
for l, r in zip(list(range(0, n - k + 1)), list(range(k - 1, n))):
    if  0 >= x[r]:
        if first:
            min_time = -x[l]
            first = False
        else:
            time =-x[l]
            if time < min_time:
                min_time = time
    elif 0 <= x[l]:
        if first:
            min_time = x[r]
            first = False
        else:
            time = x[r]
            if time < min_time:
                min_time = time
    else:
        if first:
            min_time = (x[r] - x[l]) + min(-x[l], x[r])
            first = False
        else:
            time =  2 * (x[r] - x[l]) - max(-x[l], x[r])
            if time < min_time:
                min_time = time
print(min_time)

# Optimized solution
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))
min_time = 10 ** 10
for l, r in zip(list(range(0, n - k + 1)), list(range(k - 1, n))):
    time = x[r] if x[l] >= 0 else (-x[l] if x[r] <= 0 else (x[r] - x[l]) + min(-x[l], x[r]))
    if time < min_time:
        min_time = time
print(min_time)
# Original solution
N, K = list(map(int, input().split()))
x = list(map(int, input().split()))

ans = 10**18
for i in range(N-K+1):
    y = x[i:i+K]
    y0 = x[i]
    yk = x[i+K-1]
    if yk < 0:
        ans = min(ans, abs(y0))
    elif y0 <= 0 and 0 <= yk:
        ans = min(ans, yk-2*y0, 2*yk-y0)
    else:
        ans = min(ans, yk)

print(ans)


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

ans = 10**18
for i in range(N-K+1):
    y0 = x[i]
    yk = x[i+K-1]
    if yk < 0:
        ans = min(ans, abs(y0))
    elif y0 <= 0 and 0 <= yk:
        ans = min(ans, yk-2*y0, 2*yk-y0)
    else:
        ans = min(ans, yk)

print(ans)
# Original solution
def main():
    N, K = (int(i)for i in input().split())
    x = [int(i) for i in input().split()]
    ans = 3 * (10**8)
    st_val = min(x,key=abs)
    st_idx = x.index(st_val)
    
    for i in range(K+1):
        dist = 3 * (10**8)
        if 0 <= st_idx-K+1+i and st_idx+1+i <= N:
            if (x[st_idx-K+1+i] < 0 and x[st_idx+i] <= 0):
                dist = abs(x[st_idx-K+1+i])
            elif (x[st_idx-K+1+i] >= 0 and x[st_idx+i] > 0):
                dist = abs(x[st_idx+i])
            else:
                if abs(x[st_idx-K+1+i]) > abs(x[st_idx+i]):
                    dist = abs(x[st_idx-K+1+i]) + abs(x[st_idx+i]) * 2
                else:
                    dist = abs(x[st_idx-K+1+i]) * 2 + abs(x[st_idx+i])
        elif N < st_idx+1+i:
            break
        ans = min(ans,dist)
    print(ans)

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    N, K = (int(i)for i in input().split())
    x = [int(i) for i in input().split()]
    ans = 3 * (10**8)
    
    for i in range(N-K+1):
        dist = min(abs(x[i]),abs(x[i+K-1])) + abs(x[i+K-1] - x[i])
        ans = min(ans,dist)
    print(ans)

if __name__ == "__main__":
    main()
# Original solution
from itertools import combinations

n, k = list(map(int, input().split()))
x = [int(i) for i in input().split()]

c = combinations(x, k)

# print(list(c))

ans = 10 ** 10

for g in c:
    a = max(0, max(g))
    b = min(0, min(g))
    # print(a, b)
    if (a * b) < 0:
        tmp = min(2 * abs(a) + abs(b), 2 * abs(b) + abs(a))
    else:
        tmp = abs(a) + abs(b)
    ans = min(ans, tmp)

print(ans)


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

# c = combinations(x, k)
c = []
for i in range(n - k + 1):
    l = x[i]
    r = x[i + k - 1]
    c.append([l, r])


# print(list(c))

ans = 10 ** 10

for l, r in c:
    tmp = min(abs(l) + abs(r - l), abs(r) + abs(r - l))
    ans = min(ans, tmp)

# for g in c:
#     a = max(0, max(g))
#     b = min(0, min(g))
#     # print(a, b)
#     if (a * b) < 0:
#         tmp = min(2 * abs(a) + abs(b), 2 * abs(b) + abs(a))
#     else:
#         tmp = abs(a) + abs(b)
#     ans = min(ans, tmp)

print(ans)
# Original solution
N,K = list(map(int,input().split()))
X_all = list(map(int,input().split()))
m = float("inf")
for i in range(N-K+1):
    X = X_all[i:i+K]
    if X[0] > 0:
        d = X[-1]
    elif X[-1] < 0:
        d = -X[0]
    else:
        d = X[-1]-X[0]+min(-X[0],X[-1])
    m = min(m,d)
print(m)

# Optimized solution
N,K = list(map(int,input().split()))
X = list(map(int,input().split()))
m = 2*(abs(X[-1])+abs(X[0]))
for i in range(N-K+1):
    if X[i] > 0:
        d = X[i+K-1]
    elif X[i+K-1] < 0:
        d = -X[i]
    else:
        d = X[i+K-1]-X[i]+min(-X[i],X[i+K-1])
    m = min(m,d)
print(m)
# Original solution
import bisect

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

if 0 in X:
  K=K-1
ans=[]
Right=[]
Left=[]
  
for x in X:
  if x>0:
    Right.append(x)
  else:
    Left=[abs(x)]+Left

Right=[0]+Right
Left=[0]+Left
    
for i in range(K+1):
  if i<=len(Right)-1 and K-i<=len(Left)-1:
    ans.append(min(Right[i],Left[K-i])*2+max(Right[i],Left[K-i]))

if K==0:
  ans.append(0)

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):
  xl=X[i]
  xr=X[i+K-1]
  ans.append(min(abs(xl)+abs(xr-xl),abs(xr)+abs(xl-xr)))

print((min(ans)))
# Original solution
import sys
input = sys.stdin.readline
def func(a):
    global alist
    cnt = 1
    for i in range(len(alist)):
        if abs(alist[i][0]) > abs(int(a)):
            alist[i][1] += 1
        else:cnt += 1
    alist.append([int(a),cnt])

    return int(a)



alist = []
n,k = list(map(int,input().split()))
x = list(map(func,input().split()))#sort済み
anslist = []
for i in range(len(alist)):
    if alist[i][1] <= k:
        anslist.append(alist[i][0])

anslist.sort()
#print(alist)
#print(anslist)
if anslist[0] >= 0 and anslist[-1] >= 0:
    print((anslist[-1]))

elif anslist[0] <= 0 and anslist[-1] <= 0:
    print((-anslist[0]))

else:
    if anslist[-1] > -anslist[0]:
        print((-2*anslist[0] + anslist[-1]))
    else:
        print((2*anslist[-1] - anslist[0]))






# 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):
    left = i
    right = i+k-1
    ans = min(ans, min(abs(x[left])+abs(x[right]-x[left]),abs(x[right])+abs(x[left]-x[right])))
print(ans)
# Original solution
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(eval(input()))


def readnums():
    return list(map(int, input().split()))


def readstrs():
    return input().split()


def main():
    N, K = readnums()
    x = list(readnums())
    ans = 0
    for i in range(K, N + 1):
        l = x[i - K:i]
        if l[0] > 0:
            val = abs(l[-1])
        elif l[-1] < 0:
            val = abs(l[0])
        else:
            val = abs(l[0]) + abs(l[-1])
            val += min(abs(l[0]), abs(l[-1]))
        if not ans:
            ans = val
        else:
            ans = min(ans, val)

    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(eval(input()))


def readnums():
    return list(map(int, input().split()))


def readstrs():
    return input().split()


def main():
    N, K = readnums()
    x = list(readnums())
    ans = 0
    for i in range(K - 1, N):
        ls = i - K + 1
        le = i
        if x[ls] > 0:
            val = abs(x[le])
        elif x[le] < 0:
            val = abs(x[ls])
        else:
            val = abs(x[ls]) + abs(x[le])
            val += min(abs(x[ls]), abs(x[le]))
        if not ans:
            ans = val
        else:
            ans = min(ans, val)

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
import itertools
import collections
n,k=list(map(int,input().split()))
candle=list(map(int,input().split()))
com=list(itertools.product(["1","0"], repeat=n))
ans=200000000
for i in range(2**n):
  count=collections.Counter(com[i])
  if count["1"]==k:
    comtemp="".join(com[i])
    start=candle[comtemp.find("1")]
    end=candle[comtemp.rfind("1")]
    temp=0
    if start>=0:
      temp=abs(end)
      if temp<ans:
        ans=temp
    if end<=0:
      temp=abs(start)
      if temp<ans:
        ans=temp
    else:
      temp=min(abs(start), end)*2+max(abs(start), end)
      if temp<ans:
        ans=temp
print(ans)

# Optimized solution
n,k=list(map(int,input().split()))
candle=list(map(int,input().split()))
ans=2000000000
for i in range(n-k+1):
  if candle[i]<0 and candle[i+k-1]>0:
    temp=min(abs(candle[i]), candle[i+k-1])*2+max(abs(candle[i]), candle[i+k-1])
  elif candle[i+k-1]<=0:
    temp=abs(candle[i])
  elif candle[i]>=0:
    temp=candle[i+k-1]
  ans=min(temp, ans)
print(ans)
# Original solution
N, K = list(map(int, input().split()))
x = list(map(int, input().split()))
ans = pow(10, 10)
for i in range(N-K+1):
    temp_l = abs(x[i]) + abs(x[i]-x[i+K-1])
    temp_r = abs(x[i+K-1]) + abs(x[i]-x[i+K-1])
    ans = min(ans, temp_l, temp_r)
print(ans)


# Optimized solution
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 10 ** 9
for i in range(len(a) - K + 1):
  l = a[i]
  r = a[i+K-1]
  ans = min(ans, abs(l) + abs(r - l), abs(r) + abs(l - r))
print(ans)
# Original solution
n, k = list(map(int, input().split()))
X = list(map(int, input().split()))

ans = float('inf')
for i in range(n-k+1):
    l, r = X[i:i+k][0], X[i:i+k][-1]
    if r < 0:
        ans = min(abs(l), ans)
    elif 0 < l:
        ans = min(abs(r), ans)
    else:
        ans = min(min(abs(l), abs(r))*2+max(abs(l), abs(r)), ans)
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):
    l, r = X[i], X[i+k-1]
    if r <= 0:
        ans = min(abs(l), ans)
    elif 0 <= l:
        ans = min(abs(r), ans)
    else:
        dist = min(abs(l), abs(r))*2+max(abs(l), abs(r))
        ans = min(dist, ans)
print(ans)