Under construction

Still being built. Things may change

Lineup

Interview

Time limit1sMemory limit1024 MB

Summary
Given how many taller children stand to each child's left and right, find the one lineup that matches all the slips for up to 8 children.
Level

Easy3 of 10

Topics
Backtracking, Brute force
Solved
No attempts yet

Problem

A group of n children, which we will call A, B, C, and so on, decides to test your reasoning. Without you watching, they line up in a row. Then each child counts how many taller children are to their left, and does the same for the children to their right. After leaving the lineup, each child writes these two counts on a slip of paper and hands it to you. Their simple request is that you tell them the order in which they stood.

Here is an example with five children, shown in the figure. A has one taller child (D) to the left and two (C and E) to the right. B has three taller children to the left and one to the right. C has one taller child to the left and none to the right, and so on. The information on the slips can be summarized like this:

ChildLeftRight
A12
B31
C10
D00
E20

You did not solve the puzzle, so you sneak away and write a computer program that solves it. To make things easier the next time the children challenge you, you want to vary both the number of children (between 3 and 8, inclusive) and the information on the slips. You may assume that all children have different heights and that they made no mistakes when writing the slips. Interestingly, there is never more than one solution.

Input

The first line contains an integer nn (3≤n≤83 \le n \le 8), the number of children. The next nn lines each contain two integers: the number of taller children to the left of the child, and the number of taller children to the right of the child.

Output

Print one line of nn characters that describes the lineup, as a rearrangement of the letters A, B, C, and so on.

Examples1

  1. Example 1

    Input
    5
    1 2
    3 1
    1 0
    0 0
    2 0
    
    Expected output
    DACBE