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 Java (OpenJDK 11.0.6) (judge verdict: Wrong Answer)

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.io.IOException;
import java.util.Random;
import java.io.InputStreamReader;
import java.io.BufferedOutputStream;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.util.StringTokenizer;
import java.util.concurrent.ThreadLocalRandom;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Queue;
import java.io.BufferedReader;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        LightWriter out = new LightWriter(outputStream);
        FPondSkater solver = new FPondSkater();
        solver.solve(1, in, out);
        out.close();
    }

    static class FPondSkater {
        private static final int REP = 5;
        private static final int INF = 1_000_000_000;

        public void solve(int testNumber, LightScanner in, LightWriter out) {
            int h = in.ints(), w = in.ints(), k = in.ints();
            int sy = in.ints() - 1, sx = in.ints() - 1, gy = in.ints() - 1, gx = in.ints() - 1;
            char[][] s = in.chars(h);
            int[][][] visited = new int[2][h][w];
            int[][] cost = new int[h][w];
            ArrayUtil.fill(cost, INF);
            cost[sy][sx] = 0;
            Queue<FPondSkater.P> q = new ArrayDeque<>();
            q.offer(new FPondSkater.P(sx, sy));
            while (!q.isEmpty()) {
                FPondSkater.P now = q.poll();
                int[] rand = {0, 1, 2, 3};
                ArrayUtil.shuffle(rand);
                for (int r : rand) {
                    switch (r) {
                        case 0:
                            if (visited[0][now.y][now.x] < REP) {
                                for (int d = 1; d <= k; d++) {
                                    if (now.x - d < 0
                                            || s[now.y][now.x - d] == '@'
                                            || visited[0][now.y][now.x - d] >= REP) break;
                                    if (d != k) visited[0][now.y][now.x - d]++;
                                    if (cost[now.y][now.x - d] > cost[now.y][now.x] + 1) {
                                        cost[now.y][now.x - d] = cost[now.y][now.x] + 1;
                                    }
                                    q.offer(new FPondSkater.P(now.x - d, now.y));
                                }
                            }
                            break;
                        case 1:
                            if (visited[0][now.y][now.x] < REP) {
                                for (int d = 1; d <= k; d++) {
                                    if (w <= now.x + d
                                            || s[now.y][now.x + d] == '@'
                                            || visited[0][now.y][now.x + d] >= REP) break;
                                    if (d != k) visited[0][now.y][now.x + d]++;
                                    if (cost[now.y][now.x + d] > cost[now.y][now.x] + 1) {
                                        cost[now.y][now.x + d] = cost[now.y][now.x] + 1;
                                    }
                                    q.offer(new FPondSkater.P(now.x + d, now.y));
                                }
                            }
                            break;
                        case 2:
                            if (visited[1][now.y][now.x] < REP) {
                                for (int d = 1; d <= k; d++) {
                                    if (now.y - d < 0
                                            || s[now.y - d][now.x] == '@'
                                            || visited[1][now.y - d][now.x] >= REP) break;
                                    if (d != k) visited[1][now.y - d][now.x]++;
                                    if (cost[now.y - d][now.x] > cost[now.y][now.x] + 1) {
                                        cost[now.y - d][now.x] = cost[now.y][now.x] + 1;
                                    }
                                    q.offer(new FPondSkater.P(now.x, now.y - d));
                                }
                            }
                            break;
                        case 3:
                            if (visited[1][now.y][now.x] < REP) {
                                for (int d = 1; d <= k; d++) {
                                    if (h <= now.y + d
                                            || s[now.y + d][now.x] == '@'
                                            || visited[1][now.y + d][now.x] >= REP) break;
                                    if (d != k) visited[1][now.y + d][now.x]++;
                                    if (cost[now.y + d][now.x] > cost[now.y][now.x] + 1) {
                                        cost[now.y + d][now.x] = cost[now.y][now.x] + 1;
                                    }
                                    q.offer(new FPondSkater.P(now.x, now.y + d));
                                }
                            }
                            break;
                    }
                }
                visited[0][now.y][now.x]++;
                visited[1][now.y][now.x]++;
            }
            out.ans(cost[gy][gx] == INF ? -1 : cost[gy][gx]).ln();
        }

        private static class P {
            int x;
            int y;

            P(int x, int y) {
                this.x = x;
                this.y = y;
            }

        }

    }

    static class LightScanner implements AutoCloseable {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public char[] chars() {
            return string().toCharArray();
        }

        public char[][] chars(int h) {
            char[][] res = new char[h][];
            for (int i = 0; i < h; i++) res[i] = chars();
            return res;
        }

        public int ints() {
            return Integer.parseInt(string());
        }

        public void close() {
            try {
                this.reader.close();
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
        }

    }

    static final class ArrayUtil {
        private ArrayUtil() {
        }

        public static void fill(int[] a, int v) {
            Arrays.fill(a, v);
        }

        public static void fill(int[][] a, int v) {
            for (int i = 0; i < a.length; i++) {
                fill(a[i], v);
            }
        }

        public static void shuffle(int[] array) {
            Random rnd = ThreadLocalRandom.current();
            for (int i = array.length - 1; i > 0; i--) {
                int index = rnd.nextInt(i + 1);
                int tmp = array[index];
                array[index] = array[i];
                array[i] = tmp;
            }
        }

    }

    static class LightWriter implements AutoCloseable {
        private final Writer out;
        private boolean autoflush = false;
        private boolean breaked = true;

        public LightWriter(Writer out) {
            this.out = out;
        }

        public LightWriter(OutputStream out) {
            this(new OutputStreamWriter(new BufferedOutputStream(out), Charset.defaultCharset()));
        }

        public LightWriter print(char c) {
            try {
                out.write(c);
                breaked = false;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return this;
        }

        public LightWriter print(String s) {
            try {
                out.write(s, 0, s.length());
                breaked = false;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return this;
        }

        public LightWriter ans(String s) {
            if (!breaked) {
                print(' ');
            }
            return print(s);
        }

        public LightWriter ans(int i) {
            return ans(Integer.toString(i));
        }

        public LightWriter ln() {
            print(System.lineSeparator());
            breaked = true;
            if (autoflush) {
                try {
                    out.flush();
                } catch (IOException ex) {
                    throw new UncheckedIOException(ex);
                }
            }
            return this;
        }

        public void close() {
            try {
                out.close();
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
        }

    }
}