#include <bits/stdc++.h>

using namespace std;

long long n,z=0,c=0,a[100069],e;
map<long long,bool> fq;

int main()
{
	long long i,k;

	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",a+i);
		fq[a[i]]++;
		if(fq[a[i]]>1)
		{
			e=a[i];
			c++;
			if(c>1)
			{
				printf("cslnb\n");
				return 0;
			}
		}
		z+=k;
	}
	if(fq[e-1]==1)
	{
		printf("cslnb\n");
		return 0;
	}
	if((z-n*(n-1)/2)%2==0)
	{
		printf("cslnb\n");
	}
	else
	{
		printf("sjfnb\n");
	}
}


#include <bits/stdc++.h>

using namespace std;

long long n,z=0,c=0,a[100069],e;
map<long long,bool> fq;

int main()
{
	long long i;

	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",a+i);
		fq[a[i]]++;
		if(fq[a[i]]>1)
		{
			e=a[i];
			c++;
			if(c>1)
			{
				printf("cslnb\n");
				return 0;
			}
		}
		z+=a[i];
	}
	if(c&&fq[e-1]==1)
	{
		printf("cslnb\n");
		return 0;
	}
	if((z-n*(n-1)/2)%2==0)
	{
		printf("cslnb\n");
	}
	else
	{
		printf("sjfnb\n");
	}
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef long double ld;
template<class T>
void PR_VEC(const vector<T> &vec){
    cout<<"size("<<vec.size()<<"):[ '";
    if(vec.size()==0) {
        cout<<"!EMPTY!' ]\n";
        return;
    }
    cout<<vec[0]<<"'";
    for(int i=1;i<vec.size();++i) cout<<" , '"<<vec[i]<<"'";
    cout<<" ]\n";
}
const ll INFll = 8e18;
const int INFint = 2e9;
const ll MOD = 1e9 + 7  ;
void needForSpeed(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
bool isPrime(ll a){if(a<2)return 0;for(ll i=2;i<=sqrt(a);i++)if(a%i==0) return 0;return 1;}
ll binpow(ll base, ll pow, ll mod=MOD){
    if(pow==0) return 1;
    else if(pow%2) return base*binpow(base,pow-1,mod)%mod;
    else{
        ll p = binpow(base,pow/2LL,mod);
        return p*p%mod;
    }
}

int solve(){
    int n;cin>>n;
    map<int,int> cnt;
    vector<int> a;
    ll sum=0;
    int last = -1;
    while(n--){
        int x;cin>>x;
        a.push_back(x);
        ++cnt[x];
        if(cnt[x]>2) return cout<<"cslnb",0;
        if(cnt[x]>1){
            if(x==0) return cout<<"cslnb",0;
            else{
                if(last == -1) last = x;
                else{
                    if(last != x) return cout<<"cslnb",0;
                }
            }
        }
    }
    for(auto jek:cnt){
        if(cnt.count(jek.first-1)){
            if(jek.second>1) return cout<<"cslnb",0;
        }
    }
    sort(a.begin(),a.end());
    for(int i=0; i<n; ++i){
        sum+= a[i] - i;
    }
    if(sum%2) return cout<<"sjfnb",0;
    else return cout<<"cslnb",0;
    return 0;
}

int main(){
    needForSpeed();
    int tests=1;
    //cin>>tests;
    while (tests--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef long double ld;
template<class T>
void PR_VEC(const vector<T> &vec){
    cout<<"size("<<vec.size()<<"):[ '";
    if(vec.size()==0) {
        cout<<"!EMPTY!' ]\n";
        return;
    }
    cout<<vec[0]<<"'";
    for(int i=1;i<vec.size();++i) cout<<" , '"<<vec[i]<<"'";
    cout<<" ]\n";
}
const ll INFll = 8e18;
const int INFint = 2e9;
const ll MOD = 1e9 + 7  ;
void needForSpeed(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
bool isPrime(ll a){if(a<2)return 0;for(ll i=2;i<=sqrt(a);i++)if(a%i==0) return 0;return 1;}
ll binpow(ll base, ll pow, ll mod=MOD){
    if(pow==0) return 1;
    else if(pow%2) return base*binpow(base,pow-1,mod)%mod;
    else{
        ll p = binpow(base,pow/2LL,mod);
        return p*p%mod;
    }
}

int solve(){
    int n;cin>>n;
    map<int,int> cnt;
    vector<int> a;
    ll sum=0;
    int last = -1;
    while(n--){
        int x;cin>>x;
        a.push_back(x);
        ++cnt[x];
        if(cnt[x]>2) return cout<<"cslnb",0;
        if(cnt[x]>1){
            if(x==0) return cout<<"cslnb",0;
            else{
                if(last == -1) last = x;
                else{
                    if(last != x) return cout<<"cslnb",0;
                }
            }
        }
    }
    for(auto jek:cnt){
        if(cnt.count(jek.first-1)){
            if(jek.second>1) return cout<<"cslnb",0;
        }
    }
    sort(a.begin(),a.end());
    for(int i=0; i<(int)a.size(); ++i){
        sum+= a[i] - i;
    }
    if(sum%2) return cout<<"sjfnb",0;
    else return cout<<"cslnb",0;
    return 0;
}

int main(){
    needForSpeed();
    int tests=1;
    //cin>>tests;
    while (tests--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef long double ld;
template<class T>
void PR_VEC(const vector<T> &vec){
    cout<<"size("<<vec.size()<<"):[ '";
    if(vec.size()==0) {
        cout<<"!EMPTY!' ]\n";
        return;
    }
    cout<<vec[0]<<"'";
    for(int i=1;i<vec.size();++i) cout<<" , '"<<vec[i]<<"'";
    cout<<" ]\n";
}
const ll INFll = 8e18;
const int INFint = 2e9;
const ll MOD = 1e9 + 7  ;
void needForSpeed(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
bool isPrime(ll a){if(a<2)return 0;for(ll i=2;i<=sqrt(a);i++)if(a%i==0) return 0;return 1;}
ll binpow(ll base, ll pow, ll mod=MOD){
    if(pow==0) return 1;
    else if(pow%2) return base*binpow(base,pow-1,mod)%mod;
    else{
        ll p = binpow(base,pow/2LL,mod);
        return p*p%mod;
    }
}

int solve(){
    int n;cin>>n;
    map<int,int> cnt;
    ll sum=0;
    int last = -1;
    while(n--){
        int x;cin>>x;
        sum+=x;
        ++cnt[x];
        if(cnt[x]>2) return cout<<"cslnb",0;
        if(cnt[x]>1){
            if(x==0) return cout<<"cslnb",0;
            else{
                if(last == -1) last = x;
                else{
                    if(last != x) return cout<<"cslnb",0;
                }
            }
        }
    }
    for(auto jek:cnt){
        if(cnt.count(jek.first-1)){
            if(jek.second>1) return cout<<"cslnb",0;
        }
    }
    if(sum%2) return cout<<"cslnb",0;
    else return cout<<"sjfnb",0;
    return 0;
}

int main(){
    needForSpeed();
    int tests=1;
    //cin>>tests;
    while (tests--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef long double ld;
template<class T>
void PR_VEC(const vector<T> &vec){
    cout<<"size("<<vec.size()<<"):[ '";
    if(vec.size()==0) {
        cout<<"!EMPTY!' ]\n";
        return;
    }
    cout<<vec[0]<<"'";
    for(int i=1;i<vec.size();++i) cout<<" , '"<<vec[i]<<"'";
    cout<<" ]\n";
}
const ll INFll = 8e18;
const int INFint = 2e9;
const ll MOD = 1e9 + 7  ;
void needForSpeed(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
bool isPrime(ll a){if(a<2)return 0;for(ll i=2;i<=sqrt(a);i++)if(a%i==0) return 0;return 1;}
ll binpow(ll base, ll pow, ll mod=MOD){
    if(pow==0) return 1;
    else if(pow%2) return base*binpow(base,pow-1,mod)%mod;
    else{
        ll p = binpow(base,pow/2LL,mod);
        return p*p%mod;
    }
}

int solve(){
    int n;cin>>n;
    map<int,int> cnt;
    ll sum=0;
    int last = -1;
    while(n--){
        int x;cin>>x;
        sum+=x;
        ++cnt[x];
        if(cnt[x]>2) return cout<<"cslnb",0;
        if(cnt[x]>1){
            if(x==0) return cout<<"cslnb",0;
            else{
                if(last == -1) last = x;
                else{
                    if(last != x) return cout<<"cslnb",0;
                }
            }
        }
    }
    for(auto jek:cnt){
        if(cnt.count(jek.first-1)){
            if(jek.second>1) return cout<<"cslnb",0;
        }
    }
    if(sum%2) return cout<<"sjfnb",0;
    else return cout<<"cslnb",0;
    return 0;
}

int main(){
    needForSpeed();
    int tests=1;
    //cin>>tests;
    while (tests--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define MAXN 100000
using namespace std;

int n, a, sum;
map <int, int> appr;
int tf = 2;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    appr[a]++;
    sum += a;
  }
  if (n == 1 && a == 0) tf = 0;
  if (appr[0] >= 2 || (appr[1] == 2 && appr[0] == 1)) tf = 0;
  for (auto i : appr) {
    if (i.second >= 3) tf = 0;
    if (i.second == 2) tf--;
  }
  if ((sum - n*(n-1)/2)%2 == 0) tf = 0;
  if (tf > 0) cout << "sjfnb" << endl;
  else cout << "cslnb" << endl;
  return 0;
}


#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define MAXN 100000
using namespace std;

int n, a, sum;
map <int, int> appr;
int tf = 2;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    appr[a]++;
    sum += a;
  }
  if (n == 1 && a == 0) tf = 0;
  if (appr[0] >= 2) tf = 0;
  for (auto i : appr) {
    if (i.second >= 3) tf = 0;
    if (i.second == 2) tf--;
    if (i.second == 2 && appr[i.first-1] == 1) tf = 0;
  }
  if ((sum - n*(n-1)/2)%2 == 0) tf = 0;
  if (tf > 0) cout << "sjfnb" << endl;
  else cout << "cslnb" << endl;
  return 0;
}


#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define MAXN 100000
using namespace std;

int n, a, sum;
map <int, int> appr;
int tf = 2;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    appr[a]++;
    sum += a;
  }
  if (n == 1 && a == 0) tf = 0;
  if (appr[0] >= 2) tf = 0;
  for (auto i : appr) {
    if (i.second >= 3) tf = 0;
    if (i.second == 2) tf--;
    if (i.second == 2 && appr[i.first] == 1) tf = 0;
  }
  if ((sum - n*(n-1)/2)%2 == 0) tf = 0;
  if (tf > 0) cout << "sjfnb" << endl;
  else cout << "cslnb" << endl;
  return 0;
}


#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define MAXN 100000
using namespace std;

int n, a, sum;
map <int, int> appr;
int tf = 2;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    appr[a]++;
    sum += a;
  }
  if (n == 1 && a == 0) tf = 0;
  for (auto i : appr) {
    if (i.second >= 3) tf = 0;
    if (i.second == 2) tf--;
    if (i.second == 2 && appr[i.first] == 1) tf = 0;
  }
  if ((sum - n*(n-1)/2)%2 == 0) tf = 0;
  if (tf > 0) cout << "sjfnb" << endl;
  else cout << "cslnb" << endl;
  return 0;
}


#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define MAXN 100000
using namespace std;

int n, a, sum;
map <int, int> appr;
int tf = 2;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    appr[a] = 1;
    sum += a;
  }
  if (n == 1 && a == 0) tf = 0;
  if (appr[0] >= 2 || (appr[1] == 2 && appr[0] == 1)) tf = 0;
  for (auto i : appr) {
    if (i.second >= 3) tf = 0;
    if (i.second == 2) tf--;
  }
  if ((sum - n*(n-1)/2)%2 == 0) tf = 0;
  if (tf) cout << "sjfnb" << endl;
  else cout << "cslnb" << endl;
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=100005;

int n;
int a[maxn];
int g[maxn];
int g1[maxn];
int main(){
    ios::sync_with_stdio(0);
    cin>>n;
    long long sm=0;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        if(a[i-1])g[i]=g[i-1]+1;
        sm+=a[i];
    }
    for(int i=1;i<=n;i++) g1[i]=g[i-1];
    long long ocn=0,ocn1=0;
    int sc=0;
    for(int i=1;i<=n;i++){
        ocn+=a[i]-g[i];
        ocn1+=a[i]-g1[i];
    }
    for(int i=2;i<=n;i++){
        if(a[i]==a[i-1]) sc++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]!=0&&a[i]!=a[i-1]){
            a[i]--;
            long long cnt=0;
            if(a[i]==0) cnt=ocn1;
            else cnt=ocn;
            if(a[i]+1==a[i+1]&&i!=n) sc--;
            if(a[i]==a[i-1]&&i!=1) sc++;
            //cnt--;
            if(sc){
            	a[i]++;
                continue;
            }
            if(cnt&1){
                cout<<"sjfnb";
                return 0;
            }
            a[i]++;
        }
    }
    cout<<"cslnb";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=100005;

int n;
int a[maxn];
int g[maxn];
int g1[maxn];
int main(){
    ios::sync_with_stdio(0);
    cin>>n;
    long long sm=0;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    g[0]=-1;
    for(int i=1;i<=n;i++){
        g[i]=g[i-1]+1;
        sm+=a[i];
    }
    for(int i=1;i<=n;i++) g1[i]=g[i-1];
    long long ocn=0,ocn1=0;
    int sc=0;
    for(int i=1;i<=n;i++){
        ocn+=a[i]-g[i];
        ocn1+=a[i]-g1[i];
    }
    for(int i=2;i<=n;i++){
        if(a[i]==a[i-1]) sc++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]!=0&&a[i]!=a[i-1]){
            a[i]--;
            long long cnt=ocn;
            if(a[i]+1==a[i+1]&&i!=n) sc--;
            if(a[i]==a[i-1]&&i!=1) sc++;
            cnt--;
            if(sc){
            	a[i]++;
                continue;
            }
            if(cnt%2==0){
                cout<<"sjfnb";
                return 0;
            }
            a[i]++;
        }
    }
    cout<<"cslnb";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=100005;

int n;
int a[maxn];
int g[maxn];
int g1[maxn];
int main(){
    ios::sync_with_stdio(0);
    cin>>n;
    long long sm=0;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        if(a[i])g[i]=g[i-1]+1;
        sm+=a[i];
    }
    for(int i=1;i<=n;i++) g1[i]=g[i-1];
    long long ocn=0,ocn1;
    int sc=0;
    for(int i=1;i<=n;i++){
        ocn+=a[i]-g[i];
        ocn1+=a[i]-g1[i];
    }
    for(int i=2;i<=n;i++){
        if(a[i]==a[i-1]) sc++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]!=0&&a[i]!=a[i-1]){
            a[i]--;
            long long cnt=0;
            if(a[i]==0) cnt=ocn1;
            else cnt=ocn;
            if(a[i]+1==a[i+1]&&i!=n) sc--;
            if(a[i]==a[i-1]&&i!=1) sc++;
            //cnt--;
            if(sc||sm==1){
                continue;
            }
            if(cnt&1){
                cout<<"sjfnb";
                return 0;
            }
            a[i]++;
        }
    }
    cout<<"cslnb";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=100005;

int n;
int a[maxn];
int g[maxn];
int g1[maxn];
int main(){
    ios::sync_with_stdio(0);
    cin>>n;
    long long sm=0;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        if(a[i])g[i]=g[i-1]+1;
        sm+=a[i];
    }
    for(int i=1;i<=n;i++) g1[i]=g[i-1];
    long long ocn=0,ocn1=0;
    int sc=0;
    for(int i=1;i<=n;i++){
        ocn+=a[i]-g[i];
        ocn1+=a[i]-g1[i];
    }
    for(int i=2;i<=n;i++){
        if(a[i]==a[i-1]) sc++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]!=0&&a[i]!=a[i-1]){
            a[i]--;
            long long cnt=0;
            if(a[i]==0) cnt=ocn1;
            else cnt=ocn;
            if(a[i]+1==a[i+1]&&i!=n) sc--;
            if(a[i]==a[i-1]&&i!=1) sc++;
            //cnt--;
            if(sc){
            	a[i]++;
                continue;
            }
            if(cnt&1){
                cout<<"sjfnb";
                return 0;
            }
            a[i]++;
        }
    }
    cout<<"cslnb";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=100005;

int n;
int a[maxn];
int g[maxn];
int g1[maxn];
int main(){
    ios::sync_with_stdio(0);
    cin>>n;
    long long sm=0;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        if(a[i-1])g[i]=g[i-1]+1;
        sm+=a[i];
    }
    for(int i=1;i<=n;i++) g1[i]=g[i-1];
    long long ocn=0,ocn1=0;
    int sc=0;
    for(int i=1;i<=n;i++){
        ocn+=a[i]-g[i];
        ocn1+=a[i]-g1[i];
    }
    for(int i=2;i<=n;i++){
        if(a[i]==a[i-1]) sc++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]!=0&&a[i]!=a[i-1]){
            a[i]--;
            long long cnt=0;
            if(a[i]==0) cnt=ocn1;
            else cnt=ocn;
            if(a[i]+1==a[i+1]&&i!=n) sc--;
            if(a[i]==a[i-1]&&i!=1) sc++;
            //cnt--;
            if(sc||sm==1){
            	a[i]++;
                continue;
            }
            if(cnt&1){
                cout<<"sjfnb";
                return 0;
            }
            a[i]++;
        }
    }
    cout<<"cslnb";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=100005;

int n;
int a[maxn];
int g[maxn];
int g1[maxn];
int main(){
    ios::sync_with_stdio(0);
    cin>>n;
    long long sm=0;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    g[0]=-1;
    for(int i=1;i<=n;i++){
        g[i]=g[i-1]+1;
        sm+=a[i];
    }
    long long ocn=0;
    int sc=0;
    for(int i=1;i<=n;i++){
        ocn+=a[i]-g[i];
    }
    for(int i=2;i<=n;i++){
        if(a[i]==a[i-1]) sc++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]!=0&&a[i]!=a[i-1]){
            long long cnt=ocn;
            int nsc=sc;
            if(a[i]==a[i+1]&&i!=n) nsc--;
            if(a[i]-1==a[i-1]&&i!=1) nsc++;
            cnt--;
            if(nsc){
                continue;
            }
            if(cnt%2==0){
                cout<<"sjfnb";
                return 0;
            }
        }
    }
    cout<<"cslnb";
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include <iomanip>
using namespace std;
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define gap ' '
#define abs(x) ((x)>0?(x):-(x))
#define INF 1e18
#define mod  1000000007
ll powr(ll m,ll n)
{
    if(m==1)
        return 1;
    if(n==0)
        return 1;
    if(n==1)
        return m%mod;
    if(n%2)
    {
        ll te=powr(m,n/2);
        return (((te*te)%mod)*(m%mod))%mod;
    }
    else
    {
        ll te=powr(m,n/2);
        return (te*te)%mod;
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1;
    //cin>>tc;
    while(tc--)
    {
      int n;
      cin>>n;
      ll a[n];
      for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int cnt=0;
    for(int i=1;i<n;i++)
        if(a[i]==a[i-1])
        cnt++;
    if(cnt>1)
    {
        cout<<"cslnb";
    }
    else
    {
        if(cnt==1)
        {
            for(int i=1;i<n;i++)
        if(a[i]==a[i-1])
        {
            a[i-1]--;
            break;
        }
        }
        ll sum=0;
        for(int i=0;i<n;i++)
            sum+=(a[i]-i);
        if(cnt==1 && sum%2==1)
            cout<<"cslnb";
        else if(sum%2==1)
            cout<<"sjfnb";
        else if(cnt==1 && sum%2==0)
            cout<<"sjfnb";
        else cout<<"cslnb";

    }

    }

}


#include<bits/stdc++.h>
#include<iostream>
#include <iomanip>
using namespace std;
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define gap ' '
#define abs(x) ((x)>0?(x):-(x))
#define INF 1e18
#define mod  1000000007
ll powr(ll m,ll n)
{
    if(m==1)
        return 1;
    if(n==0)
        return 1;
    if(n==1)
        return m%mod;
    if(n%2)
    {
        ll te=powr(m,n/2);
        return (((te*te)%mod)*(m%mod))%mod;
    }
    else
    {
        ll te=powr(m,n/2);
        return (te*te)%mod;
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1;
    //cin>>tc;
    while(tc--)
    {
      int n;
      cin>>n;
      ll a[n];
      for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int cnt=0;
    for(int i=1;i<n;i++)
        if(a[i]==a[i-1])
        cnt++;
    if(cnt>1)
    {
        cout<<"sjfnb";
    }
    else
    {
        if(cnt==1)
        {
            for(int i=1;i<n;i++)
        if(a[i]==a[i-1])
        {
            a[i-1]--;
            break;
        }
        }
        ll sum=0;
        for(int i=0;i<n;i++)
            sum+=(a[i]-i);
        if(cnt==1 && sum%2==1)
            cout<<"cslnb";
        else if(sum%2==1)
            cout<<"sjfnb";
        else if(cnt==1 && sum%2==0)
            cout<<"sjfnb";
        else cout<<"cslnb";

    }

    }

}


#include<bits/stdc++.h>
#include<iostream>
#include <iomanip>
using namespace std;
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define gap ' '
#define abs(x) ((x)>0?(x):-(x))
#define INF 1e18
#define mod  1000000007
ll powr(ll m,ll n)
{
    if(m==1)
        return 1;
    if(n==0)
        return 1;
    if(n==1)
        return m%mod;
    if(n%2)
    {
        ll te=powr(m,n/2);
        return (((te*te)%mod)*(m%mod))%mod;
    }
    else
    {
        ll te=powr(m,n/2);
        return (te*te)%mod;
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1;
    //cin>>tc;
    while(tc--)
    {
      int n;
      cin>>n;
      ll a[n];
      for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int cnt=0;
    for(int i=1;i<n;i++)
        if(a[i]==a[i-1])
        cnt++;
    if(cnt>1)
    {
        cout<<"cslnb";
    }
    else
    {
        int i=0;
        if(cnt==1)
        {
            for(i=1;i<n;i++)
        if(a[i]==a[i-1])
        {
            if(a[i-1]==0)
            {
                cout<<"cslnb";
                return 0;
            }
            a[i-1]--;
            break;
        }
        if(i-2>=0 && a[i-1]==a[i-2])
        {
            cout<<"cslnb";
                return 0;
        }
        }
        ll sum=0;
        for(int i=0;i<n;i++)
            sum+=(a[i]-i);
        if(cnt==1 && sum%2==1)
            cout<<"cslnb";
        else if(sum%2==1)
            cout<<"sjfnb";
        else if(cnt==1 && sum%2==0)
            cout<<"sjfnb";
        else cout<<"cslnb";

    }

    }

}


#include<bits/stdc++.h>
#include<iostream>
#include <iomanip>
using namespace std;
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define gap ' '
#define abs(x) ((x)>0?(x):-(x))
#define INF 1e18
#define mod  1000000007
ll powr(ll m,ll n)
{
    if(m==1)
        return 1;
    if(n==0)
        return 1;
    if(n==1)
        return m%mod;
    if(n%2)
    {
        ll te=powr(m,n/2);
        return (((te*te)%mod)*(m%mod))%mod;
    }
    else
    {
        ll te=powr(m,n/2);
        return (te*te)%mod;
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1;
    //cin>>tc;
    while(tc--)
    {
      int n;
      cin>>n;
      ll a[n];
      for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int cnt=0;
    for(int i=1;i<n;i++)
        if(a[i]==a[i-1])
        cnt++;
    if(cnt>1)
    {
        cout<<"cslnb";
    }
    else
    {
        if(cnt==1)
        {
            for(int i=1;i<n;i++)
        if(a[i]==a[i-1])
        {
            if(a[i-1]==0)
            {
                cout<<"cslnb";
                return 0;
            }
            a[i-1]--;
            break;
        }
        }
        ll sum=0;
        for(int i=0;i<n;i++)
            sum+=(a[i]-i);
        if(cnt==1 && sum%2==1)
            cout<<"cslnb";
        else if(sum%2==1)
            cout<<"sjfnb";
        else if(cnt==1 && sum%2==0)
            cout<<"sjfnb";
        else cout<<"cslnb";

    }

    }

}


#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
long long n,q,ans,w[N]; map<int,int>s;
signed main(){
	cin>>n; for(int i=1;i<=n;i++) scanf("%lld",&w[i]),ans=ans+w[i]; int cnt=0;
	for(int i=1;i<=n;i++) cnt+=s[w[i]],s[w[i]]++;
	for(int i=1;i<=n;i++) if(s[w[i]]==2) q=w[i];
	if(cnt>1) {puts("cslnb"); return 0;}
	if(cnt==1){
		if(s[q-1]){
			puts("cslnb");
			return 0;
		}
	}
	if(s[0]>=2){
		puts("sjfnb"); return 0;
	}

	ans=ans-n*(n-1)/2; if(ans&1) puts("sjfnb"); else puts("cslnb");
	return 0;
}
//5
//0 1 1 2 3


#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
long long n,q,ans,w[N]; map<int,int>s;
signed main(){
	cin>>n; for(int i=1;i<=n;i++) scanf("%lld",&w[i]),ans=ans+w[i]; int cnt=0;
	for(int i=1;i<=n;i++) cnt+=s[w[i]],s[w[i]]++;
	for(int i=1;i<=n;i++) if(s[w[i]]==2) q=w[i];
	if(cnt>1) {puts("cslnb"); return 0;}
	if(cnt==1){
		if(s[q-1]){
			puts("cslnb");
			return 0;
		}
	}
	if(s[0]>=2){
		puts("cslnb"); return 0;
	}

	ans=ans-n*(n-1)/2; if(ans&1) puts("sjfnb"); else puts("cslnb");
	return 0;
}
//5
//0 1 1 2 3


#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
long long n,q,ans,w[N]; map<int,int>s;
signed main(){
	cin>>n; for(int i=1;i<=n;i++) scanf("%lld",&w[i]),ans=ans+w[i]; int cnt=0;
	for(int i=1;i<=n;i++) cnt+=s[w[i]],s[w[i]]++;
	for(int i=1;i<=n;i++) if(s[w[i]]==2) q=w[i];
	if(cnt>1) {puts("sjfnb"); return 0;}
	if(cnt==1){
		if(s[q-1]){
			puts("sjfnb");
			return 0;
		}
	}
	if(s[0]>=2){
		puts("sjfnb"); return 0;
	}
	ans=ans-n*(n-1)/2; if(ans&1) puts("sjfnb"); else puts("cslnb");
	return 0;
}
//3
//1 1 4


#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
long long n,q,ans,w[N]; map<int,int>s;
signed main(){
	cin>>n; for(int i=1;i<=n;i++) scanf("%lld",&w[i]),ans=ans+w[i]; int cnt=0;
	for(int i=1;i<=n;i++) cnt+=s[w[i]],s[w[i]]++;
	for(int i=1;i<=n;i++) if(s[w[i]]==2) q=w[i];
	if(cnt>1) {puts("sjfnb"); return 0;}
	if(cnt==1){
		if(s[q]){
			puts("sjfnb");
			return 0;
		}
	}
	ans=ans-n*(n-1)/2; if(ans&1) puts("sjfnb"); else puts("cslnb");
	return 0;
}
//3
//1 1 1


#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
long long n,q,ans,w[N]; map<int,int>s;
signed main(){
	cin>>n; for(int i=1;i<=n;i++) scanf("%lld",&w[i]),ans=ans+w[i]; int cnt=0;
	for(int i=1;i<=n;i++) cnt+=s[w[i]],s[w[i]]++;
	for(int i=1;i<=n;i++) if(s[w[i]]==2) q=w[i];
	if(cnt>1) {puts("sjfnb"); return 0;}
	if(cnt==1){
		if(s[q]){
			puts("sjfnb");
			return 0;
		}
	}
	if(s[0]>=2){
		puts("sjfnb"); return 0;
	}
	ans=ans-n*(n-1)/2; if(ans&1) puts("sjfnb"); else puts("cslnb");
	return 0;
}
//3
//1 1 1


#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
long long n,ans,w[N]; map<int,int>s;
signed main(){
	cin>>n; for(int i=1;i<=n;i++) scanf("%lld",&w[i]),ans=ans+w[i]; int cnt=0;
	for(int i=1;i<=n;i++) cnt+=s[w[i]],s[w[i]]++;
	if(cnt>1) {puts("sjfnb"); return 0;}
	ans=ans-n*(n-1)/2; if(ans&1) puts("sjfnb"); else puts("cslnb");
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[100005];
    long long sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    if(sum<=1)
    {
        cout<<"cslnb"<<endl;
        return 0;
    }
    if(n==1)
    {
        if(a[0]%2==0)
        {
            cout<<"sjfnb"<<endl;
            return 0;
        }
        else
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
    }
    sort(a,a+n);
    int s=0;
    if(a[0]==a[1] ) s++;
    for(int i=1;i<n;i++)
    {
        if( a[i]==0 )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if( a[i]==a[i-1] && a[i]==a[i+1] )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if(a[i]==a[i+1] && a[i-1]==a[i]-1 )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if(a[i]==a[i+1]) s++;
        if(s>=2)
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
    }
    int l=sum- (n-1)*n/2;
    if( l%2==0 )
    {
        cout<<"cslnb"<<endl;
        return 0;
    }
    else
    {
        cout<<"sjfnb"<<endl;
        return 0;
    }
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[100005];
    long long sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    if(sum==0)
    {
         cout<<"cslnb"<<endl;
            return 0;
    }
    if(n==1)
    {
        if(a[0]%2==0)
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        else
        {

            cout<<"sjfnb"<<endl;

            return 0;
        }
    }
    if(sum<=1)
    {
        cout<<"cslnb"<<endl;
        return 0;
    }

    sort(a,a+n);
    int s=0;
    if(a[0]==a[1] ) s++;
    for(int i=1;i<n;i++)
    {
        if( a[i]==0 )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if( a[i]==a[i-1] && a[i]==a[i+1] )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if(a[i]==a[i+1] && a[i-1]==a[i]-1 )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if(a[i]==a[i+1]) s++;
        if(s>=2)
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
    }
    int l=sum- (n-1)*n/2;
    if( l%2==0 )
    {
        cout<<"cslnb"<<endl;
        return 0;
    }
    else
    {
        cout<<"sjfnb"<<endl;
        return 0;
    }
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[100005];
    long long sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    if(n==1)
    {
        if(a[0]%2==0)
        {
            cout<<"sjfnb"<<endl;
            return 0;
        }
        else
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
    }
    if(sum<=1)
    {
        cout<<"cslnb"<<endl;
        return 0;
    }

    sort(a,a+n);
    int s=0;
    if(a[0]==a[1] ) s++;
    for(int i=1;i<n;i++)
    {
        if( a[i]==0 )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if( a[i]==a[i-1] && a[i]==a[i+1] )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if(a[i]==a[i+1] && a[i-1]==a[i]-1 )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if(a[i]==a[i+1]) s++;
        if(s>=2)
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
    }
    int l=sum- (n-1)*n/2;
    if( l%2==0 )
    {
        cout<<"cslnb"<<endl;
        return 0;
    }
    else
    {
        cout<<"sjfnb"<<endl;
        return 0;
    }
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[100005];
    long long sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    if(sum==0)
    {
         cout<<"cslnb"<<endl;
            return 0;
    }
    if(n==1)
    {
        if(a[0]%2==0)
        {
            cout<<"sjfnb"<<endl;
            return 0;
        }
        else
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
    }
    if(sum<=1)
    {
        cout<<"cslnb"<<endl;
        return 0;
    }

    sort(a,a+n);
    int s=0;
    if(a[0]==a[1] ) s++;
    for(int i=1;i<n;i++)
    {
        if( a[i]==0 )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if( a[i]==a[i-1] && a[i]==a[i+1] )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if(a[i]==a[i+1] && a[i-1]==a[i]-1 )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if(a[i]==a[i+1]) s++;
        if(s>=2)
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
    }
    int l=sum- (n-1)*n/2;
    if( l%2==0 )
    {
        cout<<"cslnb"<<endl;
        return 0;
    }
    else
    {
        cout<<"sjfnb"<<endl;
        return 0;
    }
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[100005];
    long long sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    if(sum<=1)
    {
        cout<<"cslnb"<<endl;
        return 0;
    }
    if(n==1)
    {
        if(a[0]%2==0)
        {
            cout<<"sjfnb"<<endl;
            return 0;
        }
        else
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
    }a
    sort(a,a+n);
    int s=0;
    if(a[0]==a[1] ) s++;
    for(int i=1;i<n;i++)
    {
        if( a[i]==0 )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if( a[i]==a[i-1] && a[i]==a[i+1] )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if(a[i]==a[i+1] && a[i-1]==a[i]-1 )
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
        if(a[i]==a[i+1]) s++;
        if(s>=2)
        {
            cout<<"cslnb"<<endl;
            return 0;
        }
    }
    int l=sum- (n-1)*n/2;
    if( l%2==0 )
    {
        cout<<"cslnb"<<endl;
        return 0;
    }
    else
    {
        cout<<"sjfnb"<<endl;
        return 0;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<algorithm>
#define maxn 1000100

using namespace std;

int n,a[maxn],tot,cnt,js;

int main(){
	scanf("%d",&n);
//	if(n==1 &&a[1]==0){
//		cout<<"cslnb";
//	    return 0;
//	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		tot+=a[i];
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		if(a[i]==a[i+1]) js++;
	}
	if(js>=2){
		cout<<"cslnb";//有两堆以上一样的时后手必赢
	}
	if(js==1){
		for(int i=1;i<=n;i++){
			if((a[i]==a[i+1] &&a[i-1]+1==a[i]) ||(a[i]==a[i+1] &&a[i]==0)) cout<<"cslnb";//此时先手无所下手，后手赢
		}
	}
//	if(n==2 &&((a[1]==1&&a[2]==0) ||(a[2]==1 &&a[1]==0))){
//		cout<<"sjfnb";
//		return 0;
//	}
	for(int i=0;i<=n-1;i++){
		cnt+=i;
	}
	if((tot-cnt)%2==0) cout<<"cslnb";
	else cout<<"sjfnb";
	return 0;
}


#include <cstdio>
#include <map>
#include <algorithm>
#define MAXN 100005
#define Int register int
using namespace std;
inline void read(int &x)
{
	x = 0;
	int f = 1;
	char s = getchar();
	while (s < '0' || s > '9')
	{
		if (s == '-')
			f = -1;
		s = getchar();
	}
	while (s >= '0' && s <= '9')
	{
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getchar();
	}
	x *= f;
}
map<int, int> M;
int main()
{
	int n;
	read( n );
	bool flag = 0;
	int Big = 0;
	long long Sum = 0;
	for (Int i = 1; i <= n; ++ i)
	{
		int a;
		read( a );
		Sum += a;
		M[a] ++;
		if (M[a] == 2 && ! a)
			return !printf("sjfnb");
		if (M[a] == 3)
			flag = 1;
		if (M[a] == 2)
			Big ++;
		if (M[a] >= 2 && M[a - 1] >= 1)
			flag = 1;
	}
	if (Big >= 2)
		flag = 1;
	if ( flag )
		return !printf("sjfnb");
	long long DC = (n - 1) * n / 2;
	long long JO = Sum - DC;
	if (JO <= 0)
		return !printf("cslnb");
	if (JO & 1)
		return !printf("sjfnb");
	printf("cslnb");
	return 0;
}


#include <cstdio>
#include <algorithm>
#define Int register int
using namespace std;
const int N = 1e5;
typedef long long LL;

static inline char Get_Char() {
	static char buffer[100000], *S = buffer, *T = buffer;
	if (S == T) {
		T = (S = buffer) + fread(buffer, 1, 100000, stdin);
		if (S == T) return EOF;
	}
	return *S++;
}

//#define Get_Char() getchar()

static inline int Read() {
	int f = 1, x = 0;
	register char sign = Get_Char();
	for (; sign > '9' || sign < '0'; sign = Get_Char())
		if (sign == '-') f = -1;
	for (; sign >= '0' && sign <= '9'; sign = Get_Char())
		x = (x << 3) + (x << 1) + (sign ^ 48);
	return x * f;
}

//Irressey胜利，输出sjfnb
//urzhang胜利，输出cslnb
//如果在某个人的回合前所有的石子堆都是空的，
//或者在他取完后有两堆的石子数量相同（两堆都没有石子也算），则他输掉游戏。

LL Sum;
int val[N + 1];
bool flag[N + 1];

int main() {
	Int n = Read();
	for (Int i = 1, x; i <= n; ++ i) {
		Sum += val[i] = Read();
	}

	sort(val + 1, val + n + 1);

	Int Cnt = 0, Rec = val[1];
	val[1] = 0;
	flag[0] = 1;
	for (Int i = 2; i <= n; ++ i) {
		if (val[i] != Rec) {
			Rec = val[i];
			val[i] = ++Cnt;
		} else if (val[i] == Rec)
			val[i] = Cnt;
		flag[val[i]] = 1;
	}

	Cnt = 0;
	bool pd = 0;
	for (Int i = 2; i <= n; ++ i) {
		if (val[i] == val[i - 1]) {
			++Cnt;
			if (flag[val[i] - 1])
				pd = 1;
		}
	}

	if (Cnt >= 2 || pd) {
		return !printf("cslnb\n");
	}

	LL num = (1 + n - 1) * (n - 1) >> 1;

	Sum -= num;

	if (Sum & 1) return !printf("sjfnb\n");
	printf("cslnb\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define f first
#define INTMAX 1e18+1e9
#define pb push_back
#define pencho ios_base::sync_with_stdio(false);cin.tie(NULL);
#define s second
#define int long long
#define endl '\n'

const int N = 300100;
const int mod = 1000000007;

int bp(int x, int y) {int ans = 1; x %= mod; while (y) {if (y & 1) ans = ans * x % mod; x = x * x % mod; y >>= 1;} return ans;}
int mod_inverse(int x) {return bp(x, mod - 2); }
int gcd (int a, int b) { while (b) {a %= b; swap(a, b);} return a;}
int max(int a, int b) {     if (a < b)    swap(a, b);   return a;}
int min(int a, int b) { if (a > b) swap(a, b); return a;}
int countSetBits(int n) {int count = 0; while (n) {count += n & 1; n >>= 1;} return count;}
/*int mul_inv(int a, int b) { int b0 = b, t, q; int x0 = 0, x1 = 1; if (b == 1) return 1; while (a > 1) { q = a / b;t = b, b = a % b, a = t;t = x0, x0 = x1 - q * x0, x1 = t;}if (x1 < 0) x1 += b0;return x1;}
int chinese_remainder(vector <int> &a, int len = 3) {vector <int> n = {26, 25, 23};int p, i, prod = 1, sum = 0;for(int i = 0; i < len; i++) prod *= n[i];for(int i = 0; i < len; i++) {p = prod / n[i];sum += a[i] * mul_inv(p, n[i]) * p;}return sum % prod;}*/

void solve(){
    pencho
    int n;  cin>>n;
    string s; cin>>s;
    int dp[n][3] = {0};
    int cur = 1;
    if(s[0]=='a') dp[0][0] = 1;
    if(s[0]=='?') dp[0][0] = 1, cur = 3;
    for(int i=1;i<n;i++){
        if(s[i]=='?'){
            dp[i][0] = (3*dp[i-1][0])%mod;
            dp[i][1] = (3*dp[i-1][1])%mod;
            dp[i][2] = (3*dp[i-1][2])%mod;
            dp[i][0] = (dp[i][0]+cur)%mod;
            dp[i][1] = (dp[i][1]+dp[i-1][0])%mod;
            dp[i][2] = (dp[i-1][1]+dp[i][2])%mod;
            cur = (cur*3)%mod;
           // cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
            continue;
        }

        if(s[i]=='a')   dp[i][0] = cur;
        else if(s[i]=='b')  dp[i][1] = dp[i-1][0];
        else if(s[i]=='c')  dp[i][2] = dp[i-1][1];

        dp[i][0] = (dp[i][0]+dp[i-1][0])%mod;
        dp[i][1] = (dp[i-1][1] + dp[i][1])%mod;
        dp[i][2] = (dp[i-1][2] + dp[i][2])%mod;
        //cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
    }
    cout<<dp[n-1][2]<<endl;

}

signed main()
{
#ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("o.txt", "w", stdout);
#endif
      solve();

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long mod = 10000000007;
	int n;
	cin >> n;
	string s;
	cin >> s;
	long long dp[n];
	long long bc = 0;
	long long count_c[n+1];
	long long count_bc[n];
	long long ques = 0;
	long long p[n+1];
	count_c[n] = 0;
	p[0] = 1;
	for(int i = 1;i <= n;i++)
	{
		p[i] = (p[i-1]*3)%mod;
	}
	for(int i = 0;i < n;i++)
	{
		if(s[i] == '?')
			ques++;
	}
	//cout << ques << endl;
	int q = ques;
	for(int i = n-1;i >= 0;i--)
	{
		if(s[i] == 'c')
		{
			count_c[i] = count_c[i+1] + p[q];
			count_c[i]%=mod;
		}
		else if(s[i] == '?')
		{
			count_c[i] = count_c[i+1] + p[q-1];
			count_c[i]%=mod;
		}
		else
		{
			count_c[i] = count_c[i+1];
		}
	}
	/*for(int i = 0;i < n;i++)
		cout << count_c[i] << " ";
	cout << endl;*/

	for(int i = n-1;i >= 0;i--)
	{
		if(s[i] == 'b')
		{
			bc += count_c[i+1];
		}
		if(s[i] == '?')
		{
			bc += count_c[i+1]/3;
		}
		bc%=mod;
		count_bc[i] = bc;
	}
	/*for(int i = n-2;i >= 0;i--)
	{
		count_bc[i] += count_bc[i+1];
	}*/
	/*for(int i = 0;i < n;i++)
	{
		cout << count_bc[i] << " ";
	}*/
	//cout << endl;
	long long result = 0;
	int a = 0;
	for(int i = n-2;i >= 0 ;i--)
	{
		if(s[i] == 'a')
		{
			result+= count_bc[i+1];
		}
		if(s[i] == '?')
		{
			result += count_bc[i+1]/3;
		}
		result%=mod;
	}
	cout << result << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long mod = 1000000007;
	int n;
	cin >> n;
	string s;
	cin >> s;
	long long dp[n];
	long long bc = 0;
	long long count_c[n+1];
	long long count_bc[n];
	long long ques = 0;
	long long p[n+1];
	count_c[n] = 0;
	p[0] = 1;
	for(int i = 1;i <= n;i++)
	{
		p[i] = (p[i-1]*3)%mod;
	}
	for(int i = 0;i < n;i++)
	{
		if(s[i] == '?')
			ques++;
	}
	//cout << ques << endl;
	int q = ques;
	for(int i = n-1;i >= 0;i--)
	{
		if(s[i] == 'c')
		{
			count_c[i] = count_c[i+1] + p[q];
		}
		else if(s[i] == '?')
		{
			count_c[i] = count_c[i+1] + p[q-1];
		}
		else
		{
			count_c[i] = count_c[i+1];
		}
		count_c[i]%=mod;
	}
	/*for(int i = 0;i < n;i++)
		cout << count_c[i] << " ";
	cout << endl;*/

	for(int i = n-1;i >= 0;i--)
	{
		if(s[i] == 'b')
		{
			bc += count_c[i+1];
		}
		if(s[i] == '?')
		{
			bc += count_c[i+1]/3;
		}
		bc%=mod;
		count_bc[i] = bc;
	}
	/*for(int i = n-2;i >= 0;i--)
	{
		count_bc[i] += count_bc[i+1];
	}*/
	/*for(int i = 0;i < n;i++)
	{
		cout << count_bc[i] << " ";
	}*/
	//cout << endl;
	long long result = 0;
	int a = 0;
	for(int i = n-2;i >= 0 ;i--)
	{
		if(s[i] == 'a')
		{
			result+= count_bc[i+1];
		}
		if(s[i] == '?')
		{
			result += count_bc[i+1]/3;
		}
		result%=mod;
	}
	cout << result << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long mod = 1000000007;
	int n;
	cin >> n;
	string s;
	cin >> s;
	long long dp[n];
	long long bc = 0;
	long long count_c[n+1];
	long long count_bc[n];
	long long ques = 0;
	long long p[n+1];
	long long c = 0;
	count_c[n] = 0;
	count_bc[n-1] = 0;
	p[0] = 1;
	for(int i = 1;i <= n;i++)
	{
		p[i] = p[i-1]*3;
		p[i]%=mod;
	}
	for(int i = 0;i < n;i++)
	{
		if(s[i] == '?')
			ques++;
	}
	//cout << ques << endl;
	int q = ques;

	for(int i = n-1;i >= 0;i--)
	{
		if(s[i] == 'c')
		{
			count_c[i] = count_c[i+1] + p[q];
		}
		else if(s[i] == '?')
		{
			count_c[i] = count_c[i+1] + p[q-1];
		}
		else
		{
			count_c[i] = count_c[i+1];
		}
		count_c[i]%=mod;
	}
	/*for(int i = 0;i < n;i++)
		cout << count_c[i] << " ";
	cout << endl;*/

	for(int i = n-1;i >= 0;i--)
	{
		if(s[i] == 'b')
		{
			bc += count_c[i+1];
		}
		else if(s[i] == '?')
		{
			bc += (count_c[i+1]*(333333336))%mod;
		}
		bc%=mod;
		count_bc[i] = bc;
	}
	/*for(int i = n-2;i >= 0;i--)
	{
		count_bc[i] += count_bc[i+1];
	}*/
	/*for(int i = 0;i < n;i++)
	{
		cout << count_bc[i] << " ";
	}*/
	//cout << endl;
	long long result = 0;
	for(int i = n-2;i >= 0 ;i--)
	{
		if(s[i] == 'a')
		{
			result += count_bc[i+1];
		}
		else if(s[i] == '?')
		{
			result += (count_bc[i+1]*333333336)%mod;
		}
		result%=mod;
	}
	cout << result << endl;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int mod=1e9;
#define ll long long int
int main() {
	// your code goes here
	int n;cin>>n;
	string s;cin>>s;
	ll x=1,a=0,ab=0,abc=0;
	for(int i=0;i<s.size();i++){

	    if(s[i]=='?'){
	        abc=(abc*3+ab)%mod;
	         ab=(ab*3+ a)%mod;
	        a=(a*3+x)%mod;
	        x=(x*3)%mod;
	    }
	    else if(s[i]=='a'){
	        a=(a+x)%mod;
	    }
	    else if(s[i]=='b'){
	        ab=(ab+a)%mod;
	    }
	    else {
	        abc=(abc+ab)%mod;
	    }

	}
	cout<<abc<<endl;
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int mod=1e9+7;
#define ll long long int
int main() {
	// your code goes here
	int n;cin>>n;
	string s;cin>>s;
	ll x=1,a=0,ab=0,abc=0;
	for(int i=0;i<s.size();i++){

	    if(s[i]=='?'){
	        abc=(abc*3+ab)%mod;
	         ab=(ab*3+ a)%mod;
	        a=(a*3+x)%mod;
	        x=(x*3)%mod;
	    }
	    else if(s[i]=='a'){
	        a=(a+x)%mod;
	    }
	    else if(s[i]=='b'){
	        ab=(ab+a)%mod;
	    }
	    else {
	        abc=(abc+ab)%mod;
	    }

	}
	cout<<abc<<endl;
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int mod=1e9;
#define ll long long int
int main() {
	// your code goes here
	int n;cin>>n;
	string s;cin>>s;
	ll x=1,a=0,ab=0,abc=0;
	for(int i=0;i<n;i++){

	    if(s[i]=='a'){
	        a=(a+x)%mod;
	    }
	    else if(s[i]=='b'){
	        ab=(ab+a)%mod;
	    }
	    else if(s[i]=='c'){
	        abc=(abc+ab)%mod;
	    }
	    else{
	        //ll A=a,AB=ab;
	        abc=(abc*3+ab)%mod;
	         ab=(ab*3+ a)%mod;
	        a=(a*3+x)%mod;
	      x=x*3%mod;
	    }

	}
	cout<<abc<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MOD = int(1e9) + 7;
const int N = 200043;
const int K = 4;
int n;
string s;
int dp[N][K][K];
int pow3[N];
int main() {
	cin >> n >> s;
	int cntQ = 0;
	for(auto c : s)
		if(c == '?')
			cntQ++;
	pow3[0] = 1;
	for(int i = 1; i < N; i++)
		pow3[i] = (1ll * pow3[i - 1] * 3) % MOD;
	dp[0][0][0] = 1;
	for(int i = 0; i < n; i++)
		for(int j = 0; j <= 3; j++)
			for(int k = 0; k <= 3; k++){
			 	if(!dp[i][j][k])
          continue;
			 	dp[i + 1][j][k] = (dp[i + 1][j][k] + dp[i][j][k]) % MOD;
        if(j < 3 && (s[i] == '?' || s[i] - 'a' == j)){
			 	 	int nk = (s[i] == '?' ? k + 1 : k);
			 	 	dp[i + 1][j + 1][nk] = (dp[i + 1][j + 1][nk] + dp[i][j][k]) % MOD;
			 	}
		   	}
	int ans = 0;
	for(int i = 0; i <= 3; i++)
		if(cntQ >= i)
			ans = (ans, (1ll * dp[n][3][i] * pow3[cntQ - i]) % MOD) % MOD;
	cout << ans;
}


#include <bits/stdc++.h>
#define DEBUG puts("Here is a BUG")
#define MEM(a,b) memset((a),(b),sizeof(a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define PI 3.1415926535897932626
#define all(a) a.begin(),a.end()
typedef long long ll;
using namespace std;
const double eps=1e-8;
const int MAXN=(int)1e5+5;
const int MOD=(int)1e9+7;
const int INF=0x3f3f3f3f;
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};
ll cnta,cntx,ax,xx,xb,ab;
string buf;
ll powmod(ll a,ll b,ll mod=MOD) {ll res=1;a%=mod; if(b<0)return 0; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE

    #endif
    int n;
    ll res=0;
    cin>>n;
    cin>>buf;
    ll s=count(all(buf),'?');
    for (int i = 0; i < buf.length(); i++)
    {
        if(buf[i]=='a')cnta++;
        else if(buf[i]=='b'){xb+=cntx;ab+=cnta;xb%=MOD;ab%=MOD;}
        else if(buf[i]=='c'){res=(res+ax*powmod(3,s-1)%MOD+cntx*(cntx-1)/2*powmod(3,s-2)%MOD+xb*powmod(3,s-1)%MOD+ab*powmod(3,s)%MOD)%MOD;}
        else
        {
            res=(res+ax*powmod(3,s-2)%MOD+(cntx*(cntx-1)/2)%MOD*powmod(3,s-3)%MOD+xb*powmod(3,s-2)%MOD+ab*powmod(3,s-1)%MOD)%MOD;
            cntx++;
            ax+=cnta;
            ax%=MOD;
        }
    }
    cout<<res<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define DEBUG puts("Here is a BUG")
#define MEM(a,b) memset((a),(b),sizeof(a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define PI 3.1415926535897932626
#define all(a) a.begin(),a.end()
typedef long long ll;
using namespace std;
const double eps=1e-8;
const int MAXN=(int)1e5+5;
const int MOD=(int)1e9+7;
const int INF=0x3f3f3f3f;
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};
ll cnta,cntx,ax,xx,xb,ab;
string buf;
ll powmod(ll a,ll b,ll mod=MOD) {ll res=1;a%=mod; if(b<0)return 0; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE

    #endif
    int n;
    ll res=0;
    cin>>n;
    cin>>buf;
    ll s=count(all(buf),'?');
    for (int i = 0; i < buf.length(); i++)
    {
        if(buf[i]=='a')cnta++;
        else if(buf[i]=='b'){xb+=cntx;ab+=cnta;}
        else if(buf[i]=='c'){res=(res+ax*powmod(3,s-1)%MOD+cntx*(cntx-1)/2*powmod(3,s-2)%MOD+xb*powmod(3,s-1)%MOD+ab*powmod(3,s)%MOD)%MOD;}
        else
        {
            res=(res+ax*powmod(3,s-2)%MOD+cntx*(cntx-1)/2*powmod(3,s-3)%MOD+xb*powmod(3,s-2)%MOD+ab*powmod(3,s-1)%MOD)%MOD;
            cntx++;
            ax+=cnta;
            ax%=MOD;
        }
    }
    cout<<res<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define DEBUG puts("Here is a BUG")
#define MEM(a,b) memset((a),(b),sizeof(a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define PI 3.1415926535897932626
#define all(a) a.begin(),a.end()
typedef long long ll;
using namespace std;
const double eps=1e-8;
const int MAXN=(int)1e5+5;
const int MOD=(int)1e9+7;
const int INF=0x3f3f3f3f;
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};
ll cnta,cntx,ax,xx,xb,ab;
string buf;
ll powmod(ll a,ll b,ll mod=MOD) {ll res=1;a%=mod; if(b<0)return 0; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE

    #endif
    int n;
    ll res=0;
    cin>>n;
    cin>>buf;
    ll s=count(all(buf),'?');
    for (int i = 0; i < buf.length(); i++)
    {
        if(buf[i]=='a')cnta++;
        else if(buf[i]=='b'){xb+=cntx;ab+=cnta;xb%=MOD;ab%=MOD;}
        else if(buf[i]=='c'){res=(res+ax*powmod(3,s-1)%MOD+(cntx*(cntx-1)/2)%MOD*powmod(3,s-2)%MOD+xb*powmod(3,s-1)%MOD+ab*powmod(3,s)%MOD)%MOD;}
        else
        {
            res=(res+ax*powmod(3,s-2)%MOD+(cntx*(cntx-1)/2)%MOD*powmod(3,s-3)%MOD+xb*powmod(3,s-2)%MOD+ab*powmod(3,s-1)%MOD)%MOD;
            cntx++;
            ax+=cnta;
            ax%=MOD;
        }
    }
    cout<<res<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define DEBUG puts("Here is a BUG")
#define MEM(a,b) memset((a),(b),sizeof(a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define PI 3.1415926535897932626
#define all(a) a.begin(),a.end()
typedef long long ll;
using namespace std;
const double eps=1e-8;
const int MAXN=(int)1e5+5;
const int MOD=(int)1e9+7;
const int INF=0x3f3f3f3f;
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};
ll cnta,cntx,ax,xx,xb,ab;
string buf;
ll powmod(ll a,ll b,ll mod=MOD) {ll res=1;a%=mod; if(b<0)return 0; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE

    #endif
    int n;
    ll res=0;
    cin>>n;
    cin>>buf;
    ll s=count(all(buf),'?');
    for (int i = 0; i < buf.length(); i++)
    {
        if(buf[i]=='a')cnta++;
        else if(buf[i]=='b'){xb+=cntx;ab+=cnta;}
        else if(buf[i]=='c'){res+=ax*powmod(3,s-1)+cntx*(cntx-1)/2*powmod(3,s-2)+xb*powmod(3,s-1)+ab*powmod(3,s);}
        else
        {
            if(s>=3)res+=cntx*(cntx-1)/2*powmod(3,s-3);
            if(s>=2)res+=ax*powmod(3,s-2)+xb*powmod(3,s-2);
            res+=ab*powmod(3,s-1);
            cntx++;
            ax+=cnta;
        }
    }
    cout<<res<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define endl "\n"
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
int main() {
    FIO;
    ll n; cin>>n;
    string s; cin>>s;
    ll ca=0,cab=0,cabc=0,mul=1;
    for(auto it:s){
        if(it=='a') ca=(ca+mul)%mod;
        else if(it=='b') cab=(cab+ca)%mod;
        else if(it=='c') cabc=(cabc+cab)%mod;
        else{
            cabc=(3*cabc+cab)%mod;
            cab=(3*cab+ca)%mod;
            ca=(3*ca+mul)%mod;
            mul*=3;
            mul%=mod;
        }
    }
    cout<<cabc<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define endl "\n"
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
int main() {
    FIO;
    ll n; cin>>n;
    string s; cin>>s;
    ll ca=0,cab=0,cabc=0,mul=1;
    for(auto it:s){
        if(it=='a') ca=(ca+1)%mod;
        else if(it=='b') cab=(cab+ca)%mod;
        else if(it=='c') cabc=(cabc+cab)%mod;
        else{
            cabc=(3*cabc+cab)%mod;
            cab=(3*cab+ca)%mod;
            ca=(3*ca+mul)%mod;
            mul*=3;
            mul%=mod;
        }
    }
    cout<<cabc<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <cstring>
//#include<bits/stdc++.h>
#define int long long
#define all(x) begin(x), end(x)
#define SZ(x) ((int)(x).size())
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define F first
#define S second

#define de(x) if(x && x == MODE)
#define MODE 1

using namespace std;

typedef pair<int, int> pii;

const int INF = 1e18;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	string s;
	cin >> n >> s;
	int a = 0, b = 0, c = 0, ret = 1;
	for (int i = 1; i <= n; i++) {
		if (s[i - 1] == 'a') {
			a += ret;
		}
		if (s[i - 1] == 'b') {
			b = (b + a) % mod;
		}
		if (s[i - 1] == 'c') {
			c = (c + b) % mod;
		}
		if (s[i - 1] == '?') {
			int A = 0, B = 0, C = 0;
			A += ret;
			B = a;
			C = b;
			a = (a * 3 + A) % mod;
			b = (b * 3 + B) % mod;
			c = (c * 3 + C)% mod;
			ret = ret * 3 % mod;
//			c = (c + b
//			cout << a << " " << b << " " << c << "\n";
		}
//		cout << a << " " << b << " " << c << "\n";

//		cout << bit[0].qry(i + 1) << " " << bit[1].qry(i + 1) << " " << bit[2].qry(i + 1) << "\n";
	}
	cout << c << "\n";
}


#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <cstring>
//#include<bits/stdc++.h>
#define int long long
#define all(x) begin(x), end(x)
#define SZ(x) ((int)(x).size())
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define F first
#define S second

#define de(x) if(x && x == MODE)
#define MODE 1

using namespace std;

typedef pair<int, int> pii;

const int INF = 1e18;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;

struct Bit {
	int bit[maxn];
	int lowbit(int x) {
		return (x) & -(x);
	}
	void add(int x,int val) {
		for (int i = x; i < maxn; i += lowbit(i)) {
			bit[i] += val;
		}
	}
	int qry(int x) {
		int ret = 0;
		for (int i = x - 1; i > 0; i -= lowbit(i)) {
			ret += bit[i];
			ret %= mod;
		}
		return ret;
	}
} bit[7];

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	string s;
	cin >> n >> s;
	int a = 0, b = 0, c = 0, ret = 1;
	for (int i = 1; i <= n; i++) {
		if (s[i - 1] == 'a') {
			a += ret;
		}
		if (s[i - 1] == 'b') {
			b = (b + a) % mod;
		}
		if (s[i - 1] == 'c') {
			c = (c + b) % mod;
		}
		if (s[i - 1] == '?') {
			int A = 0, B = 0, C = 0;
			A += ret;
			B = a;
			C = b;
			a = (a * 3 + A) % mod;
			b = (b * 3 + B) % mod;
			c = (c * 3 +  C)% mod;
			ret = ret * 3 % mod;
//			c = (c + b
//			cout << a << " " << b << " " << c << "\n";
		}
//		cout << a << " " << b << " " << c << "\n";

//		cout << bit[0].qry(i + 1) << " " << bit[1].qry(i + 1) << " " << bit[2].qry(i + 1) << "\n";
	}
	cout << c << "\n";
}


#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <cstring>
//#include<bits/stdc++.h>
#define int long long
#define all(x) begin(x), end(x)
#define SZ(x) ((int)(x).size())
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define F first
#define S second

#define de(x) if(x && x == MODE)
#define MODE 1

using namespace std;

typedef pair<int, int> pii;

const int INF = 1e18;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;

struct Bit {
	int bit[maxn];
	int lowbit(int x) {
		return (x) & -(x);
	}
	void add(int x,int val) {
		for (int i = x; i < maxn; i += lowbit(i)) {
			bit[i] += val;
		}
	}
	int qry(int x) {
		int ret = 0;
		for (int i = x - 1; i > 0; i -= lowbit(i)) {
			ret += bit[i];
			ret %= mod;
		}
		return ret;
	}
} bit[7];

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	string s;
	cin >> n >> s;
	int a = 0, b = 0, c = 0, ret = 1;
	for (int i = 1; i <= n; i++) {
		if (s[i - 1] == 'a') {
			a++;
		}
		if (s[i - 1] == 'b') {
			b = (b + a) % mod;
		}
		if (s[i - 1] == 'c') {
			c = (c + b) % mod;
		}
		if (s[i - 1] == '?') {
			int A = 0, B = 0, C = 0;
			A += ret;
			B = a;
			C = b;
			a = a * 3 + A % mod;
			b = b * 3 + B % mod;
			c = c * 3 + C % mod;
			ret = ret * 3 % mod;
//			c = (c + b
//			cout << a << " " << b << " " << c << "\n";
		}
//		cout << a << " " << b << " " << c << "\n";

//		cout << bit[0].qry(i + 1) << " " << bit[1].qry(i + 1) << " " << bit[2].qry(i + 1) << "\n";
	}
	cout << c << "\n";
}


#include <cstdio>
#define int long long

int mod = 1e9 + 7;
signed main() {

	int n;
	scanf("%lld\n", &n);
//	char c;
//	scanf("%c");
	int a = 0, b = 0, c = 0, ret = 1;
	for (int i = 1; i <= n; i++) {
		char cr;
		scanf("%c", &cr);
		if (cr == 'a') {
			a += ret;
		}
		if (cr == 'b') {
			b = (b + a) % mod;
		}
		if (cr == 'c') {
			c = (c + b) % mod;
		}
		if (cr == '?') {
			int A = 0, B = 0, C = 0;
			A += ret;
			B = a;
			C = b;
			a = (a * 3 + A) % mod;
			b = (b * 3 + B) % mod;
			c = (c * 3 + C) % mod;
			ret = ret * 3 % mod;
//			cout << a << " " << b << " " << c << "\n";
		}
	}
	printf("%lld", c);
}


#include<bits\stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
const ll mod=1e9+7;
const int maxn=2e5+10;
string s;
ll dp[maxn][3];
int main()
{
    int n;cin>>n;
    cin>>s;
    ll cnt=1;
    for(int i=1;i<=n;i++)
    {
        if(s[i-1]=='?')
        {
            dp[i][0]=(dp[i-1][0]*3+cnt)%mod;
            dp[i][1]=(dp[i-1][1]*3+dp[i-1][0])%mod;
            dp[i][2]=(dp[i-1][2]*3+dp[i-1][1])%mod;
            cnt*=3;
            cnt%=mod;
        }
        else
        {
            dp[i][0]=(dp[i-1][0]+cnt*int(s[i-1]=='a'))%mod;
            dp[i][1]=(dp[i-1][1]+dp[i-1][0]*int(s[i-1]=='b'))%mod;
            dp[i][2]=(dp[i-1][2]+dp[i-1][1]*int(s[i-1]=='c'))%mod;
        }
    }
//    for(int i=1;i<=n;i++)
//    {
//        cout<<dp[i][0]<<' '<<dp[i][1]<<' '<<dp[i][2]<<endl;
//    }
    cout<<dp[n][2]<<endl;
    return 0;
}


#include<bits\stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
const ll mod=1e9+7;
const int maxn=1e5+10;
string s;
ll dp[maxn][3];
int main()
{
    int n;cin>>n;
    cin>>s;
    ll cnt=1;
    for(int i=1;i<=n;i++)
    {
        if(s[i-1]=='?')
        {
            dp[i][0]=(dp[i-1][0]*3+cnt)%mod;
            dp[i][1]=(dp[i-1][1]*3+dp[i-1][0])%mod;
            dp[i][2]=(dp[i-1][2]*3+dp[i-1][1])%mod;
            cnt*=3;
            cnt%=mod;
        }
        else
        {
            dp[i][0]=(dp[i-1][0]+int(s[i-1]=='a'))%mod;
            dp[i][1]=(dp[i-1][1]+int(s[i-1]=='b')*dp[i-1][0])%mod;
            dp[i][2]=(dp[i-1][2]+int(s[i-1]=='c')*dp[i-1][1])%mod;
        }
    }
//    for(int i=1;i<=n;i++)
//    {
//        cout<<dp[i][0]<<' '<<dp[i][1]<<' '<<dp[i][2]<<endl;
//    }
    cout<<dp[n][2]<<endl;
    return 0;
}


#include<bits\stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
const ll mod=1e9+7;
const int maxn=1e5+10;
string s;
ll dp[maxn][3];
int main()
{
    int n;cin>>n;
    cin>>s;
    ll cnt=1;
    for(int i=1;i<=n;i++)
    {
        if(s[i-1]=='?')
        {
            dp[i][0]=(dp[i-1][0]*3+cnt)%mod;
            dp[i][1]=(dp[i-1][1]*3+dp[i-1][0])%mod;
            dp[i][2]=(dp[i-1][2]*3+dp[i-1][1])%mod;
            cnt*=3;
            cnt%=mod;
        }
        else
        {
            dp[i][0]=(dp[i-1][0]+cnt*int(s[i-1]=='a'))%mod;
            dp[i][1]=(dp[i-1][1]+dp[i-1][0]*int(s[i-1]=='b'))%mod;
            dp[i][2]=(dp[i-1][2]+dp[i-1][1]*int(s[i-1]=='c'))%mod;
        }
    }
//    for(int i=1;i<=n;i++)
//    {
//        cout<<dp[i][0]<<' '<<dp[i][1]<<' '<<dp[i][2]<<endl;
//    }
    cout<<dp[n][2]<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
#define e exp(1.0)
#define ios ios::sync_with_stdio(false)
#define rep(i,l,r) for(int i=(l);i<(r);i++)
using namespace std;

const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;

ll dp[maxn][3];

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    s = " "+s;
    ll pre = 1;
    for(int i = 1;i <= n;++i){
        if(s[i] == 'a'){
            dp[i][0] =(dp[i-1][0] + pre) % mod;
            dp[i][1] = dp[i-1][1];
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'b'){
            dp[i][0] = dp[i-1][0];
            dp[i][1]=(dp[i-1][1] + dp[i-1][0]) % mod;
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'c'){
            dp[i][0] = dp[i-1][0];
            dp[i][1] = dp[i-1][1];
            dp[i][2]= (dp[i-1][2] + dp[i-1][1])%mod;
        }
        else if(s[i] == '?'){
            dp[i][0] = (pre + dp[i-1][0] * 3) % mod;
            dp[i][1]=(dp[i-1][1]*3 + dp[i-1][0])%mod;
            dp[i][2]=(dp[i-1][2]*3 + dp[i-1][1])%mod;
            pre = pre*3 % mod;
        }
    }
    printf("%lld",dp[n][2]);

   return 0;
}


#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
#define e exp(1.0)
#define ios ios::sync_with_stdio(false)
#define rep(i,l,r) for(int i=(l);i<(r);i++)
using namespace std;

const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;

ll dp[maxn][3];

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    ll res = 0;
    dp[-1][0] = dp[-1][1] = dp[-1][2] = 0;
    int pre = 1;
    for(int i = 0;i < n;++i){
        if(s[i] == 'a'){
            dp[i][0] =(dp[i-1][0] + 1) % mod;
            dp[i][1] = dp[i-1][1];
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'b'){
            dp[i][0] = dp[i-1][0];
            dp[i][1]=(dp[i-1][1] + dp[i-1][0]) % mod;
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'c'){
            dp[i][0] = dp[i-1][0];
            dp[i][1] = dp[i-1][1];
            dp[i][2]= (dp[i-1][2] + dp[i-1][1])%mod;
        }
        else if(s[i] == '?'){
            dp[i][0] = (pre + dp[i-1][0] * 3) % mod;
            dp[i][1]=(dp[i-1][1]*3 + dp[i-1][0])%mod;
            dp[i][2]=(dp[i-1][2]*3 + dp[i-1][1])%mod;
            pre = pre*3 % mod;
        }
    }
    printf("%lld",dp[n-1][2]);

   return 0;
}


#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
#define e exp(1.0)
#define ios ios::sync_with_stdio(false)
#define rep(i,l,r) for(int i=(l);i<(r);i++)
using namespace std;

const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;

ll dp[maxn][3];

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    s = " "+s;
    int pre = 1;
    for(int i = 1;i <= n;++i){
        if(s[i] == 'a'){
            dp[i][0] =(dp[i-1][0] + 1) % mod;
            dp[i][1] = dp[i-1][1];
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'b'){
            dp[i][0] = dp[i-1][0];
            dp[i][1]=(dp[i-1][1] + dp[i-1][0]) % mod;
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'c'){
            dp[i][0] = dp[i-1][0];
            dp[i][1] = dp[i-1][1];
            dp[i][2]= (dp[i-1][2] + dp[i-1][1])%mod;
        }
        else if(s[i] == '?'){
            dp[i][0] = (pre + dp[i-1][0] * 3) % mod;
            dp[i][1]=(dp[i-1][1]*3 + dp[i-1][0])%mod;
            dp[i][2]=(dp[i-1][2]*3 + dp[i-1][1])%mod;
            pre = pre*3 % mod;
        }
    }
    printf("%lld",dp[n][2]);

   return 0;
}


#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
#define e exp(1.0)
#define ios ios::sync_with_stdio(false)
#define rep(i,l,r) for(int i=(l);i<(r);i++)
using namespace std;

const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;

ll dp[maxn][3];

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    s = " "+s;
    int pre = 1;
    for(int i = 1;i <= n;++i){
        if(s[i] == 'a'){
            dp[i][0] =(dp[i-1][0] + 1) % mod;
            dp[i][1] = dp[i-1][1];
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'b'){
            dp[i][0] = dp[i-1][0];
            dp[i][1]=(dp[i-1][1] + dp[i-1][0]) % mod;
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'c'){
            dp[i][0] = dp[i-1][0];
            dp[i][1] = dp[i-1][1];
            dp[i][2]= (dp[i-1][2] + dp[i-1][1])%mod;
        }
        else if(s[i] == '?'){
            dp[i][0] = (pre + dp[i-1][0] * 3) % mod;
            dp[i][1]=(dp[i-1][1]*3 + dp[i-1][0])%mod;
            dp[i][2]=(dp[i-1][2]*3 + dp[i-1][1])%mod;
            pre = pre*3 % mod;
        }
    }
    printf("%lld",dp[n-1][2]);

   return 0;
}


#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
#define e exp(1.0)
#define ios ios::sync_with_stdio(false)
#define rep(i,l,r) for(int i=(l);i<(r);i++)
using namespace std;

const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;

ll dp[maxn][3];

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    s = " "+s;
    int pre = 1;
    for(int i = 1;i <= n;++i){
        if(s[i] == 'a'){
            dp[i][0] =(dp[i-1][0] + pre) % mod;
            dp[i][1] = dp[i-1][1];
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'b'){
            dp[i][0] = dp[i-1][0];
            dp[i][1]=(dp[i-1][1] + dp[i-1][0]) % mod;
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'c'){
            dp[i][0] = dp[i-1][0];
            dp[i][1] = dp[i-1][1];
            dp[i][2]= (dp[i-1][2] + dp[i-1][1])%mod;
        }
        else if(s[i] == '?'){
            dp[i][0] = (pre + dp[i-1][0] * 3) % mod;
            dp[i][1]=(dp[i-1][1]*3 + dp[i-1][0])%mod;
            dp[i][2]=(dp[i-1][2]*3 + dp[i-1][1])%mod;
            pre = pre*3 % mod;
        }
    }
    printf("%lld",dp[n][2]);

   return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename has_less>
using ordered_set =
tree<has_less,
    null_type,
    less<has_less>,
    rb_tree_tag,
    tree_order_statistics_node_update>;

// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

# define ll long long int
#define M 1000000007
#define pb push_back
#define ss second
#define ff first
#define inf 1000000000000000

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x ;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

													//nestedcode
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll dp[8][500005][4];
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,i,d = 0,ans = 0;
    cin>>n;
    string s;
    cin>>s;
    n = s.length();
    for(i=0;i<n;i++){
    	if(s[i] == 'a'){
    		dp[4][i][0] = 1;
		}

		if(s[i] == 'b'){
    		dp[2][i][0] = 1;
		}

		if(s[i] == 'c'){
    		dp[1][i][0] = 1;
		}

		if(s[i] == '?'){
			d++;
    		dp[4][i][1] = 1;
    		dp[2][i][1] = 1;
    		dp[1][i][1] = 1;
		}

	}
	for(i=1;i<n;i++){
		dp[4][i][0] += dp[4][i-1][0];
		dp[4][i][1] += dp[4][i-1][1];
//		dp[2][i][0] += dp[2][i-1][0];
//		dp[1][i][0] += dp[1][i-1][0];
	}

	for(i=1;i<n;i++){

		dp[6][i][0] = dp[6][i-1][0];
		if(s[i] == 'b') dp[6][i][0] += dp[4][i-1][0];

		dp[6][i][1] = dp[6][i-1][1];
		if(s[i] == 'b') dp[6][i][1] += dp[4][i-1][1];

		if(s[i] == '?') dp[6][i][1] += dp[4][i-1][0];

		dp[6][i][2] = dp[6][i-1][2];
		if(s[i] == '?') dp[6][i][2] += dp[4][i-1][1];

//		dp[5][i] = dp[5][i-1];
//		if(s[i] == 'c') dp[5][i] += dp[4][i-1];
//		dp[3][i] = dp[3][i-1];
//		if(s[i] == 'c') dp[3][i] += dp[2][i-1];

	}

	for(i=1;i<n;i++){
		dp[7][i][0] = dp[7][i-1][0];
		if(s[i] == 'c')
		dp[7][i][0] += dp[6][i-1][0];

		dp[7][i][1] = dp[7][i-1][1];
		if(s[i] == 'c')
		dp[7][i][1] += dp[6][i-1][1];
		if(s[i] == '?')
		dp[7][i][1] += dp[6][i-1][0];

		dp[7][i][2] = dp[7][i-1][2];
		if(s[i] == 'c')
		dp[7][i][2] += dp[6][i-1][2];
		if(s[i] == '?')
		dp[7][i][2] += dp[6][i-1][1];

		dp[7][i][3] = dp[7][i-1][3];
		if(s[i] == '?')
		dp[7][i][3] += dp[6][i-1][2];
	}
//	debug(dp[7][n-1][0],dp[7][n-1][1],dp[7][n-1][2],dp[7][n-1][3]);
	ans += (dp[7][n-1][0] * binpow(3,d,M))%M;
	ans %= M;
	if(d>=1)
	ans += (dp[7][n-1][1] * binpow(3,d-1,M))%M;
	ans %= M;
	if(d>=2)
	ans += (dp[7][n-1][2] * binpow(3,d-2,M))%M;
	ans %= M;
	if(d>=3)
	ans += (dp[7][n-1][3] * binpow(3,d-3,M))%M;
	ans %= M;

	cout<<ans<<endl;

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename has_less>
using ordered_set =
tree<has_less,
    null_type,
    less<has_less>,
    rb_tree_tag,
    tree_order_statistics_node_update>;

// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

# define ll long long int
#define M 1000000007
#define pb push_back
#define ss second
#define ff first
#define inf 1000000000000000

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x ;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

													//nestedcode
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll dp[8][500005][4];
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,i,d = 0,ans = 0;
    cin>>n;
    string s;
    cin>>s;
    n = s.length();
    for(i=0;i<n;i++){
    	if(s[i] == 'a'){
    		dp[4][i][0] = 1;
		}

		if(s[i] == 'b'){
    		dp[2][i][0] = 1;
		}

		if(s[i] == 'c'){
    		dp[1][i][0] = 1;
		}

		if(s[i] == '?'){
			d++;
    		dp[4][i][1] = 1;
    		dp[2][i][1] = 1;
    		dp[1][i][1] = 1;
		}

	}
	for(i=1;i<n;i++){
		dp[4][i][0] += dp[4][i-1][0];
		dp[4][i][1] += dp[4][i-1][1];
//		dp[2][i][0] += dp[2][i-1][0];
//		dp[1][i][0] += dp[1][i-1][0];
	}

	for(i=1;i<n;i++){

		dp[6][i][0] = dp[6][i-1][0];
		if(s[i] == 'b') dp[6][i][0] += dp[4][i-1][0];

		dp[6][i][1] = dp[6][i-1][1];
		if(s[i] == 'b') dp[6][i][1] += dp[4][i-1][1];

		if(s[i] == '?') dp[6][i][1] += dp[4][i-1][0];

		dp[6][i][2] = dp[6][i-1][2];
		if(s[i] == '?') dp[6][i][2] += dp[4][i-1][1];

//		dp[5][i] = dp[5][i-1];
//		if(s[i] == 'c') dp[5][i] += dp[4][i-1];
//		dp[3][i] = dp[3][i-1];
//		if(s[i] == 'c') dp[3][i] += dp[2][i-1];

	}

	for(i=1;i<n;i++){
		dp[7][i][0] = dp[7][i-1][0];
		if(s[i] == 'c')
		dp[7][i][0] += dp[6][i-1][0];

		dp[7][i][1] = dp[7][i-1][1];
		if(s[i] == 'c')
		dp[7][i][1] += dp[6][i-1][1];
		if(s[i] == '?')
		dp[7][i][1] += dp[6][i-1][0];

		dp[7][i][2] = dp[7][i-1][2];
		if(s[i] == 'c')
		dp[7][i][2] += dp[6][i-1][2];
		if(s[i] == '?')
		dp[7][i][2] += dp[6][i-1][1];

		dp[7][i][3] = dp[7][i-1][3];
		if(s[i] == '?')
		dp[7][i][3] += dp[6][i-1][2];
	}
//	debug(dp[7][n-1][0],dp[7][n-1][1],dp[7][n-1][2],dp[7][n-1][3]);
	ans += (dp[7][n-1][0] %M * binpow(3,d,M))%M;
	ans %= M;
	if(d>=1)
	ans += (dp[7][n-1][1]%M * binpow(3,d-1,M))%M;
	ans %= M;
	if(d>=2)
	ans += (dp[7][n-1][2]%M * binpow(3,d-2,M))%M;
	ans %= M;
	if(d>=3)
	ans += (dp[7][n-1][3]%M * binpow(3,d-3,M))%M;
	ans %= M;

	cout<<ans<<endl;

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename has_less>
using ordered_set =
tree<has_less,
    null_type,
    less<has_less>,
    rb_tree_tag,
    tree_order_statistics_node_update>;

// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

# define ll long long int
#define M 1000000007
#define pb push_back
#define ss second
#define ff first
#define inf 1000000000000000

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x ;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

													//nestedcode
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll dp[8][500005][4];
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,i,d = 0,ans = 0;
    cin>>n;
    string s;
    cin>>s;
    n = s.length();
    for(i=0;i<n;i++){
    	if(s[i] == 'a'){
    		dp[4][i][0] = 1;
		}

		if(s[i] == 'b'){
    		dp[2][i][0] = 1;
		}

		if(s[i] == 'c'){
    		dp[1][i][0] = 1;
		}

		if(s[i] == '?'){
			d++;
    		dp[4][i][1] = 1;
    		dp[2][i][1] = 1;
    		dp[1][i][1] = 1;
		}

	}
	for(i=1;i<n;i++){
		dp[4][i][0] += dp[4][i-1][0];
		dp[4][i][1] += dp[4][i-1][1];
//		dp[2][i][0] += dp[2][i-1][0];
//		dp[1][i][0] += dp[1][i-1][0];
	}

	for(i=1;i<n;i++){

		dp[6][i][0] = dp[6][i-1][0];
		if(s[i] == 'b') dp[6][i][0] += dp[4][i-1][0];

		dp[6][i][1] = dp[6][i-1][1];
		if(s[i] == 'b') dp[6][i][1] += dp[4][i-1][1];

		if(s[i] == '?') dp[6][i][1] += dp[4][i-1][0];

		dp[6][i][2] = dp[6][i-1][2];
		if(s[i] == '?') dp[6][i][2] += dp[4][i-1][1];

//		dp[5][i] = dp[5][i-1];
//		if(s[i] == 'c') dp[5][i] += dp[4][i-1];
//		dp[3][i] = dp[3][i-1];
//		if(s[i] == 'c') dp[3][i] += dp[2][i-1];

	}

	for(i=1;i<n;i++){
		dp[7][i][0] = dp[7][i-1][0];
		if(s[i] == 'c')
		dp[7][i][0] += dp[6][i-1][0];

		dp[7][i][1] = dp[7][i-1][1];
		if(s[i] == 'c')
		dp[7][i][1] += dp[6][i-1][1];
		if(s[i] == '?')
		dp[7][i][1] += dp[6][i-1][0];

		dp[7][i][2] = dp[7][i-1][2];
		if(s[i] == 'c')
		dp[7][i][2] += dp[6][i-1][2];
		if(s[i] == '?')
		dp[7][i][2] += dp[6][i-1][1];

		dp[7][i][3] = dp[7][i-1][3];
		if(s[i] == '?')
		dp[7][i][3] += dp[6][i-1][2];
	}
//	debug(dp[7][n-1][0],dp[7][n-1][1],dp[7][n-1][2],dp[7][n-1][3]);
	ans += dp[7][n-1][0] * binpow(3,d,M);
	ans %= M;
	if(d>=1)
	ans += dp[7][n-1][1] * binpow(3,d-1,M);
	ans %= M;
	if(d>=2)
	ans += dp[7][n-1][2] * binpow(3,d-2,M);
	ans %= M;
	if(d>=3)
	ans += dp[7][n-1][3] * binpow(3,d-3,M);
	ans %= M;

	cout<<ans<<endl;

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename has_less>
using ordered_set =
tree<has_less,
    null_type,
    less<has_less>,
    rb_tree_tag,
    tree_order_statistics_node_update>;

// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

# define ll long long int
#define M 1000000007
#define pb push_back
#define ss second
#define ff first
#define inf 1000000000000000

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x ;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

													//nestedcode
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll dp[8][500005][4];
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,i,d = 0,ans = 0;
    cin>>n;
    string s;
    cin>>s;
    n = s.length();
    for(i=0;i<n;i++){
    	if(s[i] == 'a'){
    		dp[4][i][0] = 1;
		}

		if(s[i] == 'b'){
    		dp[2][i][0] = 1;
		}

		if(s[i] == 'c'){
    		dp[1][i][0] = 1;
		}

		if(s[i] == '?'){
			d++;
    		dp[4][i][1] = 1;
    		dp[2][i][1] = 1;
    		dp[1][i][1] = 1;
		}

	}
	for(i=1;i<n;i++){
		dp[4][i][0] += dp[4][i-1][0];
		dp[4][i][1] += dp[4][i-1][1];
//		dp[2][i][0] += dp[2][i-1][0];
//		dp[1][i][0] += dp[1][i-1][0];
	}

	for(i=1;i<n;i++){

		dp[6][i][0] = dp[6][i-1][0];
		if(s[i] == 'b') dp[6][i][0] += dp[4][i-1][0];

		dp[6][i][1] = dp[6][i-1][1];
		if(s[i] == 'b') dp[6][i][1] += dp[4][i-1][1];

		if(s[i] == '?') dp[6][i][1] += dp[4][i-1][0];

		dp[6][i][2] = dp[6][i-1][2];
		if(s[i] == '?') dp[6][i][2] += dp[4][i-1][1];

//		dp[5][i] = dp[5][i-1];
//		if(s[i] == 'c') dp[5][i] += dp[4][i-1];
//		dp[3][i] = dp[3][i-1];
//		if(s[i] == 'c') dp[3][i] += dp[2][i-1];

	}

	for(i=1;i<n;i++){
		dp[7][i][0] = dp[7][i-1][0];
		if(s[i] == 'c')
		dp[7][i][0] += dp[6][i-1][0];

		dp[7][i][1] = dp[7][i-1][1];
		if(s[i] == 'c')
		dp[7][i][1] += dp[6][i-1][1];
		if(s[i] == '?')
		dp[7][i][1] += dp[6][i-1][0];

		dp[7][i][2] = dp[7][i-1][2];
		if(s[i] == 'c')
		dp[7][i][2] += dp[6][i-1][2];
		if(s[i] == '?')
		dp[7][i][2] += dp[6][i-1][1];

		dp[7][i][3] = dp[7][i-1][3];
		if(s[i] == '?')
		dp[7][i][3] += dp[6][i-1][2];
	}
//	debug(dp[7][n-1][0],dp[7][n-1][1],dp[7][n-1][2],dp[7][n-1][3]);
	ans += dp[7][n-1][0] * binpow(3,d,M);
	ans %= M;

	ans += dp[7][n-1][1] * binpow(3,d-1,M);
	ans %= M;

	ans += dp[7][n-1][2] * binpow(3,d-2,M);
	ans %= M;

	ans += dp[7][n-1][3] * binpow(3,d-3,M);
	ans %= M;

	cout<<ans<<endl;

}


/*input
6
ac?b?c

*/
//#pragma GCC optimize(3,"inline","Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma comment(linker, "/STACK:128000000")
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
//using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define le .length()
#define FOR(i,a,b)for(int i=a;i<b;i++)
#define f0r(i,b)for(int i=0;i<b;i++)
#define rep(i,a,b)for(int i=a;i<=b;i++)
#define per(i,a,b)for(int i=b;i>=a;i--)
#define debug(X) std::cout << "[DEBUG] ("<<__FILE__<<":"<<__FUNCTION__<<":"<<__LINE__<<") " << #X << " = " << X << std::endl;
template<typename T>ostream& operator<<(ostream& os, const vector<T>& v){for(int i=0;i<sz(v);i++){cout<<v[i]<<(i==sz(v)-1?'\n':' ');}return os;}
template<typename T>ostream& operator<<(ostream& os, const set<T>& v){for(auto& i:v){cout<<i<<" ";}cout<<endl;return os;}

#define inf 1000005000
#define lnf 2000000000000500000ll
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
ll mod=1e9+7;
long long modpow(long long base, long long pow, long long mod){base%=mod;long long res=1;for(;pow;pow>>=1){if(pow&1)res=res*base%mod;base=base*base%mod;}return res;}
ll singmodpow(ll div, ll mod){
	return modpow(div,mod-2,mod);
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n;cin>>n;
	string s;cin>>s;
	ll k=0;
	for_each(all(s),[&k](char &c){if(c=='?')k++;});
	ll ma(0),mb(0),mc(0);
	ll sigma=0;//i love siguma chan~
	ll totalstr=modpow(3,k,mod);
	f0r(i,n){
		if(s[i]=='a')ma+=totalstr,ma%=mod;
		if(s[i]=='b')mb+=ma,mb%=mod;
		if(s[i]=='c')mc+=mb,mc%=mod;
		if(s[i]=='?'){
			mc+=mb*singmodpow(3,mod);mc%=mod;
			mb+=ma*singmodpow(3,mod);mb%=mod;
			ma+=totalstr*singmodpow(3,mod);ma%=mod;
		}
	}
	cout<<mc<<endl;
}


/*input
7
???????

*/
//#pragma GCC optimize(3,"inline","Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma comment(linker, "/STACK:128000000")
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
//using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define le .length()
#define FOR(i,a,b)for(int i=a;i<b;i++)
#define f0r(i,b)for(int i=0;i<b;i++)
#define rep(i,a,b)for(int i=a;i<=b;i++)
#define per(i,a,b)for(int i=b;i>=a;i--)
#define debug(X) std::cout << "[DEBUG] ("<<__FILE__<<":"<<__FUNCTION__<<":"<<__LINE__<<") " << #X << " = " << X << std::endl;
template<typename T>ostream& operator<<(ostream& os, const vector<T>& v){for(int i=0;i<sz(v);i++){cout<<v[i]<<(i==sz(v)-1?'\n':' ');}return os;}
template<typename T>ostream& operator<<(ostream& os, const set<T>& v){for(auto& i:v){cout<<i<<" ";}cout<<endl;return os;}

#define inf 1000005000
#define lnf 2000000000000500000ll
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
ll mod=1e9+7;
long long modpow(long long base, long long pow, long long mod){base%=mod;long long res=1;for(;pow;pow>>=1){if(pow&1)res=res*base%mod;base=base*base%mod;}return res;}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n;cin>>n;
	string s;cin>>s;
	ll k=0;
	for_each(all(s),[&k](char &c){if(c=='?')k++;});
	int cur[4],last[4];memset(cur,0,sizeof(cur));memset(last,0,sizeof(last));//should have keep tracking of string of length 3 but what ever i guess...
	ll sigma=0;//i love siguma chan~
	ll totalstr=modpow(3,k,mod);
	last[0]=totalstr;
	f0r(i,n){
		memset(cur,0,sizeof(cur));
		if(s[i]=='a'){
			cur[1]+=totalstr;
			cur[0]=totalstr-cur[1];
		}
		if(s[i]=='b'){
			cur[2]+=last[1];
			cur[0]=totalstr-cur[2];
		}
		if(s[i]=='c'){
			cur[3]+=last[2];
			cur[0]=totalstr;
		}
		if(s[i]=='?'){
			cur[1]+=totalstr/3ll;
			cur[2]+=last[1]/3ll;
			cur[3]+=last[2]/3ll;
			cur[0]=totalstr-cur[1]-cur[2];
		}
		sigma+=cur[3];sigma%=mod;
		memcpy(last,cur,sizeof(cur));
	}
	cout<<sigma<<endl;
}


/*input
6
ac?b?c

*/
//#pragma GCC optimize(3,"inline","Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma comment(linker, "/STACK:128000000")
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
//using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define le .length()
#define FOR(i,a,b)for(int i=a;i<b;i++)
#define f0r(i,b)for(int i=0;i<b;i++)
#define rep(i,a,b)for(int i=a;i<=b;i++)
#define per(i,a,b)for(int i=b;i>=a;i--)
#define debug(X) std::cout << "[DEBUG] ("<<__FILE__<<":"<<__FUNCTION__<<":"<<__LINE__<<") " << #X << " = " << X << std::endl;
template<typename T>ostream& operator<<(ostream& os, const vector<T>& v){for(int i=0;i<sz(v);i++){cout<<v[i]<<(i==sz(v)-1?'\n':' ');}return os;}
template<typename T>ostream& operator<<(ostream& os, const set<T>& v){for(auto& i:v){cout<<i<<" ";}cout<<endl;return os;}

#define inf 1000005000
#define lnf 2000000000000500000ll
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
ll mod=1e9+7;
long long modpow(long long base, long long pow, long long mod){base%=mod;long long res=1;for(;pow;pow>>=1){if(pow&1)res=res*base%mod;base=base*base%mod;}return res;}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n;cin>>n;
	string s;cin>>s;
	ll k=0;
	for_each(all(s),[&k](char &c){if(c=='?')k++;});
	ll ma(0),mb(0),mc(0);
	ll sigma=0;//i love siguma chan~
	ll totalstr=modpow(3,k,mod);
	f0r(i,n){
		if(s[i]=='a')ma+=totalstr,ma%=mod;
		if(s[i]=='b')mb+=ma,mb%=mod;
		if(s[i]=='c')mc+=mb,mc%=mod;
		if(s[i]=='?'){
			mc+=mb/3ll;mc%=mod;
			mb+=ma/3ll;mb%=mod;
			ma+=totalstr/3ll;ma%=mod;
		}
	}
	cout<<mc<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e4 + 4;//

int power(int a, int b, int c) {
	int ans = 1;
	while (b)
	{
		if (b & 1) ans = ans * a%c;
		b >> 1;
		a = a * a%c;
	}
	return ans;
}

int main(){
	int n;
	int a = 0, b = 0, w = 0, num = 0;
	int ans = 0;
	const int maxn = 2e5 + 7;
	const int mod = 1e9 + 7;
	char ch[maxn];
	int dp[maxn];

	scanf("%d", &n);
	scanf("%s", ch);
	for (int i = 0;i < n;i++) {
		if (i) dp[i] = dp[i - 1];
		if (ch[i] == 'a') a += power(3, num, mod);
		else if (ch[i] == 'b') dp[i] += a;
		else if (ch[i] == 'c') ans += dp[i];
		else {
			ans *= 3;ans += dp[i];
			dp[i] *= 3;dp[i] += a;
			a *= 3;a += power(3, num, mod);
			num++;
		}
		a %= mod;b %= mod;c %= mod;dp[i] %= mod;
	}
	printf("%lld\n", ans);
}


#include<bits/stdc++.h>
#define int long long
using namespace std;

int power(long long  a, long long  b, long long  c) {
	long long  ans = 1;
	while (b)
	{
		if (b & 1) ans = ans * a%c;
		b >>=1;
		a = a * a%c;
	}
	return ans;
}

signed main(){
	int n;
	long long  a = 0, b = 0, num = 0;
	long long  ans = 0;
	const int maxn = 2e5 + 7;
	const long long  mod = 1e9 + 7;
	char ch[maxn];
	long long  dp[maxn];

	scanf("%d", &n);
	scanf("%s", ch);
	for (int i = 0;i < n;i++) {
		if (i) dp[i] = dp[i - 1];
		if (ch[i] == 'a') a += power(3, num, mod);
		else if (ch[i] == 'b') dp[i] += a;
		else if (ch[i] == 'c') ans += dp[i];
		else {
			ans *= 3;ans += dp[i];
			dp[i] *= 3;dp[i] += a;
			a *= 3;a += power(3, num, mod);
			num++;
		}
		a %= mod;b %= mod;ans%= mod;dp[i] %= mod;
	}
	printf("%lld\n", ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e4 + 4;//

int power(int a, int b, int c) {
	int ans = 1;
	while (b)
	{
		if (b & 1) ans = ans * a%c;
		b >>=1;
		a = a * a%c;
	}
	return ans;
}

int main(){
	int n;
	int a = 0, b = 0, num = 0;
	int ans = 0;
	const int maxn = 2e5 + 7;
	const int mod = 1e9 + 7;
	char ch[maxn];
	int dp[maxn];

	scanf("%d", &n);
	scanf("%s", ch);
	for (int i = 0;i < n;i++) {
		if (i) dp[i] = dp[i - 1];
		if (ch[i] == 'a') a += power(3, num, mod);
		else if (ch[i] == 'b') dp[i] += a;
		else if (ch[i] == 'c') ans += dp[i];
		else {
			ans *= 3;ans += dp[i];
			dp[i] *= 3;dp[i] += a;
			a *= 3;a += power(3, num, mod);
			num++;
		}
		a %= mod;b %= mod;ans%= mod;dp[i] %= mod;
	}
	printf("%lld\n", ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e4 + 4;//

int power(int a, int b, int c) {
	int ans = 1;
	while (b)
	{
		if (b & 1) ans = ans * a%c;
		b >> 1;
		a = a * a%c;
	}
	return ans;
}

int main(){
	int n;
	int a = 0, b = 0, num = 0;
	int ans = 0;
	const int maxn = 2e5 + 7;
	const int mod = 1e9 + 7;
	char ch[maxn];
	int dp[maxn];

	scanf("%d", &n);
	scanf("%s", ch);
	for (int i = 0;i < n;i++) {
		if (i) dp[i] = dp[i - 1];
		if (ch[i] == 'a') a += power(3, num, mod);
		else if (ch[i] == 'b') dp[i] += a;
		else if (ch[i] == 'c') ans += dp[i];
		else {
			ans *= 3;ans += dp[i];
			dp[i] *= 3;dp[i] += a;
			a *= 3;a += power(3, num, mod);
			num++;
		}
		a %= mod;b %= mod;ans%= mod;dp[i] %= mod;
	}
	printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N=2e5+10,M=1e9+7;
int n,dp[N][3];
string s;
ll ans=0;

ll count(const string& s)
{
	//cerr<<s<<endl;
	if(s=="ccccccc"){
		cout<<s<<endl;
	}
	for(int i=0;i<s.length();++i){
		for(int j=0;j<3;++j)dp[i+1][j]=dp[i][j];
		switch(s[i]){
			case 'a':
				dp[i+1][0]=(dp[i][0]+1)%M;
				break;
			case 'b':
				dp[i+1][1]=(dp[i][1]+dp[i][0])%M;
				break;
			case 'c':
				dp[i+1][2]=(dp[i][2]+dp[i][1])%M;
				break;
			default:
				assert(0);
				break;
		}
	}
	//cerr<<dp[s.length()][2]<<endl;
	return dp[s.length()][2];
}
void dfs(string s,int pos=0)
{
	while(pos<s.length()&&s[pos]!='?')++pos;
	if(pos==s.length()){
		ans+=count(s);
		return;
	}
	for(int i='a';i<='c';++i){
		s[pos]=i;
		dfs(s,pos+1);
	}
}
int main()
{
    cin>>n>>s;
	dfs(s,0);
	cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N=2e5+10,M=1e9+7;
int n,dp[N][3];
string s;
ll ans=0;

ll count(const string& s)
{
	//cerr<<s<<endl;
	for(int i=0;i<s.length();++i){
		for(int j=0;j<3;++j)dp[i+1][j]=dp[i][j];
		switch(s[i]){
			case 'a':
				dp[i+1][0]=(dp[i][0]+1)%M;
				break;
			case 'b':
				dp[i+1][1]=(dp[i][1]+dp[i][0])%M;
				break;
			case 'c':
				dp[i+1][2]=(dp[i][2]+dp[i][1])%M;
				break;
			default:
				assert(0);
				break;
		}
	}
	//cerr<<dp[s.length()][2]<<endl;
	return dp[s.length()][2];
}
void dfs(string s,int pos=0)
{
	while(pos<s.length()&&s[pos]!='?')++pos;
	if(pos==s.length()){
		ans+=count(s);
		return;
	}
	for(int i='a';i<='c';++i){
		s[pos]=i;
		dfs(s,pos+1);
	}
}
int main()
{
    cin>>n>>s;
	dfs(s,0);
	cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <stack>
#define LL __int128
#define ll long long
#define lowbit(x) x&(-x)
#define ls p << 1
#define rs p << 1 | 1
using namespace std;
inline ll read()
{
    ll x=0;char ch=getchar();
    while(ch>'9'||ch<'0')ch=getchar();
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x;
}
/*~~~~~This is my coding part!~~~~~*/

const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
int a, ab, abc, p = 1, n;
int main()
{
//#ifndef ONLINE_JUDGE
////  freopen("data.in.txt","r",stdin);
////  freopen("data.out.txt","w",stdout);
//#endif
//    ios::sync_with_stdio(false);
    string s;
    cin >> n >> s;
    for(int i = 0; i < n; i ++)
    {
        if(s[i] == 'a')
        {
            a = (a + p) % mod;
        }
        else if(s[i] == 'b')
        {
            ab = (ab + a) % mod;
        }
        else if(s[i] == 'c')
        {
            abc = (abc + ab) % mod;
        }
        else if(s[i] == '?')
        {
            abc = (abc * 3 + ab) % mod;
            ab = (ab * 3 + a) % mod;
            a = (a * 3 + p) % mod;
            p = p * 3 % mod;
        }
    }
    cout << abc << endl;
    return 0;
}

/*~~~~~Hope to be accepted! ^v^~~~~~*/


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <stack>
#define LL __int128
#define ll long long
#define lowbit(x) x&(-x)
#define ls p << 1
#define rs p << 1 | 1
using namespace std;
inline ll read()
{
    ll x=0;char ch=getchar();
    while(ch>'9'||ch<'0')ch=getchar();
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x;
}
/*~~~~~This is my coding part!~~~~~*/

const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;

ll dp[5];
char a[maxn];
string s = "abc";

int main()
{
//#ifndef ONLINE_JUDGE
////  freopen("data.in.txt","r",stdin);
////  freopen("data.out.txt","w",stdout);
//#endif
//    ios::sync_with_stdio(false);

    int n; cin >> n >> (a + 1);
    dp[0] = 1;
    for(int i = 1; i <= n; i ++)
    {
        if(a[i] == '?')
        {
            for(int j = 3; j >= 1; j --)
                dp[j] = (dp[j] * 3 + dp[j - 1]) % mod;
            dp[0] = dp[0] * 3 % mod;
        }
        else
        {
            for(int j = 3; j >= 1; j --)
                if(a[i] == s[j - 1])
                    dp[j] = (dp[j] + dp[j - 1]) % mod;
        }
    }
    cout << dp[3] << endl;
    return 0;
}

/*~~~~~Hope to be accepted! ^v^~~~~~*/


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <stack>
#define LL __int128
#define ll long long
#define lowbit(x) x&(-x)
#define ls p << 1
#define rs p << 1 | 1
using namespace std;
inline ll read()
{
    ll x=0;char ch=getchar();
    while(ch>'9'||ch<'0')ch=getchar();
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x;
}
/*~~~~~This is my coding part!~~~~~*/

const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
ll a, ab, abc, p = 1, n;
int main()
{
//#ifndef ONLINE_JUDGE
////  freopen("data.in.txt","r",stdin);
////  freopen("data.out.txt","w",stdout);
//#endif
//    ios::sync_with_stdio(false);
    string s;
    cin >> n >> s;
    for(int i = 0; i < n; i ++)
    {
        if(s[i] == 'a')
        {
            a = (a + p) % mod;
        }
        else if(s[i] == 'b')
        {
            ab = (ab + a) % mod;
        }
        else if(s[i] == 'c')
        {
            abc = (abc + ab) % mod;
        }
        else if(s[i] == '?')
        {
            abc = (abc * 3 + ab) % mod;
            ab = (ab * 3 + a) % mod;
            a = (a * 3 + p) % mod;
            p = p * 3 % mod;
        }
    }
    cout << abc << endl;
    return 0;
}

/*~~~~~Hope to be accepted! ^v^~~~~~*/


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=2e5+5;
const int mod=1e9+7;
char s[maxm];
int d[3];
int n;
signed main(){
    cin>>n;
    scanf("%s",s+1);
    int p=1;
    for(int i=1;i<=n;i++){
        if(s[i]=='a'){
            d[0]+=p;
        }else if(s[i]=='b'){
            d[1]+=d[0];
        }else if(s[i]=='c'){
            d[2]+=d[1];
        }else if(s[i]=='?'){
            d[2]=d[2]*3+d[1];
            d[1]=d[1]*3+d[0];
            d[0]=d[0]*3+p;
            p=p*3%mod;
        }
        d[0]%=mod;
        d[1]%=mod;
        d[2]%=mod;
    }
    cout<<d[2]<<endl;
    return 0;
}


//#include<iostream>
//#include<cstring>
//#include<cstdio>
//#include<map>
//#include<queue>
//#include<cmath>
//#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define PI pair<int,int>
const int maxm=2e5+5;
const int mod=1e9+7;
char s[maxm];
int d[3];
int n;
signed main(){
    cin>>n;
    scanf("%s",s+1);
    int p=1;
    for(int i=1;i<=n;i++){
        if(s[i]=='a'){
            d[0]+=p;
        }else if(s[i]=='b'){
            d[1]+=d[0];
        }else if(s[i]=='c'){
            d[2]+=d[1];
        }else if(s[i]=='?'){
            d[2]=d[2]*3+d[1];
            d[1]=d[1]*3+d[0];
            d[0]=d[0]*3+p;
            p=p*3%mod;
        }
        d[0]%=mod;
        d[1]%=mod;
        d[2]%=mod;
    }
    cout<<d[2]<<endl;
    return 0;
}
/*

*/


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=2e5+5;
const int mod=1e9+7;
char s[maxm];
int p3[maxm];
int lx[maxm],rx[maxm];
int ly[maxm],ry[maxm];
int n;
void init(){
    p3[0]=1;
    for(int i=1;i<maxm;i++)p3[i]=1ll*p3[i-1]*3%mod;
}
signed main(){
    init();
    cin>>n;
    scanf("%s",s+1);
    for(int i=1;i<=n;i++){
        lx[i]=lx[i-1];
        ly[i]=ly[i-1];
        if(s[i]=='a')lx[i]++;
        else if(s[i]=='?')ly[i]++;
    }
    for(int i=n;i>=1;i--){
        rx[i]=rx[i+1];
        ry[i]=ry[i+1];
        if(s[i]=='c')rx[i]++;
        else if(s[i]=='?')ry[i]++;
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(s[i]=='b'||s[i]=='?'){
            int L=0;
            L+=p3[ly[i-1]]*lx[i-1]%mod;
            if(ly[i-1])L+=p3[ly[i-1]-1]*ly[i-1]%mod;
            int R=0;
            R+=p3[ry[i+1]]*rx[i+1]%mod;
            if(ry[i+1])R+=p3[ry[i+1]-1]*ry[i+1]%mod;
            ans=(ans+L*R)%mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}


//#include<iostream>
//#include<cstring>
//#include<cstdio>
//#include<map>
//#include<queue>
//#include<cmath>
//#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define PI pair<int,int>
const int maxm=2e5+5;
const int mod=1e9+7;
char s[maxm];
int p3[maxm];
int lx[maxm],rx[maxm];
int ly[maxm],ry[maxm];
int n;
void init(){
    p3[0]=1;
    for(int i=1;i<maxm;i++)p3[i]=1ll*p3[i-1]*3%mod;
}
signed main(){
    init();
    cin>>n;
    scanf("%s",s+1);
    for(int i=1;i<=n;i++){
        lx[i]=lx[i-1];
        ly[i]=ly[i-1];
        if(s[i]=='a')lx[i]++;
        else if(s[i]=='?')ly[i]++;
    }
    for(int i=n;i>=1;i--){
        rx[i]=rx[i+1];
        ry[i]=ry[i+1];
        if(s[i]=='c')rx[i]++;
        else if(s[i]=='?')ry[i]++;
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(s[i]=='b'||s[i]=='?'){
            int L=0;
            L+=p3[ly[i-1]]*lx[i-1]%mod;
            if(ly[i-1])L+=p3[ly[i-1]-1]*ly[i-1]%mod;
            int R=0;
            R+=p3[ry[i+1]]*rx[i+1]%mod;
            if(ry[i+1])R+=p3[ry[i+1]-1]*ry[i+1]%mod;
            ans=(ans+L*R)%mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}
/*

*/