Problem list
Log in
#coci00025 · COCI 2006/2007 Contest 5

Trik

Bronze II 1.0 s 32 MB

Jealous of Mirko's position as head of the village, Borko stormed into his tent and tried to demonstrate Mirko's incompetence for leadership with a trick.

Borko puts three opaque cups onto the table next to each other (opening facing down) and a small ball under the leftmost cup. He then swaps two cups in one of three possible ways a number of times. Mirko has to tell which cup the ball ends up under.

There are three possible swaps, each denoted by a letter:

  • A — swap the left and middle cups;
  • B — swap the middle and right cups;
  • C — swap the left and right cups.

Wise Mirko grins with his arms crossed while Borko struggles to move the cups faster and faster. What Borko does not know is that programmers in the back are recording all his moves and will use a simple program to determine where the ball is. Write that program.

Input

The first and only line contains a string of at most $50$ characters, Borko's moves.

Each of the characters is A, B or C.

Output

Output the index of the cup under which the ball is: $1$ if it is under the left cup, $2$ if it is under the middle cup or $3$ if it is under the right cup.

Example 1

Input
AB
Output
3

Example 2

Input
CBABCACCC
Output
1
Source
COCI 2006/2007 Contest 5
Appears in
Not part of a ladder, contest or set yet.
Accepted 1 Submissions 1 Acceptance 100% Solvers 1

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code