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)

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v)-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)
int h,w,k;
bool ok(ll a,ll b){
if(a>=0&&a<h&&b>=0&&b<w)
	return 1;
return 0;
}


int main(){

    FAST
//	PRECISE


cin>>h>>w>>k;
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
x1--;y1--;x2--;y2--;

ve <ve <int> > used(h,ve <int> (w,-1) );
FOR(i,0,h){
	string s;
	cin>>s;
	FOR(j,0,w){
		if(s[j]=='@'){
			used[i][j]=M;
		}
	}
} 

set <tuple<int,int,int> > s;// val,x,y
s.insert({0,x1,y1});
used[x1][y1]=0;

while(!s.empty()){
	tuple <int,int,int> t=*s.begin();
	s.erase(s.begin());
	int val=GET(t,0);
	int x=GET(t,1);
	int y=GET(t,2);
	FOR(i,x+1,h){
		if(i-x<=k){
		if(ok(i,y)&&used[i][y]==-1){
			used[i][y]=val+1;
			s.insert({used[i][y],i,y});
		}
		else
			break;}
		else
			break;
	}
		FORR(i,x,0){
			if(x-i<=k){
		if(ok(i,y)&&used[i][y]==-1){
			used[i][y]=val;
				used[i][y]++;
			s.insert({used[i][y],i,y});
		}
		else
			break;}
		else
			break;
	}
		FOR(j,y+1,w){
			if(j-y<=k){
		if(ok(x,j)&&used[x][j]==-1){
			used[x][j]=val;
				used[x][j]++;
			s.insert({used[x][j],x,j});
		}
		else
			break;}
		else
			break;
	}
		FORR(j,y,0){
			if(y-j<=k){
		if(ok(x,j)&&used[x][j]==-1){
			used[x][j]=val;
				used[x][j]++;
			s.insert({used[x][j],x,j});
		}
		else
			break;}
		else
			break;
	}
}

if(used[x2][y2]==M)
	cout<<-1;
else
cout<<used[x2][y2];




return 0;
 }