Problem: Problem

Kotatsu turtle is a turtle with a kotatsu shell.


As soon as Kotatsu was pokita (getting up), he was trapped in a stage divided into grid-like sections. There is only one exit on this stage. The parcel is either a road, a fence or a bomb, and the kotatsu can move up, down, left and right to enter the parcel of the road or bomb. It cannot be moved diagonally. In addition, the fence section cannot be passed. The road section extends infinitely outside the stage, but it cannot be passed because there is a crocodile, the natural enemy of the turtle.

Kotatsu wants to go home (sleep) quickly, so I decided to head to the exit of this stage.

The kotatsu turtle, which can freely manipulate the infrared rays of the kotatsu, has the ability to turn eight sections around it into a road at the same time. However, if the 8 sections and one of the sections where you are located are bomb sections, the kotatsu will burn up when you explode, and you will not even be able to use the famous SNS "Kametta", so you will activate the ability. I can't do that.

<image>

An example is illustrated. The section where the illustration is not placed and the section where the kotatsu is placed are the sections of the road. The eight compartments around the kotatsu are the orange compartments. In the figure on the left, the 8 compartments around the kotatsu and the compartment where you are are not included in the bomb compartment, so you can activate the ability. However, in the figure on the right, the ability cannot be activated because the bomb compartment is included in either the surrounding 8 compartments or the compartment where you are.

The cost to move is $ A $ for each parcel move, and the cost to activate the ability is $ B $ each time. Please note that it is not the cost per wall turned into a road. The starting point and the exit of the stage are roads. Output the minimum sum of the cost of moving from the starting point to the exit of the stage and the cost of activating the ability. However, if you cannot reach the exit of the stage, output "INF" instead.

Constraints

The input satisfies the following conditions.

* $ 1 \ le H, W, A, B \ le 1000 $
* $ 3 \ le H + W $
* $ c_ {i, j} \ in $ {'s','g','.','#','*'}
*'s' and'g' appear once each

Input

The input is given in the following format.


$ H $ $ W $ $ A $ $ B $
$ c_ {1,1} \ cdots c_ {1, W} $
$ \ vdots $
$ c_ {H, 1} \ cdots c_ {H, W} $


The input consists of $ H + 1 $ lines.
On the $ 1 $ line, there are an integer $ H $ that represents the vertical length, an integer $ W $ that represents the left and right length, an integer $ A $ that represents the cost to move, and an integer $ B $ that represents the cost to activate the ability. Each is given with a blank delimiter.
The $ H $ line from the $ 2 $ line is given the state $ c_ {i, j} $ in each section of the stage where the kotatsu is confined.
$ c_ {i, j} $ consists of one of's','g','.','#','*', Each, and the partition $ (i, j) $ is in the following state. Represents that.
's': Indicates that the section is the starting point.
'g': Indicates that the parcel is the exit of the stage.
'.': Indicates that the section is a road.
'#': Indicates that the section is a fence.
'*': Indicates that the parcel is a bomb.

Output

Output the minimum sum of the cost of moving from the starting point to the exit of the stage and the cost of activating the ability. However, if you cannot reach the exit of the stage, output "INF" instead.

Examples

Input

4 4 1 1
g#..
#...
.*..
...s


Output

7


Input

4 4 1 1
g#..
...
.*..
...s


Output

7


Input

4 4 1 1
g#..
*..
....
...s


Output

INF


Input

2 4 1 1
g
s###


Output

6


Input

3 3 1 10
g..
.
s..


Output

6


Input

3 3 10 1
g..
.
s..


Output

21

Solution (in CPP):

Solution:
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>
#include <cmath>
#include <queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

class Pos{
public:
    int x, y;
    Pos(int i, int j){
        x = i;
        y = j;
    }
};

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[9]={0,1,0,-1, -1, -1, 1, 1, 0},dy[9]={1,0,-1,0, -1, 1, -1, 1, 0};

class Graph{
private:
    int n;
    vvp g;
public:
    int DIJ(int s,int t){
        priority_queue<P> q;
        vi d(n,inf);
        d[s]=0;
        q.push({0,s});
        while(!q.empty()){
            P p=q.top();
            q.pop();
            int v=p.second;
            if(d[v]<-p.first) continue;
            for(auto i:g[v]){
                int u=i.first,D=d[v]+i.second;
                if(d[u]>D){
                    d[u]=D;
                    q.push({-D,u});
                }
            }
        }
        return d[t];
    }
    Graph(int v){
        n=v;
        g=vvp(v);
    }
    void add_edge(int s,int t,int c){
        g[s].push_back({t,c});
    }
};

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    vector<string> c(h);
    vector<vector<bool>> visited(h);
    generate(visited.begin(), visited.end(), [w](){ return vector<bool>(w, false); });
    in_arr(string, c, h);
    int sx, sy, gx, gy;
    rep(i, h){
        rep(j, w){
            if(c[i][j] == 's'){
                sx = i;
                sy = j;
                c[i][j] = '.';
            }else if(c[i][j] == 'g'){
                gx = i;
                gy = j;
                c[i][j] = '.';
            }
        }
    }
    
    Graph g = Graph(h * w);
    rep(i, h){
        rep(j, w){
            bool can_ab = true;
            rep(k, 9){
                int x = i + dx[k];
                int y = j + dy[k];
                if(x < 0 || x >= h || y < 0 || y >= w){
                    continue;
                }
                if(c[x][y] == '*'){
                    can_ab = false;
                    break;
                }
            }
            
            rep(k, 4){
                int x = i + dx[k];
                int y = j + dy[k];
                if(x < 0 || x >= h || y < 0 || y >= w){
                    continue;
                }
                if(c[x][y] != '#'){
                    g.add_edge(i * w + j, x * w + y, a);
                }
            }
            if(!can_ab){
                continue;
            }
            rep(k, 8){
                int x = i + dx[k];
                int y = j + dy[k];
                if(x < 0 || x >= h || y < 0 || y >= w || c[x][y] != '#'){
                    continue;
                }
                if(abs(dx[k]) + abs(dy[k]) < 2){
                    g.add_edge(i * w + j, x * w + y, a + b);
                }else{
                    g.add_edge(i * w + j, x * w + y, 2 * a + b);
                }
            }
        }
    }
    int ans = g.DIJ(sx * w + sy, gx * w + gy);
    if(ans == inf){
        cout << "INF" << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}