#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,a,b,c) for(ll i=a;i<b;i+=c)
#define For2(i,a,b,c) for(ll i=a;i>=b;i-=c)
#define vec_ll vector<vector<ll>>
#define vec_pr vector<pair<ll,ll>>
#define pr pair<ll,ll>
#define pbk push_back
#define mkpr make_pair
#define fst first
#define snd second

void print(ll *arr, ll n){
    For(i,0,n,1)cout<<arr[i]<<" ";
    cout<<endl;
}


bool s_sec(const pair<ll,ll> &a, const pair<ll,ll> &b) {
    return (a.second < b.second);
}

ll fast_expo(ll a, ll p){
    //cout<<a<<" ";
    ll x=p-2;
    ll curr=a;
    ll ans=1;
    while(x!=0){
        if(x%2==1){
            ans=(ans*curr)%p;
        }
        x/=2;
        curr=(curr*curr)%p;
    }
    return ans;
}

void solve(string &s, ll n, vector<ll> &ans){
    ll pref[n+1],suff[n+1];

    ///pref
    if(s[0]=='R'){
        pref[1]=1;
    }
    else{
        pref[1]=0;
    }

    For(i,1,n,1){
        if(s[i]=='R'){
            if(s[i-1]=='R'){
                pref[i+1]=1;
            }
            else{
                pref[i+1]=pref[i]+1;
            }
        }
        else{
            if(s[i-1]=='R'){
                pref[i+1]=pref[i]+1;
            }
            else{
                pref[i]=0;
            }
        }
    }

    ll mark_r[n+1];
    ll cnt=n;
    For(i,n,1,1){
        mark_r[i]=cnt;
        if(pref[i]==0){
            cnt=i;
        }
    }
    mark_r[0]=cnt;

    ///suff
    if(s[n-1]=='L'){
        suff[n-1]=1;
    }
    else{
        suff[n-1]=0;
    }

    For2(i,n-2,0,1){
       if(s[i]!=s[i+1]){
            suff[i]=suff[i+1]+1;
       }
       else{
            if(s[i]=='L'){
                suff[i]=1;
            }
            else{
                suff[i]=0;
            }
       }
    }

    ll mark_l[n+1];
    cnt=0;
    For(i,0,n,1){
        mark_l[i]=cnt;
        if(suff[i]==0){
            cnt=i;
        }
    }
    mark_l[n]=cnt;

    ans.pbk(mark_r[0]);
    For(i,1,n,1){
        ans.pbk(mark_r[i]-mark_l[i]-1);
    }
    ans.pbk(suff[n]);

    return ;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    /*ll T,p=1000000007;
    cin>>T;

    ll fact[1001],inverse[1001];
    fact[0]=fact[1]=inverse[0]=inverse[1]=1;

    For(i,2,1001,1){
        fact[i]=(fact[i-1]*i)%p;
        inverse[i]=fast_expo(fact[i],p);
    }*/

    /*ll T;
    cin>>T;

    while(T--){
        ll n;
        cin>>n;

        string s;
        cin>>s;

        vector<ll> ans;
        solve(s,n,ans);

        For(i,0,n+1,1)cout<<ans[i]<<" ";
        cout<<"\n";
    }*/

    ll N;
    cin>>N;
    ll lim=2*N;

    ll root=sqrt(lim);
    ll ans=0;

    For(i,1,root+1,1){
        ///Check if answer is possible
        if(lim%i==0){
            ll fact[2]={i,lim/i-1};

            ll x=(fact[0]+fact[1]), y=(fact[1]-fact[0]);
            if(x%2==0&&y%2==0)ans++;
        }
    }

    cout<<2*ans;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define FOR(i, a, b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = (ll)(a - 1); i >= (ll)(b); i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

long long mod_pow(long long x, long long y, long long M){
    if(y == 0){
        return 1;
    }
    if(y & 1){
        return mod_pow(x, y - 1, M) * x % M;
    }
    long long t = mod_pow(x, y / 2, M);
    return t * t % M;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    char c0,c1,c2,c3;
    cin >> N >> c0 >> c1 >> c2 >> c3;
    if(N<=3){
        cout << 1 << endl;
        return 0;
    }
    string s="";
    s+=c0;
    s+=c1;
    s+=c2;
    s+=c3;
    if(s=="ABAA"||s=="BABA"||s=="BABB"||s=="BBAA"){
        cout << mod_pow(2,N-3,MOD) << endl;
    }
    else if(s=="ABBA"||s=="BAAA"||s=="BAAB"||s=="BBBA"){
        vl dp(10000,0);
        dp[2]=dp[3]=1;
        FOR(i,4,10000){
            dp[i]=dp[i-1]+dp[i-2];
            dp[i]%=MOD;
        }
        cout << dp[N] << endl;
    }
    else{
        cout << 1 << endl;
    }
}