#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define db double
#define pb push_back
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
#define cps(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define cps2(x, y) sort(all(x), y), (x).erase(unique(all(x)), end(x))
#define mem(x, y) memset(& x, y, sizeof(x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int n0 = 2e5 + 123;
ll a[n0], b[n0];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n; cin >> n; for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] += a[i - 1];
		//cerr << a[i] << ' ';
	}
	ll res = 0, mx = 0;
	for (int i = 1; i <= n; i++) {
		mx = max(mx, a[i]);
		ll tmp = b[i - 1] + mx;
		b[i] = b[i - 1] + a[i];
		res = max(res, max(b[i], tmp));
	}
	cout << res;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <queue>
#include<deque>

using namespace std;
const int mod = 1e9 + 7;
typedef long long LL;
int ans[110] = {1,2,3,3,1,3,2,2,1,2,1,1,1,3,1,1};
int f[1010];
int b[1010];
int n;

void solve()
{
    scanf("%d",&n);
    int state = 0;
    for(int i = 0;i < 4;i ++)
    {
        int a;
        scanf("%s",&a);
        state |= (a - 'A') << i;
    }
    f[2] = 1;
    b[0] = 1;
    for(int i = 3;i <= n;i ++) f[i] = ((LL)f[i] + f[i - 1] + f[i - 2]) % mod;
    for(int i = 1;i <= n - 3;i ++) b[i] = (LL)b[i - 1] * 2 % mod;
    
    if(n < 3) printf("1\n");
    else if(ans[state] == 1) printf("1\n");
    else if(ans[state] == 2) printf("%d\n",f[n]);
    else if(ans[state] == 3) printf("%d\n",b[n - 3]);
}

int main()
{
    int T = 1;
    //scanf("%d",&T);
    while(T --)
    {
        solve();
    }
    return 0;
}

