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;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll H, W, K;
string field[1005];
vector<i_i> Apples;
int sh, sw, gh, gw;
ll dist[22][22];
ll DIST[1005][1005];
ll sdist[22], gdist[22];
ll dp[1 << 20][20];
int dh[4] = {1, -1, 0, 0};
int dw[4] = {0, 0, 1, -1};
void search(int index) {
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            DIST[h][w] = 1e9;
        }
    }
    i_i start = Apples[index];
    DIST[start.first][start.second] = 0;
    queue<i_i> que;
    que.push(start);
    while(!que.empty()) {
        i_i now = que.front();
        int nowh = now.first;
        int noww = now.second;
        que.pop();
        for(int i = 0; i < 4; i++) {
            int newh = nowh + dh[i];
            int neww = noww + dw[i];
            if(newh < 0 or newh >= H) continue;
            if(neww < 0 or neww >= W) continue;
            if(field[newh][neww] == '#') continue;
            if(chmin(DIST[newh][neww], DIST[nowh][noww] + 1)) {
                que.push({newh, neww});
            }
        }
    }
    for(int i = 0; i < Apples.size(); i++) {
        ll d = DIST[Apples[i].first][Apples[i].second];
        dist[index][i] = d;
        //cerr << d << " ";
    }
    sdist[index] = DIST[sh][sw];
    gdist[index] = DIST[gh][gw];
    //cerr << endl;
}

ll counter(ll x) {
    if(x == 0) return 0;
    return (x & 1) + (counter(x/ 2));
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W >> K;
    for(int h = 0; h < H; h++) {
        cin >> field[h];
        for(int w = 0; w < W; w++) {
            if(field[h][w] == 's') {
                sh = h;
                sw = w;
            }
            if(field[h][w] == 'e') {
                gh = h;
                gw = w;
            }
            if(field[h][w] == 'a') {
                Apples.emplace_back(h, w);
            }
        }
    }
    ll ans = 1e18;
    for(int i = 0; i <= 20; i++) {
        for(int j = 0; j < (1 << 20); j++) {
            dp[j][i] = 1e18;
        }
    }
    for(int i = 0; i < Apples.size(); i++) {
        search(i);
        dp[1 << i][i] = sdist[i];
    }
    for(int bits = 1; bits < (1 << Apples.size()); bits++) {
        for(int i = 0; i < Apples.size(); i++) {
            if(!(bits & (1 << i))) continue;
            //cerr << bits << " " << i << " " << dp[bits][i] << endl;
            if(counter(bits) >= K) {
                chmin(ans, dp[bits][i] + gdist[i]);
            }
            for(int j = 0; j < Apples.size(); j++) {
                if(bits & (1 << j)) continue;
                chmin(dp[bits | (1 << j)][j], dp[bits][i] + dist[i][j]);
            }
        }
    }
    if(ans >= 1e9) ans = -1;
    cout << ans << endl;
    return 0;
}