Under construction

Still being built. Things may change

Gangs

Time limit1sMemory limit128 MB

Summary
Rank all lattice paths of E and S steps from (1,1) to the diagonal at (N,N) by a recursive 'OG' order, and output the run at rank M or ERROR.
Level

Hard8 of 10

Topics
Combinatorics, Dynamic programming, Recursion, Math
Solved
No attempts yet

Problem

The downtown core of a city is a grid. Streets run north-south and are numbered from 1st Street in the west to 20th Street in the east; avenues run east-west and are numbered from 1st Avenue in the north to 20th Avenue in the south. The city is split between two gangs, the Blips and the Cruds, by the Green Line, which runs diagonally from the corner of 1st Street and 1st Avenue to the corner of 20th Street and 20th Avenue. The Blips control the area to the southwest of the Green Line, and the Cruds the area to the northeast.

To prove themselves, the Blips make runs through Crud territory. A run starts at the intersection of 1st Street and 1st Avenue and ends at a point on the Green Line. A run may touch the Green Line along the way but never crosses it. It moves along avenues only toward the east and along streets only toward the south, so it is a string of E's (east) and S's (south). A run of length 2N−22N-2 ends at the intersection of the NNth Street and the NNth Avenue.

On a given night every run has the same length, and the Blips rank them by how OG they are. A run R1R_1 is more OG than a run R2R_2 if and only if one of the following holds:

  • R2R_2 returns to the Green Line for the first time strictly earlier than R1R_1 does; or
  • R1R_1 and R2R_2 return to the Green Line for the first time at the same point, but the part of R1R_1 up to that point, with its leading E and trailing S removed, is more OG than the corresponding part of R2R_2; or
  • R1R_1 and R2R_2 return to the Green Line for the first time at the same point and are identical up to that point, but the remainder of R1R_1 is more OG than the remainder of R2R_2.

For example:

  • EESS is more OG than ESES.
  • EEESSS is more OG than EESESS.
  • EESSEESS is more OG than EESSESES.

List all runs of a given length from most OG to least OG. The rank of a run is its 1-based position in this list. For length 4, EESS has rank 1 and ESES has rank 2.

Input

The input is a sequence of instances, terminated by a line containing 0 0.

Each instance is a single line with two positive integers NN and MM: NN is the terminus of that night's runs (the NNth Street and NNth Avenue), and MM is the desired rank. You may assume 1≤N≤201 \le N \le 20.

Output

For each instance, print the run of length 2N−22N-2 whose rank is MM, or ERROR if there are fewer than MM runs of length 2N−22N-2.

Examples3

  1. Example 1

    Input
    3 1
    3 2
    3 3
    0 0
    
    Expected output
    EESS
    ESES
    ERROR
    
  2. Example 2

    Input
    4 1
    4 2
    4 3
    4 4
    4 5
    4 6
    0 0
    
    Expected output
    EEESSS
    EESESS
    EESSES
    ESEESS
    ESESES
    ERROR
    
  3. Example 3

    Input
    5 8
    5 9
    5 14
    5 15
    0 0
    
    Expected output
    EESSEESS
    EESSESES
    ESESESES
    ERROR