Problem: You are a manager of a prestigious soccer team in the JOI league.

The team has $N$ players numbered from 1 to $N$. The players are practicing hard in order to win the tournament game. The field is a rectangle whose height is $H$ meters and width is $W$ meters. The vertical line of the field is in the north-south direction, and the horizontal line of the field is in the east-west direction. A point in the field is denoted by ($i, j$) if it is $i$-meters to the south and $j$ meters to the east from the northwest corner of the field.

After the practice finishes, players must clear the ball. In the beginning of the clearance, the player $i$ ($1 \leq i \leq N$) stands at ($S_i, T_i$). There is only one ball in the field, and the player 1 has it. You stand at ($S_N, T_N$) with the player $N$. The clearance is finished if the ball is passed to ($S_N, T_N$), and you catch it. You cannot move during the clearance process.

You can ask players to act. But, if a player acts, his fatigue degree will be increased according to the action. Here is a list of possible actions of the players. If a player has the ball, he can act (i),(ii), or (iii). Otherwise, he can act (ii) or (iv).

* (i) Choose one of the 4 directions (east/west/south/north), and choose a positive integer $p$. Kick the ball to that direction. Then, the ball moves exactly p meters. The kicker does not move by this action, and he loses the ball. His fatigue degree is increased by $A \times p + B$.
* (ii) Choose one of the 4 directions (east/west/south/north), and move 1 meter to that direction. If he has the ball, he moves with it. His fatigue degree is increased by $C$ regardless of whether he has the ball or not.
* (iii) Place the ball where he stands. He loses the ball. His fatigue degree does not change.
* (iv) Take the ball. His fatigue degree does not change. A player can take this action only if he stands at the same place as the ball, and nobody has the ball.



Note that it is possible for a player or a ball to leave the field. More than one players can stand at the same place.

Since the players just finished the practice, their fatigue degrees must not be increased too much. You want to calculate the minimum possible value of the sum of fatigue degrees of the players for the clearance process.





Example

Input

6 5
1 3 6
3
1 1
0 4
6 5


Output

26

Solution (in CPP):

Solution:
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
typedef long long ll;
struct edge { int to; ll cost; };
struct state { int pos; ll cost; };
bool operator<(const state& s1, const state& s2) { return s1.cost > s2.cost; }
int dx[] = { 0, 1, 0, -1 };
int dy[] = { 1, 0, -1, 0 };
int H, W, A, B, C, N, x[100009], y[100009], xl[100009], xr[100009], yl[100009], yr[100009], ds[509][509]; vector<vector<edge> > g;
void add_edge(int v1, int v2, ll c) {
	g[v1].push_back(edge{ v2, c });
}
void add_edge2(int v1, int v2, ll c) {
	add_edge(v1, v2, c);
	add_edge(v2, v1, c);
}
ll shortest_path(int start, int goal) {
	vector<ll> dist(g.size(), 1LL << 60); dist[start] = 0;
	priority_queue<state> que; que.push(state{ start, 0 });
	while (!que.empty()) {
		int u = que.top().pos; que.pop();
		for (edge e : g[u]) {
			ll nd = dist[u] + e.cost;
			if (dist[e.to] > nd) {
				dist[e.to] = nd;
				que.push(state{ e.to, nd });
			}
		}
	}
	return dist[goal];
}
int main() {
	ios::sync_with_stdio(false);
	cin >> H >> W >> A >> B >> C >> N; H++; W++;
	g.resize(3 * H * W);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (j >= 1) {
				add_edge2(i * W + j, i * W + j - 1, C);
				add_edge2(H * W + i * W + j, H * W + i * W + j - 1, A);
			}
			if (i >= 1) {
				add_edge2(i * W + j, i * W + j - W, C);
				add_edge2(2 * H * W + i * W + j, 2 * H * W + i * W + j - W, A);
			}
			add_edge(i * W + j, H * W + i * W + j, B);
			add_edge(i * W + j, 2 * H * W + i * W + j, B);
			ds[i][j] = -1;
		}
	}
	fill(xl, xl + H, W + 1);
	fill(xr, xr + H, -1);
	fill(yl, yl + W, H + 1);
	fill(yr, yr + W, -1);
	queue<pair<int, int> > qs;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
		xl[x[i]] = min(xl[x[i]], y[i]);
		xr[x[i]] = max(xr[x[i]], y[i]);
		yl[y[i]] = min(yl[y[i]], x[i]);
		yr[y[i]] = max(yr[y[i]], x[i]);
		ds[x[i]][y[i]] = 0;
		add_edge(H * W + x[i] * W + y[i], x[i] * W + y[i], 0);
		add_edge(2 * H * W + x[i] * W + y[i], x[i] * W + y[i], 0);
		qs.push(make_pair(x[i], y[i]));
	}
	while (!qs.empty()) {
		pair<int, int> u = qs.front(); qs.pop();
		for (int i = 0; i < 4; i++) {
			int px = u.first + dx[i], py = u.second + dy[i];
			if (0 <= px && px < H && 0 <= py && py < W && ds[px][py] == -1) {
				ds[px][py] = ds[u.first][u.second] + 1;
				add_edge(H * W + px * W + py, px * W + py, 1LL * ds[px][py] * C);
				add_edge(2 * H * W + px * W + py, px * W + py, 1LL * ds[px][py] * C);
				qs.push(make_pair(px, py));
			}
		}
	}
	cout << shortest_path(x[0] * W + y[0], x[N - 1] * W + y[N - 1]) << '\n';
	return 0;
}