Problem:
Score : 600 points

Problem Statement

Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.

Some of the squares have a lotus leaf on it and cannot be entered.
The square (i,j) has a lotus leaf on it if c_{ij} is @, and it does not if c_{ij} is ..

In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west.
The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.

Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2).
If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.

Constraints

1 \leq H,W,K \leq 10^6

H \times W \leq 10^6

1 \leq x_1,x_2 \leq H

1 \leq y_1,y_2 \leq W

x_1 \neq x_2 or y_1 \neq y_2.

c_{i,j} is . or @.

c_{x_1,y_1} = .

c_{x_2,y_2} = .

All numbers in input are integers.

Input

Input is given from Standard Input in the following format:

H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}

Output

Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print -1 if the travel is impossible.

Sample Input 1

3 5 2
3 2 3 4
.....
.@..@
..@..

Sample Output 1

5

Initially, Snuke is at the square (3,2).
He can reach the square (3, 4) by making five strokes as follows:

From (3, 2), go west one square to (3, 1).

From (3, 1), go north two squares to (1, 1).

From (1, 1), go east two squares to (1, 3).

From (1, 3), go east one square to (1, 4).

From (1, 4), go south two squares to (3, 4).

Sample Input 2

1 6 4
1 1 1 6
......

Sample Output 2

2

Sample Input 3

3 3 1
2 1 2 3
.@.
.@.
.@.

Sample Output 3

-1

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#line 1 "/workspaces/compro/lib/template.hpp"


#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "tmp.cpp"

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int h, w;
  cin >> h >> w;
  ll K;
  cin >> K;
  int x1, y1, x2, y2;
  cin >> y1 >> x1 >> y2 >> x2;

  x1--;
  x2--;
  y1--;
  y2--;

  vector<string> grid(h);
  REP(i, h) { cin >> grid[i]; }

  constexpr ll M = numeric_limits<ll>::max();
  vector<ll> ans(h * w * 4, M);

  auto convert = [&](int x, int y, int k) -> int { return w * h * k + y * w + x; };

  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};

  priority_queue<pair<ll, tuple<int, int, int>>, vector<pair<ll, tuple<int, int, int>>>,
                 greater<pair<ll, tuple<int, int, int>>>>
      q;

  ans[convert(x1, y1, 0)] = 0;
  q.push({0, {x1, y1, 0}});

  while (!q.empty()) {
    auto p = q.top();
    q.pop();

    int x = get<0>(p.second);
    int y = get<1>(p.second);
    int k = get<2>(p.second);
    ll cost = ans.at(convert(x, y, k));

    if (cost < p.first) {
      continue;
    }

    // 目の前に進む場合
    int nx = x + dx[k];
    int ny = y + dy[k];
    if (0 <= nx && nx < w && 0 <= ny && ny < h && grid[ny][nx] == '.') {
      ll next_cost = p.first + 1LL;
      if (ans.at(convert(nx, ny, k)) <= next_cost)
        continue;
      ans[convert(nx, ny, k)] = next_cost;
      q.push({next_cost, {nx, ny, k}});
    }

    ll next_cost = K * ((p.first + K - 1) / K);
    if (ans[convert(x, y, (k + 1) % 4)] <= next_cost)
      continue;
    ans[convert(x, y, (k + 1) % 4)] = next_cost;
    q.push({next_cost, {x, y, (k + 1) % 4}});
  }

  ll ret = M;
  REP(i, 4) { chmin(ret, ans[convert(x2, y2, i)]); }
  cout << (ret == M ? -1 : (ret + K - 1) / K) << endl;

  return 0;
}