시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 154 73 69 47.260%

문제

홍준이가 자주 가는 호프에 폭탄이 설치되었다는 신고가 들어왔다. 홍준이는 즉시 호프로 달려갔다.

폭탄을 잠시 살펴보니 술집에 설치된 폭탄은 해체하기 매우 까다로운 폭탄이었다. 홍준이는 폭탄의 상단에 숫자가 표시되고 있다는 점에 주목했다.

잠시 인터넷으로 폭탄 해체법을 검색해보니, 폭탄의 상단에 표시되는 숫자를 코드라고 한다는 것을 알게 되었다. 또, 코드가 6으로 나누어 떨어질 때 전선을 잘라야 한다고 나왔다.

폭탄의 코드가 주어졌을 때, 전선을 자르면 폭탄을 해체할 수 있는지, 폭탄이 폭발하는지 구하는 프로그램을 작성하시오.

입력

입력으로 폭탄의 코드가 주어진다. 코드는 2자리 이상, 8자리 이하이고, 각 자리는 5행 3열의 문자로 주어진다. 문자는 공백과 별표('*') 중 하나이다. 또, 각 숫자를 구분하기 위해 숫자 사이에는 빈 칸이 하나씩 있다.

모든 숫자는 5×3 크기이지만, 올바르지 않은 숫자가 주어질 수도 있다. 올바르지 않은 숫자가 주어진 경우에는 전선을 자르면 안된다.

0부터 9까지 숫자를 5×3으로 나타내는 방법은 아래에 나와있다.

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

그림 1. 맨 위의 #는 열을 알아보기 쉽게 하기 위해 주어진 문자이다.

코드는 0으로 시작하는 숫자일 수도 있다. 예를 들어, 00000076는 76이다.

출력

첫째 줄에 입력으로 주어진 코드인 경우에 전선을 잘라도 되면 "BEER!!"를, 자르면 폭발하는 경우에는 "BOOM!!"을 출력한다.

예제 입력 1

***   * * * *** *** *** ***
* *   * * *   *   *   * *  
* *   * *** *** *** *** ***
* *   *   * *     * *   * *
***   *   * *** *** *** ***

예제 출력 1

BEER!!

예제 입력 2

  *   * *** *** *** * *
  *   * **    * * * * *
  *   * *** *** *** ***
  *   * *   *   * *   *
  *   * *** *** ***   *

예제 출력 2

BOOM!!

예제 입력 3

*** ***   * *** *** *
*   * *   * * *   * *
*** * *   * *** *** *
  * * *   *   * *   *
*** ***   * *** *** *

예제 출력 3

BOOM!!

예제 입력 4

*** *** *** * * ***
  *   *   * * * * *
***   * *** *** ***
*     *   *   * * *
***   * ***   * ***

예제 출력 4

BEER!!
W3sicHJvYmxlbV9pZCI6IjkyNDIiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWQzZWRcdWQwYzQgXHVkNTc0XHVjY2I0IiwiZGVzY3JpcHRpb24iOiI8cD5cdWQ2NGRcdWM5MDBcdWM3NzRcdWFjMDAgXHVjNzkwXHVjOGZjIFx1YWMwMFx1YjI5NCBcdWQ2MzhcdWQ1MDRcdWM1ZDAgXHVkM2VkXHVkMGM0XHVjNzc0IFx1YzEyNFx1Y2U1OFx1YjQxOFx1YzVjOFx1YjJlNFx1YjI5NCBcdWMyZTBcdWFjZTBcdWFjMDAgXHViNGU0XHVjNWI0XHVjNjU0XHViMmU0LiBcdWQ2NGRcdWM5MDBcdWM3NzRcdWIyOTQgXHVjOTg5XHVjMmRjIFx1ZDYzOFx1ZDUwNFx1Yjg1YyBcdWIyZWNcdWI4MjRcdWFjMTRcdWIyZTQuPFwvcD5cclxuXHJcbjxwPlx1ZDNlZFx1ZDBjNFx1Yzc0NCBcdWM3YTBcdWMyZGMgXHVjMGI0XHVkM2I0XHViY2Y0XHViMmM4IFx1YzIyMFx1YzlkMVx1YzVkMCBcdWMxMjRcdWNlNThcdWI0MWMgXHVkM2VkXHVkMGM0XHVjNzQwIFx1ZDU3NFx1Y2NiNFx1ZDU1OFx1YWUzMCBcdWI5ZTRcdWM2YjAgXHVhZTRjXHViMmU0XHViODVjXHVjNmI0IFx1ZDNlZFx1ZDBjNFx1Yzc3NFx1YzVjOFx1YjJlNC4gXHVkNjRkXHV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