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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAX = 130;
long long dp[MAX][2], dt[MAX];
int slen;
char s[MAX];
struct node {
  int ty;
  char c;
  int cnt;
  void print() { printf("(ty=%d,c=%c,cnt=%d) ", ty, c, cnt); }
};
node tmp[MAX];
int tnt;
node li[MAX];
int lnt;
int main() {
  scanf("%s", s);
  for (int i = (1); i <= (90); ++i) {
    if (i == 1)
      dp[i][0] = dp[i][1] = 1;
    else {
      dp[i][0] = dp[i - 1][1];
      dp[i][1] = dp[i - 1][0] + dp[i - 1][1];
    }
  }
  for (int i = (1); i <= (90); ++i) dt[i] = dp[i][0] + dp[i][1];
  slen = strlen(s);
  int fb = -1;
  for (int i = (0); i <= (slen - 1); ++i)
    if (s[i] == 'B') {
      fb = i;
      break;
    }
  if (fb == -1) {
    printf("%d\n", 1);
  } else {
    bool hasA = 0;
    for (int i = (0); i <= (slen - 1); ++i)
      if (s[i] == 'A') {
        hasA = 1;
        break;
      }
    if (!hasA)
      printf("%d\n", 1);
    else {
      int pos = fb;
      tnt = 0;
      do {
        int nxt = (pos + 1) % slen;
        if (s[pos] == 'A') {
          tmp[tnt].ty = 0, tmp[tnt].c = 'A';
          tnt++;
          pos = nxt;
        } else {
          if (nxt == fb || s[nxt] == 'B') {
            tmp[tnt].ty = 0;
            tmp[tnt].c = s[pos];
            tnt++;
            pos = nxt;
          } else {
            tmp[tnt].ty = 1;
            tnt++;
            pos = (nxt + 1) % slen;
          }
        }
      } while (pos != fb);
      int ty0 = -1;
      for (int i = (0); i <= (tnt - 1); ++i) {
        if (tmp[i].ty == 0) {
          ty0 = i;
          break;
        }
      }
      if (ty0 == -1) {
        if (tnt == 2)
          printf("%d\n", 2);
        else if (tnt == 3)
          printf("%d\n", 4);
        else
          printf("%lld\n", dt[tnt - 1] + dt[tnt - 3]);
      } else {
        lnt = 0;
        int pos = ty0;
        do {
          int nxt = (pos + 1) % tnt;
          if (tmp[pos].ty == 0) {
            li[lnt] = tmp[pos];
            lnt++;
            pos = nxt;
          } else {
            int j = nxt;
            int cnt = 1;
            while (j != ty0 && tmp[j].ty == 1) {
              cnt++, j = (j + 1) % tnt;
            }
            li[lnt].ty = 1;
            li[lnt].cnt = cnt;
            lnt++;
            pos = j;
          }
        } while (pos != ty0);
        bool yab = 0;
        int fty1;
        for (int i = (0); i <= (lnt - 1); ++i)
          if (li[i].ty == 1) {
            fty1 = i;
            break;
          };
        pos = fty1;
        do {
          int j = (pos + 1) % lnt;
          while (li[j].ty == 0) j = (j + 1) % lnt;
          int nxt = j;
          j = ((j - 1) % lnt + lnt) % lnt;
          int k = (pos + 1) % lnt;
          while (k != j) {
            int nxtk = (k + 1) % lnt;
            if (li[k].c == 'A' && li[nxtk].c == 'B') {
              yab = 1;
              break;
            }
            k = nxtk;
          }
          if (yab == 1) break;
          pos = nxt;
        } while (pos != fty1);
        if (yab)
          printf("%d\n", 0);
        else {
          long long ans = 1;
          for (int i = (0); i <= (lnt - 1); ++i) {
            if (li[i].ty == 1) {
              int prev = ((i - 1) % lnt + lnt) % lnt, nxt = (i + 1) % lnt;
              bool hb = li[prev].c == 'A', tb = li[nxt].c == 'B';
              if (li[i].cnt == 1) {
                if (!hb && !tb) ans *= 2;
              } else {
                int tmp = li[i].cnt;
                if (hb) tmp--;
                if (tb) tmp--;
                if (tmp) ans *= dt[tmp];
              }
            }
          }
          printf("%lld\n", ans);
        }
      }
    }
  }
  return 0;
}