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

~/algor $ cat problems/case-robot-burilib-yuradi

A robot that turns and walks

Easy 1000 ms 64 MB 23%
Share

A robot stands at the point $(x; y)$ of the coordinate plane facing direction $c$. First it gets a turn command $k$: $0$ — no turn, $1$ — left by $90^{\circ}$ (counterclockwise), $2$ — right by $90^{\circ}$ (clockwise), $-1$ — a turn by $180^{\circ}$ (back). Then the robot walks $n$ steps in the new direction. Directions: s — north (each step increases $y$ by $1$), j — south ($y$ decreases by $1$), q — east ($x$ increases by $1$), g — west ($x$ decreases by $1$). Find the point where the robot stops and its final direction.

The robot turns and then walks straight

Input

One line: integers $x$ and $y$, a direction letter $c$ (s, j, q or g), integers $k$ and $n$.

Output

One line: the $x$ and $y$ coordinates of the point where the robot stops and the letter of its new direction.

Note

$-1000 \le x, y \le 1000$
$k \in \{-1, 0, 1, 2\}$
$0 \le n \le 1000$

Examples

Input #1
1 2 s 2 3
Output #1
4 2 q
Input #2
0 0 q 1 4
Output #2
0 4 s

Sign in to submit a solution

Signing up is free and takes a minute.