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 in Python (3.4.3) (judge verdict: Wrong Answer)

# なぜかうまくいかない
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_right, bisect_left

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

N, K = MAP()
A = LIST()
# 0 0 0の左
zero = A.count(0)
# A.(0)
l = bisect_left(A, 0)
r = bisect(A, 0)
zero = r - l
C = []
for a in A[:l]:
    if a == 0:
        continue
    C.append(a)
    
B = C + A[r:]


w = K - zero
ans = INF
B.insert(0, -INF)
B.append(INF)
if zero == K:
    print(0)
    exit()

for i in range(len(B) - K + 1):
    r = B[i + K - zero - 1]
    l = B[i]
    tmp = INF
    if l < 0 and r > 0:
        tmp = min(abs(l), r) + r - l
    # ans = min(ans, tmp)
    elif l > 0 and B[i-1] < 0:
        tmp = min(abs(l), r) + r - l

    elif r < 0 and B[i + K - zero - 1 + 1] < 0:
        tmp = min(abs(l), r) + r - l
    ans = min(ans, tmp)
print(ans)


        # if abs(B[i]) <= :

#         tmp = B[i + K - zero-1] - B[i]
#         print(B[i+K-zero-1])
#         print(B[i])
#         ans = min(ans, tmp)
# print(ans)