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<iostream>
#include<vector>
#include<cstring>
#include<queue>
using namespace std;

#define inRange(x,a,b) (a <= x && x < b)
int di[8] = {0,0,1,-1,1,1,-1,-1};
int dj[8] = {1,-1,0,0,1,-1,1,-1};

int dist[22][22];
int dp[22][1<<22];
int bfs[1000][1000];
int cnt = 0;

int dec(char c){
    if(c == 's')    return 0;
    if(c == 'e')    return cnt+1;
    return c-'A'+1;
}

int main(){
    memset(dist, 0x3f, sizeof(dist));
    memset(dp, 0x3f, sizeof(dp));
    int h, w, k;
    cin >> h >> w >> k;
    char mat[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
            if(mat[i][j] == 'a'){
                mat[i][j] = (char)('A' + cnt++);
            }
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(mat[i][j] == '#' || mat[i][j] == '.')    continue;
            int ind = dec(mat[i][j]);
            memset(bfs, 0x3f, sizeof(bfs));
            bfs[i][j] = 0;
            queue<int> q;
            q.push(i*w+j);
            while(!q.empty()){
                int x = q.front();  q.pop();
                int i = x/w, j = x%w;
                if(mat[i][j] != '.'){
                    dist[ind][dec(mat[i][j])] = bfs[i][j];
                }
                for(int k = 0; k < 4; k++){
                    int ni = i+di[k], nj = j+dj[k];
                    if(inRange(ni,0,h)&&inRange(nj,0,w)&&bfs[ni][nj]>bfs[i][j]+1&&mat[ni][nj]!='#'){
                        bfs[ni][nj] = bfs[i][j]+1;
                        q.push(ni*w+nj);
                    }
                }
            }
        }
    }
    dp[0][1] = 0;
    for(int s = 1; s < 1<<(cnt+1); s++){
        for(int i = 0; i < cnt+1; i++){
            if(((s>>i)&1) == 0) continue;
            if(dp[i][s] > 1e9)  continue;
            for(int j = 0; j < cnt+1; j++){
                if((s>>j)&1)   continue;
                if(dist[i][j] > 1e9)    continue;
                dp[j][s|(1<<j)] = min(dp[j][s|(1<<j)], dp[i][s]+dist[i][j]);
            }
        }
    }
    int ret = 2e9;
    for(int s = 1; s < 1<<(cnt+1); s++){
        int pop = -1;
        for(int j = 0; j < cnt+1; j++)  pop += (s>>j)&1;
        if(pop < k) continue;
        for(int j = 1; j <= cnt; j++){
            if(dist[j][cnt+1] < 1e9 && dp[j][s] < 1e9)  ret = min(ret, dp[j][s]+dist[j][cnt+1]);
        }
    }
    cout << (ret >= 2e9 ? -1 : ret) << endl;
    return 0;
}