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 int 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 << 29;

vs field;
int w, h;

//((cost, (y, x)) 
typedef pair<int, pii> State;

#define F first
#define S second

vi dx = { 1, 0,-1, 0};
vi dy = { 0,-1, 0, 1};

void bfs(char tar, vvi & minDist){
    minDist = vvi(h, vi(w, inf));

    priority_queue<State, vector<State>, greater<State>> q;
    rep(y, h){
        rep(x, w){
            if(field[y][x] != tar) continue;
            q.push(mp(0, mp(y, x)));
        }
    }

    while(!q.empty()){
        int cur_cost = q.top().F;
        pii cur_pos = q.top().S;
        q.pop();

        if(minDist[cur_pos.F][cur_pos.S] != inf) continue;

        if(field[cur_pos.F][cur_pos.S] == '.'){
            minDist[cur_pos.F][cur_pos.S] = cur_cost;
        }

        int next_cost = cur_cost + 1;
        rep(i, 4){
            pii next_pos = mp(cur_pos.F + dy[i], cur_pos.S + dx[i]);

            if(field[next_pos.F][next_pos.S] == '#' ||
               field[next_pos.F][next_pos.S] == 'g' ||
               field[next_pos.F][next_pos.S] == '*' ||
               minDist[next_pos.F][next_pos.S] != inf)
                continue;
            
            q.push(mp(next_cost, next_pos));
        }
    }
}

signed main(void){
    for(; cin >> w >> h;){
        field = vs(h);
        pii s;
        int num_f = 0;
        rep(y, h){
            cin >> field[y];
            
            rep(x, w){
                if(field[y][x] == 's'){
                    s = mp(y, x);
                    field[y][x] = '.';
                }
                if(field[y][x] == '.'){
                    num_f++;
                }
            }
        }

        vvi minDist_s, minDist_g;
        bfs('*', minDist_s);
        bfs('g', minDist_g);

//        rep(y, h){
//            rep(x, w){
//                printf("%4d", (minDist_s[y][x] == inf ? -1:minDist_s[y][x]));
//            }
//            cout << endl;
//        }
//        cout << endl;
//        rep(y, h){
//            rep(x, w){
//                printf("%4d", (minDist_g[y][x] == inf ? -1:minDist_g[y][x]));
//            }
//            cout << endl;
//        }
//        cout << "----------" <<endl;
        
        vector<pair<int, pii>> deltaSG;
        int sum_dist = 0, num_tos = 0;
        rep(y, h){
            rep(x, w){
                if(field[y][x] != '.') continue;

                if(minDist_g[y][x] != inf){
                    sum_dist += minDist_g[y][x];

                    if(minDist_s[y][x] != inf){
                        deltaSG.pb(mp(minDist_g[y][x] - minDist_s[y][x], mp(y, x)));
                    }
                }
                else{
                    sum_dist += minDist_s[y][x];
                    num_tos++;
                }
            }
        }
        sort(all(deltaSG), greater<pair<int, pii>>());
        
#define F first
#define S second

        long double e = 1.0 / (num_f - num_tos) * sum_dist;
        for(auto state : deltaSG){
            pii pos = state.S;

            num_tos++;
            sum_dist = sum_dist - minDist_g[pos.F][pos.S] + minDist_s[pos.F][pos.S];

            if(num_f == num_tos) break;
            long double cur = 1.0 / (num_f - num_tos) * sum_dist;

            if(cur < e) e = cur;
            else break;
        }
        long double res = minDist_s[s.F][s.S] + e;
        if(minDist_g[s.F][s.S] != inf) res = min(res, (long double)minDist_g[s.F][s.S]);
        printf("%.12Lf\n", res);
    }

    return 0;
}