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:
#include <bits/stdc++.h>
using namespace std;

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int pop_count(int bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

void chmin(int64_t& a, int64_t b){
    a = min(a, b);
}

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    string S[1000];
    vector<pair<int, int>> pos;
    pair<int, int> ps, pg;
    for(int i=0; i<H; i++){
        cin >> S[i];
        for(int j=0; j<W; j++){
            if(S[i][j] == 's') ps = {i, j};
            if(S[i][j] == 'e') pg = {i, j};
            if(S[i][j] == 'a') pos.emplace_back(i, j);
        }
    }
    int KK = pos.size();

    const int64_t INF = 1e15;
    int64_t dist[20][20], grid_dist[1000][1000], toS[20], toG[20];
    const int dx[] = {-1, 1, 0, 0};
    const int dy[] = {0, 0, -1, 1};
    auto inside = [&](int i, int j){ return 0<=i && i<H && 0<=j && j<W && S[i][j] != '#'; };

    for(int k=0; k<KK; k++){
        for(int i=0; i<H; i++) for(int j=0; j<W; j++) grid_dist[i][j] = INF;
        queue<pair<int, int>> que;
        grid_dist[pos[k].first][pos[k].second] = 0;
        que.push(pos[k]);
        while(que.size()){
            auto p = que.front(); que.pop();
            int i = p.first, j = p.second;
            for(int t=0; t<4; t++){
                int x = i + dx[t], y = j + dy[t];
                if(inside(x, y) && grid_dist[x][y] == INF){
                    grid_dist[x][y] = grid_dist[i][j] + 1;
                    que.emplace(x, y);
                }
            }
        }
        toS[k] = grid_dist[ps.first][ps.second];
        toG[k] = grid_dist[pg.first][pg.second];
        for(int l=0; l<KK; l++) dist[k][l] = grid_dist[pos[l].first][pos[l].second];
    }

    static int64_t dp[1<<20][20];
    for(int i=0; i<(1<<KK); i++) for(int k=0; k<KK; k++) dp[i][k] = INF;
    for(int k=0; k<KK; k++) dp[1<<k][k] = toS[k];
    for(int i=0; i<(1<<KK); i++) for(int k=0; k<KK; k++) for(int t=0; t<KK; t++) if(!nth_bit(i, t)){
        chmin(dp[i+(1<<t)][t], dp[i][k] + dist[k][t]);
    }

    int64_t ans = INF;
    for(int i=0; i<(1<<KK); i++) if(pop_count(i) >= K) for(int k=0; k<KK; k++) chmin(ans, dp[i][k] + toG[k]);
    if(ans >= INF) ans = -1;
    cout << ans << endl;
    return 0;
}