#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp>   
using namespace std;
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  tree_order_statistics_node_update>  ordered_set; 
typedef long long ll;
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ff(i, c, n) for (ll i = c; i < n; i++)
#define fr(i, c, n) for (ll i = c; i >= n; --i)
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef pair<int, int> pii;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

// DEBUGGING TEMPLATE
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const ll mod=1000000007;
const ll mod1=998244353;

ll modpow(ll a, ll b, ll c)
{ //a^b%c in O(logb)
	ll res = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			res = (res * a) % c;
		}
		a = (a * a) % c;
		b >>= 1;
	}
	return res;
}
ll modinv(ll m, ll n)
{ //modular inverse of n w.r.t m provided 1<=n<=(m-1) in O(logn) and m is prime
	ll inv[n + 1];
	inv[1] = 1;
	for (int i = 2; i < n + 1; ++i)
		inv[i] = (m - (m / i) * inv[m % i] % m) % m;
	return inv[n];
}
ll n1 = 1e10;
void solve(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	if(s.length() == 1) {
		if(s[0] == '1') {
			cout << 2 * n1 << endl;
		}
		else cout << n1<< endl;
	}
	else {
		int i = 0;
		while(i < n && s[i] == '1') {
			i++;
		}
		if(i > 2) {
			cout << "0\n";
			return;
		}
		for(int j = i + 1; j < n; j += 3) {
			if(j < n && s[j] != '1') {
				cout << "0\n";
				return;
			}
			if(j + 1 < n && s[j + 1] != '1') {
				cout << "0\n";
				return;
			}
			if(j + 2 < n && s[j + 2] != '0') {
				cout << "0\n";
				return;
			}
		}
		cout << (3 * n1 - (2 - i) - n + 3) / 3 << endl;
	}
}

//a+b=a^b+2*(a&b)
int main()
{
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	t = 1;
	while(t--){
		solve();
	}


	return 0;
}

/*
LL         JJ  SSSS    ii  ssss     SSSS BBBB
LL         JJ S           s        S     B   B
LL         JJ  SSS     ii  sss      SSS  BBBB
LL     JJ  JJ     S    ii     s        S B   B
LLLLLL  JJJJ  SSSS     ii ssss     SSSS  BBBB

 SSSS BBBB     ii  ssss    LL         JJ  SSSS
S     B   B       s        LL         JJ S
 SSS  BBBB     ii  sss     LL         JJ  SSS
    S B   B    ii     s    LL     JJ  JJ     S
SSSS  BBBB     ii ssss     LLLLLL  JJJJ  SSSS
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n;
bool st[200005],sdt[6000005];
LL nxt[200005];
/*
 10^10
------- = 10^5
  10^5
*/
int main(){
	for(LL i=1;i<=6000000;++i)	sdt[i]=bool(i%3);
	scanf("%lld",&n);
	for(LL i=1;i<=n;++i)
	{
		LL x;
		scanf("%1lld",&x);
		st[i]=x;
	}
	LL j=0;
	for(LL i=2;i<=n;++i)
	{
		while(j && st[j+1]!=st[i])	j=nxt[j];
		if(st[j+1]==st[i])	++j;
		nxt[i]=j;
	}
	j=0;
	LL ans=0,ans2=0;
	for(LL i=1;i<=6000000;++i)
	{
		while(j && st[j+1]!=sdt[i])	j=nxt[j];
		if(sdt[i]==st[j+1])	++j;
		if(j==n)
		{
			if(i-n+1<=1500000)
			{
				if(i<=1500000)	++ans;
				else	++ans,++ans2;
			}
			j=nxt[j];
		}
	}
	printf("%lld",ans*20000-ans2);
	return 0;
}