Problem: One morning when you woke up, it was in a springy labyrinth.

I don't know why I'm in such a strange place. You have the option of waiting for help here, but you know from experience that if you stay in a labyrinth like this for a long time, a gust of wind will surely blow you away. It was. However, the time until the gust blows cannot be judged. So you thought it was best to act to minimize the expected number of moves required to escape the labyrinth.

When I picked up an unidentified scroll that had fallen under my feet and read it as a trial, I happened to be able to perceive the entire map of the labyrinth. Furthermore, by drinking the grass that I happened to have, I was able to know the positions of all the traps. Apparently, there are no traps other than dangerous monsters and springs in this labyrinth.

This labyrinth is shaped like a rectangle with several types of tiles, for example:



.. ## g. #
* #. * #. #
...... #
* s # *. * #



".":floor. You can walk around freely on this.

"#":wall. You can't get inside the wall.

"S": Your first position. Below this tile is the floor.

"G": Stairs. If you ride on this tile, you have escaped from the labyrinth.

"*":Spring. If you ride on this tile, it will be randomly blown onto one of the floors (excluding stairs and spring tiles). The odds of being hit on each floor are all equal.

The type of tile is one of these five.

You can move one square at a time from the tile you are currently riding to an adjacent tile in either the up, down, left, or right direction. However, you cannot move to Naname.

Given a map of the labyrinth, find the expected number of moves required to escape the labyrinth if you take the best strategy. It is not included in the number of movements that is blown by the spring.



Input

W H
c11 c12 ... c1w
c21 c22 ... c2w
:::
ch1 ch2 ... ccw


On the first line of input, the integer W (3 ≤ W ≤ 500) and the integer H (3 ≤ H ≤ 500) are written in this order, separated by blanks. The integer W represents the width of the labyrinth, and the integer H represents the height of the labyrinth.

The following H line contains W letters (not blank delimiters) that represent the map of the labyrinth. The format of this part is as in the example given above. Note that "s" and "g" appear exactly once in the data. In addition, one square around the labyrinth is always surrounded by a wall.

In addition, in the given labyrinth, no matter how you move and how it is blown by the spring, you will fall into a state where you cannot escape even if you can arbitrarily set the floor to be blown by the spring. You can assume that there is no such thing.

Output

Output the expected number of moves to escape when you take the best strategy. The output may contain errors, but the relative error to the true value must be less than 10-9.

Examples

Input

8 6
########
#..##g.#
#*#.*#.#
#......#
#*s#*.*#
########


Output

5.857142857143


Input

8 6

..##g.#
*#.*#.#
......#
*s#*.*#


Output

5.857142857143


Input

21 11

*#*.*.*.*.*.*.*.*#*#
*#...............#*#
*#.#.#.#.#.#.#.#.#*#
.#.#.#.#.#.#.#.#.##
...................#
.#.#.#.#.#.#.#.#.##
s#.#.#.#.#.#.#.#.#g#
...................#
...................#


Output

20.000000000000


Input

9 8

...#*.*#
.*.#...#
...#*.*#

.s....g#
.*#.*..#


Output

5.000000000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;

const int inf =1 << 18;

const int cmax=250010;
int w,h;
ll d[cmax];
ll e[cmax];

struct state{
	int d,e;
	bool operator<(const state &arg)const{
		return (d-e) >  (arg.d-arg.e);
	}
};

string table[510];

int n=0;
state ex[cmax];

void dijkstra(char s,char o,ll* dist){
	rep(i,cmax) dist[i]=inf;
	queue<pii> q;
	rep(i,h)rep(j,w){
		if(table[i][j]==s){
			int idx=w*i+j;
			dist[idx]=0;
			pii in=mp(idx,0);
			q.push(in);
		}
	}
	while(!q.empty()){
		pii cur=q.front();q.pop();
		if(dist[cur.first]<cur.second)
			continue;
		int dir[4]={-w,-1,1,w};
		rep(i,4){
			pii next=cur;
			next.first+=dir[i];
			next.second++;
			int cw=next.first%w;
			int ch=next.first/w;
			if(table[ch][cw]=='#'||table[ch][cw]==o)
				continue;
			if(dist[next.first]>next.second){
				dist[next.first]=next.second;
				q.push(next);
			}
		}
	}
	return;
}

int main(void){
	cin >> w >> h;
	rep(i,h) cin >> table[i];
	dijkstra('g','*',d);
	dijkstra('*','#',e);

	int sidx;
	ll dsum=0;
	ll esum=0;
	rep(i,h)rep(j,w) {
		int idx=i*w+j;
		if(table[i][j]=='.'||table[i][j]=='s'){
			if(d[idx]!=inf){
				ex[n].d=d[idx];
				ex[n++].e=e[idx];
			}else
				esum+=e[idx];
		}
		if(table[i][j]=='s')
			sidx=idx;
	}
	sort(ex,ex+n);
	rep(i,n) dsum+=ex[i].d;
	double ans=(1.0*(dsum+esum)/n+e[sidx]);
	for(int i=n;i>=1;--i){
		ans=min(ans,1.0*(dsum+esum)/i+e[sidx]);
		int cur=n-i;
		dsum-=ex[cur].d;
		dsum+=ex[cur].e;
	}
	if(d[sidx]!=inf)
		ans=min(ans,1.0*d[sidx]);
	cout.precision(16);
	cout << fixed << ans << endl;
	return 0;
}