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 "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R


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

	cin >> H >> W >> L >> R;
	vector<string>s(H);
	for (auto &i : s)cin >> i;
	int sy, sx, gy, gx;
	vector<vector<int>>v(H + 2, vector<int>(W + 2, -1));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == 's') {
				sy = i, sx = j;
				s[i][j] = '.';
			}
			else if (s[i][j] == 'g') {
				s[i][j] = '.';
				gy = i;
				gx = j;
			}
			if (s[i][j] == '.')v[i + 1][j + 1] = 0;
			if (s[i][j] == '#')v[i + 1][j + 1] = 1;
			if (s[i][j] == '*')v[i + 1][j + 1] = -2;
		}
	}
	sx++, sy++, gx++, gy++;
	int diry[] = { 1,1,1,0,-1,-1,-1,0 };
	int dirx[] = { 1,0,-1,-1,-1,0,1,1 };
	vector<vector<long long int>>dp(H + 2, vector<long long int>(W + 2, MOD*MOD));
	dp[sy][sx] = 0;
	queue<pair<int, int>>Q;
	Q.push({ sy,sx });
	while (!Q.empty()) {
		int cy = Q.front().first;
		int cx = Q.front().second;
	//	cout << cy << " " << cx << endl;
		Q.pop();
		for (int i = 0; i < 8; i++) {
			int ny = cy + diry[i];
			int nx = cx + dirx[i];
			if (v[ny][nx] == -1)continue;
			if (abs(diry[i]) + abs(dirx[i]) == 2 && (v[ny][nx] == 0 || v[ny][nx] == -2))continue;
			//cout << ny << " " << nx << endl;
			if (v[ny][nx] == 1) {
				bool flag = true;
				if (v[cy][cx] == -2)flag = false;
				for (int j = 0; j < 8; j++) {
					int nny = cy + diry[j];
					int nnx = cx + dirx[j];
					if (v[nny][nnx] == -2)flag = false;
				}
				if (flag) {
					if (dp[ny][nx] > dp[cy][cx] + R + L * (abs(diry[i]) + abs(dirx[i]))) {
						dp[ny][nx] = dp[cy][cx] + R + L * (abs(diry[i]) + abs(dirx[i]));
						Q.push({ ny,nx });
						//cout << ny << " " << nx << " " << dp[ny][nx] << " ei1333" << endl;
					}
				}
			}
			else {
				if (dp[ny][nx] > dp[cy][cx] + L) {
					dp[ny][nx] = dp[cy][cx] + L;
					Q.push({ ny,nx });
				}
			}
		}
	}
	//cout << "hoge" << endl;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
	//		cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}
	if (dp[gy][gx] == MOD * MOD) {
		cout << "INF\n";
		return 0;
	}
	cout << dp[gy][gx] << endl;
}