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<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const int MAX = 1010;
int dp[MAX][MAX];
int bm[MAX][MAX];

signed main(){
  int h,w,p,q;
  cin>>h>>w>>p>>q;
  vector<string> st(h);
  for(int i=0;i<h;i++) cin>>st[i];

  memset(bm,0,sizeof(dp));

  auto in=[&](int y,int x){return 0<=y&&y<h&&0<=x&&x<w;};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(st[i][j]!='*') continue;
      for(int a=-1;a<=1;a++)
        for(int b=-1;b<=1;b++)
          if(in(i+a,j+b)) bm[i+a][j+b]=1;
    }
  }
    
  memset(dp,-1,sizeof(dp));
  struct T{
    int y,x,d;
    T(){}
    T(int y,int x,int d):y(y),x(x),d(d){}
    bool operator<(const T &a)const{return d>a.d;};
  };

  priority_queue<T> pq;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(st[i][j]=='s') pq.emplace(i,j,dp[i][j]=0);

  int dy[]={1,-1,0,0};
  int dx[]={0,0,1,-1};
  auto cmp=[&](int a,int b){return a<0||b<a;};
  while(!pq.empty()){
    T s=pq.top();pq.pop();
    int y=s.y,x=s.x,d=s.d;
    //cout<<y<<" "<<x<<":"<<d<<endl;
    if(dp[y][x]<d) continue;
    if(st[y][x]=='g'){
      cout<<d<<endl;
      return 0;
    }
    
    auto check=
      [&](int ny,int nx,int nd)->void{
        if(!in(ny,nx)||!cmp(dp[ny][nx],nd)) return;
        dp[ny][nx]=nd;
        pq.emplace(ny,nx,dp[ny][nx]);
      };
    
    for(int k=0;k<4;k++){
      int ny=y+dy[k],nx=x+dx[k];
      if(in(ny,nx)&&st[ny][nx]!='#') check(ny,nx,d+p);
    }
    
    if(bm[y][x]) continue;
    
    for(int a=-1;a<=1;a++)
      for(int b=-1;b<=1;b++)
        check(y+a,x+b,d+(abs(a)+abs(b))*p+q);
  }
  cout<<"INF"<<endl;
  return 0;
}