#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
long long int n;
string s, abc = "abc";
long long int mod = 1e9 + 7;
long long int dp[200010][5];
long long int go(long long int i, long long int x) {
  if (i == n) {
    return x == 3;
  }
  if (dp[i][x] != -1) return dp[i][x];
  if (s[i] != '?') {
    long long int ans = 0;
    if (x < 3 && s[i] == abc[x]) {
      ans += go(i + 1, x + 1);
      ans %= mod;
    }
    ans += go(i + 1, x);
    return dp[i][x] = ans % mod;
  }
  long long int ans = 0;
  for (long long int ch = 'a'; ch <= 'c'; ch++) {
    if (x < 3 && ch == abc[x]) {
      ans += go(i + 1, x + 1);
      ans %= mod;
    }
    ans += go(i + 1, x);
    ans %= mod;
  }
  return dp[i][x] = ans %= mod;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> s;
  cout << go(0, 0) << "\n";
}
