Under construction

Still being built. Things may change

Bomb Defusal

Time limit1sMemory limit128 MB

Summary
Decode up to 8 digits from 5 rows of ASCII art and print BEER!! only when every digit is valid and the value is divisible by 6.
Level

Easy3 of 10

Topics
Implementation, Math
Solved
No attempts yet

Problem

Someone reported a bomb at the pub Hongjun goes to all the time. Hongjun ran straight over.

One look was enough to tell that this bomb is a hard one to defuse. Hongjun noticed a number showing on the top of the bomb.

He searched the internet for a way to defuse it and learned that the number on top is called the code, and that the wire has to be cut when the code is divisible by 6.

Given the code of the bomb, write a program that decides whether cutting the wire defuses the bomb or sets it off.

Input

The input is the code of the bomb. The code has at least 2 and at most 8 digits, and each digit is drawn with characters in 5 rows and 3 columns. Every character is either a space or an asterisk ('*'). A single blank column separates one digit from the next.

Every digit is 5×3 in size, but a shape that is not a valid digit may appear. If even one shape is not a valid digit, the wire must not be cut.

The 5×3 drawings of the digits 0 to 9 are below.

### ### ### ### ### ### ### ### ### ###
***   * *** *** * * *** *** *** *** ***
* *   *   *   * * * *   *     * * * * *
* *   * *** *** *** *** ***   * *** ***
* *   * *     *   *   * * *   * * *   *
***   * *** ***   * *** ***   * *** ***

Figure 1. The # characters on the top line belong to the figure only. They make the columns easier to tell apart.

The code may start with a zero. For example, 00000076 is 76.

Output

Print "BEER!!" on the first line if the wire may be cut for the given code, or "BOOM!!" if cutting it sets the bomb off.

Examples4

  1. Example 1

    Input
    ***   * * * *** *** *** ***
    * *   * * *   *   *   * *  
    * *   * *** *** *** *** ***
    * *   *   * *     * *   * *
    ***   *   * *** *** *** ***
    
    Expected output
    BEER!!
    
  2. Example 2

    Input
      *   * *** *** *** * *
      *   * **    * * * * *
      *   * *** *** *** ***
      *   * *   *   * *   *
      *   * *** *** ***   *
    
    Expected output
    BOOM!!
    
  3. Example 3

    Input
    *** ***   * *** *** *
    *   * *   * * *   * *
    *** * *   * *** *** *
      * * *   *   * *   *
    *** ***   * *** *** *
    
    Expected output
    BOOM!!
    
  4. Example 4

    Input
    *** *** *** * * ***
      *   *   * * * * *
    ***   * *** *** ***
    *     *   *   * * *
    ***   * ***   * ***
    
    Expected output
    BEER!!