#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define LL long long
#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<int, int>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 1e3+9;
constexpr int M = 1e9+7;
#ifdef int
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;
#else
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
#endif

int n;
char aa, ab, ba, bb;

int fact[N], inv[N];
int qpow(int a, int b){
    int c = 1;
    while(b){
        if(b & 1) c = c * a % M;
        a = a * a % M;
        b >>= 1;
    }
    return c;
}
int C(int n,int m){
    if(n < 0 || m > n) return 0;
    return fact[n] * inv[m] % M * inv[n-m] % M;
}
void init(){
    fact[0] = 1;
    for (int i = 1; i < N; i++) fact[i] = fact[i-1] * i % M;
    inv[N-1] = qpow(fact[N-1], M - 2);
    for(int i= N-2; i >= 0; i--) inv[i] = inv[i+1] * (i+1) % M;
}
void add(int& x, int y) {
    x %= M, y %= M;
    x = (x + M + y) % M;
}
int Lucas(int n, int m) {
    if(n < 0 || m > n) return 0;
    if (m == 0) return 1;
    return (C(n % M, m % M) * Lucas(n / M, m / M)) % M;
}

// 想清楚计数的依据

signed main() {
    fastio;
    init();
    cin >> n >> aa >> ab >> ba >> bb;
    if (n <= 3) {
        cout << 1 << "\n";
        return 0;
    }
    if (ab == 'A') {
        if (aa == 'A') {
            cout << 1 << "\n";
        } else {
            if (ba == 'A') {
                int ans = 0;
                for (int innerB = 0; innerB*2+2 <= n; innerB++) {
                    add(ans, C(n-1-innerB-1, innerB));
                }
                cout << ans << "\n";
            } else {
                cout << qpow(2, n-3) << "\n";
            }
        }
    } else {
        if (bb == 'B') {
            cout << 1 << "\n";
        } else {
            if (ba == 'B') {
                int ans = 0;
                for (int innerB = 0; innerB*2+2 <= n; innerB++) {
                    add(ans, C(n-1-innerB-1, innerB));
                }
                cout << ans << "\n";
            } else {
                cout << qpow(2, n-3) << "\n";
            }
        }
    }
    return 0;
}
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    cin >> a>>b>>c>>d;
    cout << max(a,b)-min(c,d);
    return 0;
}