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;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

// debug
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, -1, 0, 1};
vector<int> ex = {-1, -1, 1, 1};
vector<int> ey = {-1, 1, -1, 1};

signed main() {
  int h, w, a, b; cin >> h >> w >> a >> b;
  vector<string> t(h); REP (i, h) cin >> t[i];
  ii s, g;
  REP (i, h) {
    REP (j, w) {
      if (t[i][j] == 's') s = {i, j};
      if (t[i][j] == 'g') g = {i, j};
    }
  }
  auto valid = [&](ii p) {
    return 0 <= p.fi && p.fi < h && 0 <= p.se && p.se < w;
  };
  auto around_bomb = [&](ii p) {
    bool ret = false;
    ret |= t[p.fi][p.se] == '*';
    REP (i, 4) {
      ii to = {p.fi + dy[i], p.se + dx[i]};
      if (valid(to)) ret |= t[to.fi][to.se] == '*';
    }
    REP (i, 4) {
      ii to = {p.fi + ey[i], p.se + ex[i]};
      if (valid(to)) ret |= t[to.fi][to.se] == '*';
    }
    return ret;
  };

  vector<vector<int>> d(h, vector<int>(w, 1e17));
  d[s.fi][s.se] = 0;
  priority_queue<pair<int, ii>, vector<pair<int, ii>>, greater<pair<int, ii>>> q;
  q.push({0, {s}});
  while (!q.empty()) {
    pair<int, ii> pii = q.top(); q.pop();
    ii p = pii.se;
    if (d[p.fi][p.se] < pii.fi) continue;
    bool bomb = around_bomb(p);
    REP (i, 4) {
      ii to = {p.fi + dy[i], p.se + dx[i]};
      if (!valid(to)) continue;
      int tmp = d[p.fi][p.se] + a;
      if (t[to.fi][to.se] == '#') {
        if (bomb) continue;
        tmp += b;
      }
      if (chmin(d[to.fi][to.se], tmp)) {
        q.push({tmp, to});
      }
    }
    REP (i, 4) {
      ii to = {p.fi + ey[i], p.se + ex[i]};
      if (!valid(to)) continue;
      int tmp = d[p.fi][p.se] + 2 * a;
      if (t[to.fi][to.se] == '#' || (t[p.fi + ey[i]][p.se] == '#' && t[p.fi][p.se + ex[i]])) {
        if (bomb) continue;
        tmp += b;
      }
      if (chmin(d[to.fi][to.se], tmp)) {
        q.push({tmp, to});
      }
    }
  }
  dump(d);
  if (d[g.fi][g.se] == 1e17) {
    cout << "INF" << endl;
  } else {
    cout << d[g.fi][g.se] << endl;
  }
}