Problem: Takahashi is locked within a building.

This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the room is not locked and can be freely entered. Takahashi is currently at the room where A_{i,j}= `S`, which can also be freely entered.

Each room in the 1-st row, 1-st column, H-th row or W-th column, has an exit. Each of the other rooms (i,j) is connected to four rooms: (i-1,j), (i+1,j), (i,j-1) and (i,j+1).

Takahashi will use his magic to get out of the building. In one cast, he can do the following:

* Move to an adjacent room at most K times, possibly zero. Here, locked rooms cannot be entered.
* Then, select and unlock at most K locked rooms, possibly zero. Those rooms will remain unlocked from then on.



His objective is to reach a room with an exit. Find the minimum necessary number of casts to do so.

It is guaranteed that Takahashi is initially at a room without an exit.

Constraints

* 3 ≤ H ≤ 800
* 3 ≤ W ≤ 800
* 1 ≤ K ≤ H×W
* Each A_{i,j} is `#` , `.` or `S`.
* There uniquely exists (i,j) such that A_{i,j}= `S`, and it satisfies 2 ≤ i ≤ H-1 and 2 ≤ j ≤ W-1.

Input

Input is given from Standard Input in the following format:


H W K
A_{1,1}A_{1,2}...A_{1,W}
:
A_{H,1}A_{H,2}...A_{H,W}


Output

Print the minimum necessary number of casts.

Examples

Input

3 3 3
#.#
#S.
###


Output

1


Input

3 3 3
.#
S.


Output

1


Input

3 3 3

S#


Output

2


Input

7 7 2


...##
S###
.#.##
.###


Output

2

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

public class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static int iinf = 0xfffffff;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        int h = in.nextInt();
        int w = in.nextInt();
        Point.h = h;
        Point.w = w;
        int k = in.nextInt();
        boolean[][] a = new boolean[h][w];
        int sx = -1, sy = -1;
        for (int i = 0; i < h; i++) {
            String s = in.next();
            for (int j = 0; j < w; j++) {
                if (s.charAt(j) == 'S') {
                    sx = j;
                    sy = i;
                }
                a[i][j] = s.charAt(j) != '#';
            }
        }
        int[][] dist = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                dist[i][j] = iinf;
            }
        }
        dist[sy][sx] = 0;
        Deque<Point> deque = new ArrayDeque<>();
        deque.addFirst(new Point(sx, sy));
        while (!deque.isEmpty()) {
            Point p = deque.pollLast();
            if (dist[p.y][p.x] == k) {
                continue;
            }
            for (Point q : p.aroundPoints(4)) {
                if (a[q.y][q.x] && dist[q.y][q.x] > dist[p.y][p.x] + 1) {
                    dist[q.y][q.x] = dist[p.y][p.x] + 1;
                    deque.addFirst(q);
                }
            }
        }
        long ans = inf;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (dist[i][j] < iinf) {
                    ans = Math.min(ans, 1 + (Math.min(Math.min(i, j), Math.min(h - 1 - i, w - 1 - j)) + k - 1) / k);
                }
            }
        }
        out.println(ans);
    }


    static class Point implements Comparable<Point> {
        static int h, w;
        static int[] da = {-1, 0, 1, 0, -1, 1, 1, -1, -1};
        int x, y, z;

        Point(int z) {
            this.x = z % w;
            this.y = z / w;
            this.z = z;
        }

        Point(int x, int y) {
            this.x = x;
            this.y = y;
            this.z = y * w + x;
        }

        Point move(int d) {
            x += da[d];
            y += da[d + 1];
            return this;
        }

        boolean isInner() {
            return 0 <= x && x < w && 0 <= y && y < h;
        }

        List<Point> aroundPoints(int type) {
            List<Point> list = new ArrayList<>();
            for (int i = 0; i < type; i++) {
                int nx = x + da[i];
                int ny = y + da[i + 1];
                Point point = new Point(nx, ny);
                if (point.isInner()) {
                    list.add(point);
                }
            }
            return list;
        }

        @Override
        public int compareTo(Point o) {
            return x == o.x ? Integer.compare(y, o.y) : Integer.compare(x, o.x);
        }

        @Override
        public String toString() {
            return String.format("(%d, %d)", x, y);
        }
    }

    public static void main(String[]$) {
        new Main().solve();
        out.flush();
    }
}

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private PrintWriter out = new PrintWriter(System.out);
    boolean autoFlush = false;

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void println(int[] a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int i : a) {
            joiner.add(Integer.toString(i));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void println(long[] a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (long i : a) {
            joiner.add(Long.toString(i));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void flush() {
        out.flush();
    }
}