#0002CF

z-dimension

After a hard training of programming, Little Z decided that he needed a break, so he went on a holiday on the beautiful beaches in the Hawaii. While he was lying under the umbrella, watching the waves constantly arriving at the shore, the wind whispering in his ears, he fell asleep. When he woke up, he noticed that he wasn't anymore on the Hawaii, but he was in some strange room with 4 walls and doors on them. He realised that while he was sleeping, aliens have abducted him, thus transported him to the dimension Z, and put him in a maze of rooms. Little Z must immediately get out of there, and get back to planet Earth. Help him escape, before the aliens return from their coffee break and dissect him.

The maze has rooms and passages between rooms. Rooms are organized as chess fields.There are passages between adjacent horizontal and vertical rooms (but not diagonal rooms).
This is example maze with 3 rows and 4 columns (12 rooms):

Image: timepath

Little Z starts from the room marked with 'S' and needs to get to the room marked with 'E'.
Little Z walks uniformly while traveling through the maze, but the time does not pass uniformly in all rooms in dimension Z.So, the time that will pass after Little Z enters the room and before he exits the room is specific for each room.
There are some rooms that can not be visited.
Moving through a horizontal passage takes H minutes and moving through a vertical passage takes V minutes. (All horizontal passages are the same, and all vertical passages are the same).
Find the minimum time Little Z needs to escape from the maze.
If Little Z can not escape, output -1.



InputIn the first line are the numbers N, M,H and V. From the next N lines read M characters that represent the maze (1<=N,M<=100). The maze will be composed of the characters:
'S' - the start room,
'E' - the end room, which Little Z needs to reach,
'#' -room that can not be visited,
-all other cells of the maze have number between 1 and 9, the time that passes while you travel through that room.
(1<=H,V<=9).

OutputThe shortest time it takes to escape the maze. If there is no solution, output "-1" without qoutes.


Input1 10 2 2
111#SE#222

Output2


Input1 3 2 2
S#E

Output-1


Input3 7 1 1
S111111
9#####1
99E1111

Output23


Input5 5 1 1
S3333
33333
33333
33333
3333E

Output29

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.