#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
char s[200005];
int main() {
  int n;
  scanf("%d%s", &n, s + 1);
  long long way[4] = {1, 0, 0, 0};
  for (int i = 1; i <= n; i++) {
    if (s[i] == '?') {
      long long sum[4] = {0, 0, 0, 0};
      for (int j = 1; j <= 3; j++) {
        long long next[4] = {way[0], way[1], way[2], way[3]};
        next[j] += next[j - 1];
        if (next[j] >= mod) next[j] -= mod;
        for (int k = 0; k < 4; k++) {
          sum[k] += next[k];
          if (sum[k] >= mod) sum[k] -= mod;
        }
      }
      for (int j = 0; j < 4; j++) way[j] = sum[j];
    } else {
      if (s[i] == 'a') {
        way[1] += way[0];
        if (way[1] >= mod) way[1] -= mod;
      } else if (s[i] == 'b') {
        way[2] += way[1];
        if (way[2] >= mod) way[2] -= mod;
      } else {
        way[3] += way[2];
        if (way[3] >= mod) way[3] -= mod;
      }
    }
  }
  printf("%lld\n", way[3]);
  return 0;
}
