Under construction

Still being built. Things may change

Strange Machine

Interview

Time limit3sMemory limit1024 MB

Summary
Given a button press sequence where some presses are unknown (-1), find which of the four bulbs can be lit after the last press.
Level

Medium4 of 10

Topics
Dynamic programming, Simulation
Solved
No attempts yet

Statement

The machine has four bulbs: red, green, blue, and yellow. Exactly one bulb is lit at any time. When the machine is started, the red bulb is lit.

The machine has two buttons, 0 and 1. Pressing a button changes which bulb is lit.

  • If red is lit, pressing either button lights green.
  • If green is lit, pressing 0 lights red, and pressing 1 lights blue.
  • If blue is lit, pressing 0 lights yellow, and pressing 1 keeps blue lit.
  • If yellow is lit, pressing 0 keeps yellow lit, and pressing 1 lights red.

Juku wrote down the sequence of button presses. His sister Juta dropped the paper into a muddy puddle, and some symbols are now unreadable. Help Juta find every bulb that could be lit after the last press.

Input

The first line contains the number of presses NN (1≤N≤1061 \le N \le 10^6).

The second line contains NN integers separated by spaces. Each value is 00, 11, or −1-1. A 00 means button 0 was pressed, and a 11 means button 1 was pressed. A −1-1 marks a position the water damaged, so button 0 or button 1 was pressed there.

Output

Print four lines. The first line is the answer for red, the second for green, the third for blue, and the fourth for yellow. Print JAH if that bulb can be lit after the last press, and EI if it cannot.

Examples2

  1. Example 1

    Input
    6
    1 -1 0 1 0 1
    
    Expected output
    JAH
    EI
    JAH
    EI
    
  2. Example 2

    Input
    4
    -1 -1 -1 -1
    
    Expected output
    JAH
    EI
    JAH
    JAH