#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>
#include<math.h>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll modq=998244353;
const ll INF=1e18;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}

ll modpow(ll a,ll n) {
    ll res = 1;
    while (n>0) {
        if(n&1) res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}
   
int main(void){
    vector<ll> Fib(1050);
    Fib.at(0)=0,Fib.at(1)=1;
    rep(i,1010) Fib.at(i+2)=(Fib.at(i+1)+Fib.at(i))%mod;

    ll N;
    cin>>N;
    char caa,cab,cba,cbb;
    cin>>caa>>cab>>cba>>cbb;
    if(N<4){
        cout<<1<<endl;
        return 0;
    }
    if(caa=='A' && cab=='A'){
        cout<<1<<endl;
        return 0;
    }
    if(cbb=='B' && cab=='B'){
        cout<<1<<endl;
        return 0;
    }
    if(cab=='B' && cbb=='A'){
        if(cba=='A'){
            cout<<modpow(2,N-3)<<endl;
            return 0;
        }
        cout<<Fib.at(N-1)<<endl;
        return 0;
    }
    if(cba=='B'){
        cout<<modpow(2,N-3)<<endl;
        return 0;
    }
    cout<<Fib.at(N-1)<<endl;
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin>>N;
  vector<int> A(N);
  vector<int> B(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  for(int i=0;i<N;i++){
    cin>>B[i];
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  int x=A[N-1],y=B[0];
  //cout<<x<<","<<y<<endl;
  if(y-x+1<0){
    cout<<"0"<<endl;
  }
  else cout<<y-x+1<<endl;
}
