Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/case-burilish-buyrugi

Turn command

Easy 1000 ms 64 MB 23%
Share

A radar faces direction $c_{1}$ and has to be turned to direction $c_{2}$. Directions: s — north, j — south, q — east, g — west. The radar executes one command: $0$ — no turn, $1$ — left by $90^{\circ}$ (counterclockwise), $2$ — right by $90^{\circ}$ (clockwise), $-1$ — a turn by $180^{\circ}$ (back). Find which command is needed to go from $c_{1}$ to $c_{2}$.

The turning angle between the starting and the final directions

Input

One line with two letters: $c_{1}$ and $c_{2}$.

Output

One integer: $0$, $1$, $2$ or $-1$.

Note

$c_{1}$, $c_{2}$ are s, j, q or g
$c_{1}$ and $c_{2}$ may be equal.

Examples

Input #1
s g
Output #1
1
Input #2
q j
Output #2
2

Sign in to submit a solution

Signing up is free and takes a minute.