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:
// #ifdef DEBUG
// #define _GLIBCXX_DEBUG
// #endif
#include <iostream>
#include <cassert>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

// these require C++11
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <thread>
#include <chrono>
#include <tuple>

using namespace std;

#define int long long

#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x) 
#endif
#define double long double
template<typename A,typename B>
ostream &operator<<(ostream&os,const pair<A,B>& p){
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

typedef complex<double> point;

// template<typename T,std::size_t N>
// struct _v_traits {using type = std::vector<typename _v_traits<T,N-1>::type>;};
// template<typename T>
// struct _v_traits<T,1> {using type = std::vector<T>;};
// template<typename T,std::size_t N=1>
// using vec = typename _v_traits<T,N>::type;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

const int INF = 1000000000000ll;

struct Info {
    int to_goal;
    int to_spring;
    bool is_start;
};

ostream &operator<<(ostream &os, const Info &i) {
    return os << "(" << i.to_goal << "," << i.to_spring << ")";
}

const char wall = '#';
const char spring = '*';
const char dot = '.';
const char start = 's';
const char goal = 'g';

const vector<int> dx = {-1,0,1,0};
const vector<int> dy = {0, 1,0,-1};
// ?????¢??°????\???§??????????????¨??????
template<typename F,typename T>
T ternary_search(F f,T left,T right,int try_cnt = 1000){
    for(int i=0;i<try_cnt;i++){
        T l = (2*left + right) / 3;
        T r = (left + 2*right) / 3;
        if(f(l) < f(r)){
            left = l;
        }else{
            right = r;
        }
    }
    return (left+right)/2;
}

// ?????¢??°????\??°???????????±???????
template<typename F,typename T>
T ternary_search_concave(F f,T left,T right,int try_cnt=1000){
    return ternary_search([f](T x){return -f(x);},left,right);
}

// [0 ~ k)
/*long double calc_e(const vector<Info>& v,
                   const vector<int>& as,
                   const vector<int>& bs,
                   const int k,
                   const int s=0){
    const int N = v.size();
    int l = as[k];
    int r = bs[N] - bs[k];
    if(s > 1000) return 1.0F * (l+r) / N;
    return (l + r + (1.0F * (N-k) * calc_e(v,as,bs,k,s+1)))/N;
    }*/

double target(const vector<Info>& dots, double e) {
    double t = 0.0;
    for (const auto & i : dots) {
        t += min((double)i.to_spring, i.to_goal - e);
    }
    return t;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int W,H; cin >> W >> H;
    vector<string> field(H);
    for(string& s : field){
        cin >> s;
    }

    vector<vector<Info> > info(H,vector<Info>(W,Info{INF,INF,false}));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(field[i][j] == start) info[i][j].is_start = true;
        }
    }

    for(int to_finding_spring=0;to_finding_spring<2;to_finding_spring++){
        // value,y,x
        queue<tuple<int,int,int> > queue;
        set<tuple<int,int> > already;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if((to_finding_spring and field[i][j] == spring) or
                   (!to_finding_spring and field[i][j] == goal)){
                    queue.emplace(0,i,j);
                }
            }
        }
        while(not queue.empty()){
            auto t = queue.front();
            queue.pop();
            int v = get<0>(t);
            int y = get<1>(t);
            int x = get<2>(t);
            if(already.find(make_tuple(y,x)) != already.end()){
                continue;
            }
            if(to_finding_spring && (field[y][x] == wall or field[y][x] == goal)){
                continue;
            }
            if(not to_finding_spring && (field[y][x] == wall or field[y][x] == spring)){
                continue;
            }

            already.insert(make_tuple(y,x));
            if(to_finding_spring){
                info[y][x].to_spring = v;
            }else{
                info[y][x].to_goal = v;
            }
            for(int i=0;i<4;i++){
                int nx = x + dx[i];
                int ny = y + dy[i];
                if(0 <= nx and nx < W and 0 <= ny and ny < H
                   and already.find(make_tuple(ny,nx)) == already.end()){
                    queue.emplace(v+1,ny,nx);
                }
            }
        }
    }
    /* {info[i][j] |-> ??´???????????§????????¢?????´?????????????????§????????¢} */
    
    
    vector<Info> dots;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(field[i][j] == dot || field[i][j] == start){
                if (info[i][j].to_goal > INF / 2 &&
                    info[i][j].to_spring > INF / 2) {continue;}
                dots.push_back(info[i][j]);
            }
        }
    }
    /* dots???????????§?£?????????´?????¨??????info?????\?????? */ 
    double minimum = 0, maximum = 1e15;
    //    assert (target(dots, minimum) > 0);
    //    dump(dots);
    //    dump(target(dots, maximum));
    //    assert (target(dots, maximum) < 0);

    for (int i = 0; i < 500; i++) {
        double half = (minimum + maximum) / 2.;
        double val = target(dots, half);
        //        dump(half);
        //        dump(val);
        if (val > 0) {
            minimum = half;
        } else {
            maximum = half;
        }
    }
    dump(minimum);
    auto si = find_if(dots.begin(),dots.end(),[](const Info& i){return i.is_start;});
    cout << fixed << setprecision(12);
    cout << min(si->to_spring + minimum, (double)si->to_goal) << endl;
    return 0;
    /*    
    sort(dots.begin(),dots.end(),[](const Info& left,const Info& right){
            int l = left.to_goal - left.to_spring;
            int r = right.to_goal - right.to_spring;
            return l < r;
        });


    int si = find_if(dots.begin(),dots.end(),[](const Info& i){return i.is_start;}) - dots.begin();

    int N = dots.size();
    vector<int> as(N+1);
    vector<int> bs(N+1);

    for(int i=1;i<N+1;i++){
        as[i] = as[i-1] + dots[i-1].to_goal;
        bs[i] = bs[i-1] + dots[i-1].to_spring;
    }
    // dump(bs[N]);
    // dump(as[N]);
    // dump((long double)(as[si+1] - as[si]));
    // dump((long double)(bs[si+1] - bs[si]));
    auto f = [&](long double c){
        int k = 0;
        for(k=0;k<N;k++){
            if(dots[k].to_goal - dots[k].to_spring > c + 1e-9){
                break;
            }
        }
        if(si < k){
            return (long double)(as[si+1]-as[si]);
        }else{
            return (bs[si+1] - bs[si]) + calc_e(dots,as,bs,k);
        }
    };
    int ls = as[1] - bs[1];
    int rs = as[N] - as[N-1] - (bs[N] - bs[N-1]);
    auto r = ternary_search_concave(f,ls,rs);
    // for(int i=0;i<N;i++){
    //     double d = as[i+1] - as[i] - (bs[i+1] - bs[i]);
    //     cerr << d << " -> " << f(d) << endl;
    // }

    cout << fixed << setprecision(12);
    cout << f(r) << endl;
    return 0;
    */
}