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

~/algor $ cat problems/lokator-yonalishi

Radar direction

Easy 1000 ms 64 MB 23%
Share

A radar can face four directions: s — north, j — south, q — east, g — west. The starting direction $c$ and two commands $N_{1}$ and $N_{2}$, executed one after the other, are given. Commands: $0$ — no turn, $1$ — left by $90^{\circ}$, $2$ — right by $90^{\circ}$, $-1$ — a turn by $180^{\circ}$. Find the final direction of the radar.

Two consecutive turns of the radar

Input

One line with a direction letter $c$ and two integers $N_{1}$ and $N_{2}$.

Output

One letter: the final direction (s, j, q or g).

Note

$c$ is s, j, q or g
$N_{1}, N_{2} \in \{-1, 0, 1, 2\}$

Examples

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

Sign in to submit a solution

Signing up is free and takes a minute.