There are N candles placed on a number line.
The i-th candle from the left is placed on coordinate x_i.
Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning.
Snuke decides to light K of the N candles.
Now, he is at coordinate 0.
He can move left and right along the line with speed 1.
He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.

-----Constraints-----
 - 1 \leq N \leq 10^5
 - 1 \leq K \leq N
 - x_i is an integer.
 - |x_i| \leq 10^8
 - x_1 < x_2 < ... < x_N

-----Input-----
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N

-----Output-----
Print the minimum time required to light K candles.

-----Sample Input-----
5 3
-30 -10 10 20 50

-----Sample Output-----
40

He should move and light candles as follows:
 - Move from coordinate 0 to -10.
 - Light the second candle from the left.
 - Move from coordinate -10 to 10.
 - Light the third candle from the left.
 - Move from coordinate 10 to 20.
 - Light the fourth candle from the left.

Difficulty: introductory

Starter code:

Solutions:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *X = list(map(int, read().split()))

    A = [abs(x - X[0]) for x in X]

    ans = INF
    for i in range(N - K + 1):
        if ans > min(abs(X[i]), abs(X[i + K - 1])) + A[i + K - 1] - A[i]:
            ans = min(abs(X[i]), abs(X[i + K - 1])) + A[i + K - 1] - A[i]

    print(ans)
    return


def __starting_point():
    main()

__starting_point()

N, K = list(map(int, input().split()))
X = 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(r-l)))
print((min(a)))



def __starting_point():

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

	ans = float("inf")

	for i in range(k+1):
		if i+k > n:
			break

		left = A[i]
		right = A[i+k-1]

		#1 abs(left) < abs(right) の場合
		tmp2 = abs(left) + abs(right - left)

		#2 abs(right) > abs(left)の場合
		tmp3 = abs(right) + abs(left - right)

		ans = min(ans,min(tmp2,tmp3))

	print(ans)

__starting_point()

# 初期入力 2020-0730-2150
from bisect import bisect_left
import sys
input = sys.stdin.readline  #文字列では使わない
N,K = map(int, input().split())
x = list(map(int, input().split()))
x_shift =[i +abs(x[0]) for i in x]
bis_0 =bisect_left(x,0)
 
d_end =[0]*(N-K+1)
d_left =0
d_right =0
dist =[]
for i in range(N-K+1):
    d_end =x_shift[i+K-1] -x_shift[i] #ローソクK本の内、端と端の距離
    d_left =abs(x[i])
    d_right =abs(x[i+K-1])
    dist.append(d_end +min(d_left,d_right))
print(min(dist))

n,k=map(int,input().split())
x=list(map(int,input().split()))
ans=10**18

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

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

s = 10**9

for i in range(n-k+1):
    if x[i] * x[i+k-1] >= 0:
        t = max(abs(x[i]), abs(x[i+k-1]))
    else:
        t = abs(x[i]) + abs(x[i+k-1]) + min(abs(x[i]), abs(x[i+k-1]))

    s = min(s, t)

print(s)

n, k = map(int, input().split())
list_X = list(map(int, input().split()))
ans = pow(10, 14)

for i in range(n - k + 1):
    if list_X[i] * list_X[i + k - 1] < 0:
        ans = min(ans, list_X[i + k - 1] - list_X[i] + min(abs(list_X[i]), abs(list_X[i + k - 1])))
    else:
        ans = min(ans, max(abs(list_X[i + k - 1]), abs(list_X[i])))

print(ans)

import sys;          from decimal import Decimal
import math;         from numba import njit, i8, u1, b1
import bisect;       from itertools import combinations, product
import numpy as np;  from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

def Main():
    n, k = read_ints()
    x = read_int_list()
    ans = INF

    for i in range(n - k + 1):
        left = x[i]
        right = x[i + k - 1]
        if left < 0 and right > 0:
            ans = min(ans, min(abs(left), abs(right)) * 2 + max(abs(left), abs(right)))
        else:
            ans = min(ans, max(abs(left), abs(right)))
    
    print(ans)
    
def __starting_point():
    Main()
__starting_point()

N,K = map(int,input().split())
x = list(map(int,input().split()))
xp = [i for i in x if i >= 0]
xn = [i for i in x if i < 0]
xn.reverse()
lp = len(xp)
ln = len(xn)
if lp == 0:
    print(-xn[K-1])
    return
if ln == 0:
    print(xp[K-1])
    return
pc = min(K,lp)
pp = xp[pc-1]
if K>lp:
    nc = K-lp
    np = -xn[nc-1]
else:
    nc = 0
    np = 0
ans = pp + np + min(pp,np)
for i in range(pc-1):
    if nc == ln:
        break
    pp = xp[pc-i-2]
    np = -xn[nc]
    nc += 1
    ans = min(ans,pp + np + min(pp,np))
print(ans)

def main():
    n,k = list(map(int,input().split()))
    x = list(map(int,input().split()))
    m,p = [],[]
    for i in range(n):
        if x[i]<0:
            m.append(x[i])
        else:
            p.append(x[i])
    M,P = len(m),len(p)
    ans = float('inf')
    for i in range(min(M+1,k+1)):
        t = 0
        if i>0:
            t += 2*abs(m[M-i])
        r = k-i
        if r==0:
            if t//2<ans:
                ans = t//2
        elif r<=P:
            t += p[r-1]
            if t<ans:
                ans = t
    for i in range(min(P+1,k+1)):
        t = 0
        if i>0:
            t += 2*p[i-1]
        r = k-i
        if r==0:
            if t//2<ans:
                ans = t//2
        elif r<=M:
            t += abs(m[M-r])
            if t<ans:
                ans = t
    print(ans)

def __starting_point():
    main()

__starting_point()

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


l = []
# 連続するK本の選び方について、左端は0,1,2,...,N-K
for i in range(N - K + 1):
    left = i
    right = i + K - 1
    # leftが先、rightが後の場合
    ans1 = abs(x[left]) + abs(x[right] - x[left])
    # rightが先、leftが後の場合
    ans2 = abs(x[right]) + abs(x[right] - x[left])
    tmp_ans = min(ans1, ans2)
    l.append(tmp_ans)

ans = min(l)
print(ans)


n,k = list(map(int,input().split()))
x = list(map(int,input().split()))
ans = 10 ** 12
for i in range(n-k+1):
    ans = min(ans,abs(x[i])+(abs(x[i+k-1]-x[i])),abs(x[i+k-1])+(abs(x[i+k-1]-x[i])))
print(ans)


N,K = map(int,input().split())
x = list(map(int,input().split()))
mi = 10 ** 18
for i in range(N-K+1):
    l = x[i]
    r = x[i+K-1]
    lr = abs(l)+abs(l-r)
    rl = abs(r)+abs(l-r)
    mi = min(mi,min(lr,rl))
print(mi)

# 初期入力 2020-0730-2150
from bisect import bisect_left
import sys
input = sys.stdin.readline  #文字列では使わない
N,K = map(int, input().split())
x = list(map(int, input().split()))
x_shift =[i +abs(x[0]) for i in x]
 
dist =[]
for i in range(N-K+1):
    d_end =x_shift[i+K-1] -x_shift[i] #ローソクK本の内、端と端の距離
    d_left =abs(x[i])
    d_right =abs(x[i+K-1])
    dist.append(d_end +min(d_left,d_right))
print(min(dist))

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

import bisect

i=bisect.bisect_left(X,0)
L=max(0, bisect.bisect_right(X,0)-K)
R=min(N-1, bisect.bisect_left(X,0)+K-1)

ans=float('inf')

for i in range(L,R-K+2):
    t=0
    l=X[i]
    r=X[i+K-1]
    if r<=0:
        t=abs(l)
    elif 0<=l:
        t=r
    else:
        t=min(abs(l),r)*2+max(abs(l),r) 
    # print(X[i:i+K],t)
    ans=min(ans,t)
print(ans)

n,k = map(int,input().split())
l = list(map(int,input().split()))
ls = []
for i in range(n-k+1):
  a = l[i]
  b = l[i+k-1]
  ls.append(min(abs(a)+abs(a-b), abs(b)+abs(a-b)))
print(min(ls))

import sys

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

def Main():
    n, k = read_ints()
    x = read_int_list()
    ans = INF

    for i in range(n - k + 1):
        left = x[i]
        right = x[i + k - 1]
        if left < 0 and right > 0:
            ans = min(ans, min(abs(left), abs(right)) * 2 + max(abs(left), abs(right)))
        else:
            ans = min(ans, max(abs(left), abs(right)))
    
    print(ans)
    
def __starting_point():
    Main()
__starting_point()

n,k = map(int, input().split())
x = list(map(int, input().split()))
minus = [0]
plus = [0]
for i in x:
    if x:
        plus.append(x)
    else:
        minus.append(-x)
k -= 1
ans = 1000000000000000
for i in range(n-k):
    if x[i+k] < 0:
        ans = min(ans, -x[i])
    elif 0 < x[i+k] and x[i] < 0:
        if -x[i] < x[i+k]:
            ans = min(ans, abs(2*(x[i])) + x[i+k])
        else:
            ans = min(ans, 2*x[i+k] + abs(x[i]))
    else:
        ans = min(ans, x[i+k])
    
print(ans)

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

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


import bisect
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=bisect.bisect_left(a,0)#0以上が何個か調べるため、0が入る位置のインデックス
X=n-x#0以上の個数
#print(x,X)
if a[0]>=0:
    print(a[k-1])
    return
elif a[-1]<=0:
    print(-1*a[-1-k+1])
    return
#右スタート
if X>=k:
    c=0
    for i in range(x,n):
        c+=1
        if c==k:
            ans=a[i]
            j=i
            r=x
            break
    #print(ans,j,r)
    while (j>x and r>0):
        j-=1
        r-=1
        #print(a[j],a[r],j,r)
        ans=min(ans,a[j]*2-a[r])
else:
    c=0
    ans=2*a[-1]
    #print(x,ans)
    for i in range(x-1,-1,-1):
        c+=1
        #print(a[i])
        if c==k-X:
            ans+=-1*a[i]
            j=n-1
            r=i
            break
    #print(ans,j,r)
    while (j>x and r>0):
        j-=1
        r-=1
        #print(a[j],a[r],j,r)
        ans=min(ans,a[j]*2-a[r])
#print(ans)
#print(n-X,k)
#左スタート
#x=bisect.bisect_left(a,0)#0以上が何個か調べるため、0が入る位置のインデックス
#X=n-x#0以上の個数
if n-X>=k:#0以下の個数がkより多い場合
    c=0
    for i in range(x-1,-1,-1):
        c+=1
        #print(i)
        if c==k:
            ans2=-1*a[i]
            j=i
            r=x-1
            break
    #print(ans2,j,r)
    while (j<x-1 and r<n-1):
        j+=1
        r+=1
        #print(a[j],a[r],j,r)
        ans2=min(ans2,-2*a[j]+a[r])
        #print(ans2)
else:
    c=0
    ans2=-2*a[0]
    #print(x,k,ans2,"sss")
    for i in range(x,n):
        c+=1
        #print(a[i],i)
        if c==k-(n-X):
            ans2+=a[i]
            #print(ans2)
            j=0
            r=i
            break
    #print(ans2,j,r)
    while (j<x-1 and r<n-1):
        j+=1
        r+=1
        #print(a[j],a[r],j,r)
        ans2=min(ans2,-2*a[j]+a[r])
#print(ans)
print(min(ans,ans2))


def resolve():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    ans = 1 << 60

    for i in range(N - K + 1):
        l = A[i]
        r = A[i + K - 1]
        l_to_r = abs(l) + abs(l - r)
        r_to_l = abs(r) + abs(r - l)
        res = min(l_to_r, r_to_l)
        ans = min(ans, res)

    print(ans)


def __starting_point():
    resolve()

__starting_point()

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

tp = N
for i in range(N):
    if x[i] >= 0:
        tp = i
        break
    x[i] *= -1

s = max(0, tp-K+1)
g = min(tp-1, N-K)

ans = float("INF")
if K <= tp:
    ans = min(ans, x[tp-K])
if K <= N - tp:
    ans = min(ans, x[tp+K-1])

for i in range(s, g+1):
    ans = min(ans, x[i] + x[i+K-1] + min(x[i], x[i+K-1]))
    #print(x[i], x[i+K-1])

print(ans)

n,k = map(int, input().split())
x = list(map(int, input().split()))
ans = abs(x[k-1]) + 2*abs(x[0])
for i in range (n-k+1):
  if x[i+k-1] <= 0:
    ans = min(ans, -x[i])
  elif x[i] >= 0:
    ans = min(ans, x[i+k-1])
  else:
    ans = min(ans, -2*x[i] + x[i+k-1], 2*x[i+k-1] - x[i])
print(ans)

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

# ==================================================-
# 二分探索
# functionを満たす,search_listの最大の要素を出力
# 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき
import math
import sys
sys.setrecursionlimit(10**9)
def binary_research(start,end,function):
    if start==end:
        return start
    middle=math.ceil((start+end)/2)
    if function(middle):
        start=middle
    else:
        end=middle-1
    return binary_research(start, end, function)
positive=[]
negative=[]
zero=False


for i in x:
    if i<0:
        negative.append(abs(i))
    elif i>0:
        positive.append(i)
    else:
        zero=True
positive.sort()
negative.sort()


def function(time):
    if time==-1:
        return True
    ans_list=[]
    ans=0
    if zero:
        ans+=1
    for i in positive:
        if i<=time:
            ans_list.append(i)
            ans+=1
        else:
            break
    negative_list=[]
    for i in negative:
        if i<=time:
            negative_list.append(i)
        else:
            break
    negative_list=negative_list[::-1]
    newans=ans
    while negative_list:
        newans,ans_list,negative_list=function2(ans_list,negative_list,newans,time)
        ans=max(ans,newans)
        if ans_list==[]:
            break
        else:
            ans_list.pop()
            newans-=1
    if ans>=k:
        return False
    return True



def function2(ans_list,negative_list,ans,time):
    if ans_list==[]:
        max_num=0
    else:
        max_num=ans_list[-1]
    remain_time=time-max_num*2
    while negative_list:
        i=negative_list.pop()
        if max_num==0:
            if i<=remain_time:
                ans+=1
        elif max_num+i+min(i,max_num)<=time:
            ans+=1
        else:
            negative_list.append(i)
            break
    return ans,ans_list,negative_list


print(binary_research(-1,3*10**8+1,function)+1)

#!/usr/bin/env python3
n, k, *x = list(map(int, open(0).read().split()))
ans = 10**18
neg = [i for i in x if i<0]+[0]
pos = [0]+[i for i in x if i>=0]
l = len(neg) -max(0, k + 1 - len(pos))
r = min(k+1, len(pos))
while l > 0 and r > 0:
    l -= 1
    r -= 1
    ans = min(ans, -neg[l] * 2 + pos[r], -neg[l] + pos[r] * 2)
print(ans)


N,K=map(int,input().split())
X=list(map(int,input().split()))
p=True
for i in range(N):
    if X[i]<0:
        continue
    elif X[i]==0:
        K-=1
        if i<K:
            mX=[0]+[-x for x in X[:i]][::-1]
        else:
            mX=[0]+[-x for x in X[i-K:i]][::-1]
        pX=[0]+X[i+1:i+1+K]
        p=False
        break
    else:
        if i<K:
            mX=[0]+[-x for x in X[:i]][::-1]
        else:
            mX=[0]+[-x for x in X[i-K:i]][::-1]
        pX=[0]+X[i:i+K]
        p=False
        break
if p:
    mX=[0]+[-x for x in X[::-1]]
    pX=[0]
ans=10**9
l=K-(len(pX)-1)
n=len(mX)
for i in range(len(pX)-1,-1,-1):
    if l<n:
        ans=min(ans,pX[i]+mX[l]*2,pX[i]*2+mX[l])
    else:
        break
    l+=1
print(ans)

N,K=list(map(int,input().split()))
x=list(map(int,input().split()))
positive=[]
negative=[]
for i in range(N):
    if x[i]<0:
        negative.append(-x[i])
    else:
        positive.append(x[i])
negative.sort()
n=len(negative)
m=len(positive)
ans=1000000000
if n>=K:
    ans=min(ans,negative[K-1])
if m>=K:
    ans=min(ans,positive[K-1])

for i in range(n):
    j=K-(i+1)
    if j>m:
        continue
    if j<=0:
        continue
    ans=min(ans,negative[i]+positive[j-1]+min(negative[i],positive[j-1]))
print(ans)


N, K = map(int, input().split())
X = list(map(int, input().split()))
T = 10**18
for i in range(N-K+1):
  if X[i+K-1]<=0:
    T = min(T, -X[i])
  elif X[i]>=0:
    T = min(T, X[i+K-1])
  else:
    T = min(T, X[i+K-1]-X[i]+min(-X[i], X[i+K-1]))
print(T)

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

ne_lst = []
po_lst = []
for i in lst:
    if i < 0:
        ne_lst.append(-i)
    else:
        po_lst.append(i)
ne_lst.reverse()

res = 10**10
if len(ne_lst) >= k:
    res = min(res, ne_lst[k-1])
if len(po_lst) >= k:
    res = min(res, po_lst[k-1])
for i, j in enumerate(ne_lst):
    if  k-(i+1)>0 and len(po_lst) > (k-1)-(i+1):
        res = min(res, ne_lst[i]*2 + po_lst[(k-1)-(i+1)])
for i,j in enumerate(po_lst):
    if k-(i+1)>0 and len(ne_lst) > (k-1)-(i+1):
        res = min(res, po_lst[i]*2 + ne_lst[(k-1)-(i+1)])
print(res)

import math
N, K = map(int, input().split())
x = list(map(int, input().split()))
for i in range(N):
  if x[i] == 0:
    p, m = i, i+1
    break
  elif x[i] > 0:
    p, m = i, i
    break
    
if (x[0]<0) and (x[-1]>0):
  pls = x[p:]
  mns = x[:m]
  ans = math.inf

  for i in range(len(pls)):
    if i < K-1:
      if pls[0] == 0:
        n = K - i
      else:
        n = K - i - 1
      if len(mns) >= n:
        tmp = 2*abs(mns[-n]) + pls[i]
        ans = min(ans, tmp)
    if i == K-1:
      ans = min(ans, pls[i])
      break
    
  for i in range(len(mns)):
    m = len(mns)-i
    if m < K:
      if pls[0] == 0:
        n = K - m
      else:
        n = K - m - 1
      if len(pls) > n:
        tmp = 2*pls[n] + abs(mns[-m])
        ans = min(ans, tmp)
    if m == K:
      ans = min(ans, abs(mns[i]))
    
elif x[0] >= 0:
  ans = x[K-1]
  
else:
  ans = abs(x[-K])
  
print(ans)

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

import bisect
c=bisect.bisect_left(x,0)
mt=2*10**8

for i in range(n-k+1):
  if i+k<c:continue
  mt=min(mt,2*abs(x[i])+abs(x[i+k-1]),abs(x[i])+2*abs(x[i+k-1]))
  if i+k-1 ==c-1:mt=min(mt,abs(x[i]))
  if i==c:mt=min(mt,x[i+k-1])
if n==k:
  if c!=n and c!=0:
    mt=min(2*abs(x[0])+x[-1],2*x[-1]+abs(x[0]))
  else:
    mt=max(abs(x[0]),abs(x[-1]))
print(mt)
    


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

res=[]
for i in range(N-K+1):
  tmp = min(abs(x[i]),abs(x[i+K-1]))+x[i+K-1]-x[i]
  res.append(tmp)
  
print(min(res))

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

ans = float('inf')
for i in range(n-k+1):
    ans = min(ans, min(abs(x[i]) + abs(x[i+k-1]-x[i]), abs(x[i+k-1]) + abs(x[i+k-1]-x[i])))
print(ans)

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

neg_to_pos = n
for i in range(n):
    if x[i] > 0:
        neg_to_pos = i
        break

res = 10 ** 14
for i in range(n - k + 1):
    l = min(x[i], 0)
    r = max(0, x[i + k - 1])
    if i <= neg_to_pos and neg_to_pos - 1 <= i + k - 1:
        tmp = min(-2 * l + r, -l + 2 * r)
        res = min(res, tmp) 
print(res)

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 10**10
for i in range(n-k+1):
    tmp = min(abs(a[k+i-1] - a[i]) + abs(a[i]), abs(a[k+i-1] - a[i]) + abs(a[k+i-1]))
    if ans > tmp:
        ans = tmp
print(ans)

n,k = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(abs,x))
ans = float("inf")

for i in range(n-k+1):
    if 0 < x[i] * x[i+k-1]:
        cost = max(y[i],y[i+k-1])
        
    else:
        cost = y[i] + y[i+k-1] + min(-x[i],x[i+k-1])
        
    ans = min(ans,cost)
    
print(ans)

N, K = list(map(int, input().split()))
X = [int(x) for x in input().split()]
ans = 10**10

for i in range(N-K+1):
    tmp = X[i+K-1] - X[i] + min(abs(X[i+K-1]), abs(X[i]))
    if tmp < ans:
        ans = tmp
print(ans)


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

ans = float("inf")
for i in range(n-k+1):
  l = abs(x[i]) + abs(x[i]-x[i+k-1])
  r = abs(x[n-1-i]) + (x[n-1-i]-x[n-k-i])
  ans = min(ans,l,r)
print(ans)

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

inf = 10**12
z = len(x)

if n == 1 and k == 1:
    print((0))
    return

for i in range(len(x)):
    if x[i] >= 0:
        z = i
        break

r = [inf] * (n - z)
l = [inf] * z

for i in range(n-z):
    r[i] = x[z+i]

for i in range(z):
    l[i] = abs(x[z-i-1])

# 左からすべて取る場合
tl = inf
if len(l) < k:
    tl = inf
else:
    tl = abs(l[k-1])

if z == n-1:
    print(tl)
    return

# 右からすべて取る場合
tr = inf
if len(r) < k:
    tr = inf
else:
    tr = abs(r[k-1])
    
# 両方から取る場合
# 右からi個取る
t_arr = []
for i in range(1,k):
    if i-1 >= len(r):
        pass
    else:
        if k-i-1 >= len(l):
            pass
        else:
            t1 = r[i-1]
            t2 = l[k-i-1]
            t_arr.append(t1*2 + t2*2 - max(t1,t2))
tc = inf
if len(t_arr) != 0:
    tc = min(t_arr)
else:
    tc = inf
print((min(tl,tr,tc)))


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

x1 = [i for i in x0 if i >= 0]
x2 = list(reversed([i for i in x0 if i < 0]))
count0 = len(x1)
count1 = len(x2)
ans = float('inf')

if count1 == 0:
    print((x1[k-1]))
elif count0 == 0:
    print((-x2[k-1]))
else:
    if 0 in x1:
        x1.remove(0)
        k -= 1
        count0 -= 1
    for i in range(min(count0, k)):
        if count1 >= k-i-1:
            ans = min(ans, x1[i]*2-x2[k-i-2])
    for i in range(min(count1, k)):
        if count0 >= k-i-1:
            ans = min(ans, -x2[i]*2+x1[k-i-2])
    print(ans)


N,K=map(int,input().split())
X=list(map(int,input().split()))
for i in range(N):
    if X[i]<0:
        continue
    elif X[i]==0:
        K-=1
        if i<K:
            mX=[0]+[-x for x in X[:i]][::-1]
        else:
            mX=[0]+[-x for x in X[i-K:i]][::-1]
        pX=[0]+X[i+1:i+1+K]
        break
    else:
        if i<K:
            mX=[0]+[-x for x in X[:i]][::-1]
        else:
            mX=[0]+[-x for x in X[i-K:i]][::-1]
        pX=[0]+X[i:i+K]
        break
else:
    mX=[0]+[-x for x in X[::-1]]
    pX=[0]
ans=10**9
l=K-(len(pX)-1)
n=len(mX)
for i in range(len(pX)-1,-1,-1):
    if l<n:
        ans=min(ans,pX[i]+mX[l]*2,pX[i]*2+mX[l])
    else:
        break
    l+=1
print(ans)

n,k=list(map(int,input().split()))
x=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(r-l)))
print((min(a)))


n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = []
for j in range(n-k+1):
    if x[j] > 0:
        ans.append(x[j+k-1])
    elif x[j] <= 0 <= x[j+k-1]:
        ans.append(min(2*abs(x[j])+x[j+k-1], abs(x[j])+2*x[j+k-1]))
    else:
        ans.append(-x[j])
print(min(ans))

import sys

input = sys.stdin.readline


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

    INF = float("inf")
    M = [INF] * N
    P = [INF] * N
    i_m, i_p = 0, 0
    for x in X:
        if x == 0:
            K -= 1
        elif x > 0:
            P[i_p] = x
            i_p += 1
        else:
            M[i_m] = -x
            i_m += 1

    if K <= 0:
        print((0))
        return

    M.sort()
    P.sort()
    ans = min(M[K - 1], P[K - 1])
    for n_M in range(1, K + 1):
        dist = 2 * M[n_M - 1] + P[K - n_M - 1]
        if ans > dist:
            ans = dist
    for n_P in range(1, K + 1):
        dist = 2 * P[n_P - 1] + M[K - n_P - 1]
        if ans > dist:
            ans = dist

    print(ans)


def __starting_point():
    main()

__starting_point()

n,k=map(int, input().split())
xlist=list(map(int, input().split()))
ans=10**20
for i in range(n-k+1):
  ans=min(abs(xlist[i]-xlist[i+k-1])+min(abs(xlist[i]),abs(xlist[i+k-1])),ans)
print(ans)

import sys
n,k = list(map(int,input().split()))
x_ls = list(map(int, input().split()))
x_ls.sort()
if x_ls[0] >= 0:
    print((x_ls[k-1]))
    return
elif x_ls[-1] <= 0:
    x_ls.sort(reverse=True)
    print((abs(x_ls[k-1])))
    return
l = 0
r = k - 1
ans = float('inf')
while r < n:
    cost_1 = 2*abs(x_ls[l]) + abs(x_ls[r])
    cost_2 = abs(x_ls[l]) + 2*abs(x_ls[r])
    cost = min(cost_1,cost_2)
    ans = min(cost, ans)
    r += 1
    l += 1
print(ans)


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

ans = 10 ** 10
nega = sorted(-x for x in X if x < 0)
posi = sorted(x for x in X if 0 < x)
if 0 in X:
    K -= 1

if 0 < K <= len(posi):
    t = posi[K - 1]
    ans = min(ans, t)
if 0 < K <= len(nega):
    t = nega[K - 1]
    ans = min(ans, t)

if 0 < K:
    for np in range(1, len(posi) + 1):
        if 0 <= K - np - 1 < len(nega):
            t = posi[np - 1] * 2 + nega[K - np - 1]
            ans = min(ans, t)
    for nn in range(1, len(nega) + 1):
        if 0 <= K - nn - 1 < len(posi):
            t = nega[nn - 1] * 2 + posi[K - nn - 1]
            ans = min(ans, t)
else:
    ans = 0
print(ans)

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

lis = sorted(list(map(int, input().split())))

ans = []
for i in range(n-k+1):
    a = lis[i]
    b = lis[i+k-1]
    ans.append(min(abs(a)+abs(b-a),abs(b)+abs(a-b)))

print(min(ans))

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

ans = []
for i in range(N - K + 1):
    left = i
    right = left + K - 1
    if x[left] < 0 and x[right] >= 0:
        q = min(abs(x[left]) * 2 + x[right], x[right] * 2 + abs(x[left]))
        ans.append(q)
        continue
    elif x[right] < 0:
        q = abs(x[left])
        ans.append(q)
        continue
    elif x[left] > 0:
        q = abs(x[right])
        ans.append(q)
        continue
if len(ans) == 0:
    print((0))
    return

print((min(ans)))


N, K = list(map(int, input().split()))
X_list = list(map(int, input().split()))
INF = 10 ** 18
ans = INF
import bisect

zero_index = bisect.bisect_left(X_list, 0)
candidate_list = []
ans = INF
for i in range(K + 1):
    head = zero_index - i
    tail = head + K - 1
    if head < 0 or tail > N - 1: continue
    if i == 0:
        ans = min(ans, abs(X_list[tail]))
    elif i == K:
        ans = min(ans, abs(X_list[head]))
    else:
        head_abs = abs(X_list[head])
        tail_abs = abs(X_list[tail])
        ans = min(ans, head_abs + tail_abs + min(head_abs, tail_abs))
print(ans)


N, K = list(map(int, input().split()))
X = sorted(list(map(int, input().split())))
cnt = []

for i in range(N - K + 1):
    left = X[i]
    right = X[i+K-1]
    cnt.append(min(abs(right)+abs(left-right), abs(left) + abs(right - left)))
print((min(cnt)))



# 連続するK本のろうそくに火をつけるので、最小となる組を全探索する
N, K = map(int, input().split())
X = list(map(int, input().split()))

ans = float("INF")
for i in range(N - K + 1):
    lr = abs(X[i]) + abs(X[i] - X[i + K - 1])
    rl = abs(X[i + K - 1]) + abs(X[i + K - 1] - X[i])
    ans = min(ans, min([lr, rl]))

print(ans)

n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10 ** 12
for i in range(n-k+1):
    ans = min(ans,abs(x[i])+(abs(x[i+k-1]-x[i])),abs(x[i+k-1])+(abs(x[i+k-1]-x[i])))
print(ans)

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def solve(N, K, X):
    A = [abs(x - X[0]) for x in X]

    ans = INF
    for i in range(N - K + 1):
        if ans > abs(X[i]) + A[i + K - 1] - A[i]:
            ans = abs(X[i]) + A[i + K - 1] - A[i]

    return ans


def main():
    N, K, *X = list(map(int, read().split()))

    ans = solve(N, K, X)
    ans = min(ans, solve(N, K, X[::-1]))

    print(ans)
    return


def __starting_point():
    main()

__starting_point()

#!/usr/bin/env python
# coding: utf-8

# In[26]:


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


# In[35]:


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


# In[ ]:






n, k = list(map(int, input().split()))
x = list(map(int, input().split()))
ans = 10**9
for l in range(n - k + 1):
    r = l + k - 1
    ans = min(ans, abs(x[r]) + abs(x[r]-x[l]), abs(x[l]) + abs(x[r]-x[l]))

print(ans)


N, K = [int(x) for x in input().split()]
X = [int(x) for x in input().split()]


ans = float("inf")
for i in range(N - K + 1):
    left = X[i]
    right = X[i + K - 1]
    if left * right >= 0:
        ans = min(ans, max(abs(left), right))
    else:
        ans = min(ans, right - left + min(abs(left), right))
print(ans)



url = "https://atcoder.jp//contests/abc107/tasks/arc101_a"

def main():
    n, k = list(map(int, input().split()))
    xs = list(map(int, input().split()))
    ans = 100000000000000
    se = [0, k-1]
    while se[1] < n:
        if xs[se[0]] < 0 <= xs[se[1]]:
            tmp = min(abs(xs[se[0]]), xs[se[1]]) * 2 + max(abs(xs[se[0]]), xs[se[1]])
            ans = min(ans, tmp)
        elif xs[se[0]] < 0:
            ans = min(ans, abs(xs[se[0]]))
        elif xs[se[1]] >= 0:
            ans = min(ans, xs[se[1]])
        se = [v + 1 for v in se]
    print(ans)


def __starting_point():
    main()

__starting_point()

import math

N, K = map(int, input().split())
cd = list(map(int, input().split()))
cd_plus, cd_minus = [], []

res = math.inf

for i in range(N):
    if cd[i] == 0:
        N -= 1
        K -= 1
        res = 0
    elif cd[i] > 0:
        cd_plus.append(cd[i])
    else:
        cd_minus.append(-cd[i])

cd_minus.sort()

for i in range(len(cd_plus)):
    if i + len(cd_minus) + 1 >= K:
        if K >= i + 2:
            res = min(res, cd_plus[i] * 2 + cd_minus[K - i - 2])
        else:
            res = min(res, cd_plus[i])

for i in range(len(cd_minus)):
    if i + len(cd_plus) + 1 >= K:
        if K >= i + 2:
            res = min(res, cd_minus[i] * 2 + cd_plus[K - i - 2])
        else:
            res = min(res, cd_minus[i])

print(res)

n, k = map(int, input().split())
x = list(map(int, input().split()))
pos, nega = [], []
for v in x:
    if v >= 0:pos.append(v)
    else:nega.append(-v)
nega.sort()
ans = 10**9
if k <= len(pos):ans = min(ans, pos[k-1])
if k <= len(nega):ans = min(ans, nega[k-1])
for i in range(k):
    if i < len(pos) and 0 <= k - i - 2 < len(nega):
        ans = min(ans, 2 * pos[i] + nega[k-i-2])
    if i < len(nega) and 0 <= k - i - 2 < len(pos):
        ans = min(ans, 2 * nega[i] + pos[k-i-2])
print(ans)

# n=int(input())
n, k = list(map(int, input().split()))
xl = list(map(int, input().split()))
#l=[list(input()) for i in range(h)]

if 0 in xl:
    k -= 1
else:
    xl.append(0)
    xl.sort()
if k == 0:
    ans = 0
else:
    ans = 10**9
    zeropoint = xl.index(0)
    endpoint = len(xl)-1
    startpoint = max(0, zeropoint-k)
    cur = startpoint
    while cur+k <= endpoint and cur <= zeropoint:
        # print(cur)
        # もし折り返すなら
        if cur < zeropoint < cur+k:
            tempdis = abs(xl[cur]-xl[cur+k])
            tempdis += min(abs(xl[cur]), xl[cur+k])
            ans = min(ans, tempdis)
        else:
            ans = min(ans, abs(xl[cur]-xl[cur+k]))
        cur += 1
print(ans)


import sys
N,K = map(int,input().split())
lsx = list(map(int,input().split()))
if 0 in lsx:
    K = K-1
    lsx.remove(0)
if bool(lsx) == False or K == 0:
    print(0)
    return
lshu = []
sei = len(lsx)
for i in range(len(lsx)):
    if lsx[i] < 0:
        lshu.append(lsx[i])
    else:
        sei = i
        break
lssei = lsx[sei:]
lenhu = len(lshu)
lensei = len(lssei)
lshu2 = [abs(lshu[i]) for i in range(lenhu-1,-1,-1)]
dishu = [0] + lshu2
dissei = [0] + lssei
ans = 10*10**8
for i in range(K+1):
    if i <= lenhu and K-i <= lensei:
        ans = min(ans,2*dishu[i]+dissei[K-i],dishu[i]+2*dissei[K-i])
print(ans)

N,K=map(int,input().split())
*X,=map(int,input().split())
A=[]
B=[]
for x in X:
    if x>=0:
        A.append(x)
    else:
        B.append(abs(x))
B.sort()
i=min(K,len(A))
j=K-i
ans=[]
while i>=0 and j<=len(B):
    if i==0:
        ans.append(B[j-1])
    elif j==0:
        ans.append(A[i-1])
    else:
        a,b=A[i-1],B[j-1]
        ans.append(a+b+min(a,b))
    i-=1
    j+=1
print(min(ans))

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

import bisect

b=bisect.bisect_left(x,0)

r=x[b:]
l=list(reversed(x[:b]))


R=len(r)
L=len(l)

ans=float('inf')

if k<=R:
    ans=min(ans,r[k-1])

if k<=L:
    ans=min(ans,abs(l[k-1]))

#右折り返し
for i in range(R):
    if i<k and k-i-2<=L-1 and k-i-2>=0:
        tmp=2*r[i] + abs(l[k-i-2])
        ans=min(ans,tmp)
#左折り返し
for j in range(L):
    if j<k and k-j-2<=R-1 and k-j-2>=0:
        tmp = 2*abs(l[j]) +r[k-j-2]
        ans=min(ans,tmp)


print(ans) 


n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=float('inf')

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

n,k = map(int,input().split())
x = list(map(int,input().split()))
li = []
for i in range(n-k+1):
    li += [x[k-1+i]-x[i]+min(abs(x[k-1+i]),abs(x[i]))]
print(min(li))

n,k = map(int, input().split())
x = list(map(int, input().split()))
ans = 10**10
for i in range(n-k+1):
  a = x[i+k-1]
  b = x[i]
  if a < 0:
    ans = min(ans,abs(b))
  else:
    if b < 0:
      ans = min(ans,min(a,abs(b))*2+max(a,abs(b)))
    else:
      ans = min(ans,a)
print (ans)

n,k = list(map(int,input().split()))
ls = list(map(int,input().split()))
flag = True
if 0 not in ls:
    ls.append(0)
    ls.sort()
    flag = False
ind = ls.index(0)
if flag == True:
    if ind >= k-1:
        l = ind - k + 1
    else:
        l = 0
    if ind + k - 1 <= n - 1:
        r = ind + k - 1
    else:
        r = n - 1 
    mn = float("inf")
    while True:
        if l+k-1 > r:
            break
        a = abs(ls[l]) + ls[l+k-1] + min(abs(ls[l]),ls[l+k-1])
        if a < mn:
            mn = a
        l += 1
else:
    if ind >= k:
        l = ind - k
    else:
        l = 0
    if ind + k <= n:
        r = ind + k
    else:
        r = n
    mn = float("inf")
    while True:
        if l+k > r:
            break
        a = abs(ls[l]) + ls[l+k] + min(abs(ls[l]),ls[l+k])
        if a < mn:
            mn = a
        l += 1
print(mn)


from collections import deque
    
N,K=map(int,input().strip().split())
x=list(map(int,input().strip().split()))
inf=10**9
    
l=inf
dp=deque(x[N-K:N])
i=0
while True:
    if dp[0]>=0:
        tmp=dp[K-1]
    elif dp[K-1]<=0:
        tmp=-dp[0]
    else:
        if abs(dp[K-1])>=abs(dp[0]):
            tmp=abs(dp[0])*2+abs(dp[K-1])
        else:
            tmp=abs(dp[K-1])*2+abs(dp[0])
    l=min(l,tmp)
    i+=1
    if N-K-i<0:
        break
    else:
        dp.appendleft(x[N-K-i])
        dp.pop()
print(l)

N,K = list(map(int,input().split()))
x = list(map(int,input().split()))
minTime = 10000000000
for i in range(N-K+1):
    time = 0
    minValue = x[i]
    maxValue = x[i+K-1]
    if minValue < 0 and maxValue < 0:
        time = minValue * -1
    elif minValue >= 0 and maxValue >= 0:
        time = maxValue
    elif minValue < 0 and maxValue >= 0:
        leftTime = minValue * -1
        rightTime = maxValue
        if leftTime < rightTime:
            time = leftTime * 2 + rightTime
        else:
            time = leftTime + rightTime * 2
    if time < minTime:
        minTime = time
print(minTime)

n,k=list(map(int,input().split()))
x=list(map(int,input().split()))
a=[x[i] for i in range(n) if x[i]<0]
b=[x[i] for i in range(n) if x[i]>=0]
na=len(a)
nb=len(b)
if 0 in x:
    k-=1
    b=[x[i] for i in range(n) if x[i]>0]
    nb=nb-1

if k==0:
    print((0))
    return
ans=10**10
if na>=k:
    ans=-a[-k]

if nb>=k:
    ans=min(ans,b[k-1])

if nb==0:
    print((-a[-k]))
    return

if na==0:
    print((b[k-1]))
    return

for i in range(1,nb+1):
    m=k-i
    if m>na or m<0:
        continue
    elif 0<m<=na:
        ans=min(ans,min(b[i-1]-2*a[-m],2*b[i-1]-a[-m]))
    elif m==0:
        ans=min(ans,b[k-1])
print((ans if k!=0 else 0))


def resolve():
    '''
    code here
    '''
    N, K = [int(item) for item in input().split()]
    xs = [int(item) for item in input().split()]
    
    min_lr = 10**9
    min_rl = 10**9

    if N != K:
        for i in range(N-K+1):
            min_lr = min(min_lr, abs(xs[i]) + abs(xs[i+K-1] - xs[i]))
            min_rl = min(min_rl, abs(xs[i+K-1]) + abs(xs[i+K-1] - xs[i]))

        print((min(min_lr, min_rl)))
    elif N ==1:
        print((abs(xs[0])))
    else:
        print((min(abs(xs[0]) + abs(xs[N-1] - xs[0]), abs(xs[N-1]) + abs(xs[N-1] - xs[0]))))

def __starting_point():
    resolve()

__starting_point()

import sys
n,k=map(int,input().split())
x=list(map(int,input().split()))
left=[]
right=[]
origin=0
for u in x:
  if u<0:
    left.append(abs(u))
  elif u==0:
    origin+=1
  else:
    right.append(u)
left.sort()
k-=origin
if k==0:
  print(0)
  return
r=len(right)
l=len(left)
ans=float('inf')
if k<=r:
  ans=right[k-1]
if k<=l:
  ans=min(ans,left[k-1])
for i in range(k-1):
  if i<r and k-i-2<l:
    y=right[i]+left[k-i-2]+min(right[i],left[k-i-2])
    ans=min(ans,y)
print(ans)

#!/usr/bin/env python3
n, k, *x = list(map(int, open(0).read().split()))
ans = 10**18
neg = []
pos = [0]
for i in x:
    if i < 0:
        neg.append(i)
    else:
        pos.append(i)
neg.append(0)
k += 1
c = len(neg)
c -= k -min(k, len(pos))
k = min(k, len(pos))
while c > 0 and k > 0:
    c -= 1
    k -= 1
    ans = min(ans, -neg[c] * 2 + pos[k], -neg[c] + pos[k] * 2)
print(ans)


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

for i in range(n):
    if x[i] > 0:
        neg_num = i
        break
pos_num = n - neg_num

l = min(k, neg_num)
res = 10 ** 13
for i in range(l, -1, -1):
    r = k - i
    if r <= pos_num:
        l_val = min(0, x[neg_num - i])
        r_val = max(0, x[neg_num + k - i - 1])
        tmp = min( -l_val * 2 + r_val, -l_val + r_val * 2)
        res = min(tmp, res)
print(res)

# coding: utf-8
import math
import bisect
import numpy as np
N, k = list(map(int,input().split()))
X = list(map(int,input().split()))
#if 0 in X:
 #   k -= 1
ans = float('inf')
for i in range(N-k+1):
    a = X[i]
    b = X[i+k-1]
    #print(a, b)
    if np.sign(a)*np.sign(b) >= 0:
        ans = min(ans, max(abs(a), abs(b)))
        #print("d="+str(max(abs(a), abs(b))))
    else:
        ans = min(ans, abs(a)+abs(b)+min(abs(a), abs(b)))
        #print("d="+str(abs(a)+abs(b)))
print(ans)


import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n, k = i_map()
    x = i_list()

    l = []
    r = []

    for i in x:
        if i < 0:
            l.append(-i)
        else:
            r.append(i)
    l.reverse()

    # if len(l) > 0:
    #     L = [l[0]]
    #     if len(l) > 1:
    #         for i in range(1, len(l)):
    #             L.append(L[i-1]+l[i])
    #
    # if len(r) > 0:
    #     R = [r[0]]
    #     if len(r) > 1:
    #         for i in range(1, len(r)):
    #             R.append(R[i-1]+r[i])


    R_len = len(r)
    L_len = len(l)

    ans = INF
    for i,j in enumerate(l):
        if R_len >= k - i - 1:
            if R_len == 0:
                ans = min(ans, j)
            else:
                ans = min(ans,2*j+r[k-i-2])

    for i,j in enumerate(r):
        if L_len >= k - i - 1:
            if L_len == 0:
                ans = min(ans,j)
            else:
                ans = min(ans,2*j+l[k-i-2])

    print(ans)


def __starting_point():
    main()

__starting_point()

# -*- coding: utf-8 -*-
"""
Created on Mon Oct  5 20:18:18 2020

@author: liang
"""

N, K = map(int, input().split())
X = [int(x) for x in input().split()]
ans = 10**10

for i in range(N-K+1):
    tmp = X[i+K-1] - X[i] + min(abs(X[i+K-1]),abs(X[i])) 
    if tmp < ans:
        ans = tmp
print(ans)

def main():
  N, K = [int(n) for n in input().split(" ")]
  X = [int(x) for x in input().split(" ")]
  X.sort()
  
  minus = []
  plus = []
  for i in range(len(X)):
    if X[i] < 0:
      minus.append(-X[i])
    else:
      plus += X[i:]
      break

  minus.reverse()

  T = []
  
  if len(plus) >= K:
    T.append(plus[K - 1])
  if len(minus) >= K:
    T.append(minus[K - 1])
  for i in range(K):
    if i < len(plus) and 0 <= K - i - 2 < len(minus):
      T.append(2 * plus[i] + minus[K - i - 2])
      T.append(2 * minus[K - i - 2] + plus[i])
    if i < len(minus) and 0 <= K - i - 2 < len(plus):
      T.append(2 * minus[i] + plus[K - i - 2])
      T.append(2 * plus[K - i - 2] + minus[i])
  
  print((min(T)))

main()



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

res= 10**10

for i in range(n-k+1):
    st = al[i]
    en = al[i+k-1]
    if st *en <0:
        temp = min(abs(st),abs(en))*2+max(abs(st),abs(en))
    else:
        temp = max(abs(st),abs(en))
    res = min(temp,res)

print(res)

#!/usr/bin/env python3
# import bisect

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

# index = bisect.bisect(list, 0)

# left = index
# right = n - index

# if left != 0:
#     if x[index-1] == 0:
#         k -= 1
#         del(x[index-1])

ans = 10**9
for i in range(0, n-k+1):
    # print(x[i], x[i+k-1])
    if x[i]*x[i+k-1] >= 0:
        ans_tmp = max(abs(x[i]), abs(x[i+k-1]))
    else:
        ans_tmp = abs(x[i]) + abs(x[i+k-1]) + min(abs(x[i]), abs(x[i+k-1]))

    # print(ans_tmp)
    ans = min(ans, ans_tmp)
# print()
print(ans)


N,K=map(int,input().split())
*X,=map(int,input().split())
i=0
ans=[]
while i+K-1<N:
    a,b=X[i],X[i+K-1]
    if b<0:
        ans.append(abs(a))
    elif a>0:
        ans.append(b)
    else:
        a=abs(a)
        ans.append(a+b+min(a,b))
    i+=1
print(min(ans))

import numpy as np
N,K = list(map(int,input().split()))
X = np.array(input().split(), dtype=np.int64)

INF = 10 ** 18
neg = np.concatenate([-X[X <= 0][::-1], np.full(N+1,INF,dtype=np.int64)])[:K]
pos = np.concatenate([X[X > 0], np.full(N+1,INF,dtype=np.int64)])[:K]

answer = INF
# 左のみ
answer = min(answer, neg[-1])
# 右のみ
answer = min(answer, pos[-1])
if K >= 2:
  # 左にa個、右にK-a個
  answer = min(answer, (neg[:K-1] * 2 + pos[K-2::-1]).min())
  # 右にa個、右にK-a個
  answer = min(answer, (pos[:K-1] * 2 + neg[K-2::-1]).min())

print(answer)


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

ans = float("inf")
for i in range(n-k+1):
  # 0の位置から移動し、i〜i+kまでのろうそくに火をつけた場合の移動時間について左右で確認し、最小を求める
  l = abs(x[i]) + abs(x[i]-x[i+k-1])
  r = abs(x[i+k-1]) + abs(x[i] - x[i+k-1])
  ans = min(ans, l, r)
print(ans)

# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, K, x):
    l = [abs(xi) for xi in x if xi < 0] + [0]
    l.reverse()
    r = [0] + [xi for xi in x if xi >= 0]
    ans = 10 ** 18 * 2 + 1
    for i in range(max(K - (len(l) - 1), 0), min(K + 1, len(r))):
        ll = l[K - i]
        rr = r[i]
        ans = min(ans, min(ll, rr) * 2 + max(ll, rr))
    print(ans)


def __starting_point():
    # S = input()
    # N = int(input())
    N, K = list(map(int, input().split()))
    x = [int(i) for i in input().split()]
    # B = [int(i) for i in input().split()]
    # AB = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N, K, x)

    # # test
    # from random import randint
    # from func import random_str
    # solve()

__starting_point()

import bisect
import math

N,K = map(int, input().split())
X = list(map(int, input().split()))
a = bisect.bisect_left(X,0)
X.insert(a,0)

ans = math.inf

for i in range(max(0,a+K-N), min(a+1,K+1)):
    ans = min(ans, -X[a-i]*2+X[a+K-i], -X[a-i]+X[a+K-i]*2)

print(ans)

n, k = list(map(int, input().split()))
xlst = list(map(int, input().split()))
minus = []
plus = []
for x in xlst:
    if x < 0:
        minus.append(-1 * x)
    elif x > 0:
        plus.append(x)
    else:
        k -= 1
if k == 0:
    print((0))
    return
minus.append(0)
minus = minus[::-1]
plus = [0] + plus
ans = 10 ** 20
ml = len(minus)
pl = len(plus)

pos = min(k, ml - 1)
while 1:
    mm = minus[pos]
    pp = plus[k - pos]
    ans_tmp = max(mm, pp) + min(mm, pp) * 2
    ans = min(ans, ans_tmp)
    pos -= 1
    if pos == -1 or k - pos == pl:
        break
print(ans)


N, K = list(map(int, input().split()))
D = [int(n) for n in input().split()]
ans = 10000000000

for i in range(N-K+1):
    L = D[i]
    R = D[i+K-1]
    LR = abs(L) + abs(L - R)
    RL = abs(R) + abs(R - L)
    ans = min(ans, min(LR, RL))

print(ans)


n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
ans = 10000000000000
for i in range(n-k+1):
    ans1 = abs(l[i]) + abs(l[i+k-1] - l[i])
    ans2 = abs(l[i+k-1]) + abs(l[i+k-1] - l[i])
    ans = min(ans, ans1, ans2)
print(ans)


from bisect import bisect_left

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

pos = bisect_left(x, 0)
if pos < len(x) and x[pos] == 0:
    k -= 1
else:
    x.insert(pos, 0)

l = pos
r = pos+k

if r >= len(x):
    diff = r-len(x) + 1
    l -= diff
    r -= diff

ans = min(abs(x[l]), x[r])*2 + max(abs(x[l]), x[r])

while r >= pos:
    if l < 0:
        break

    dist = min(abs(x[l]), x[r])*2 + max(abs(x[l]), x[r])
    if dist < ans:
        ans = dist

    l -= 1
    r -= 1

print(ans)

n,k=map(int,input().split())
x=[int(i) for i in input().split()]
ans=10**9
 
for i in range(n-k+1):
    temp=0
    temp+=(min(abs(x[i]),abs(x[i+k-1]))+abs(x[i]-x[i+k-1]))
    ans=min(ans,temp)
print(ans)

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

mt=5*10**8

for i in range(n-k+1):
  mt=min(mt,2*abs(x[i])+abs(x[i+k-1]),abs(x[i])+2*abs(x[i+k-1]))

if x[0]>0:mt=min(mt,x[k-1])
elif x[-1]<0:mt=min(mt,abs(x[-1-k+1]))
print(mt)
    


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

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

from sys import stdin

def getval():
    n,k = map(int,input().split())
    x = list(map(int,input().split()))
    return n,k,x

def main(n,k,x):
    idx = k-1
    ans = 0
    if x[0]>=0:
        ans = x[idx]
    elif x[idx]<=0:
        ans = abs(x[0])
    else:
        ans = min(abs(x[0]),abs(x[idx]))*2+max(abs(x[0]),abs(x[idx]))
    for i in range(k,n):
        temp = 0
        #print(ans)
        if x[i-k+1]>=0:
            temp = x[i]
        elif x[i]<=0:
            temp = abs(x[i-k+1])
        else:
            temp = min(abs(x[i]),abs(x[i-k+1]))*2+max(abs(x[i]),abs(x[i-k+1]))
        ans = min(ans,temp)
    print(ans)


def __starting_point():
    n,k,x = getval()
    main(n,k,x)
__starting_point()

n,k=map(int, input().split())
x=list(map(int, input().split()))
c=10**9
for i in range(n-k+1):
  a=x[i+k-1]
  b=x[i]
  if a<0:
    c=min(c,abs(b))
  else:
    if b<0:
      c=min(c,min(a,abs(b))*2+max(a,abs(b)))
    else:
      c=min(c,a)
print(c)

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

if len(lis) == 1:
    print(abs(lis[0]))
    return

ans = 10**9+7
for i in range(n-k+1):
    l = abs(lis[i]) + abs(lis[i+k-1]-lis[i])
    r = abs(lis[i+k-1]) + abs(lis[i+k-1]-lis[i])
    ans = min(ans, l, r)

print(ans)

import sys

input = sys.stdin.readline


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

    X.sort()
    ans = float("inf")
    for l in range(N - K + 1):
        r = l + K - 1
        l2r = abs(X[l]) + abs(X[l] - X[r])
        r2l = abs(X[r]) + abs(X[r] - X[l])
        ans = min(ans, l2r, r2l)

    print(ans)


def __starting_point():
    main()

__starting_point()

n,k= list(map(int,input().split()))
pos= list(map(int,input().split()))
ans = 10**13
for i in range(n-k+1):
    a1 = abs(pos[i]) + abs(pos[i] - pos[i+k-1])
    a2 = abs(pos[i+k-1]) + abs(pos[i] - pos[i+k-1])
    ans = min(ans, a1,a2)
print(ans)

n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = 10**10
for left in range(n-k+1):
    right = left+k-1
    ans = min(ans, abs(x[left])+abs(x[right]-x[left]), abs(x[right])+abs(x[right]-x[left]))
print(ans)