Problem: Apple adventure

square1001 and E869120 got lost in the grid world of $ H $ rows and $ W $ rows!

Said the god of this world.

"When you collect $ K $ apples and they meet, you'll be back in the original world."

Upon hearing this word, square1001 decided to collect more than $ K $ of apples and head to the square where E869120 is.




Here, each cell in the grid is represented as follows.

's': square1001 This is the square where you are.

'e': E869120 This is the square where you are.

'a': A square with one apple on it. You can get an apple the first time you visit this trout. There are no more than 20 squares on this grid.

'#': It's a wall. You cannot visit this square.

'.': A square with nothing. You can visit this square.




square1001 You try to achieve your goal by repeatedly moving from the square you are in to the squares that are adjacent to each other up, down, left, and right. However, you cannot get out of the grid.

square1001 Find the minimum number of moves you need to achieve your goal.

However, it is assumed that E869120 will not move. Also, square1001 shall be capable of carrying $ K $ or more of apples.

If the goal cannot be achieved, output "-1".

input

Input is given from standard input in the following format.

Let $ A_ {i, j} $ be the characters in the $ i $ square from the top of the grid and the $ j $ square from the left.


$ H $ $ W $ $ K $
$ A_ {1,1} A_ {1,2} A_ {1,3} \ cdots A_ {1, W} $
$ A_ {2,1} A_ {2,2} A_ {2,3} \ cdots A_ {2, W} $
$ A_ {3,1} A_ {3,2} A_ {3,3} \ cdots A_ {3, W} $
$ \ ldots $
$ A_ {H, 1} A_ {H, 2} A_ {H, 3} \ cdots A_ {H, W} $


output

square1001 Find the minimum number of moves you need to reach your goal. However, if this is not possible, output "-1".

However, insert a line break at the end.

Constraint

* $ 1 \ leq H \ leq 1000 $
* $ 1 \ leq W \ leq 1000 $
* $ 1 \ leq K \ leq 20 $
* $ H, W, K $ are integers.
* $ A_ {i, j} $ is one of's','e','a','#','.'.
* The grid contains only one's' and one'e'.
* The number of'a'in the grid is greater than or equal to $ K $ and less than or equal to $ 20 $.



Input example 1


5 5 2
s .. # a
. # ...
a # e. #
... # a
. # ...


Output example 1


14


Input example 2


7 7 3
.......
.s ... a.
a ## ... a
.. ### ..
.a # e # .a
. ### ..
a .. # .. a


Output example 2


-1


If the purpose cannot be achieved, output "-1".

Input example 3


12 12 10
. ##### ......
.## ..... # ...
.... a.a # a .. #
. # .. # a ......
..... a # s ..
..a ###. ##. #
.e #. #. #. # A ..
.. # a # ..... #.
.. ## a ......
.a ... a.a .. #.
a .... # a.aa ..
... a. # ... # a.


Output example 3


30






Example

Input

5 5 2
s..#a
.#...
a#e.#
...#a
.#...


Output

14

Solution (in CPP):

Solution:
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

char board[1010][1010];
int H, W, K, dist[1010][1010], adj[25][25], dp[1 << 22][22];
vector< pair<int, int> > apples;
pair<int, int> S, G;

void calc_dist(int idx) {
    int sx, sy; tie(sx, sy) = apples[idx];
    fill(dist[0], dist[H], INF);
    dist[sx][sy] = 0;
    queue< tuple<int, int, int> > que;
    que.emplace(sx, sy, 0);
    while(que.size()) {
        int x, y, c; tie(x, y, c) = que.front(); que.pop();
        if(dist[x][y] < c) continue;
        for(int k=0; k<4; k++) {
            int nx = x + dx[k], ny = y + dy[k];
            if(nx < 0 or nx >= H or ny < 0 or ny >= W) continue;
            if(board[nx][ny] == '#') continue;
            if(dist[nx][ny] > c + 1) {
                dist[nx][ny] = c + 1;
                que.emplace(nx, ny, dist[nx][ny]);
            }
        }
    }

    for(size_t i=0; i<apples.size(); i++) {
        int tx, ty; tie(tx, ty) = apples[i];
        // fprintf(stderr, "i = %d, tx = %d, ty = %d, cost = %d\n", i, tx, ty, dist[tx][ty]);
        adj[idx][i] = adj[i][idx] = dist[tx][ty];
    }
}

int main() {
    scanf("%d%d%d", &H, &W, &K);
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            scanf(" %c", &board[i][j]);
            if(board[i][j] == 'a') apples.emplace_back(i, j);
            if(board[i][j] == 's') S = make_pair(i, j);
            if(board[i][j] == 'e') G = make_pair(i, j);
        }
    }

    apples.emplace_back(G);
    apples.emplace_back(S);
    for(size_t i=0; i<apples.size(); i++) {
        calc_dist(i);
    }

    int M = apples.size() - 1, src = M, dst = M - 1;

    /*
    for(int i=0; i<M; i++) {
        for(int j=0; j<M; j++) {
            fprintf(stderr, "%d ", adj[i][j]);
        }
        fprintf(stderr, "\n");
    }
    */
    
    fill(dp[0], dp[1 << M], INF);
    dp[0][src] = 0;
    for(int bit=0; bit<(1<<M); bit++) {
        for(int i=0; i<=M; i++) {
            for(int k=0; k<M; k++) {
                if(bit >> k & 1) continue;
                int nbit = bit | (1 << k);
                chmin(dp[nbit][k], dp[bit][i] + adj[i][k]);
            }
        }
    }

    int ans = INF;
    for(int bit=0; bit<(1<<M); bit++) {
        int c = __builtin_popcount(bit);
        if(bit >> src & 1) c--;
        if(bit >> dst & 1) c--;
        if(dp[bit][dst] == INF or c < K) continue;
        chmin(ans, dp[bit][dst]);
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}