//12252024832524
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; 

typedef long long LL;
const int MAXN = 100005;
const int MOD = 1e9 + 7;
int n;

int Read()
{
	int x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
void Put1(int x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
void Put(int x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x);
	if(c >= 0) putchar(c);
}
template <typename T>T Max(T x,T y){return x > y ? x : y;}
template <typename T>T Min(T x,T y){return x < y ? x : y;}
template <typename T>T Abs(T x){return x < 0 ? -x : x;}

int qpow(int x,int y)
{
	int ret = 1;
	while(y){if(y & 1) ret = 1ll * ret * x % MOD;x = 1ll * x * x % MOD;y >>= 1;}
	return ret;
}
char gc()
{
	char c = getchar();
	while(c != 'A' && c != 'B') c = getchar();
	return c;
}
int f[MAXN];
int getf(int x)
{
	f[1] = 2;f[2] = 3;
	for(int i = 3;i <= x;++ i) f[i] = (f[i-1] + f[i-2]) % MOD;
	return f[x];
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n = Read();
	if(n <= 3) {Put(1);return 0;}
	char aa = gc(),ab = gc(),ba = gc(),bb = gc();
	if(ab == 'B')
	{
		if(bb == 'B') Put(1);
		else
		{
			if(ba == 'A') Put(qpow(2,n-3));
			else Put(getf(n-3));
		}
	}
	else
	{
		if(aa == 'A') Put(1);
		else
		{
			if(ab == 'B' || ba == 'B') Put(qpow(2,n-3));
			else Put(getf(n-3));
		}
	}
	return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <set>
//#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define all(v) v.begin(), v.end()
#define front(v) *v.begin()
#define back(v) *(--v.end())
#define len(v) v.size()
#define int long long

using longl = long long;
using longd = long double;

const longl INF = 1e9;
const longl LINF = 1e18;
const longl mod = 1e9 + 7;
const double PI = acos(-1);
//------------------------------------------------------------------------------------------------

longl divup(longl a, longl b){
    return (a + b - 1) / b;
}

longl bin_pow(longl a, longl b){
    longl res = 1;

    while (b > 0){
        if (b % 2)
            res = res * a % mod;

        a = a * a % mod;
        b /= 2;
    }
    return res;
}


//------------------------------------------------------------------------------------------------
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n;
    cin >> n;

    vector<int> v(n);

    for (int i = 0; i < n; i++){
        cin >> v[i];
    }

    sort(all(v));
    v.resize(unique(all(v)) - v.begin());
    reverse(all(v));

    int ans = 1;

    for (int i = 1; i < v.size(); i++){
        ans = (ans * (v[i - 1] - v[i] + 1)) % mod;
    }
    ans = ans * (v[v.size() - 1] + 1) % mod;
    cout << ans << endl;
    return 0;
}