#include <bits/stdc++.h>
using namespace std;
char s[200002];
int n, a[200002], b[200002], c[200002];
int t3[200002];
int C(int x, int y) {
  if (!y) return x;
  return (1LL * x * t3[y] + 1LL * y * t3[y - 1]) % 1000000007;
}
int main() {
  scanf("%d%s", &n, s + 1);
  for (int i = 1; i <= n; i++) {
    a[i] = a[i - 1] + (s[i] == 'a');
    b[i] = b[i - 1] + (s[i] == '?');
    c[i] = c[i - 1] + (s[i] == 'c');
  }
  t3[0] = 1;
  for (int i = 1; i <= n; i++) t3[i] = t3[i - 1] * 3LL % 1000000007;
  int ans = 0;
  for (int i = 2; i < n; i++) {
    if (s[i] == 'b' || s[i] == '?') {
      ans = (ans + 1LL * C(a[i - 1], b[i - 1]) * C(c[n] - c[i], b[n] - b[i])) %
            1000000007;
    }
  }
  printf("%d\n", ans);
}
