Buggy python submission (verdict: Runtime Error):
N, K = [int(item) for item in input().split()]
candles = []
for item in input().split():
  if int(item) == 0:
    K -= 1
    continue
  candles.append(int(item))
K = max(K-1, 0) 
l = []
for i, candle in enumerate(candles):
  sign = candle > 0
  s = 1 if sign else -1
  ik = i-K if sign else i+K
  if ik > N or ik < 0:
    continue
  if (candles[ik] > 0) == sign:
    l.append(candle * s)
  else:
    l.append(candle * s + candles[ik] * -2 * s)
if len(l) == 0:
  l.append(0)
l.sort()
print(l[0])

Fixed submission:
N, K = [int(item) for item in input().split()]
candles = [int(item) for item in input().split()]
ans = []
for i in range(N-K+1):
  l, r = i, i+K-1
  ans.append(abs(candles[l]) + abs(candles[l] - candles[r]))
  ans.append(abs(candles[r]) + abs(candles[r] - candles[l]))
ans.sort()
print(ans[0])

Buggy python submission (verdict: Runtime Error):
N, K = [int(item) for item in input().split()]
candles = []
for item in input().split():
  if int(item) == 0:
    K -= 1
    continue
  candles.append(int(item))
K = max(K-1, 0) 
print(K)
l = []
for i, candle in enumerate(candles):
  sign = candle > 0
  s = 1 if sign else -1
  ik = i-K if sign else i+K
  if ik > N or ik < 0:
    continue
  if (candles[ik] > 0) == sign:
    l.append(candle * s)
  else:
    l.append(candle * s + candles[ik] * -2 * s)
if len(l) == 0:
  l.append(0)
l.sort()
print(l[0])

Fixed submission:
N, K = [int(item) for item in input().split()]
candles = [int(item) for item in input().split()]
ans = []
for i in range(N-K+1):
  l, r = i, i+K-1
  ans.append(abs(candles[l]) + abs(candles[l] - candles[r]))
  ans.append(abs(candles[r]) + abs(candles[r] - candles[l]))
ans.sort()
print(ans[0])

Buggy python submission (verdict: Runtime Error):
N, K = [int(item) for item in input().split()]
candles = []
for item in input().split():
  if int(item) == 0:
    K -= 1
    continue
  candles.append(int(item))
K = max(K-1, 0) 
print(K)
l = []
for i, candle in enumerate(candles):
  sign = candle > 0
  s = 1 if sign else -1
  ik = i-K if sign else i+K
  if ik > N or ik < 0:
    continue
  if (candles[ik] > 0) == sign:
    l.append(candle * s)
  else:
    l.append(candle * s + candles[ik] * -2 * s)
if len(l) == 0:
  l.append(0)
l.sort()
print(l[0])

Fixed submission:
N, K = [int(item) for item in input().split()]
candles = [int(item) for item in input().split()]
ans = []
for i in range(N-K+1):
  l, r = i, i+K-1
  ans.append(abs(candles[l]) + abs(candles[l] - candles[r]))
  ans.append(abs(candles[r]) + abs(candles[r] - candles[l]))
ans.sort()
print(ans[0])

Buggy python submission (verdict: Runtime Error):
N, K = [int(item) for item in input().split()]
candles = []
for item in input().split():
  if int(item) == 0:
    K -= 1
    continue
  candles.append(int(item))
K-=1
l = []
for i in range(N):
  sign = candles[i] > 0
  s = 1 if sign else -1
  ik = i-K if sign else i+K
  if ik > N or ik < 0:
    continue
  if (candles[ik] > 0) == sign:
    l.append(candles[i] * s)
  else:
    l.append(candles[i] * s + candles[ik] * -2 * s)
l.sort()
print(l[0])

Fixed submission:
N, K = [int(item) for item in input().split()]
candles = [int(item) for item in input().split()]
ans = []
for i in range(N-K+1):
  l, r = i, i+K-1
  ans.append(abs(candles[l]) + abs(candles[l] - candles[r]))
  ans.append(abs(candles[r]) + abs(candles[r] - candles[l]))
ans.sort()
print(ans[0])