#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> order_set;

const int MAXN = 234567;
char S[MAXN], T[123] = "110";

int main() {
    int N;
    scanf("%d", &N);
    scanf("%s", S);
    LL ans = 0;
    for (int i = 0; i < 3; i++) {
        bool OK = true;
        for (int j = 0; j < N; j++) {
            if (S[j] != T[(i + j) % 3]) {
                OK = false;
                break;
            }
        }
        if (OK) {
            LL sum = (LL)1e10;
            LL need = (i + N - 1) / 3 + 1;
            ans += (sum - need + 1);
        }
    }
    printf("%lld\n", ans);
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/

#include <bits/stdc++.h>

using namespace std;

int a, b, ans;

int check(int a, int b) {
    if (a+b >= 15 && b >= 8) return 1;
    if (a+b >= 10 && b >= 3) return 2;
    if (a+b >= 3) return 3;
    return 4;
}

int main() {
    //freopen("isc.inp", "r", stdin);
    //freopen("isc.out", "w", stdout);

    scanf("%d%d", &a, &b);
    ans = check(a, b);

    printf("%d", ans);

    return 0;
}
