#D7713. Draw in Straight Lines

    ID: 6406 Type: Default 3000ms 268MiB

Draw in Straight Lines

Draw in Straight Lines

Draw in Straight Lines

You plan to draw a black-and-white painting on a rectangular canvas. The painting will be a grid array of pixels, either black or white. You can paint black or white lines or dots on the initially white canvas.

You can apply a sequence of the following two operations in any order.

  • Painting pixels on a horizontal or vertical line segment, single pixel wide and two or more pixel long, either black or white. This operation has a cost proportional to the length (the number of pixels) of the line segment multiplied by a specified coefficient in addition to a specified constant cost.
  • Painting a single pixel, either black or white. This operation has a specified constant cost.

You can overpaint already painted pixels as long as the following conditions are satisfied.

  • The pixel has been painted at most once before. Overpainting a pixel too many times results in too thick layers of inks, making the picture look ugly. Note that painting a pixel with the same color is also counted as overpainting. For instance, if you have painted a pixel with black twice, you can paint it neither black nor white anymore.
  • The pixel once painted white should not be overpainted with the black ink. As the white ink takes very long to dry, overpainting the same pixel black would make the pixel gray, rather than black. The reverse, that is, painting white over a pixel already painted black, has no problem.

Your task is to compute the minimum total cost to draw the specified image.

Input

The input consists of a single test case. The first line contains five integers nn, mm, aa, bb, and cc, where nn (1n401 \leq n \leq 40) and mm (1m401 \leq m \leq 40) are the height and the width of the canvas in the number of pixels, and aa (0a400 \leq a \leq 40), bb (0b400 \leq b \leq 40), and cc (0c400 \leq c \leq 40) are constants defining painting costs as follows. Painting a line segment of length ll costs al+bal + b and painting a single pixel costs cc. These three constants satisfy ca+bc \leq a + b.

The next nn lines show the black-and-white image you want to draw. Each of the lines contains a string of length mm. The jj-th character of the ii-th string is ‘#’ if the color of the pixel in the ii-th row and the jj-th column is to be black, and it is ‘.’ if the color is to be white.

Output

Output the minimum cost.

Sample Input 1

3 3 1 2 3 .#.

.#.

Sample Output 1

10

Sample Input 2

2 7 0 1 1 .### .###

Sample Output 2

3

Sample Input 3

5 5 1 4 4 ..#.. ..#.. .## ..#.. ..#..

Sample Output 3

24

Sample Input 4

7 24 1 10 10 ...###..#####....###. .#...#...#.#....#..#...# .#..#......#....#.#..... .#..#......#####..#..... .#..#......#......#..... .#...#...#.#.......#...# ...###..#........###.

Sample Output 4

256

Example

Input

3 3 1 2 3 .#.

.#.

Output

10

inputFormat

Input

The input consists of a single test case. The first line contains five integers nn, mm, aa, bb, and cc, where nn (1n401 \leq n \leq 40) and mm (1m401 \leq m \leq 40) are the height and the width of the canvas in the number of pixels, and aa (0a400 \leq a \leq 40), bb (0b400 \leq b \leq 40), and cc (0c400 \leq c \leq 40) are constants defining painting costs as follows. Painting a line segment of length ll costs al+bal + b and painting a single pixel costs cc. These three constants satisfy ca+bc \leq a + b.

The next nn lines show the black-and-white image you want to draw. Each of the lines contains a string of length mm. The jj-th character of the ii-th string is ‘#’ if the color of the pixel in the ii-th row and the jj-th column is to be black, and it is ‘.’ if the color is to be white.

outputFormat

Output

Output the minimum cost.

Sample Input 1

3 3 1 2 3 .#.

.#.

Sample Output 1

10

Sample Input 2

2 7 0 1 1 .### .###

Sample Output 2

3

Sample Input 3

5 5 1 4 4 ..#.. ..#.. .## ..#.. ..#..

Sample Output 3

24

Sample Input 4

7 24 1 10 10 ...###..#####....###. .#...#...#.#....#..#...# .#..#......#....#.#..... .#..#......#####..#..... .#..#......#......#..... .#...#...#.#.......#...# ...###..#........###.

Sample Output 4

256

Example

Input

3 3 1 2 3 .#.

.#.

Output

10

样例

3 3 1 2 3
.#.
###
.#.
10