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<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 505

enum Type{
	STOP,
	FLY_North,
	FLY_East,
	FLY_South,
	FLY_West,
};

struct LOC{
	int row,col;
};

struct Info{
	Info(int arg_row,int arg_col,ll arg_sum_cost){
		loc.row = arg_row;
		loc.col = arg_col;
		sum_cost = arg_sum_cost;
	}
	LOC loc;
	ll sum_cost;
};

struct Edge{
	Edge(int arg_row,int arg_col,Type arg_type,ll arg_cost){
		loc.row = arg_row;
		loc.col = arg_col;
		type = arg_type;
		cost = arg_cost;
	}
	LOC loc;
	Type type;
	ll cost;
};

struct State{
	State(int arg_row,int arg_col,Type arg_type,ll arg_sum_cost){
		loc.row = arg_row;
		loc.col = arg_col;
		type = arg_type;
		sum_cost = arg_sum_cost;
	}
	bool operator<(const struct State &arg) const{
		return sum_cost > arg.sum_cost;
	}
	LOC loc;
	Type type;
	ll sum_cost;
};

int H,W;
int N;
int diff_row[4] = {-1,0,1,0},diff_col[4] = {0,1,0,-1};
ll A,B,C;
ll nearest_cost[NUM][NUM];
ll min_cost[NUM][NUM][5];
bool table[NUM][NUM];
LOC start,goal;
Type type_array[5] = {STOP,FLY_North,FLY_East,FLY_South,FLY_West};
vector<Edge> edge[NUM][NUM][5];

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1){
		return true;
	}else{
		return false;
	}
}

int main(){

	scanf("%d %d",&H,&W);
	H += 1;
	W += 1;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			table[row][col] = false;
		}
	}

	scanf("%lld %lld %lld",&A,&B,&C);

	scanf("%d",&N);

	int tmp_row,tmp_col;

	scanf("%d %d",&start.row,&start.col);
	table[start.row][start.col] = true;

	for(int loop = 1; loop < N-1; loop++){
		scanf("%d %d",&tmp_row,&tmp_col);
		table[tmp_row][tmp_col] = true;
	}

	scanf("%d %d",&goal.row,&goal.col);
	table[goal.row][goal.col] = true;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			nearest_cost[row][col] = HUGE_NUM;
		}
	}

	queue<Info> CALC;
	int adj_row,adj_col;
	ll next_cost;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			if(!table[row][col])continue;

			nearest_cost[row][col] = 0;
			CALC.push(Info(row,col,0));

			while(!CALC.empty()){

				for(int i = 0; i < 4; i++){

					adj_row = CALC.front().loc.row+diff_row[i];
					adj_col = CALC.front().loc.col+diff_col[i];

					if(!rangeCheck(adj_row,adj_col))continue;

					next_cost = CALC.front().sum_cost+C;

					if(nearest_cost[adj_row][adj_col] > next_cost){

						nearest_cost[adj_row][adj_col] = next_cost;
						CALC.push(Info(adj_row,adj_col,next_cost));
					}
				}
				CALC.pop();
			}
		}
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){

			for(int i = 0; i < 4; i++){

				adj_row = row+diff_row[i];
				adj_col = col+diff_col[i];

				if(!rangeCheck(adj_row,adj_col))continue;

				edge[row][col][STOP].push_back(Edge(adj_row,adj_col,type_array[STOP],C));

				edge[row][col][STOP].push_back(Edge(row,col,type_array[i+1],B));
			}

			edge[row][col][FLY_North].push_back(Edge(row,col,type_array[STOP],nearest_cost[row][col]));
			if(row > 0){
				edge[row][col][FLY_North].push_back(Edge(row-1,col,type_array[FLY_North],A));
			}

			edge[row][col][FLY_East].push_back(Edge(row,col,type_array[STOP],nearest_cost[row][col]));
			if(col+1 < W){
				edge[row][col][FLY_East].push_back(Edge(row,col+1,type_array[FLY_East],A));
			}

			edge[row][col][FLY_South].push_back(Edge(row,col,type_array[STOP],nearest_cost[row][col]));
			if(row+1 < H){
				edge[row][col][FLY_South].push_back(Edge(row+1,col,type_array[FLY_South],A));
			}

			edge[row][col][FLY_West].push_back(Edge(row,col,type_array[STOP],nearest_cost[row][col]));
			if(col-1 >= 0){
				edge[row][col][FLY_West].push_back(Edge(row,col-1,type_array[FLY_West],A));
			}
		}
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			for(int a = 0; a < 5; a++){
				min_cost[row][col][a] = HUGE_NUM;
			}
		}
	}

	priority_queue<State> Q;
	min_cost[start.row][start.col][STOP] = 0;
	Q.push(State(start.row,start.col,STOP,0));
	LOC next_loc;
	Type next_type;

	while(!Q.empty()){

		if(Q.top().loc.row == goal.row && Q.top().loc.col == goal.col && Q.top().type == STOP){

			break;

		}else{

			for(int i = 0; i < edge[Q.top().loc.row][Q.top().loc.col][Q.top().type].size(); i++){

				next_loc = edge[Q.top().loc.row][Q.top().loc.col][Q.top().type][i].loc;
				next_cost = Q.top().sum_cost+edge[Q.top().loc.row][Q.top().loc.col][Q.top().type][i].cost;
				next_type = edge[Q.top().loc.row][Q.top().loc.col][Q.top().type][i].type;

				if(min_cost[next_loc.row][next_loc.col][next_type] > next_cost){

					min_cost[next_loc.row][next_loc.col][next_type] = next_cost;
					Q.push(State(next_loc.row,next_loc.col,next_type,next_cost));
				}
			}
			Q.pop();
		}
	}

	printf("%lld\n",min_cost[goal.row][goal.col][STOP]);

	return 0;
}