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<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=5e7;//減ってる
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-4;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>int LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>int UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cout<<fixed<<setprecision(20);
	int bi,i,j,H,W,K,ans=mod;cin>>H>>W>>K;
	vector<string>mat(H+2);
	mat[0]=string(W+2,'#');
	mat[H+1]=string(W+2,'#');
	int y[22]={},x[22]={};
	int ak=0;
	for(i=1;i<=H;i++){
		cin>>mat[i];
		mat[i].pub('#');
		mat[i].insert(mat[i].begin(),'#');
		for(j=1;j<=W;j++){
			if(mat[i][j]=='a'){y[ak]=i;x[ak]=j;ak++;}
			if(mat[i][j]=='s'){y[20]=i;x[20]=j;}
			if(mat[i][j]=='e'){y[21]=i;x[21]=j;}
		}
	}
	int kyo[22][22]={};
	for(i=0;i<22;i++){
		
		if(ak<=i&&i<20){continue;}
		//ここからの距離を測る
		vector<vector<int>>dist(H+2,vector<int>(W+2,mod));
		dist[y[i]][x[i]]=0;
		queue<tuple<int,int,int>>que;
		que.push(mt(0,y[i],x[i]));
		while(que.size()){
			int z,ny,nx;tie(z,ny,nx)=que.front();
			que.pop();
			
			if(mat[ny][nx-1]!='#'&&dist[ny][nx-1]==mod){
				dist[ny][nx-1]=z+1;
				que.push(mt(z+1,ny,nx-1));
			}
			if(mat[ny][nx+1]!='#'&&dist[ny][nx+1]==mod){
				dist[ny][nx+1]=z+1;
				que.push(mt(z+1,ny,nx+1));
			}
			if(mat[ny-1][nx]!='#'&&dist[ny-1][nx]==mod){
				dist[ny-1][nx]=z+1;
				que.push(mt(z+1,ny-1,nx));
			}
			if(mat[ny+1][nx]!='#'&&dist[ny+1][nx]==mod){
				dist[ny+1][nx]=z+1;
				que.push(mt(z+1,ny+1,nx));
			}
		}
		for(j=0;j<22;j++){
			if(ak<=j&&j<20){continue;}
			kyo[i][j]=dist[y[j]][x[j]];
		}
	}
	//cerr<<"de"<<endl;
	static int dp[1<<20][20];
	for(bi=0;bi<(1<<ak);bi++){
		for(i=0;i<ak;i++){dp[bi][i]=mod;}
	}
	for(i=0;i<ak;i++){dp[1<<i][i]=kyo[20][i];}
	for(bi=0;bi<(1<<ak);bi++){
		int siz=0;
		for(i=0;i<ak;i++){if(bi&(1<<i)){siz++;}}
		if(siz<K){
			for(i=0;i<ak;i++){
				if(dp[bi][i]>=mod){continue;}
				for(j=0;j<ak;j++){
					if(bi&(1<<j)){continue;}
					mineq(dp[bi+(1<<j)][j],dp[bi][i]+kyo[i][j]);
				}
				
			}
		}else{
			for(i=0;i<ak;i++){mineq(ans,dp[bi][i]+kyo[i][21]);}
		}
	}
	if(ans>=mod){ans=-1;}
	cout<<ans<<endl;
	return 0;
}