#include <bits/stdc++.h>
using namespace std;
long long C[777][777];
int r, c;
long long total;
long long best = (long long)1e18, best_z = -1;
void dfs(long long x, long long y, int v1, int v2) {
  long long diff = abs(x - y);
  if (best <= 1 || diff - C[v1][r] * C[v2][r] >= best) {
    return;
  }
  if (v1 == r - 1 && v2 == r - 1) {
    long long diff = abs(x - y);
    if (diff < best) {
      best = diff;
      best_z = x;
    }
    return;
  }
  if (v1 >= r) {
    long long cur1 = C[v1][r] - C[v1 - 1][r];
    long long sum2 = C[v2][r];
    dfs(x, y + cur1 * sum2, v1 - 1, v2);
  }
  if (v2 >= r) {
    long long sum1 = C[v1][r];
    long long cur2 = C[v2][r] - C[v2 - 1][r];
    dfs(x + sum1 * cur2, y, v1, v2 - 1);
  }
}
char s[12345];
int cntA[12345], cntB[12345];
map<long long, long long> mp;
long long solve(long long x, long long y, int v1, int v2) {
  long long state = x * 10000 + v1 * 100 + v2;
  if (mp.find(state) != mp.end()) {
    return mp[state];
  }
  long long &res = mp[state];
  long long diff = abs(x - y);
  if (diff - C[v1][r] * C[v2][r] > best) {
    return res = 0;
  }
  if (v1 < r || v2 < r) {
    if (v1 >= cntA[v1 + v2] && v2 >= cntB[v1 + v2]) {
      int sum = v1 + v2;
      v1 -= cntA[sum];
      v2 -= cntB[sum];
      return res = C[v1 + v2][v1];
    }
    return res = 0;
  }
  res = 0;
  char c = s[v1 + v2 - 1];
  if (c != 'B') {
    long long cur1 = C[v1][r] - C[v1 - 1][r];
    long long sum2 = C[v2][r];
    res += solve(x, y + cur1 * sum2, v1 - 1, v2);
  }
  if (c != 'A') {
    long long sum1 = C[v1][r];
    long long cur2 = C[v2][r] - C[v2 - 1][r];
    res += solve(x + sum1 * cur2, y, v1, v2 - 1);
  }
  return res;
}
int main() {
  scanf("%d %d", &r, &c);
  for (int i = 0; i <= 2 * (r + c); i++) {
    for (int j = 0; j <= 2 * (r + c); j++) {
      if (j == 0)
        C[i][j] = 1;
      else if (i == 0)
        C[i][j] = 0;
      else
        C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]);
    }
  }
  total = C[r + c][r] * C[r + c][r];
  {
    long long x = 0, y = 0;
    int v1 = r + c, v2 = r + c;
    while (v1 >= r && v2 >= r) {
      if (x > y) {
        long long cur1 = C[v1][r] - C[v1 - 1][r];
        long long sum2 = C[v2][r];
        y += cur1 * sum2;
        v1--;
      } else {
        long long sum1 = C[v1][r];
        long long cur2 = C[v2][r] - C[v2 - 1][r];
        x += sum1 * cur2;
        v2--;
      }
    }
    best = abs(x - y);
  }
  dfs(0, 0, r + c, r + c);
  scanf("%s", s);
  cntA[0] = cntB[0] = 0;
  for (int i = 0; i < 2 * (r + c); i++) {
    cntA[i + 1] = cntA[i] + (s[i] == 'A');
    cntB[i + 1] = cntB[i] + (s[i] == 'B');
  }
  long long ans = solve(0, 0, r + c, r + c);
  cout << ans << endl;
  return 0;
}

### Prompt

Generate a Cpp solution to the following problem:

The game of Egg Roulette is played between two players. Initially 2R raw eggs and 2C cooked eggs are placed randomly into a carton. The shells are left on so there is no way to distinguish a raw egg from a cooked egg. One at a time, a player will select an egg, and then smash the egg on his/her forehead. If the egg was cooked, not much happens, but if the egg was raw, it will make quite the mess. This continues until one player has broken R raw eggs, at which point that player is declared the loser and the other player wins.

The order in which players take turns can be described as a string of 'A' and 'B' characters, where the i-th character tells which player should choose the i-th egg. Traditionally, players take turns going one after the other. That is, they follow the ordering "ABABAB...". This isn't very fair though, because the second player will win more often than the first. We'd like you to find a better ordering for the players to take their turns. Let's define the unfairness of an ordering as the absolute difference between the first player's win probability and the second player's win probability. We're interested in orderings that minimize the unfairness. We only consider an ordering valid if it contains the same number of 'A's as 'B's.

You will also be given a string S of length 2(R + C) containing only 'A', 'B', and '?' characters. An ordering is said to match S if it only differs from S in positions where S contains a '?'. Of the valid orderings that minimize unfairness, how many match S?

Input

The first line of input will contain integers R and C (1 ≤ R, C ≤ 20, R + C ≤ 30).

The second line of input will contain the string S of length 2(R + C) consisting only of characters 'A', 'B', '?'.

Output

Print the number of valid orderings that minimize unfairness and match S.

Examples

Input

1 1
??BB


Output

0


Input

2 4
?BA??B??A???


Output

1


Input

4 14
????A??BB?????????????AB????????????


Output

314

Note

In the first test case, the minimum unfairness is 0, and the orderings that achieve it are "ABBA" and "BAAB", neither of which match S. Note that an ordering such as "ABBB" would also have an unfairness of 0, but is invalid because it does not contain the same number of 'A's as 'B's.

In the second example, the only matching ordering is "BBAAABABABBA".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long C[777][777];
int r, c;
long long total;
long long best = (long long)1e18, best_z = -1;
void dfs(long long x, long long y, int v1, int v2) {
  long long diff = abs(x - y);
  if (best <= 1 || diff - C[v1][r] * C[v2][r] >= best) {
    return;
  }
  if (v1 == r - 1 && v2 == r - 1) {
    long long diff = abs(x - y);
    if (diff < best) {
      best = diff;
      best_z = x;
    }
    return;
  }
  if (v1 >= r) {
    long long cur1 = C[v1][r] - C[v1 - 1][r];
    long long sum2 = C[v2][r];
    dfs(x, y + cur1 * sum2, v1 - 1, v2);
  }
  if (v2 >= r) {
    long long sum1 = C[v1][r];
    long long cur2 = C[v2][r] - C[v2 - 1][r];
    dfs(x + sum1 * cur2, y, v1, v2 - 1);
  }
}
char s[12345];
int cntA[12345], cntB[12345];
map<long long, long long> mp;
long long solve(long long x, long long y, int v1, int v2) {
  long long state = x * 10000 + v1 * 100 + v2;
  if (mp.find(state) != mp.end()) {
    return mp[state];
  }
  long long &res = mp[state];
  long long diff = abs(x - y);
  if (diff - C[v1][r] * C[v2][r] > best) {
    return res = 0;
  }
  if (v1 < r || v2 < r) {
    if (v1 >= cntA[v1 + v2] && v2 >= cntB[v1 + v2]) {
      int sum = v1 + v2;
      v1 -= cntA[sum];
      v2 -= cntB[sum];
      return res = C[v1 + v2][v1];
    }
    return res = 0;
  }
  res = 0;
  char c = s[v1 + v2 - 1];
  if (c != 'B') {
    long long cur1 = C[v1][r] - C[v1 - 1][r];
    long long sum2 = C[v2][r];
    res += solve(x, y + cur1 * sum2, v1 - 1, v2);
  }
  if (c != 'A') {
    long long sum1 = C[v1][r];
    long long cur2 = C[v2][r] - C[v2 - 1][r];
    res += solve(x + sum1 * cur2, y, v1, v2 - 1);
  }
  return res;
}
int main() {
  scanf("%d %d", &r, &c);
  for (int i = 0; i <= 2 * (r + c); i++) {
    for (int j = 0; j <= 2 * (r + c); j++) {
      if (j == 0)
        C[i][j] = 1;
      else if (i == 0)
        C[i][j] = 0;
      else
        C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]);
    }
  }
  total = C[r + c][r] * C[r + c][r];
  {
    long long x = 0, y = 0;
    int v1 = r + c, v2 = r + c;
    while (v1 >= r && v2 >= r) {
      if (x > y) {
        long long cur1 = C[v1][r] - C[v1 - 1][r];
        long long sum2 = C[v2][r];
        y += cur1 * sum2;
        v1--;
      } else {
        long long sum1 = C[v1][r];
        long long cur2 = C[v2][r] - C[v2 - 1][r];
        x += sum1 * cur2;
        v2--;
      }
    }
    best = abs(x - y);
  }
  dfs(0, 0, r + c, r + c);
  scanf("%s", s);
  cntA[0] = cntB[0] = 0;
  for (int i = 0; i < 2 * (r + c); i++) {
    cntA[i + 1] = cntA[i] + (s[i] == 'A');
    cntB[i + 1] = cntB[i] + (s[i] == 'B');
  }
  long long ans = solve(0, 0, r + c, r + c);
  cout << ans << endl;
  return 0;
}

```