#include <bits/stdc++.h>

using namespace std;

const int N = 2e3 + 5;
typedef long long LL;
LL const mod = 1e9 + 7;
LL n, dp[N][2];

LL qmi(LL a, LL k, LL p) {
    LL res = 1 % p;  // res记录答案, 模上p是为了防止k为0，p为1的特殊情况
    while (k) {  // 只要还有剩下位数
        if (k & 1)
            res =
                (LL)res * a % p;  // 判断最后一位是否为1，如果为1就乘上a，模上p,
                                  // 乘法时可能爆int，所以变成long long
        k >>= 1;  // 右移一位
        a = (LL)a * a %
            p;  // 当前a等于上一次的a平方，取模，平方时可能爆int，所以变成long
                // long
    }
    return res;
}

int main() {
    cin >> n;
    char caa, cab, cba, cbb;
    cin >> caa >> cab >> cba >> cbb;
    if (n <= 3)
        cout << 1 << endl;
    else if (cab == 'A') {
        if (caa == 'A') {
            cout << 1 << endl;
            return 0;
        }
        if (cba == 'A') {
            dp[0][0] = 1;
            dp[0][1] = 0;
            for (int i = 1; i <= n - 2; i++) {
                dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
                dp[i][1] = dp[i - 1][0];
            }
            cout << (dp[n - 2][0]) % mod << endl;
            return 0;
        } else {
            cout << qmi(2, n - 3, mod) << endl;
            return 0;
        }
    } else if (cab == 'B') {
        if (cbb == 'B') {
            cout << 1 << endl;
            return 0;
        }
        if (cba == 'B') {
            dp[0][0] = 1;
            dp[0][1] = 0;
            for (int i = 1; i <= n - 2; i++) {
                dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
                dp[i][1] = dp[i - 1][0];
            }
            cout << (dp[n - 2][0]) % mod << endl;
            return 0;
        } else {
            cout << qmi(2, n - 3, mod) << endl;
            return 0;
        }
    }
    return 0;
}
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
 * Author: alireza_kaviani
 * Time: 2020-12-05 16:43:07
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , m , A[MAXN] , s;

int main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

	cin >> n >> m; m += n;
	for(int i = 0 ; i < n ; i++){
		cin >> A[i];
		s += A[i] + 1;
	}
	ll ans = 1 , x = 1;
	// cout << s << sep << m << endl;
	for(int i = 1 ; i <= s ; i++){
		ans = ans * (m - i + 1) % MOD;
		x = x * i % MOD;
	}
	cout << ans * poww(x , MOD - 2 , MOD) % MOD << endl;

    return 0;
}
/*

*/
