output_description: Print the minimum time required to light K candles.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
      x_1 x_2 ... x_N
attempt: #!/usr/bin/env python3
  import sys
  
  
  def append_zero(x):
      if 0 in x:
          return
      if x[0] > 0:
          x.insert(0, 0)
          return
      if x[len(x) - 1] < 0:
          x.appnd(0)
          return
      for i in range(1, len(x)):
          if x[i - 1] < 0 and x[i] > 0:
              x.insert(i, 0)
              return
  
  
  def solve(N, K, x):
      y = [0]
      append_zero(x)
      n = len(x)
      z = 0
      for i in range(1, n):
          y.append(y[i - 1] + x[i] - x[i - 1])
          if x[i] == 0:
              z = i
      # print(x)
      # print(y)
      if n == K:
          if n - 1 == z or z == 0:
              return y[n - 1]
          else:
              l = y[z] + y[n - 1]
              r = y[n - 1] - y[z] + y[n - 1]
              return min(l, r)
      ans = 10e20
      for i in range(n - K):
          k = i + K
          if k <= z:
              ans = min(ans, y[z] - y[i])
          if z <= i:
              ans = min(ans, y[k] - y[z])
          if i <= z and z < k:
              l = y[z] - y[i] + y[k] - y[i]
              r = y[k] - y[z] + y[k] - y[i]
              ans = min(ans, l, r)
      return ans
  
  
  def main():
      def iterate_tokens():
          for line in sys.stdin:
              for word in line.split():
                  yield word
  
      tokens = iterate_tokens()
      N = int(next(tokens))  # type: int
      K = int(next(tokens))  # type: int
      x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
      print(solve(N, K, x))
  
  
  if __name__ == "__main__":
      main()
  
problem_description: 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.
samples: [{"input": "5 3\n    -30 -10 10 20 50", "output": "40\n    \n\nHe should move and light candles as follows:\n\n  * Move from coordinate 0 to -10.\n  * Light the second candle from the left.\n  * Move from coordinate -10 to 10.\n  * Light the third candle from the left.\n  * Move from coordinate 10 to 20.\n  * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n    10 20 30", "output": "20\n    \n\n* * *"}, {"input": "1 1\n    0", "output": "0\n    \n\n  * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n    -9 -7 -4 -3 1 2 3 4", "output": "10"}]