#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = 2e9;
const ld EPS = 1e-9;
const int M = 31;
const int N = 1e6 + 10;

char c[5];
/*
char get_ch(char a, char b) {
  if (a == 'A') {
    if (b == 'A') return c[0];
    return c[1];
  }
  if (b == 'A') return c[2];
  return c[3];
}
*/

set<string> pow2 = {"ABAA", "BABA", "BABB", "BBAA"};
set<string> fib = {"ABBA", "BAAA", "BAAB", "BBBA"};

const ll MOD = 1e9 + 7;

void solve() {
  int n;
  cin >> n;
  string s;
  for (int i = 0; i < 4; ++i) {
    cin >> c[i];
    s += c[i];
  }

  if (pow2.count(s)) {
    ll ans = 1;
    for (int i = 3; i < n; ++i) {
      ans = (ans * 2) % MOD;
    }
    cout << ans << endl;
  } else if (fib.count(s)) {
    ll f0 = 1;
    ll f1 = 1;
    for (int i = 3; i < n; ++i) {
      ll f_tmp = (f0 + f1) % MOD;
      f0 = f1;
      f1 = f_tmp;
    }
    cout << f1 << endl;
  } else {
    cout << 1 << endl;
  }


  /*
  string s = "AB";
  set<string> ss = {s};
  for (int len = 3; len < 10; ++len) {
    set<string> news;
    for (auto s: ss) {
      for (int pos = 0; pos + 1 < (int)s.size(); ++pos) {
        string t = s;
        t.insert(t.begin() + pos + 1, get_ch(t[pos], t[pos + 1]));
        news.insert(t);
      } 
    }
    ss = news;
    for (auto s: ss) cout << s << "\t";
    cout << endl << ss.size() << endl;
    cout << endl;
  }
  */
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while (t--) {
		solve();
	}
}

#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> plli;
typedef vector< vi > vvi ;
typedef vector< vlli > vvlli  ;
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define flli(i,a,b) for(long long int i=a;i<=b;i++)
#define bi(i,a,b) for(int i=a;i>=b;i--)
#define blli(i,a,b) for(long long int i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pi 2*acos(0.0)
#define pb push_back
#define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
#define present(v,num) (v.find(num)!=v.end())
#define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
#define pq priority_queue
#define mp make_pair
const int inf=INT_MAX;
const lli INF =LLONG_MAX;
const lli mod = 1e9+7;
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;
    string s;cin>>s;
    deque<char> a;
    bool flag=true;
    lli n=sz(s);
    flli(i,0,n-1)
    {
    	if(s[i]=='R')
    	{
    		flag=flag^true;
    	}
    	else
    	{
    		if(flag)
    		{
    			if(a.empty())
    			{
    				a.push_back(s[i]);
    				continue;
    			}
    			auto vari=a.rbegin();
    			if(*vari!=s[i])
    				a.push_back(s[i]);
    			else a.pop_back();
    		}
    		else 
    		{
    			if(a.empty())
    			{
    				a.push_front(s[i]);
    				continue;
    			}
    			auto vari=a.begin();
    			if(*vari!=s[i])
    				a.push_front(s[i]);
    			else a.pop_front();
    		}
    	}
    }
    string t;
    while(!a.empty())
    {
    	auto vari=a.begin();
    	t.pb(*vari);
    	a.pop_front();
    }
    if(!flag)reverse(all(t));
    tr(t,it)cout<<*it;
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}