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 <stdio.h>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#define inf 1e9

using namespace std;
typedef pair<int, int> P;

int h, w, k;
char c[1005][1005];
int px[25], py[25];
int d[1005][1005];
int dist[25][25];
int dp[1<<20][20];
int pop[1<<20];
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

void bfs(int sx, int sy)
{
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			d[x][y] = inf;
		}
	}
	d[sx][sy] = 0;
	
	queue<P> Q;
	Q.push(P(sx, sy));
	
	while(Q.size()){
		int x = Q.front().first, y = Q.front().second;
		Q.pop();
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i], ny = y + dy[i];
			if(nx < 1 || nx > w || ny < 1 || ny > h) continue;
			if(d[nx][ny] < inf) continue;
			if(c[nx][ny] == '#') continue;
			d[nx][ny] = d[x][y] + 1;
			Q.push(P(nx, ny));
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w >> k;
	int m = 0;
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			cin >> c[x][y];
			if(c[x][y] == 'a') px[m] = x, py[m] = y, m++;
		}
	}
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			if(c[x][y] == 's') px[m] = x, py[m] = y;
			if(c[x][y] == 'e') px[m+1] = x, py[m+1] = y;
		}
	}
	
	for(int i = 0; i <= m+1; i++){
		bfs(px[i], py[i]);
		for(int j = 0; j <= m+1; j++) dist[i][j] = d[px[j]][py[j]];
	}
	
	int M = 1<<m;
	for(int i = 0; i < M; i++){
		for(int j = 0; j < m; j++){
			dp[i][j] = inf;
		}
	}
	for(int i = 0; i < m; i++) dp[1<<i][i] = dist[m][i];
	for(int i = 0; i < M; i++){
		for(int j = 0; j < m; j++){
			for(int k = 0; k < m; k++){
				if(i & (1<<k)) continue;
				dp[i|(1<<k)][k] = min(dp[i|(1<<k)][k], dp[i][j] + dist[j][k]);
			}
		}
	}
	
	for(int i = 1; i < M; i++) pop[i] = pop[i&(i-1)] + 1;
	int ans = inf;
	for(int i = 0; i < M; i++){
		if(pop[i] < k) continue;
		for(int j = 0; j < m; j++){
			ans = min(ans, dp[i][j] + dist[j][m+1]);
		}
	}
	if(ans > inf/2) cout << -1 << endl;
	else cout << ans << endl;
	
	return 0;
}