Problem: A very tense moment: n cowboys stand in a circle and each one points his colt at a neighbor. Each cowboy can point the colt to the person who follows or precedes him in clockwise direction. Human life is worthless, just like in any real western.

The picture changes each second! Every second the cowboys analyse the situation and, if a pair of cowboys realize that they aim at each other, they turn around. In a second all such pairs of neighboring cowboys aiming at each other turn around. All actions happen instantaneously and simultaneously in a second.

We'll use character "A" to denote a cowboy who aims at his neighbour in the clockwise direction, and character "B" for a cowboy who aims at his neighbour in the counter clockwise direction. Then a string of letters "A" and "B" will denote the circle of cowboys, the record is made from the first of them in a clockwise direction.

For example, a circle that looks like "ABBBABBBA" after a second transforms into "BABBBABBA" and a circle that looks like "BABBA" transforms into "ABABB".

<image> This picture illustrates how the circle "BABBA" transforms into "ABABB" 

A second passed and now the cowboys' position is described by string s. Your task is to determine the number of possible states that lead to s in a second. Two states are considered distinct if there is a cowboy who aims at his clockwise neighbor in one state and at his counter clockwise neighbor in the other state.

Input

The input data consists of a single string s. Its length is from 3 to 100 characters, inclusive. Line s consists of letters "A" and "B".

Output

Print the sought number of states.

Examples

Input

BABBBABBA


Output

2


Input

ABABB


Output

2


Input

ABABAB


Output

4

Note

In the first sample the possible initial states are "ABBBABBAB" and "ABBBABBBA".

In the second sample the possible initial states are "AABBB" and "BABBA".

Solution (in JAVA):

Solution:
import java.util.Arrays;
import java.util.Scanner;

public class C {
    static char[] str;
    static long[][][][] dp;

    public static long solve(int st, int end, int invertedSt, int invertedEnd) {
//      System.out.println(st + " " + end + " " + invertedSt + " "
//              + invertedEnd);
        if (st == str.length || (st == end && st != 0))
            return 1;
        if (dp[st][end][invertedSt][invertedEnd] != -1)
            return dp[st][end][invertedSt][invertedEnd];

        long res = 0;
        if (st == 0) {
            if (str[st] == 'B') {
                int prev = (st - 1 + str.length) % str.length;
                if (str[prev] != 'A') {
                    res += solve(st + 1, 0, 0, 0);
                    int next = (st + 1) % str.length;
                    if (str[next] == 'A') {
                        res += solve(st + 2, 0, 1, 1);
                    }
                } else {
                    int beforePrev = prev - 1;
                    int next = (st + 1) % str.length;
                    //System.out.println(beforePrev + " " + prev);
                    if (str[beforePrev] == 'B') {
                        //System.out.println("dasj");
                        res += solve(st + 1, beforePrev, 0, 1);
                        //if (str[next] == 'A') {
                            //res += solve(st + 2, beforePrev, 1, 1);
                        //}
                    }
                    if (str[next] == 'A') {
                        res += solve(st + 2, 0, 1, 1);
                    }
                }
            } else {
                res += solve(st + 1, 0, 0, 0);
                int prev = (st - 1 + str.length) % str.length;
                if (str[prev] == 'B') {
                    res += solve(st + 1, str.length - 1, 1, 1);
                }
            }
        } else {
            if (str[st] == 'B') {
                int prev = st - 1;
                boolean mustChange = false;
                if (str[prev] == 'A' && invertedSt == 0) {
                    mustChange = true;
                }
                if (!mustChange)
                    res += solve(st + 1, end, 0, invertedEnd);
                int next = (st + 1) % str.length;
                if (next != end) {
                    // if (invertedEnd == 1 && str[next] == 'B'
                    // || invertedEnd == 0 && str[next] == 'A') {
                    // res += solve(st + 1, end, 0, invertedEnd);
                    // }
                    // } else {
                    if (str[next] == 'A') {
                        res += solve(st + 2, end, 1, invertedEnd);
                    }
                }
            } else {
                // int next = (st + 1) % str.length;
                // if (str[next] == 'B'&&next<end||(next==end&&(invertedEnd == 1
                // && str[next] == 'A'
                // || invertedEnd == 0 && str[next] == 'B'))) {
                // int prev = (st - 1 + str.length) % str.length;
                // if (str[prev] == 'A' && invertedSt == 0 || str[prev] == 'B'
                // && invertedSt == 1) {
                // res += solve(st + 1, end, 1, invertedEnd);
                // }
                // } else {
                res += solve(st + 1, end, 0, invertedEnd);
                int prev = (st - 1 + str.length) % str.length;
                if (str[prev] == 'B' && invertedSt == 1) {
                    res += solve(st + 1, end, 1, invertedEnd);
                }
                // }
            }
        }
        return dp[st][end][invertedSt][invertedEnd] = res;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        str = sc.next().toCharArray();
        dp = new long[str.length][str.length + 1][2][2];
        for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j <= str.length; j++) {
                for (int k = 0; k < 2; k++)
                    Arrays.fill(dp[i][j][k], -1);
            }
        }
        System.out.println(solve(0, 0, 0, 0));
        sc.close();
    }
}