시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 154 74 70 47.945%

문제

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

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

잠시 인터넷으로 폭탄 해체법을 검색해보니, 폭탄의 상단에 표시되는 숫자를 코드라고 한다는 것을 알게 되었다. 또, 코드가 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!!
W3sicHJvYmxlbV9pZCI6IjkyNDIiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWQzZWRcdWQwYzQgXHVkNTc0XHVjY2I0IiwiZGVzY3JpcHRpb24iOiI8cD5cdWQ2NGRcdWM5MDBcdWM3NzRcdWFjMDAgXHVjNzkwXHVjOGZjIFx1YWMwMFx1YjI5NCBcdWQ2MzhcdWQ1MDRcdWM1ZDAgXHVkM2VkXHVkMGM0XHVjNzc0IFx1YzEyNFx1Y2U1OFx1YjQxOFx1YzVjOFx1YjJlNFx1YjI5NCBcdWMyZTBcdWFjZTBcdWFjMDAgXHViNGU0XHVjNWI0XHVjNjU0XHViMmU0LiBcdWQ2NGRcdWM5MDBcdWM3NzRcdWIyOTQgXHVjOTg5XHVjMmRjIFx1ZDYzOFx1ZDUwNFx1Yjg1YyBcdWIyZWNcdWI4MjRcdWFjMTRcdWIyZTQuPFwvcD5cclxuXHJcbjxwPlx1ZDNlZFx1ZDBjNFx1Yzc0NCBcdWM3YTBcdWMyZGMgXHVjMGI0XHVkM2I0XHViY2Y0XHViMmM4IFx1YzIyMFx1YzlkMVx1YzVkMCBcdWMxMjRcdWNlNThcdWI0MWMgXHVkM2VkXHVkMGM0XHVjNzQwIFx1ZDU3NFx1Y2NiNFx1ZDU1OFx1YWUzMCBcdWI5ZTRcdWM2YjAgXHVhZTRjXHViMmU0XHViODVjXHVjNmI0IFx1ZDNlZFx1ZDBjNFx1Yzc3NFx1YzVjOFx1YjJlNC4gXHVkNjRkXH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