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<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

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

int h, w;
char mp[1000][1000];

bool used[1000][1000];

P ts[22];
int sz;
int dist[20][22];
int memo[1000][1000];
void calc(int sx, int sy,int id) {
	rep(i, h)rep(j, w)used[i][j] = false;
	used[sx][sy] = true; memo[sx][sy] = 0;
	int tmp = 0;
	queue<P> q;
	q.push({ sx,sy });
	while (!q.empty()) {
		tmp++;
		int len = q.size();
		rep(aa, len) {
			P p = q.front(); q.pop();
			int x = p.first, y = p.second;
			rep(k, 4) {
				int nx = x + dx[k], ny = y + dy[k];
				if (nx < 0 || ny < 0 || nx == h || ny == w)continue;
				if (used[nx][ny] || mp[nx][ny] == '#')continue;
				memo[nx][ny] = tmp;
				used[nx][ny] = true;
				q.push({ nx,ny });
			}
		}
	}
	rep(i, sz) {
		int x = ts[i].first, y = ts[i].second;
		if (!used[x][y])dist[id][i] = mod;
		else {
			dist[id][i] = memo[x][y];
		}
	}
}

ll dp[1 << 20][20];
void solve() {
	cin >> h >> w;
	int k; cin >> k;
	int sx, sy, gx, gy;
	vector<P> a;
	rep(i, h)rep(j, w) {
		char t; cin >> t;
		mp[i][j] = t;
		if (t == 's') {
			sx = i, sy = j;
		}
		else if (t == 'e') {
			gx = i,gy = j;
		}
		else if (t == 'a') {
			a.push_back({ i,j });
		}
	}
	int n = a.size(); sz = n + 2;
	rep(i, n) {
		dist[i][i] = 0;
		ts[i] = { a[i].first,a[i].second };
	}
	ts[n] = { sx,sy };
	ts[n + 1] = { gx,gy };
	rep(i, n)calc(a[i].first, a[i].second,i);
	rep(i, a.size()) {
		Rep(j, i + 1, a.size()) {
			//dist[i][j] = calc(a[i].first, a[i].second, a[j].first, a[j].second);
			dist[j][i] = dist[i][j];
		}
	}
	rep(i, (1 << n))rep(j, n)dp[i][j] = mod;
	rep(i, n) {
		dp[1 << i][i] = dist[i][n];
		//dp[1 << i][i] = calc(sx, sy, a[i].first, a[i].second);
	}
	rep1(i, (1 << n)-1) {
		rep(j, n) {
			rep(k, n) {
				if (i&(1 << k))continue;
				int ni = i ^ (1 << k);
				dp[ni][k] = min(dp[ni][k], dp[i][j] + dist[j][k]);
			}
		}
	}
	ll ans = INF;
	vector<int> dg(n);
	rep(i, n) {
		dg[i] = dist[i][n + 1];
		//dg[i] = calc(gx, gy, a[i].first, a[i].second);
	}
	rep(i, (1 << n)) {
		int tmp = 0;
		rep(j, n)if (i&(1 << j))tmp++;
		if (tmp != k)continue;
		rep(j, n) {
			ans = min(ans, dp[i][j] + dg[j]);
		}
	}
	if (ans >= mod)ans = -1;
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(8);
	//init();
	solve();
	stop
		return 0;
}