#BS0000070. Con tàu phép thuật (Magic Ship)
Con tàu phép thuật (Magic Ship)
Magic Ship
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A ship starts at and wants to reach . A wind string of length repeats forever; each day wind moves the ship one unit accordingly. The captain may additionally move one unit in a cardinal direction or stay. Find the minimum number of days, or if impossible.
Input
Lines contain start, destination, , and the wind string.
Output
Print the minimum days or -1.
Subtasks
- Subtask 1 — 20%: .
- Subtask 2 — 30%: .
- Subtask 3 — 50%: coordinates in , .
Example
Input
0 0
4 6
3
UUU
Output
5
Explanation
Five days are sufficient and fewer are not.