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# (.NET Core 3.1.201) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Net;
static class Program{
	const int mod=(int)1e9+7;
	static readonly int[][] di1=new int[][]{new int[]{-1,0},new int[]{1,0},new int[]{0,-1},new int[]{0,1}};
	static readonly int[][] di2=new int[][]{new int[]{-1,-1},new int[]{-1,0},new int[]{-1,1},new int[]{0,-1},new int[]{0,1},new int[]{1,-1},new int[]{1,0},new int[]{1,1}};
	static char[][] bm;
	static int[][] b;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int h=s[0],w=s[1];
		char c='@';
		var g=sc.Ia;
		bm=new char[h+2][];
		b=new int[h+2][];
		var bo=new bool[h+2][];
		var oa=new int[h+2][][];
		for(int i = 1;i<=h;i++) {
			bm[i]=(c+sc.S+c).ToCharArray();
			b[i]=new int[w+2];
			bo[i]=new bool[w+2];
			oa[i]=new int[w+2][];
			for(int j = 1;j<=w;j++) {
				oa[i][j]=new int[4];
			}
		}
		bm[0]=bm[h+1]=new string(c,w+2).ToCharArray();
		b[0]=b[h+1]=new int[w+2];
		var qu=new Qu2<Tuple<int,int>>();
		qu.Enqueue0(1,Tuple.Create(g[0],g[1]));
		while(qu.cnt>0){
			var e=qu.Dequeue;
			if(e.d.Item1==g[2]&&e.d.Item2==g[3]){
				Console.WriteLine(e.n-1);
				return;
			}
			if(bo[e.d.Item1][e.d.Item2]){continue;}
			bo[e.d.Item1][e.d.Item2]=true;
			Fdi(e.d.Item1,e.d.Item2,(y,x,o)=>{
				if(bm[y][x]=='@'){return;}
				if(oa[e.d.Item1][e.d.Item2][o]==0){
					if(b[y][x]==0||b[y][x]==e.n+1){
						if(b[y][x]==0){
							qu.Enqueue1(e.n+1,Tuple.Create(y,x));
							b[y][x]=e.n+1;
						}
						oa[y][x][o]=Max(oa[y][x][o],s[2]-1);
					}
				}
				else{
					if(b[y][x]==0||b[y][x]==e.n){
						qu.Enqueue0(e.n,Tuple.Create(y,x));
						b[y][x]=e.n;
						oa[y][x][o]=Max(oa[y][x][o],oa[e.d.Item1][e.d.Item2][o]-1);
					}
					else if(b[y][x]==e.n+1){
						qu.Enqueue0(e.n,Tuple.Create(y,x));
						b[y][x]=e.n;
						oa[y][x]=new int[4];
						oa[y][x][o]=Max(oa[y][x][o],oa[e.d.Item1][e.d.Item2][o]-1);
					}
				}
			});
		}
		Console.WriteLine("{0}",-1);
	}
	static void Fdi(int y,int x,Action<int,int,int> f){for(int i=0;i<4;i++){f(y+di1[i][0],x+di1[i][1],i);}}
}
public class Qu2<T>{
	public class Dt{
		public int n;
		public T d;
		public Dt(int n,T d){this.n=n;this.d=d;}
		public override string ToString()=>"n:"+n.ToString()+" d:"+d.ToString();
	}
	private Queue<Dt> qu0=new Queue<Dt>(),qu1=new Queue<Dt>();
	public void Enqueue(bool b,int n,T d){
		if(b){qu0.Enqueue(new Dt(n,d));}
		else{qu1.Enqueue(new Dt(n+1,d));}
	}
	public void Enqueue0(int n,T d){qu0.Enqueue(new Dt(n,d));}
	public void Enqueue1(int n,T d){qu1.Enqueue(new Dt(n,d));}
	public Dt Dequeue{get{return qu0.Count>0?qu0.Dequeue():qu1.Dequeue();}}
	public Dt Peek{get{return qu0.Count>0?qu0.Peek():qu1.Peek();}}
	public int cnt{get{return qu0.Count+qu1.Count;}}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}