시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 9 4 4 66.667%

문제

31게임은 옛날 옛날에 기차를 타고 다니던 사기꾼들이 제일 좋아했던 게임이다. 이 게임은 24개의 카드로 이루어진 카드팩을 이용한다. 1,2,3,4,5,6이 쓰여진 카드가 4개씩 있다. 카드팩의 카드는 두명의 플레이어 모두가 볼 수 있다. 두명의 플레이어는 번갈아 가면서 카드팩에서 카드를 한장씩 가져온다. 그리고 카드를 같은 곳에 쌓아놓는다.

게임의 목표는 마지막 플레이어가 카드를 쌓았을 때 쌓여 있는 카드의 합이 31을 초과하지 않아야 한다는 것이다. 

상윤이는 두명의 플레이어가 선택한 카드의 순서가 주어졌을 때 최종적으로 우승하는 플레이어가 누구인지 결정하는 프로그램을 작성하려고 한다.

두 플레이어는 나머지 카드 중 자신이 이기기 위한 완벽한 전략을 사용한다고 가정한다.

예를 들어 플레이어 찬미와 아람이가 다음과 같은 순서로 카드를 뽑는다고 가정한다.

  • 찬미 3
  • 아람 5
  • 찬미 6
  • 아람 6
  • 찬미 5
  • 아람 6

이렇게 쌓아올리면 쌓여진 총 카드의 숫자들의 합은 31이 된다 다음 차례인 찬미가 무슨 카드를 뽑던지 31을 초과하여 찬미가 지고 아람이가 이기게 된다.

상윤이가 프로그램을 짤 수 있게 도와주자

입력

몇개의 줄에 걸쳐 입력이 주어진다. 여러개의 비트로 입력이 들어온다. 첫번째 비트는 플레이어 A가 선택하는 카드의 수이고 두번째 비트는 플레이어 B가 선택하는 수이다. 이 순서로 비트가 반복해서 들어온다.

완벽한 전략으로 게임을 이어나갔을 때 두명의 플레이어 중 누가 이기는지를 결정해야 한다.

출력

각 게임별로 입력으로 주어진 값과 게임의 최종 승자를 공백을 사이에 두고 출력하여라.

예제 입력 1

356656
35665
3566
111126666
552525

예제 출력 1

356656 B
35665 B
3566 A
111126666 A
552525 A

힌트

W3sicHJvYmxlbV9pZCI6IjQxNDgiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl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