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;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const int INF = 19191919;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};

int main(){
    int h,w,k;
    cin >>h >>w >>k;
    vector<string> f(h);
    rep(i,h) cin >>f[i];

    vector<pi> a;
    pi start,goal;
    rep(i,h)rep(j,w){
        if(f[i][j]=='a') a.pb({i,j});
        if(f[i][j]=='s') start = {i,j};
        if(f[i][j]=='e') goal = {i,j};
    }
    int A = a.size();

    auto IN = [&](int y, int x){
        return 0<=y && y<h && 0<=x && x<w;
    };

    auto BFS = [&](pi s){
        vector<vector<int>> d(h,vector<int>(w,INF));
        d[s.fi][s.se] = 0;
        queue<pi> que({s});
        while(!que.empty()){
            pi now = que.front();
            que.pop();
            rep(i,4){
                int ny = now.fi+dy[i], nx = now.se+dx[i];
                if(IN(ny,nx) && f[ny][nx]!='#' && d[ny][nx] > d[now.fi][now.se]+1){
                    d[ny][nx] = d[now.fi][now.se]+1;
                    que.push({ny,nx});
                }
            }
        }
        return d;
    };

    vector<vector<int>> ds = BFS(start), dg = BFS(goal);

    vector<vector<int>> da(A, vector<int>(A,INF));
    rep(i,A){
        vector<vector<int>> d = BFS(a[i]);
        rep(j,A) da[i][j] = d[a[j].fi][a[j].se];
    }

    vector<vector<int>> dp(1<<A,vector<int>(A,INF));
    rep(i,A) dp[1<<i][i] = ds[a[i].fi][a[i].se];

    rep(mask,1<<A)rep(i,A)if(mask>>i&1){
        rep(j,A)if(!(mask>>j&1)){
            int nx = mask|(1<<j);
            dp[nx][j] = min(dp[nx][j], dp[mask][i]+da[i][j]);
        }
    }

    int ans = INF;
    rep(mask,1<<A)rep(i,A)if((mask>>i&1) && __builtin_popcount(mask)>=k){
        int t = dp[mask][i];
        t += dg[a[i].fi][a[i].se];
        ans = min(ans, t);
    }

    if(ans == INF) ans = -1;
    cout << ans << "\n";
    return 0;
}