#include <bits/stdc++.h>
using namespace std;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  for (auto _ : v) os << _ << ", ";
  os << "]";
  return os;
};
template <typename T>
ostream &operator<<(ostream &os, set<T> &st) {
  os << "(";
  for (auto _ : st) {
    os << _ << ", ";
  }
  os << ")";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "{" << p.first << ", " << p.second << "}";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp) {
  os << "[";
  for (auto _ : mp) {
    os << _ << ", ";
  }
  os << "]" << endl;
  return os;
}
void dump_func() { cerr << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
  cerr << head;
  if (sizeof...(Tail) > 0) {
    cerr << ", ";
  }
  dump_func(std::move(tail)...);
}
const int INF = (long long)1e9;
const long long INFLL = (long long)1e18 + 1;
const long long MOD = 1000000007;
const long double PI = acos(-1.0);
struct mint {
  long long x;
  mint(long long _x = 0) : x((_x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint modpow(long long t) const {
    if (!t) return 1;
    mint a = modpow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return modpow(MOD - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
  friend std::ostream &operator<<(std::ostream &os, const mint &a) {
    os << a.x;
    return os;
  }
};
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<mint> dp(4, 0);
  dp[0] = 1;
  for (int i = 0; i < int(N); ++i) {
    vector<mint> nxt(4, 0);
    if (S[i] == '?') {
      for (int _ = 0; _ < int(3); ++_)
        for (int j = 0; j < int(4); ++j) nxt[j] += dp[j];
      nxt[1] += dp[0];
      nxt[2] += dp[1];
      nxt[3] += dp[2];
    } else {
      for (int j = 0; j < int(4); ++j) nxt[j] += dp[j];
      int from = 0;
      if (S[i] == 'b') from += 1;
      if (S[i] == 'c') from += 2;
      nxt[from + 1] += dp[from];
    }
    swap(dp, nxt);
  }
  cout << dp[3] << endl;
}
