Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
X = list(map(int,input().split()))
ANS = []
for i in range(N-K+1) :
    L = X[i:K+i]
    l1 = abs(min(L))+abs(max(L)-min(L))
    l2 = abs(max(L))+abs(max(L)-min(L))
    ANS.append(min(l1,l2))
print(min(ANS))



Fixed submission:
N,K = map(int,input().split())
L = list(map(int,input().split()))
ANS = []
for i in range(len(L)-K+1) :
    p = L[i]
    q = L[i+K-1]
    if p*q == 0 :
        r = abs(p-q)
    elif p*q < 0 :
        r = 2*min(abs(p),q) + max(abs(p),q)
    else :
        if p > 0 :
            r = q
        else :
            r = abs(p)
    ANS.append(r)
ans = min(ANS)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
X = list(map(int,input().split()))
ANS = []
for i in range(N-K+1) :
    L = X[i:K+i]
    if min(L)*max(L) >= 0 :
        ANS.append(max(abs(min(L)),max(L)))
    else :
        ANS.append(min(abs(min(L))*2+abs(max(L)),abs(max(L))*2+abs(min(L))))
print(min(ANS))
#print(ANS)



Fixed submission:
N,K = map(int,input().split())
L = list(map(int,input().split()))
ANS = []
for i in range(len(L)-K+1) :
    p = L[i]
    q = L[i+K-1]
    if p*q == 0 :
        r = abs(p-q)
    elif p*q < 0 :
        r = 2*min(abs(p),q) + max(abs(p),q)
    else :
        if p > 0 :
            r = q
        else :
            r = abs(p)
    ANS.append(r)
ans = min(ANS)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
X = list(map(int,input().split()))
ANS = []
for i in range(N-K+1) :
    L = X[i:K+i]
    cplus = 0
    cminus = 0
    czero = 0
    for j in range(len(L)) :

        if L[j] > 0 :
            cplus += 1
        elif L[j] < 0 :
            cminus += 1
        else :
            czero += 1
    if (cplus == K-czero) or (cminus == K-czero):
        ANS.append(max(abs(min(L)),max(L)))
    else :
        ANS.append(min(abs(min(L))*2+abs(max(L)),abs(max(L))*2+abs(min(L))))
print(min(ANS))


Fixed submission:
N,K = map(int,input().split())
L = list(map(int,input().split()))
ANS = []
for i in range(len(L)-K+1) :
    p = L[i]
    q = L[i+K-1]
    if p*q == 0 :
        r = abs(p-q)
    elif p*q < 0 :
        r = 2*min(abs(p),q) + max(abs(p),q)
    else :
        if p > 0 :
            r = q
        else :
            r = abs(p)
    ANS.append(r)
ans = min(ANS)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
X = list(map(int,input().split()))
ANS = []
for i in range(N-K+1) :
    L = X[i:K+i]
    cplus = 0
    cminus = 0
    czero = 0
    for j in range(len(L)) :

        if L[j] > 0 :
            cplus += 1
        elif L[j] < 0 :
            cminus += 1
        else :
            czero += 1
    if (cplus == K-czero) or (cminus == K-czero):
        ANS.append(max(abs(min(L)),max(L)))
    else :
        ANS.append(min(abs(min(L))*2+abs(max(L)),abs(max(L))*2+abs(min(L))))
print(min(ANS))



Fixed submission:
N,K = map(int,input().split())
L = list(map(int,input().split()))
ANS = []
for i in range(len(L)-K+1) :
    p = L[i]
    q = L[i+K-1]
    if p*q == 0 :
        r = abs(p-q)
    elif p*q < 0 :
        r = 2*min(abs(p),q) + max(abs(p),q)
    else :
        if p > 0 :
            r = q
        else :
            r = abs(p)
    ANS.append(r)
ans = min(ANS)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
X = list(map(int,input().split()))
ANS = []
for i in range(N-K+1) :
    L = X[i:K+i]
    cplus = 0
    cminus = 0
    czero = 0
    for j in range(len(L)) :

        if L[j] > 0 :
            cplus += 1
        elif L[j] < 0 :
            cminus += 1
        else :
            czero += 1
        if (cplus == K-czero) or (cminus == K-czero):
            ANS.append(max(abs(min(L)),max(L)))
        else :
            ANS.append(min(abs(min(L))*2+abs(max(L)),abs(max(L))*2+abs(min(L))))
print(min(ANS))



Fixed submission:
N,K = map(int,input().split())
L = list(map(int,input().split()))
ANS = []
for i in range(len(L)-K+1) :
    p = L[i]
    q = L[i+K-1]
    if p*q == 0 :
        r = abs(p-q)
    elif p*q < 0 :
        r = 2*min(abs(p),q) + max(abs(p),q)
    else :
        if p > 0 :
            r = q
        else :
            r = abs(p)
    ANS.append(r)
ans = min(ANS)
print(ans)