Buggy python submission (verdict: Runtime Error):
import bisect
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )
 
zero_idx=bisect.bisect_left(X,0)
 
t=float("inf")
ans=float("inf")
for i in range(zero_idx):
	if zero_idx-i>K:
		continue
	elif zero_idx-i==K:
		t=X[i]
	else:
		nokori_cnt=K-(zero_idx-i)
		t=2*abs(X[i])+X[zero_idx+nokori_cnt-1]
	ans=min(ans,t)	

for i in range(zero_idx,N):
	if i==zero_idx+K-1:
		t=X[i]
	elif i<zero_idx+K-1:
		nokori_cnt=K-(i-zero_idx)-1
		t=2*X[i]+abs(X[zero_idx-nokori_cnt])
	ans=min(ans,t)

print ans
	


Fixed submission:
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )

ans=float("inf")
t=float("inf")
for l in range(N-K+1):
	r=l+K-1
	if X[l]<0:
		if X[r]<0:	
			ans=min(ans, abs(X[l]) )
		else:	
			ans=min(ans, 2*abs(X[l])+abs(X[r]) , abs(X[l])+2*abs(X[r]) )
	elif X[l]>=0 and X[r]>=0:
		ans=min(ans, X[r] )


print ans

Buggy python submission (verdict: Runtime Error):
import bisect
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )
 
zero_idx=bisect.bisect_left(X,0)
 
t=float("inf")
ans=float("inf")
for i in range(zero_idx):
	if zero_idx-i==K:
		t=X[i]
	else:
		nokori_cnt=K-(zero_idx-i)
		t=2*abs(X[i])+X[zero_idx+nokori_cnt-1]
	ans=min(ans,t)	

for i in range(zero_idx,N):
	if i==zero_idx+K-1:
		t=X[i]
	elif i<zero_idx+K-1:
		nokori_cnt=K-(i-zero_idx)-1
		t=2*X[i]+abs(X[zero_idx-nokori_cnt])
	ans=min(ans,t)

print ans
	


Fixed submission:
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )

ans=float("inf")
t=float("inf")
for l in range(N-K+1):
	r=l+K-1
	if X[l]<0:
		if X[r]<0:	
			ans=min(ans, abs(X[l]) )
		else:	
			ans=min(ans, 2*abs(X[l])+abs(X[r]) , abs(X[l])+2*abs(X[r]) )
	elif X[l]>=0 and X[r]>=0:
		ans=min(ans, X[r] )


print ans

Buggy python submission (verdict: Runtime Error):
import bisect
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )

zero_idx=bisect.bisect_left(X,0)


ans=float("inf")
for i in range( max(0,zero_idx-K+1) , min(N,zero_idx+K) ):
	if i < zero_idx:
		if zero_idx-i==K:
			t=X[i]
		else:
			t=2*abs(X[i])+X[K-(zero_idx-i)-1+zero_idx]
	elif i>=zero_idx:
		if i-zero_idx==K-1:
			t=X[i]
		else:
			t=2*X[i]+ abs( X[zero_idx- ( K-(i-zero_idx+1) )] )
	ans=min(ans,t)

print ans

Fixed submission:
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )

ans=float("inf")
t=float("inf")
for l in range(N-K+1):
	r=l+K-1
	if X[l]<0:
		if X[r]<0:	
			ans=min(ans, abs(X[l]) )
		else:	
			ans=min(ans, 2*abs(X[l])+abs(X[r]) , abs(X[l])+2*abs(X[r]) )
	elif X[l]>=0 and X[r]>=0:
		ans=min(ans, X[r] )


print ans

Buggy python submission (verdict: Runtime Error):
import bisect
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )

zero_idx=bisect.bisect_left(X,0)


ans=float("inf")
for i in range(zero_idx-K+1, min(N,zero_idx+K) ):
	if i < zero_idx:
		if zero_idx-i==K:
			t=X[i]
		else:
			t=2*abs(X[i])+X[K-(zero_idx-i)-1+zero_idx]
	elif i>=zero_idx:
		if i-zero_idx==K-1:
			t=X[i]
		else:
			t=2*X[i]+ abs( X[zero_idx- ( K-(i-zero_idx+1) )] )
	ans=min(ans,t)

print ans

Fixed submission:
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )

ans=float("inf")
t=float("inf")
for l in range(N-K+1):
	r=l+K-1
	if X[l]<0:
		if X[r]<0:	
			ans=min(ans, abs(X[l]) )
		else:	
			ans=min(ans, 2*abs(X[l])+abs(X[r]) , abs(X[l])+2*abs(X[r]) )
	elif X[l]>=0 and X[r]>=0:
		ans=min(ans, X[r] )


print ans