#include <bits/stdc++.h>
using namespace std;

const long long ANS=1e10;
string t;
int n;

bool into_string(string t,string a){
    for (int i=0; i<t.size(); i++)
        if (a[i%3] != t[i])
            return false;

	return true;
}

main(){
    cin>>n>>t;

    if (n==0){
        cout<<0<<endl;
        return 0;
    }
    else{
        if (n==1 && t[0]=='1')
        {
            cout<<ANS*2<<endl;
            return 0;
        }
    }

    int usin_block=0;
    if (into_string(t,"101")==true)
        usin_block=1+ceil((float)(n-2)/3);
    else
    {
        if (into_string(t,"110")==true)
            usin_block=ceil((float)n/3);
        if (into_string(t,"011")==true)
            usin_block=1+ceil((float)(n-1)/3);
    }

    if (usin_block==0)
    {
        cout<<0;
        return 0;
    }

    cout<<(long long)ANS-usin_block+1;
}

#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef long double ld;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n;
	cin>>n;
	string t;
	cin>>t;
	ll ans = 0;
	ll N = 3e10l;
	for (ll o=0; o<3; ++o) {
	    string s = "";
	    while (s.size()<n+10) s+="110";
	    s = s.substr(o, n);
	    if (t!=s) continue;
	    ll l = N-n;
	    while (l%3!=o) --l;
	    ans += (l-o)/3 + 1;
	}
	cout<<ans<<endl;
}