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

typedef unsigned long long UINT64;
int n;
string s;
int main() {
    scanf("%d", &n);
    s.resize(n);    
    scanf("%s", &s[0]);
    UINT64 res = 0;
    if(n == 1) {
        if(s == "1") res = 20000000000;
        else res = 10000000000;
    }
    else if(n == 2) {
        if(s == "11" || s == "10") res = 10000000000;
        else if(s == "01") res = 9999999999;
    }
    else {
        if(s.substr(0, 3) == "110") {
            res = 10000000000;
            int sub = n/3;
            if(n%3 > 0) ++sub;
            res -= sub - 1;
        }
        else if(s.substr(0, 3) == "101") {
            res = 10000000000;
            int sub = (n+1)/3;
            if((n+1)%3 > 0) ++sub;
            res -= sub - 1;
        }
        else if(s.substr(0, 3) == "011") {
            res = 10000000000;
            int sub = (n+2)/3;
            if((n+2)%3 > 0) ++sub;
            res -= sub - 1;
        }
        for (int i = 3; i < s.size(); ++i) {
            if(s[i] != s[i%3]) {
                res = 0;
                break;
            }
        }
    }
    printf("%llu\n", res);
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	long long p = 1;
	for(int i = 0; i < 10; i++) p *= 10;
	int pieces = (n + 5) / 3;
	vector<int> vs;
	string to_match;
	for(int i = 0; i < pieces; i++){
		vs.push_back(i); vs.push_back(i); vs.push_back(i);
		to_match.push_back('1');
		to_match.push_back('1');
		to_match.push_back('0');
	}
	long long ans = 0;
	for(int i = 0; i < 3; i++){
		bool ok = true;
		for(int j = 0; j < n; j++){
			if(to_match[i + j] != s[j])
				ok = false;
		}
		if(ok){
			int len = vs[i + n - 1] - vs[i] + 1;
			ans += (p - len + 1);
		}
	}
	cout << ans << '\n';
	return 0;
}
