After being rejected by his AI girlfriend, Dragon needed a new talent to impress his crush.
In order to seek for love, Dragon decides to take on a new hobby: Ballet!
He has practiced a set of $N$ consecutive dance moves which can be represented on a 2-Dimensional coordinate plane.
The dance starts on $(S_x$, $S_y)$ and ends on $(E_x$, $E_y)$.
The $i$-th dance move $(0\leq i < N)$ can be viewed as moving $2^i$ times in the same direction.
He is able to move vertically, horizontally and diagonally or not move.
- If he moves vertically, he moves from $(x, y)$ to $(x, y\pm2^i)$.
- If he moves horizontally, he moves from $(x, y)$ to $(x\pm2^i, y)$.
- If he moves diagonally, he moves from $(x, y)$ to $(x\pm2^i, y\pm2^i)$.
- If he does not move, he remains at $(x, y)$.
He has marked the set of dance moves with a string of lowercase letters $S$ of length $N$.
However, he has already forgotten what direction each letter represents. All he knows is that all occurences of the same letter represent the same direction.
Can you help Dragon find a valid configuration of each letter or tell him that no such configuration exists?
Input
The first line contains 5 integers: $N, S_x, S_y, E_x, E_y$.
The second line consists of a string $S$ of length $N$.
Output
On the first line, output a valid configuration if it exists or -1
if there is not.
If a valid configuration exists, output $N$ pairs of characters consisting of +
, -
or /
only.
The $i$-th pair represents the direction of the $i$-th dance move.
-
/+
represents an upward move. -
/-
represents a downward move. -
+/
represents a rightward move. -
-/
represents a leftward move. -
++
represents an up-right move. -
-+
represents an up-left move. -
+-
represents a down-right move. -
--
represents a down-left move. -
//
represents not moving.
If there exists multiple configurations, you may output any of them.
Constraints
For all subtasks:
- $1 \leq N \leq 60$
- $1 \leq S_x, S_y, E_x, E_y \leq 2^{60}$
- $S$ consists of lowercase letters only.
Subtask 1 (10%): $N \leq 26$, $S[i] \neq S[j], 0 \leq i < j < N$
Subtask 2 (15%): $2^i = |S_x-E_x|, 2^j = |S_y-E_y|$ for some $i, j$
Subtask 3 (15%): $S[i]$ is a character from a
to n
.
Subtask 4 (20%): $N \leq 20$
Subtask 5 (40%): No additional constraints
Sample Test Cases
Input | Output | |
---|---|---|
5 1 3 3 4 abcad |
/- +- /- /- /+ | |
5 1 2 1 3 abbab |
-1 |
Scoring: Per Subtask
Authored by s19x17
Appeared in 2023 Mini Contest 9 (Pre-HKOI)