bile

The great scientist Lotocus invented the device in the picture below, that functions as follows:

Task

Because the honorable scientist hopes to sell his invention to a lottery, help him by writing a program that indicates the order in which the two buttons have to be pressed so that starting from an initial ball configuration in area A we can get a specific configuration of the balls in area C (which will prove the extraordinary importance of the machine!).

Input Data

Input file bile.in has the following structure:

Output Data

Output file bile.out will contain a single line with a sequence comprised of letters I and O representing the order in which the two buttons have to be pressed so that starting from the initial configuration we get the final configuration or message imposibil if it cannot be achieved.

Constraints

  • 1 <= n <= 2000
  • Examples

    bile.in

    bile.out

    bile.in

    bile.out

    5
    5 4 2 1 3
    2 4 1 5 3

    IIIOOIOOIO 5
    5 4 2 1 3
    1 4 2 5 3

    imposibil

     

    Time limit: 0.1 seconds/test

    prof. Radu Boriga
    "Spiru Haret" Bucharest High School
    Contact:r_boriga@yahoo.com