#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef string str;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define pb(x)                       push_back(x)
#define pf(x)                       push_front(x)
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll MAXN = 1e3 + 10;
const ll INF = 1e18;
const ll LOG = 20;
const ll MOD = 1e9 + 7;

ll poww(ll a, ll b, ll md, ll ans = 1) {
    for (; b; b >>= 1, a = a * a % md)
    	if (b & 1) ans = ans * a % md;
    return ans;
}

ll fib[MAXN] , c[4];

int main(){

    fast_io;
    fib[1] = fib[2] = 1;
	for (int i = 3; i < MAXN; i++){
		fib[i] = (fib[i - 1] + fib[i - 2]) % MOD;
	}
	ll n;
	cin >> n;
	for (int i = 0; i < 4; ++ i){
		char ch;
		cin >> ch;
		c[i] = ch - 'A';
	}
	if (n < 4){
        cout << 1;
        return 0;
	}
	if (!c[1]){
		if (!c[0]){
            cout << 1;
            return 0;
		}
		if (!c[2]){
            cout << fib[n - 1];
            return 0;
		}
		cout << poww(2, n - 3, MOD);
		return 0;
	}
    if (c[3]){
        cout << 1;
        return 0;
    }
	if (c[2]){
        cout << fib[n - 1];
        return 0;
	}
	cout << poww(2, n - 3, MOD);

}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXM = 1e4 + 5;
#define pb push_back
#define eb emplace_back
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define LINF 9223372036854775807
#define LMIN -9223372036854775807
#define mp make_pair
#define tiii tuple<int, int, int>
#define tlll tuple<ll, ll, ll>
#define mid(s, e) (s + (e - s) / 2)
#define F first
#define z endl
#define S second
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)            // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)           // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n)-1; i >= 0; --i)        // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i)          // reverse 1 based
#define all(x) (x).begin(), (x).end()                            //Forward traversal
#define rall(x) (x).rbegin, (x).rend()                           //reverse traversal
// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define pll pair<long long, long long>
#define present(c, x) ((c).find(x) != (c).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, pair<int, int>> ppi;
typedef double ld;
//std::rotate(vec1.begin(), vec1.begin()+rotL, vec1.end())    Rotate vector left rotL times.  in Theta(n)
//  std::rotate(vec2.begin(), vec2.begin()+vec2.size()-rotR, vec2.end());     Rotate vector Right rotR times. int Theta(n)

class compare
{
public:
    bool operator()(const pair<int, int> &a, const pair<int, int> &b)
    {
        if (a.first == b.first)
            return a.second > b.second;
        return a.first < b.first;
    }
};
bool isprime(int n)
{
    if (n == 1)
        return false;
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

int lcm(int a, int b)
{
    return (a * b) / __gcd(a, b);
}

int gcd(int a, int b)
{
    if (b == 0)
    {
        return a;
    }
    return gcd(b, a % b);
}
int countDigits(int n)
{
    return floor(log10(n) + 1);
}
int main()
{
    // auto start = chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    if (n == 1)
        cout << 1 << endl;
    else
    {
        int count = 1;
        int x = 0;
        while (x < n)
        {
            x += count;
            count++;
        }
        cout << count - 1 << endl;
    }
    // auto end = chrono::high_resolution_clock::now();
    // double time_taken =
    //     chrono::duration_cast<chrono::nanoseconds>(end - start).count();
    // time_taken *= 1e-9;
    // cout << "Time taken by program is : " << fixed
    //      << time_taken << setprecision(9);
    // cout << " sec" << endl;
    return 0;
}