Олимпиадный тренинг

Задача 44250. Frog and Grasshopper


Задача

Темы:
A frog and a grasshopper sit in the extreme cells of a strip one cell wide and N cells long: the frog is in cell No. 1, the grasshopper is in cell No. N. Every second the frog jumps towards the grasshopper, and at the same time the grasshopper jumps towards the frog. A frog can only jump two or three cells, a grasshopper — only one or two cells. What is the shortest time they can be in the same cage?

Input
The only line of the input contains an integer N — the length of the checkered stripe (2 ≤ N ≤ 2 · 109 ).
Imprint
If the frog and the grasshopper can end up in the same cell, print a single integer — the minimum number of seconds after which they will meet. If they cannot be in the same cell, you need to print the number "-1" (without quotes).
 
Examples
# Input Output
1 5 1
2 9 2

Remark
In the first example, the frog can jump from cell 1 to cells 3 and 4, and the grasshopper can jump from cell 5 to cells 3 and 4. Therefore, after 1 second, they can end up in the same cell.
In the second example, the frog and the grasshopper can meet in 2 seconds. For example, a frog jumps to square 3, then to square 6, and a grasshopper jumps to square 8, then to square 6.