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)

// (c) 2020, redotter
// The grass was greener...

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#pragma comment(linker, "/stack:200000000")
#endif

#define pb push_back
#define the(a) (a).begin(), (a).end()
#define ft first
#define sd second
#define endl "\n"
#define forn(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define y1 y11

using i64 = int;
using i32 = int;
using f64 = double;

template <class T> using vec = vector<T>;
using str = string; using p64 = pair<i64, i64>;
using v64 = vec<i64>; using vv64 = vec<v64>;
using s64 = set<i64>; using m64 = map<i64, i64>;
template <size_t Size1> using a64 = array<i64, Size1>;
template <size_t Size1, size_t Size2> using aa64 = array<a64<Size2>, Size1>;
template <class T> using hash_set = unordered_set<T>;
template <class T, class U> using hash_map = unordered_map<T, U>;

mt19937 gen(998244353);
const i64 inf = numeric_limits<i64>::max() / 2;

template <class T> inline i64 len(const T& a) { return (i64)(a.size()); }
inline void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
template <class T, class S>
inline bool check_min(T& a, S b) { if (a > b) return a = b, 1; return 0; }
template <class T, class S>
inline bool check_max(T& a, S b) { if (a < b) return a = b, 1; return 0; }

void read() {}
template<class T, class ...U>
void read(T& a, U& ...b) { cin >> a; read(b...); }
void print() {}
template<class T, class ...U>
void print(const T& a, const U& ...b) { cout << a << " "; print(b...); }
void println() { cout << "\n"; }
template<class T, class ...U>
void println(const T& a, const U& ...b) { cout << a << " "; println(b...); }

struct Problem {
	void files(str in, str out) {
#ifdef ONLINE_JUDGE
		freopen(in.c_str(), "r", stdin), freopen(out.c_str(), "w", stdout);
#endif
	}
	void solve(), input();
	void many() { i64 t; cin >> t; while (t--) input(), solve(); }
	void make(bool mt = 0) { if (mt) many(); else input(), solve(); }
} problem;

signed main() {
	fast();
	problem.make();
#ifdef _DEBUG
	println(); println("[finished]"); system("pause > nul");
#endif
	return 0;
}

i64 n, m, k;
i64 x1, y1, x2, y2;
vv64 a;
vec<p64> dirs = { {-1, 0}, {+1, 0}, {0, -1}, {0, +1} };
str side = "UDLR";

i64 ok(i64 i, i64 j) {
	if (!(0 <= i && i < n && 0 <= j && j < m)) return 0;
	return a[i][j];
}

f64 dijkstra(p64 s, p64 t) {
	const i64 eps = 1e-9;
	map<p64, f64> d;
	map<p64, char> from;
	set<pair<f64, p64>> q;
	d[s] = 0;
	q.insert({ d[s], s });
	from[s] = 'x';
	while (!q.empty()) {
		f64 cur = q.begin()->ft;
		p64 v = q.begin()->sd;
		q.erase(q.begin());
		forn(k, 4) {
			p64 p = dirs[k];
			p64 u = { v.ft + p.ft, v.sd + p.sd };
			if (!ok(u.ft, u.sd)) continue;
			if (!d.count(u)) {
				d[u] = inf;
			}
			f64 cur = inf;
			if (side[k] == from[v] || from[v] == 'x') {
				cur = d[v] + 1.0 / ::k;
			} else {
				cur = floor(d[v]) + 1;
			}
			if (d[u] > cur) {
				auto it = q.lower_bound({ d[u], u });
				if (it != q.end()) q.erase(it);
				d[u] = cur;
				q.insert({ d[u], u });
				from[u] = side[k];
			}
		}
	}
	if (!d.count(t)) d[t] = -1;
	return d[t];
}

void Problem::solve() {
	f64 res = dijkstra({ x1, y1 }, { x2, y2 });
	i64 ans = ceil(res);
	println(ans);
}

void Problem::input() {
	read(n, m, k);
	read(x1, y1, x2, y2);
	--x1, --y1, --x2, --y2;
	a.resize(n, v64(m, 0));
	forn(i, n) {
		forn(j, m) {
			char c;
			read(c);
			a[i][j] = c != '@';
		}
	}
}