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 <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>
#include <tuple>
using namespace std;
long long H, W, A, B, C, N, x[100009], y[100009], dist[509][509][4], dp[509][509], dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
priority_queue<tuple<long long, int, int>, vector<tuple<long long, int, int>>, greater<tuple<long long, int, int>>>q;
priority_queue<tuple<long long, int, int, int>, vector<tuple<long long, int, int, int>>, greater<tuple<long long, int, int, int>>>Q;
int main() {
	cin >> H >> W >> A >> B >> C >> N;
	for (int i = 0; i <= H; i++) { for (int j = 0; j <= W; j++)dp[i][j] = (1LL << 62); }
	for (int i = 1; i <= N; i++) { cin >> x[i] >> y[i]; if (i < N) dp[x[i]][y[i]] = 0; q.push(make_tuple(0, x[i], y[i])); }
	while (!q.empty()) {
		long long a1 = get<0>(q.top()), a2 = get<1>(q.top()), a3 = get<2>(q.top()); q.pop();
		for (int i = 0; i < 4; i++) {
			int cx = a2 + dx[i], cy = a3 + dy[i];
			if (cx < 0 || cx > H || cy < 0 || cy > W)continue;
			if (dp[cx][cy] > a1 + C) {
				dp[cx][cy] = a1 + C; q.push(make_tuple(dp[cx][cy], cx, cy));
			}
		}
	}
	for (int i = 0; i <= H; i++) { for (int j = 0; j <= W; j++) { for (int k = 0; k < 4; k++)dist[i][j][k] = (1LL << 62); } }
	dist[x[1]][y[1]][1] = 0; Q.push(make_tuple(0LL, x[1], y[1], 1));
	while (!Q.empty()) {
		long long a1 = get<0>(Q.top()), a2 = get<1>(Q.top()), a3 = get<2>(Q.top()), a4 = get<3>(Q.top()); Q.pop();
		if (a4 == 0) {
			if (dist[a2][a3][1] > a1 + dp[a2][a3]) { dist[a2][a3][1] = a1 + dp[a2][a3]; Q.push(make_tuple(dist[a2][a3][1], a2, a3, 1)); }
		}
		if (a4 == 1) {
			if (dist[a2][a3][2] > a1 + B) { dist[a2][a3][2] = a1 + B; Q.push(make_tuple(dist[a2][a3][2], a2, a3, 2)); }
			if (dist[a2][a3][3] > a1 + B) { dist[a2][a3][3] = a1 + B; Q.push(make_tuple(dist[a2][a3][3], a2, a3, 3)); }
			if (a2 - 1 >= 0 && dist[a2 - 1][a3][1] > a1 + C) { dist[a2 - 1][a3][1] = a1 + C; Q.push(make_tuple(dist[a2 - 1][a3][1], a2 - 1, a3, 1)); }
			if (a2 + 1 <= H && dist[a2 + 1][a3][1] > a1 + C) { dist[a2 + 1][a3][1] = a1 + C; Q.push(make_tuple(dist[a2 + 1][a3][1], a2 + 1, a3, 1)); }
			if (a3 - 1 >= 0 && dist[a2][a3 - 1][1] > a1 + C) { dist[a2][a3 - 1][1] = a1 + C; Q.push(make_tuple(dist[a2][a3 - 1][1], a2, a3 - 1, 1)); }
			if (a3 + 1 <= W && dist[a2][a3 + 1][1] > a1 + C) { dist[a2][a3 + 1][1] = a1 + C; Q.push(make_tuple(dist[a2][a3 + 1][1], a2, a3 + 1, 1)); }
			if (dist[a2][a3][0] > a1) { dist[a2][a3][0] = a1; Q.push(make_tuple(dist[a2][a3][0], a2, a3, 0)); }
		}
		if (a4 == 2) {
			if (a2 - 1 >= 0 && dist[a2 - 1][a3][2] > a1 + A) { dist[a2 - 1][a3][2] = a1 + A; Q.push(make_tuple(dist[a2 - 1][a3][2], a2 - 1, a3, 2)); }
			if (a2 + 1 <= H && dist[a2 + 1][a3][2] > a1 + A) { dist[a2 + 1][a3][2] = a1 + A; Q.push(make_tuple(dist[a2 + 1][a3][2], a2 + 1, a3, 2)); }
			if (dist[a2][a3][0] > a1) { dist[a2][a3][0] = a1; Q.push(make_tuple(dist[a2][a3][0], a2, a3, 0)); }
		}
		if (a4 == 3) {
			if (a3 - 1 >= 0 && dist[a2][a3 - 1][3] > a1 + A) { dist[a2][a3 - 1][3] = a1 + A; Q.push(make_tuple(dist[a2][a3 - 1][3], a2, a3 - 1, 3)); }
			if (a3 + 1 <= W && dist[a2][a3 + 1][3] > a1 + A) { dist[a2][a3 + 1][3] = a1 + A; Q.push(make_tuple(dist[a2][a3 + 1][3], a2, a3 + 1, 3)); }
			if (dist[a2][a3][0] > a1) { dist[a2][a3][0] = a1; Q.push(make_tuple(dist[a2][a3][0], a2, a3, 0)); }
		}
	}
	cout << dist[x[N]][y[N]][0] << endl;
	return 0;
}