Landscaping

Pick a final low or high level for every grid cell to minimize flip costs plus border charges between differing neighbors.

Medium7GraphNo attempts yetTime limit1sMemory limit256 MB

Problem

Farmer John is getting his field ready for the spring harvest. Last year he went over budget, because the tractors driving up and down the hills burned more fuel than he expected.

During the harvest the tractors cross the whole field, both horizontally and vertically. In the picture below, light green is low ground and dark green is high ground, and the red lines mark the borders where two neighboring patches sit at different heights. The tractors cross every one of those borders, so on the field in the picture they go up or down eight times.

The field is an N×MN \times M grid of patches, and every patch is either low or high. Before sowing, John can call in bulldozers and change the height of any patch. Turning one low patch into a high patch, or one high patch into a low patch, costs BB euros.

Once the work is done, every pair of patches that share a side and sit at different heights costs an extra AA euros in tractor fuel.

So John pays BB for each patch he changes plus AA for each pair of neighboring patches that still differ in height. Find the smallest total he can pay.

Input

The first line has four integers NN, MM, AA and BB, separated by spaces. The field is N×MN \times M, AA is the cost of crossing a border between two neighboring patches at different heights, and BB is the cost of changing the height of one patch.

Each of the next NN lines has MM characters describing the current field. A . is a low patch and a # is a high patch.

Output

Print the smallest amount of money John has to pay, on one line.

Limits

  • 1N,M501 \le N, M \le 50, the size of the field
  • 1A,B1000001 \le A, B \le 100000, the cost of crossing a border and the cost of changing the height of a patch

Hint

The field in the example is 5×45 \times 4. Crossing a border between two patches at different heights costs 1000 euros, and changing the height of one patch costs 2000 euros.

The answer is 11000 euros: 2000 to lower the single isolated high patch, and 9000 of fuel for the nine borders that remain.

Changing nothing would cost 12000 euros, lowering every high patch would cost 18000 euros, and raising every low patch would cost 22000 euros.