/*Jai Shree Ram*/
// Never Give Up
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define umii            unordered_map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define F(i,s,e,j)        for(int i=s;i<=e;i+=j)
#define mt19937                 rng(chrono::steady_clock::now().tjhe_since_epoch().count());   
//shuffle(arr,arr+n,rng)
 void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int32_t main()
{   c_p_c();
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<b-c<<endl;
} 
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
#define int long long
const int Mod = 1e9 + 7;
const int N = 1005;
char c[5];
int power[N+5],f[N+5],n;
signed main () {
	cin>>n>>c[1]>>c[2]>>c[3]>>c[4]; 
	f[0] = 1,f[1] = 1;
	for(int i = 2;i <= 1005;i++) {
		f[i] = (f[i-1] + f[i-2])%Mod;
	}
	power[1] = 2;
	for(int i = 2;i <= 1005;i++) {
		power[i] = power[i-1] * 2 % Mod;
	} 
	if(n <= 3) {
		puts("1");
		return 0;
	}
	if(c[2] == 'A') {
		if(c[1] == 'A') {
			printf("1\n");
			return 0;
		}
		else {
			if(c[3] == 'B') {
				printf("%lld\n",power[n-3]);
			}
			else {
				printf("%lld\n",f[n-2]);
			}
		}
 	}
 	if(c[2] == 'B') {
		if(c[4] == 'B') {
			printf("1\n");
			return 0;
		}
        else {
        	if(c[3] == 'A') {
        		printf("%lld\n",power[n-3]);
			}
			else printf("%lld\n",f[n-2]);
		}
	}
	return 0;
} 