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

long long L = 10000000000;

int main(){
  long long N;
  string T;
  cin >> N >> T;
  
  if(N==1){
    if(T=="0") cout << L << endl;
    else cout << L*2 << endl;
  }
  else if(N==2){
    if(T=="00") cout << 0 << endl;
    else if(T=="01") cout << L-1 << endl;
    else cout << L << endl;
  }
  else{
    int s=-1;
    if(T[0]=='0') s = 0;
    else if(T[1]=='0') s = 1;
    else if(T[2]=='0') s = 2;
    else{
      cout << 0 << endl;
      return 0;
    }
    
    long long count=0;
    for(int i=s+1;i<N;i++){
      if(T[i]=='0') count++;
      if((i-s)%3==0 && T[i]!='0'){
        cout << 0 << endl;
        return 0;
      }
      if((i-s)%3!=0 && T[i]!='1'){
        cout << 0 << endl;
        return 0;
      }
    }
    
    long long ans = L - count;
    if(T[N-1]=='1') ans--;
    
    cout << ans << endl;
  }
  return 0;
}

#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;

string s;

char a[4];
int main()
{
	ll k=10000000000;
	int n;
	cin>>n;
	a[0]='1';a[1]='1';a[2]='0';
	cin>>s;
	//cout<<s[0]<<endl;
	int f=-1;
	for(int i=0;i<=2;++i)
	  {
	  	  f=i;
	  	  for(int j=0;j<n;++j)
	  	    if(s[j]!=a[(i+j)%3])
	  	      {
	  	      	  f=-1;
	  	      	 // cout<<j<<" "<<(i+j)%3<<endl;
	  	      	  //cout<<s[j]<<"  "<<a[(i+j)%3]<<endl;
	  	      	  break;
	  	      }
	  	  //cout<<endl;    
	  	  if(f>=0) break;    
	  }
	//cout<<f<<endl;  
	if(f==-1) cout<<0<<endl;
	  else 
	  if(n==1) 
	  {
	  	  if(s[0]=='1') cout<<k*2<<endl;
	  	  else cout<<k<<endl;
	  }
	  else if(n==2) 
	  {
	  	  if(s[0]=='1')
	  	  {
	  	  	  cout<<k<<endl;
	  	  }
	  	  else
	  	  {
	  	  	  if(s[1]=='1')
	  	  	    cout<<k-1<<endl;
	  	  }
	  }
	  else
	    {
	    	n=n-(3-f);
	    	ll t=n/3;
			ll l=0;
			if(n%3>0)  t++; 
			if(n>0) cout<<k-t<<endl;
			  else cout<<k<<endl; 
	    }  
}
