Landlord

Find the minimum travel time to visit a fixed sequence of districts, starting at 0, when cars parked in some districts can be used once each for faster driving.

Hard8Shortest pathDynamic programmingGraphNo attempts yetTime limit2sMemory limit512 MB

Problem

Kangho is the landlord of a city split into NN districts. The districts are numbered 0 through N1N-1, and they are connected by two way roads.

Kangho owns CC cars, and each car is parked in one district. Several cars may be parked in the same district.

Today is rent collection day. Kangho walks his buildings himself and collects the rent. There are MM buildings to collect from, and the visiting order is fixed in advance as A0,A1,,AM1A_0, A_1, \dots, A_{M-1}. He collects rent in district A0A_0 first, then in district A1A_1, and finally in district AM1A_{M-1}. Kangho starts in district 0.

There are two ways to move: walking and driving. Crossing a road of length LL on foot takes W×LW \times L time, and crossing it by car takes D×LD \times L time.

When Kangho reaches a district where one of his cars is parked, he can get into that car and drive wherever he wants. Once he gets out of a car, he never gets into that car again. He must also be out of the car when he collects rent.

Given the road information, write a program that computes the minimum time needed to collect all the rent.

Input

The first line contains the number of districts NN, the number of parked cars CC, the number of buildings MM, the walking time WW per unit of road length, and the driving time DD per unit of road length. (1N,C,M501 \le N, C, M \le 50, 1D<W1001 \le D < W \le 100)

The second line contains the CC districts where the cars are parked, separated by spaces.

The third line contains the collection order A0,A1,,AM1A_0, A_1, \dots, A_{M-1}, separated by spaces. (A00A_0 \neq 0)

Each of the next NN lines contains the road information of the city as an adjacency matrix. The jj-th number on the ii-th line describes the road between district ii and district jj. A 0 means there is no road, and a positive integer is the length of that road. Road lengths are positive integers no greater than 62.

Roads are two way, so the jj-th number on the ii-th line always equals the ii-th number on the jj-th line, and the ii-th number on the ii-th line is always 0. Every district can be reached from every other district.

Output

Print the minimum time needed to collect all the rent on the first line.

Hint

In the first example, Kangho walks from district 0 to district 2 and collects rent. He then walks from district 2 to district 3 and collects rent again. Next he walks to district 1, takes the car to district 0, and collects rent there. The total time is 5×1+5×3+5×2+1×2+1×3+1×1=365 \times 1 + 5 \times 3 + 5 \times 2 + 1 \times 2 + 1 \times 3 + 1 \times 1 = 36.

In the second example, Kangho walks from district 0 to district 1. He takes the car there and drives to district 2, gets out, and collects rent. Then he walks from district 2 through district 1 to district 0 and collects rent. The total time is 2×37+1×38+2×38+2×37=2622 \times 37 + 1 \times 38 + 2 \times 38 + 2 \times 37 = 262.