#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp(a, b) make_pair(a, b)
const int maxn = 1000 + 10;
const ll mod = 1e9 + 7;
char s[4][10];
int tr[4];		
ll f[maxn], g[maxn];
ll powMod(ll a, ll k)
{
	ll ret = 1;
	while(k > 0)
	{
		if(k & 1) ret = ret * a % mod;
		a = a * a % mod; k >>= 1;
	}
	return ret;
}
int main()
{
	int n;
	scanf("%d", &n);
	g[1] = g[0] = f[0] = 1;
	for(int i = 2; i <= n; ++i)
	{
		f[i] = g[i - 2];
		g[i] = (g[i - 1] + f[i]) % mod;
	}
	for(int i = 0; i < 4; ++i)
	{
		scanf("%s", s[i]);
		tr[i] = s[i][0] - 'A';
	}
	if(tr[1] == 0)
	{
		if(tr[0] == 0) puts("1");
		else
		{
			if(tr[2] == 0)
				printf("%lld\n", f[n]);
			else
				printf("%lld\n", powMod(2, n - 3));
		}
	}
	else
	{
		if(tr[3] == 1) puts("1");
		else
		{
			if(tr[2] == 1)
				printf("%lld\n", f[n]);
			else
				printf("%lld\n", powMod(2, n - 3));
		}
	}
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9+7;
int main(){
    int N; cin >> N;
    vector<ll> A(N), sum(N+1);
    for(int i=0; i<N; i++){
        cin >> A[i];
        sum[i+1] = sum[i]+A[i];
    }
    vector<vector<int>> dp(N+2,vector<int>(N+2));
    dp[1][0]++;
    int ans = 0;
    for(int i=0; i<N; i++){
        for(int j=N; 1<=j; j--){
            dp[j+1][sum[i+1]%(j+1)] += dp[j][sum[i+1]%j];
            dp[j+1][sum[i+1]%(j+1)] %= mod;
            if(i == N-1){
                ans += dp[j][sum[i+1]%j];
                ans %= mod;
            }
        }   
    }
    cout << ans << endl;
}