I. Ice Sliding
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
3 3
...
.#.
...
1
1 1 3 3
Output
5
Input
3 5
....#
#....
.....
2
2 2 1 1
1 1 3 5
Output
-1
13