#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string t;
    cin >> t;
    if (n == 1) {
        if (t == "1") {
            cout << (long long)2e10 << '\n';
        } else {
            cout << (long long)1e10 << '\n';
        }
        return 0;
    } else if (n == 2) {
        if (t == "11") {
            cout << (long long)1e10 << '\n';
        } else if (t == "10") {
            cout << (long long)1e10 << '\n';
        } else if (t == "01") {
            cout << (long long)(1e10) - 1 << '\n';
        } else {
            cout << 0 << '\n';
        }
        return 0;
    }
    vector<int> a(3);
    for (int i = 0; i < 3; i++) {
        a[i] = t[i] - '0';
    }
    if (a[0] + a[1] + a[2] != 2) {
        cout << 0 << '\n';
        return 0;
    }
    for (int i = 0; i < n; i++) {
        if (a[i % 3] != t[i] - '0') {
            cout << 0 << '\n';
            return 0;
        }
    }
    int b;
    if (a[0] == 0) {
        b = 2;
    } else if (a[1] == 0) {
        b = 1;
    } else {
        b = 0;
    }
    long long i = (long long)(3e10) - 1;
    i -= n - 1;
    while (i % 3 != b) {
        i--;
    }
    cout << i / 3 + 1 << '\n';
    return 0;
}
/*
You're my honeybunch, sugar plum
Pumpy-umpy-umpkin
You're my sweetie pie
You're my cuppycake, gumdrop
Snoogums, boogums, you're
The apple of my eye

And I love you so
And I want you to know
That I'm always be right here
And I want to sing
Sweet songs to you
Because you are so dear...

*/
#include <bits/stdc++.h>
#include<iostream>

#define boost ios::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define pai pair<int, int>
#define ar array

using namespace std;
int const nax=2e5;
int const M=1e9;
const int64_t Leng = int64_t(3e10);
void solve(){
    int n;
    cin >>n ;
    ll answer =0 ;
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        bool valid = true;
        for(int j=0;j<n;j++){
            int index = i+j;
            char want = index % 3 < 2 ? '1' : '0';
            valid = valid && s[j]==want;
        }
        if(valid){
            int64_t lastindex = Leng - n;
            while(lastindex%3!=i)lastindex--;
            answer += (lastindex-i)/3 +1;
        }
    }   
    cout << answer<< endl;

}

int main(){
   boost;
   int t=1,z=1;
   //cin>>t;
   while(t--){
   //cout<< "Case #"<< z++ <<  ": " ;
        solve();
    }
}