Under construction

Still being built. Things may change

Hexagonal Tour

Time limit2sMemory limit512 MB

Summary
Given a hexagonal building of side N and a start room, find a route that visits every room exactly once and returns to the start, or report -1.
Level

Medium7 of 10

Topics
Implementation, Graph
Solved
No attempts yet

Problem

Jeonghu visited a hexagonal building designed by a famous architect who took inspiration from the pentagon, and he was captivated by its unusual beauty. The building is made of 3N2−3N+13N^2-3N+1 regular hexagonal rooms. The rooms are arranged in a regular hexagon with NN rooms along each side. Put differently, the rooms form 2N−12N-1 rows, and row ii holds 2N−1−∣i−N∣2N-1-|i-N| rooms. Two rooms that share an edge are connected by a door, so people can walk between them. A room has up to six neighbors, and each move is written as one of the uppercase letters Q, E, D, C, Z, or A, as shown in the figure below. In the figure, (i,j)(i, j) is the jj-th room in the ii-th row, and Jeonghu is currently in the fourth room of the third row.

Jeonghu wants to start in the yy-th room of the xx-th row, visit every room exactly once, and return to his starting room. Find any such route for him.

Input

Three integers NN, xx, and yy are given on a single line, separated by spaces.

Output

If such a route exists, print any one of them as a string of length 3N2−3N+13N^2-3N+1. The ii-th character is one of the uppercase letters Q, E, D, C, Z, or A, and it gives the direction of the ii-th move. If no such route exists, print -1 only.

Constraints

  • 2≤N≤1 0002 \leq N \leq 1\,000
  • 1≤x≤2N−11 \leq x \leq 2N-1
  • 1≤y≤2N−1−∣x−N∣1 \leq y \leq 2N-1-|x-N|

Examples2

  1. Example 1

    Input
    2 2 2
    
    Expected output
    CAQEDCA
    
  2. Example 2

    Input
    4 2 3
    
    Expected output
    DQDCZAAZACDCDEAQDDECZZZAAAEAQQEECEQDC