Problem:
 Score : 300 points    Problem Statement 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 1 5 3
-30 -10 10 20 50      Sample Output 1 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.        Sample Input 2 3 2
10 20 30      Sample Output 2 20       Sample Input 3 1 1
0      Sample Output 3 0   There may be a candle placed at coordinate 0 .        Sample Input 4 8 5
-9 -7 -4 -3 1 2 3 4      Sample Output 4 10

Solution (Python):
n, k = map(int, input().split())
x = list(map(int, input().split()))
first = True
for l, r in zip(range(0, n - k + 1), 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)

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

x = x[::-1]

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

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

    print(now)

Solution (Python):
def solve(n, k, x):
    ans = 2 * (max(x) - min(x))
    for i in range(n-k+1):
        left = x[i]
        right = x[i+k-1]
        if left * right >= 0:
            d = max(abs(right), abs(left))
        else:
            d = min(
                2 * abs(left) + abs(right),
                abs(left) + 2 * abs(right)
            )
        ans = min(ans, d)
    return ans

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

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

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

    ans = min(ans,temp)

print(ans)

Solution (Python):
N,K=map(int,input().split())
a=list(map(int,input().split()))

ans=10**11

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

print(ans)

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

min_time = float('inf')
for i in range(N-K+1):
  cost1 = abs(X[i]-X[i+K-1]) + abs(X[i])
  cost2 = abs(X[i]-X[i+K-1]) + abs(X[i+K-1])
  min_time = min(min_time,cost1,cost2)
print(min_time)

Solution (Python):
n,k = map(int,input().split())
l = list(map(int,input().split()))

ans = 10**9

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

Solution (Python):
N,K=map(int,input().split())
x=list(map(int,input().split()))
y=[]
for i in range(N-1):
    y.append(x[i+1]-x[i])
z=[]
z.append(0)
for i in range(N-1):
    z.append(z[i]+y[i])
M=10**10
for i in range(N-K+1):
    M=min(M,min(abs(x[i]),abs(x[i+K-1]))+z[i+K-1]-z[i])
if N-K==0:
  M=min(abs(x[0]),abs(x[-1]))+z[-1]
print(M)

Solution (Python):
n,k=map(int,input().split())
x=list(map(int,input().split()))
minus_x=[i for i in x if i<0]
pz=len(minus_x)
start=pz-k
if start<0:
    start=0
if pz+k-1>n-1:
    end=n-k+1
else:
    end=pz+1
l=[]
for i in range(start,end):
    l.append(x[i+k-1]-x[i]+min(abs(x[i+k-1]),abs(x[i])))
print(min(l))

Solution (Python):
N, K = map(int, input().split())
x = [int(i) for i in input().split()]
min = 10 ** 9
for i in range(N-K+1):
  count = abs(x[i] - x[i+K-1]) + abs(x[i])
  if count < min:
    min = count
  count = abs(x[i] - x[i+K-1]) + abs(x[i+K-1])
  if count < min:
    min = count
print(min)

Solution (Python):
n,k = map(int,input().split())
lis = list(map(int,input().split()))
if n == 1:
  print(lis[0])
  exit()
ans = []
for i in range(n-k+1):
  if lis[i+k-1] <=0 or 0 <= lis[i]:
    ans.append(max(abs(lis[i+k-1]),abs(lis[i])))
  else:
    ans.append(min(abs(lis[i+k-1]),abs(lis[i]))+abs(lis[i+k-1])+abs(lis[i]))
print(min(ans))

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

Xp = [x for x in X if x>=0]
Xn = [x for x in X if x<0]
Xp.sort()
Xn.sort(reverse=True) 


answer = 1e9
for i, x in enumerate(Xp):
  if len(Xn) >= K-(i+1) > 0:
    
    answer = min(answer, 2*x -Xn[K-(i+1)-1])
  if K-(i+1)==0:
    answer = min(answer, x)
for i, x in enumerate(Xn):
  if len(Xp) >= K-(i+1) > 0:
    
    answer = min(answer, -2*x + Xp[K-(i+1)-1])
  if K-(i+1)==0:
    answer = min(answer, -x)
print(answer)

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

ans = float("inf")
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 = x[i+k-1] - x[i] + min(abs(x[i]), abs(x[i+k-1]))
  ans = min(ans, t)
print(ans)

Solution (Python):
INF = 10**9

N, K = map(int, input().split())
x_list = [int(i) for i in input().split()]
for i in range(N):
    if x_list[i] >= 0:
        T = i
        break
else:
    print(abs(x_list[-K]))
    exit()
min_take_time = INF
for i in range(K+1):
    if T-K+i < 0 or T+i>N:
        continue
    if x_list[T-K+i] *  x_list[T+i-1] <= 0:
        take_time = min(abs(x_list[T-K+i]), abs(x_list[T+i-1])) * 2 + max(abs(x_list[T-K+i]), abs(x_list[T+i-1]))
    else:
        take_time = max(abs(x_list[T-K+i]), abs(x_list[T+i-1]))
    min_take_time = min(min_take_time, take_time)


print(min_take_time)

Solution (Python):
n,k = map(int,input().split())

xn = list(map(int,input().split()))


ans = float("inf")
for i in range(n-k+1):


    tmp = min(abs(xn[i]),abs(xn[k+i-1])) + xn[k+i-1] - xn[i]


    if tmp < ans:
        ans=tmp
print(ans)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    s = S()
    c = s.count("0")
    print(2*min(c,len(s)-c))
    return


def B():
    n = I()
    h = LI()
    ans = 0
    m = min(h)
    while m:
        ans += m
        k = max(h)
        for i in range(n):
            if h[i] >= m:
                h[i] -= m
                if h[i]:k = min(k,h[i])
            else:break
        m = k
    print(ans)
    return


def C():
    n,k = LI()
    x = LI()
    ans = float("inf")
    j = bisect.bisect_left(x,0)
    if n == 1:
        print(abs(x[0]))
        quit()
    if j < n:
        if x[j] == 0:
            k -= 1
            x.pop(j)
            n -= 1
    for i in range(n):
        if i < j:
            if abs(i-j) > k:continue
            elif abs(i-j) == k:ans = min(ans,abs(x[i]))
            elif k+i-1 < n:
                ans = min(ans,abs(x[i])+x[k+i-1]-x[i])
        else:
            if abs(i-j)+1 > k:continue
            elif abs(i-j)+1 == k:ans = min(ans,x[i])
            elif i-k+1 >= 0:
                ans = min(ans,abs(x[i])+x[i]-x[i-k+1])

    print(ans)
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


def I_():
    return


def J():
    return


if __name__ == "__main__":
    C()

Solution (Python):
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = float('inf')
for i in range(K - 1, N):
    l = x[i - K + 1]
    r = x[i]
    ans = min(ans, abs(l) + abs(l - r), abs(r) + abs(r - l))
print(ans)

Solution (Python):

import sys
import itertools
import collections
from queue import Queue
import functools
import math
INF = 10**9


def solve(N: int, K: int, x: "List[int]"):
    x_neg = ([-xx for xx in x if xx < 0]+[0])[::-1]
    x_pos = [0] + [xx for xx in x if xx >= 0]

    
    left = [x_neg[i]*2 + x_pos[K-i] for i in range(len(x_neg))
            if 0 <= K-i and K-i < len(x_pos)]
    if len(left) > 0:
        ansleft = min(left)
    else:
        ansleft = INF

    
    right = [x_pos[i]*2 + x_neg[K-i] for i in range(len(x_pos))
             if 0 <= K-i and K-i < len(x_neg)]
    if len(right) > 0:
        ansright = min(right)
    else:
        ansright = INF
    
    
    print(min(ansright, ansleft))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    x = [int(next(tokens)) for _ in range(N)]  
    solve(N, K, x)


if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_right

N, K = map(int, input().split())
x = list(map(int, input().split()))
zero_pos = bisect_right(x, 0)
start = max(zero_pos - K, 0)
end = min(zero_pos, N - K)
m = 10**10
for i in range(start, end + 1):
    left = x[i]
    right = x[i+K-1]
    _m = max(abs(left), abs(right))
    if left*right < 0:
        _m += min(abs(left), abs(right))*2
    m = min(m, _m)
print(m)

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

cand = []


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

print(min(cand))

Solution (Python):
N,K = list(map(int,input().split()))
x = list(map(int,input().split()))
res = 999999999999999999
for i in range(N-K+1):
  res = min(min(abs(2*x[i])+abs(x[i+K-1]),abs(x[i])+abs(2*x[i+K-1])),res)
  if x[i]*x[i+K-1] >= 0:
    if x[i] >= 0:
    	res = min(res,x[i+K-1])
    else:
      	res = min(res,abs(x[i]))
  
print(res)

Solution (Python):
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = 10 ** 18
for i in range(N - K + 1):
    left = i
    right = i + K - 1
    tmp = min(abs(x[left]) + abs(x[right] - x[left]), abs(x[right]) + abs(x[left] - x[right]))
    ans = min(ans, tmp)
print(ans)

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

Solution (Python):
import sys
import math
import fractions
from functools import reduce
from collections import Counter
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  
def LF(): return [float(x) for x in sys.stdin.readline().split()]  
def LS(): return sys.stdin.readline().split()  
def MI(): return map(int, sys.stdin.readline().split())  
def II(): return int(sys.stdin.readline())  
def IS(): return input()  
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)

N, K = MI()
x = LI()
ans = INF
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)

Solution (Python):
n, k = map(int, input().split())
x = list(map(lambda x: int(x), input().split()))

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

print(ans)

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

d_min = 2*(x[N-1]-x[0])

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

print(d_min)

Solution (Python):
n,k=map(int,input().split())

X=list(map(int,input().split()))
V=[]
for i in range(n-k+1):
    Y=X[i+k-1]-X[i]   
    V.append(Y+min(abs(X[i]),abs(X[i+k-1])))

print(min(V))

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

left = []
right = []
for x in X:
    if x<0:
        left.append(abs(x))
    else:
        right.append(x)
left.reverse()


ans = 10**18


for i in range(K+1):
    if len(right)!=0 and right[0]==0 and i==0:
        continue;
    temp = 0
    if len(left)==0:
        temp = right[K-1]
    elif len(right)==0:
        temp = left[K-1]
    elif len(left)>=(K-i):
        if len(right)>=i:
            temp0 = left[K-i-1] if not i==K else 0
            temp1 = right[i-1] if not i==0 else 0
            temp  = temp0+temp1 + min(temp0, temp1)
        else:
            temp0 = right[-1]
            temp1 = left[K-len(right)-1]
            temp  = temp0+temp1 + min(temp0, temp1)
    else:
        temp0 = left[-1]
        temp1 = right[K-len(left)-1]
        temp  = temp0+temp1 + min(temp0, temp1)
    ans = min(ans, temp)

print(ans)

Solution (Python):
import numpy as np

N, K = (int(i) for i in input().split())
x = np.sort(np.array([int(i) for i in input().split()]))

result = []
if(N==1):
    print(np.abs(x[0]))

else:
    for i in range(N - K + 1):
        left = x[i]
        right = x[i + K - 1]

        if (left * right < 0):
            if (np.abs(left) < np.abs(right)):
                diff = np.abs(left) * 2 + np.abs(right)
            else:
                diff = np.abs(left) + np.abs(right) * 2

        else:
            diff = np.max([np.abs(left), np.abs(right)])

        result.append(diff)

    print(np.min(result))

Solution (Python):
n,m=map(int,input().split())
l=list(map(int,input().split()))
l1=[]
for i in range(n-m+1):
  if l[i]>=0:
    l1.append(l[i+m-1])
  elif l[i]<=0<=l[i+m-1]:
    l1.append(l[i+m-1]-l[i]+min(abs(l[i]),abs(l[i+m-1])))
  else:
    l1.append(abs(l[i]))
print(min(l1))

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

dis = 300000000

for i in range(N-K+1):
    disl = abs(x[i]) + abs(x[i+K-1]-x[i])
    disr = abs(x[i+K-1]) + abs(x[i+K-1]-x[i])

    dis = min(dis, disl, disr)






print(dis)

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

score = 10**10
for i in range(N-K+1):
    l = x[i]
    r = x[i+K-1]
    if r <= 0:
        score = min(score,-l)
    elif l >= 0:
        score = min(score,r)
    else:
        score = min(score,-2*l+r,-l+2*r)
print(score)

Solution (Python):
N, K = map(int, input().split())
x = list(map(int, input().split()))
m = float("INF")
for i in range(N - K + 1):
    m = min(m, x[i + K - 1] - x[i] + min(abs(x[i + K - 1]), abs(x[i])))
print(m)

Solution (Python):
N, K = map(int, input().split())
x = list(map(int, input().split()))
m = float("INF")
for i in range(N - K + 1):
    if x[i + K - 1] * x[i] < 0:
        m = min(m, x[i + K - 1] - x[i] + min(abs(x[i + K - 1]), abs(x[i])))
    else:
        m = min(m, max(abs(x[i + K - 1]), abs(x[i])))
print(m)

Solution (Python):
n,k=map(int,input().split())
li=list(map(int,input().split()))
q=[]
if k==n:
  q.append(li[n-1]-li[0]+min(abs(li[n-1]),abs(li[0])))
else:
  for i in range(k,n+1):
    if li[i-1]<0:
      q.append(-li[i-k])
    elif li[i-k]>0:
      q.append(li[i-1])
    else:
      q.append(li[i-1]-li[i-k]+min(li[i-1],abs(li[i-k])))
print(min(q))

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')



N, K = 0, 0
X = []


def set_inputs():
    global N, K, X
    N, K = get_li()
    X = get_li()
    return


def twice(x):
    return x[0] * 2, x[1]


def find_index(l, x):
    if x in l:
        return l.index(x)
    return inf


def main():
    setrecursionlimit(100000)
    set_inputs()
    ans = inf
    for i in range(N-K+1):
        l, r = X[i], X[i+K-1]
        tmp = min(abs(l) + abs(l-r), abs(r) + abs(r-l))
        ans = min(ans, tmp)
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


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


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Solution (Python):
N, K = map(int, input().split())
a = list(map(int, input().split()))

min_time = 10 ** 12
for i in range(N):
    if i + K > N:
        break
    if a[i] > 0:
        min_time = min(min_time, abs(a[i + K - 1]))
        break
    
    if a[i + K - 1] < 0:
        if (i + K < N and a[i + K] > 0) or i + K == N:
            min_time = min(min_time, abs(a[i]))
        continue
        
    min_time = min(min_time, 2 * abs(a[i]) + abs(a[i + K - 1]), abs(a[i]) + 2 * abs(a[i + K - 1]))

print(min_time)

Solution (Python):
import bisect as bs
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(int, input().split()))
m = bs.bisect_left(a, 0)
a.insert(m, 0)
ans = 10 ** 9
for i in range(K + 1):
    if m - i >= 0 and m + K - i < N + 1:
        ans = min(a[m + K - i] - a[m - i] + min(a[m + K - i], -a[m - i]), ans)
print(ans)

Solution (Python):
import bisect

ans = 10**20

N, K = list(map(int, input().split()))
x = [-10**20] + list(map(int, input().split())) + [10**20]

zero = bisect.bisect_left(x, 0)

left = x[:zero] + [0] 
right = [0] + x[zero:]
left.reverse()
l = len(left)
r = len(right)

idxs = [[K-i, i] for i in range(K+1) if K-i < l and i < r]

for l, r in idxs:
    n = abs(left[l]) + right[r] + min(abs(left[l]), right[r])
    ans = min(ans, n)
print(ans)

Solution (Python):
N,K = map(int, input().split())
x = [int(i) for i in input().split()]
ls = []
for x, y in zip(x[:N-K+1], x[K-1:]):
    ls.append(min(abs(x)+abs(x-y), abs(y)+abs(x-y)))
print(min(ls))

Solution (Python):
n,k=map(int,input().split())
x=list(map(int,input().split()))
P=[i for i in x if i>=0]
Q=[abs(i) for i in x if i<0]
ans=10**18
if len(P)>=k:
  ans=min(ans,P[k-1])
if len(Q)>=k:
  ans=min(ans,Q[-k])
for i in range(1,k):
  if i<=len(Q) and k-i<=len(P):
    ans=min(ans,Q[-i]*2+P[k-i-1],Q[-i]+P[k-i-1]*2)
print(ans)

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

Solution (Python):
n,k = map(int,input().split())
X = list(map(int,input().split()))
from bisect import bisect_left as bl
zero = bl(X,0)

temp = []
for i in range(max(zero,k-1),min(zero+k,n)):
    if X[i-k+1] >= 0:
        temp.append(X[i])
    elif X[i] <= 0:
        temp.append(abs(X[i-k+1]))
    else:
        temp.append(min(abs(X[i]),abs(X[i-k+1]))*2+max(abs(X[i]),abs(X[i-k+1])))
try:
        print(min(temp))
except:
        print(abs(X[-k]))

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

Solution (Python):
n, k = map(int, input().split())
x = [int(i) for i in input().split()]
d = []
for i in range(n-k+1):
    l, r = x[i], x[i+k-1]
    d.append(abs(l-r) + min(abs(l), abs(r)))
print(min(d))

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

Solution (Python):
N,K = map(int,input().split())
x = list(map(int,input().split()))
ans = 10**17
for i in range(N-K+1):
    l,r = i,i+K-1
    ans = min(abs(x[r])+abs(x[l]-x[r]),min(ans,abs(x[l])+abs(x[r]-x[l])))
print(ans)

Solution (Python):
n,k = map(int,input().split())
X = list(map(int,input().split()))
S = []
for i in range(n-k+1):
	if X[i]*X[i+k-1] < 0:
		S.append(X[i+k-1]-X[i]+min(abs(X[i+k-1]),abs(X[i])))
	else:
		S.append(max(abs(X[i+k-1]),abs(X[i])))
print(min(S))

Solution (Python):
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = []

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

print(min(ans))

Solution (Python):
n, k = map(int, input().split())
xlist = list(map(int, input().split()))

mink = pow(10, 18)
for i, x in enumerate(xlist[k-1:]):
  lx = xlist[i]
  if mink > abs(lx) + x - lx:
    mink = abs(lx) + x - lx
  if mink > abs(x) + x - lx:
    mink = abs(x) + x - lx
print(mink)

Solution (Python):
import numpy as np

N, K = (int(i) for i in input().split())
x = np.sort(np.array([int(i) for i in input().split()]))

result = []
if(N==1):
    print(np.abs(x[0]))

else:
    for i in range(N - K + 1):
        left = x[i]
        right = x[i + K - 1]

        if (left * right < 0):
            if (np.abs(left) < np.abs(right)):
                diff = np.abs(left) * 2 + np.abs(right)
            else:
                diff = np.abs(left) + np.abs(right) * 2

        else:
            diff = np.max([np.abs(left), np.abs(right)])

        result.append(diff)

    print(np.min(result))

Solution (Python):
N, K = map(int, input().split())
X = list(map(int, input().split()))
ans_ar = []
for i in range(N-K+1):
    ans_ar.append(min(abs(X[i]), abs(X[i+K-1])) + (X[i+K-1] - X[i]))
print(min(ans_ar))

Solution (Python):
N, K = map(int, input().split())
X = list(map(int, input().split()))
cost = []
for i in range(0, N-K+1):
    
    
    cost.append(X[i+K-1]-X[i] + min(abs(X[i+K-1]), abs(X[i])))
print(min(cost))

Solution (Python):
N,K=map(int,input().split())
x=list(map(int,input().split()))
ans=10**9
for i in range(N-K+1):
    if min(abs(x[i])+abs(x[i]-x[i+K-1]),abs(x[i+K-1])+abs(x[i]-x[i+K-1]))<ans:
        ans=min(abs(x[i])+abs(x[i]-x[i+K-1]),abs(x[i+K-1])+abs(x[i]-x[i+K-1]))
print(ans)

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

length = float("inf")
for i in range(N - K + 1):
  r = i + K - 1
  l = i
  li = min(abs(x[r]) + abs(x[r] - x[l]), abs(x[l]) + abs(x[r] - x[l]))
  if li < length:
    length = li

print(length)

Solution (Python):
N, K = map(int, input().split())
x = [int(i) for i in input().split()]
key = []
for left, right in zip(x, x[K - 1:]):
    key.append(right-left+min(abs(left), abs(right)))
print(min(key))

Solution (Python):


N, K = map(int, input().split())
INF = 10**10
x_first = [-INF for i in range(K)]
x_ap = [int(i) for i in input().split()]
x_last = [INF for i in range(K)]
x = x_first + x_ap + x_last + [0]
x.sort()
zero_index = x.index(0)

key = []
for i in range(K+1):
    left = abs(x[zero_index - i])
    right = abs(x[zero_index - i + K])
    
    if left > right:
        right *= 2
    else:
        left *= 2
    key.append(left + right)
print(min(key))

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

ans=10**9
for i in range(0,n-k+1):
    x_l=x[i]
    x_r=x[i+k-1]
    
    ans=min(ans,abs(x_r-x_l)+abs(x_l),abs(x_r-x_l)+abs(x_r))
print(ans)

Solution (Python):
N, K = map(int ,input().split())
x = list(map(int, input().split()))
xp = [0]+[xi for xi in x if xi>=0]
size_p = len(xp)-1
xn = [-xi for xi in x if xi<0] + [0]
xn.reverse()
size_n = len(xn)-1




min_t = float('inf')
for p in range(K+1):
	n = K-p
	if p>size_p or n>size_n:
		continue
	
	tmp = xp[p]+xn[n]+min(xp[p],xn[n])
	
	
	
	if min_t > tmp:
		min_t = tmp

print(min_t)

Solution (Python):
N = K = 0
N, K = map(int, input().split())
Xi = list(map(int, input().split()))

def calc(startIndex):
    if startIndex + K > N:
        return -1
    endIndex = startIndex + K - 1
    x1 = Xi[startIndex]
    x2 = Xi[endIndex]
    len1 = abs(x1) + abs(x2 - x1)
    len2 = abs(x2) + abs(x2 - x1)
    return min(len1, len2)

INF = 100000000000000
min_value = INF
for i in range(N):
    d = calc(i)
    if d >= 0 and d < min_value:
        min_value = d
if min_value == INF:
    print(0)
else:
    print(min_value)

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

min_dist = 10**10
for i in range(n-k+1):
    if x[i] > 0:
        dist = x[i+k-1]
    elif x[i+k-1] < 0:
        dist = -x[i]
    else:
        dist = x[i+k-1] - x[i] + min(-x[i], x[i+k-1])

    if dist < min_dist:
        min_dist = dist

print(min_dist)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

N, K = LI()
X = LI()
if 0 in X:
    X.remove(0)
    K -= 1

if K == 0:
    print(0)
    exit()

distances = []
mid = bisect.bisect_left(X, 0)






















for x in X:
    if x < 0:
        distances.append(-x)
    else:
        distances.append(x)



results = []
for start in range(N):
    end = start + K
    if end > N: break
    
    
    if start < mid < end:
        
        results.append(min(distances[start], distances[end-1]) * 2 + max(distances[start], distances[end-1]))
    elif start >= mid:
        
        results.append(distances[end-1])
    else:
        results.append(distances[start])


print(min(results))

Solution (Python):
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = 10**9
for i in range(N-K+1):
    l = x[i]
    r = x[i+K-1]
    sec1 = abs(l) + abs(r-l)
    sec2 = abs(r) + abs(l-r)
    ans = min(ans, sec1, sec2)
print(ans)

Solution (Python):
import numpy as np
N , K = map( int , input().split())
lst = list(map(int, input().split()))
ans = 10 ** 9

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

print(ans)

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

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

ans = 1e9
for l, r in zip(X, X[K-1:]):
  ans = min(ans, r-l+min(abs(l),abs(r)))
print(ans)

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

def main():
    k = K
    l = len(X) 

    i = 0

    ans = float('inf')
    end = l - k
    while i <= end:
        first = X[i]
        last = X[i + k - 1]
        node_abs = [abs(first), abs(last)]
        if first * last >= 0:
            curr = max(node_abs)
        else:
            curr = max(node_abs) + (min(node_abs) * 2)
        ans = min(ans, curr)
        i += 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
MAX = 300000001

N, K = 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()

Solution (Python):
MAX = 300000001

N, K = 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] and 0 != i and xn[i - 1] < 0:
            ans = min(ans, abs(xn[i + K - 1]))

        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()