output_description: Print an integer representing the minimum number of minutes needed to make N
  pieces of takoyaki.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N X T
attempt: from collections import deque
  
  H, W = map(int, input().split())
  Ch, Cw = map(int, input().split())
  Dh, Dw = map(int, input().split())
  Ch -= 1
  Cw -= 1
  Dh -= 1
  Dw -= 1
  
  S = []
  for i in range(H):
      s = list(input())
      S.append([-1 if i == "." else i for i in s])
  
  dq = deque()
  dq.append((Ch, Cw))
  S[Ch][Cw] = 0
  
  while dq:
      a = dq.pop()
      if a[0] - 1 >= 0 and (
          S[a[0] - 1][a[1]] == -1
          or (S[a[0] - 1][a[1]] != "#" and S[a[0] - 1][a[1]] > S[a[0]][a[1]])
      ):
          S[a[0] - 1][a[1]] = S[a[0]][a[1]]
          dq.appendleft((a[0] - 1, a[1]))
      if a[0] + 1 < H and (
          S[a[0] + 1][a[1]] == -1
          or (S[a[0] + 1][a[1]] != "#" and S[a[0] + 1][a[1]] > S[a[0]][a[1]])
      ):
          S[a[0] + 1][a[1]] = S[a[0]][a[1]]
          dq.appendleft((a[0] + 1, a[1]))
      if a[1] - 1 >= 0 and (
          S[a[0]][a[1] - 1] == -1
          or (S[a[0]][a[1] - 1] != "#" and S[a[0]][a[1] - 1] > S[a[0]][a[1]])
      ):
          S[a[0]][a[1] - 1] = S[a[0]][a[1]]
          dq.appendleft((a[0], a[1] - 1))
      if a[1] + 1 < W and (
          S[a[0]][a[1] + 1] == -1
          or (S[a[0]][a[1] + 1] != "#" and S[a[0]][a[1] + 1] > S[a[0]][a[1]])
      ):
          S[a[0]][a[1] + 1] = S[a[0]][a[1]]
          dq.appendleft((a[0], a[1] + 1))
      for i in range(5):
          for j in range(5):
              if (
                  a[0] - 2 + i >= 0
                  and a[0] - 2 + i < H
                  and a[1] - 2 + j >= 0
                  and a[1] - 2 + j < W
                  and (
                      S[a[0] - 2 + i][a[1] - 2 + j] == -1
                      or (
                          S[a[0] - 2 + i][a[1] - 2 + j] != "#"
                          and S[a[0] - 2 + i][a[1] - 2 + j] >= S[a[0]][a[1]] + 1
                      )
                  )
              ):
                  S[a[0] - 2 + i][a[1] - 2 + j] = S[a[0]][a[1]] + 1
                  dq.append((a[0] - 2 + i, a[1] - 2 + j))
  
  print(S[Dh][Dw])
  
problem_description: Statement
  
  Takahashi loves takoyaki - a ball-shaped snack.
  
  With a takoyaki machine, he can make at most X pieces of takoyaki at a time,
  taking T minutes regardless of the number of pieces to make.
  
  How long does it take to make N takoyaki?
samples: [{"input": "20 12 6", "output": "12\n    \n\nHe can make 12 pieces of takoyaki in the first 6 minutes and 8 more in the\nnext 6 minutes, so he can make 20 in a total of 12 minutes.\n\nNote that being able to make 12 in 6 minutes does not mean he can make 2 in 1\nminute.\n\n* * *"}, {"input": "1000 1 1000", "output": "1000000\n    \n\nIt seems to take a long time to make this kind of takoyaki."}]