Problem A
A New Adventure
‘Hunter’: a licensed profession for those who specialize in finding rare creatures or secret treasures.
Gon has embarked on a new journey to become a Hunter. Yesterday, Gon arrived in Hanoi to participate in the Hunter Exam — an annual exam which an applicant must pass, in order to become a Hunter.
The Hunter Examination Hall is surrounded by a circular
road. We can model the road as
![\includegraphics[width=0.5\textwidth ]{illustration.jpg}](/problems/anewadventure/file/statement/en/img-0001.jpg)
There are motorbikes on the road. There is at most one
motorbike in each arc, and there is no motorbike in arc
All the motorbikes are travelling at constant speed of
Gon needs to go to the Examination Hall located inside the
Because Gon moves slightly faster than any motorbikes:
-
If Gon moves from cell
to cell :-
Gon will not be hit by motorbikes coming into cell
. -
Gon will be hit by motorbikes coming from or into cell
.
-
-
If Gon stays at cell
, he will be hit by motorbikes coming into cell .
For example, in the above illustration, Gon can move as follows:
-
At second
: Gon moves to arc , the motorbikes move to arc and arc . -
At second
: Gon moves to arc , the motorbikes move to arc and arc . -
At second
: Gon moves to Examination Hall, the motorbikes move to arc and arc .
Note that:
-
If at second
, Gon moves to arc , he will be hit by the motorbike moving from arc to arc . -
If at second
, Gon stays at arc , he will also be hit by the motorbike moving from arc to arc .
The Hunter Exam is starting soon, and Gon has not figured out how to cross the road yet. Please help him.
Input
The first line contains exactly
The first character of the first line is always ‘G’, and this is the only ‘G’ in the input.
Output
Print exactly one integer — the minimum time for Gon to
reach the Examination Hall. If it is impossible for Gon to
reach the Examination Hall, print
Sample Input 1 | Sample Output 1 |
---|---|
3 8 GM...... ......M. ........ |
3 |