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 INF = 1 << 29;
inline int two(int n) { return 1 << n; }
long long extgcd(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    int g = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return g;
  }
}
long long modpow(long long a, long long b) {
  long long res = 1;
  a %= 998244353;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 998244353;
    a = a * a % 998244353;
  }
  return res;
}
const int sz = 200;
bool block[sz];
long long dp[sz][2];
string parseStr(string s) {
  string ans = "";
  int n = s.length(), pre = 0, suf = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == s[0])
      pre++;
    else
      break;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == s[n - 1])
      suf++;
    else
      break;
  }
  if (s[0] == s[n - 1]) {
    ans.push_back(s[0]);
    ans.push_back(s[0]);
  } else {
    pre = 0, suf = 0;
  }
  if (pre == n) return ans;
  char prev;
  bool vis = false;
  int cnt = 1;
  for (int i = pre; i < n - suf; i++) {
    if (vis) {
      if (s[i] == s[i - 1])
        cnt++;
      else {
        if (cnt >= 2) ans.push_back(s[i - 1]);
        ans.push_back(s[i - 1]);
        cnt = 1;
      }
    }
    vis = 1;
  }
  if (cnt >= 2) ans.push_back(s[n - suf - 1]);
  ans.push_back(s[n - suf - 1]);
  return ans;
}
vector<int> getVec(string s) {
  vector<int> ans;
  int cnt = 0, n = s.length();
  for (int i = 0; i < n; i++) {
    if (!i || s[i] == s[i - 1])
      cnt++;
    else {
      ans.push_back(cnt);
      cnt = 1;
    }
  }
  ans.push_back(cnt);
  return ans;
}
bool checkBad(string sr) {
  vector<int> v = getVec(sr);
  int vlen = v.size();
  bool startsWithA = (sr[0] == 'A'), bad = false;
  for (int i = 0; i < vlen; i++) {
    if (startsWithA ^ (i & 1)) {
      if (v[i] == 2 && v[(i + 1) % vlen] == 2) {
        bad = true;
        break;
      }
    }
  }
  return bad;
}
void preCalc() {
  dp[0][0] = 1;
  dp[0][1] = 1;
  dp[1][0] = 1;
  dp[1][1] = 1;
  dp[2][0] = 0;
  dp[2][1] = 2;
  dp[3][0] = 1;
  dp[3][1] = 1;
  for (int i = 4; i < sz; i++) {
    dp[i][0] = dp[i - 3][1];
    dp[i][1] = dp[i - 2][1] + dp[i - 4][1];
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ifstream in("input.txt");
  ofstream out("output.txt");
  string s;
  cin >> s;
  string sr = parseStr(s);
  if (sr.length() == 2) {
    cout << 1 << endl;
    return 0;
  }
  if (checkBad(sr)) {
    cout << 0 << endl;
    return 0;
  }
  int len = sr.length(), blockex;
  for (int i = 0; i < len; i++) {
    if (i && sr[i] == sr[i - 1]) {
      if (sr[i] == 'A') {
        block[i] = 1;
        block[(i + 1) % len] = 1;
        block[(i + 2) % len] = 1;
        blockex = i;
      } else {
        block[(i - 1 + len) % len] = 1;
        block[(i - 2 + len) % len] = 1;
        block[(i - 3 + len) % len] = 1;
        blockex = i - 1;
      }
    }
  }
  int pre = 0, suf = 0;
  for (int i = 0; i < len; i++) {
    if (!i || sr[i] != sr[i - 1])
      pre++;
    else
      break;
  }
  for (int i = len - 1; i >= 0; i--) {
    if (i == len - 1 || sr[i] != sr[i + 1])
      suf++;
    else
      break;
  }
  preCalc();
  if (pre == len) {
    cout << dp[len - 2][1] + dp[len - 3][1] << endl;
  } else {
    long long ans = 1;
    int cnt = 0;
    bool startWithA = false;
    for (int i = 0; i < len + 1; i++) {
      if (block[(i + blockex) % len] && cnt) {
        ans *= dp[cnt][!startWithA];
        cnt = 0;
      } else if (!cnt && !block[(i + blockex) % len]) {
        startWithA = (sr[(i + blockex) % len] == 'A');
        cnt = 1;
      } else if (!block[(i + blockex) % len])
        cnt++;
    }
    cout << ans << endl;
  }
  return 0;
}