**8 人解决**，15 人已尝试。

**8 份提交通过**，共有 18 份提交。

**6.7** EMB 奖励。

**单点时限: **2.0 sec

**内存限制: **256 MB

In this problem we consider a modification of the classical Hanoi Towers game. The rules of our modification are as follows:

There are three pegs: peg A, peg B and peg C.

Each peg initially contains zero or more discs.

All discs have the same size and there are three types of discs: type A, type B and type C.

In one move you can move a disc from the top of one peg onto the top of another peg.

Your goal is to have all discs of type A on peg A, all discs of type B on peg B and all discs of type C on peg C.

You must achieve your goal in the minimum possible number of moves.

The initial locations of the discs are given in the strings pegA, pegB and pegC. Each character of pegA represents a disc located on peg A, where ‘A’ represents a disc of type A, ‘B’ represents a disc of type B and ‘C’ represents a disc of type C. The discs are given in order, from bottom to top. pegB and pegC describe the discs on pegs B and C, respectively, in the same format.

Print the minimum number of moves required to achieve the goal of the game.

note:

We guarantee it’s always possible to achieve the goal of the game.

pegA, pegB and pegC will contain only the characters ‘A’, ‘B’ and ‘C’.

The total number of characters in pegA, pegB and pegC will be between 1 and 10, inclusive.

Only one test case.

It consists of three integers a ,b, c which represent number of characters in pegA, pegB and pegC, and 3 lines follow.

Print the minimum number of moves required to achieve the goal of the game.

Input

1 1 1 B C A

Output

5

There is exactly one disc of each type in this example, so we will refer to each disc by its type. The following sequence of moves is the shortest:

1. Move disc A to peg A.

2. Move disc C to peg C.

3. Move disc A to peg C.

4. Move disc B to peg B.

5. Move disc A to peg A.

**8 人解决**，15 人已尝试。

**8 份提交通过**，共有 18 份提交。

**6.7** EMB 奖励。

题目标签