#include <bits/stdc++.h>
#define rei register int
#define ll long long
using namespace std;


char standard[3]={'1','1','0'};
const ll N=1e10,M=2e5+100;
int n,t;
string s;
char a[M];

bool check(){
	int pos1=a[1],pos2=a[2];
	if(pos1=='1'){
		if(pos2=='1'){
			for(rei i=3;i<=n;++i)
			    if(a[i]!=standard[(i-1)%3]) return false;
		}
		if(pos2=='0'){
			for(rei i=3;i<=n;++i) 
			    if(a[i]!=standard[(i)%3]) return false;
		}
	}
	if(pos1=='0'){
		if(pos2=='1'){
			for(rei i=3;i<=n;++i)
			    if(a[i]!=standard[(i-2)%3]) return false;
		}
		if(pos2=='0'){
			return false;
		}
	}
	return true;
}

int main(){
	cin>>n;
	int pos;
	getchar();
	for(rei i=1;i<=n;++i){
	    a[i]=getchar();
	}
	if(!check()){
		cout<<0<<endl;
		return 0;
	}
	if(n==1){
		if(a[1]=='1')
			cout<<N*2<<endl;
		else
		    cout<<N<<endl;
		return 0;
	}
	if(n==2){
		if(a[1]=='0') cout<<N-1<<endl;
		else cout<<N<<endl;
		return 0;
	}
	if(!(n%3)){
		if(a[1]=='1'&&a[2]=='1'&&a[3]=='0')
		    cout<<N-n/3+1<<endl;
		else 
		    cout<<N-n/3<<endl;
		return 0;
	}
	if((n%3)==1){
		cout<<N-n/3<<endl;
		return 0;
	} 
	if(a[1]=='0')
		cout<<N-n/3-1<<endl; 
	else 
	    cout<<N-n/3<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll

signed main() {
  int n;
  string s = "110";
  string t;
  cin >> n >> t;

  int ans = 1e10;
  if (t == "1") {
    cout << ans * 2 << '\n';
    return 0;
  } else if (t == "11" || t == "10") {
    cout << ans << '\n';
    return 0;
  }

  int m = 3;
  int cnt = 1;
  int need = n+2;
  while(m < need) {
    m+=3;
    s += "110";
    cnt++;
  }

  int mod = -1;
  for (int i = 0; i <= 2; i++) {
    if (s.substr(i,n) == t) mod = i;
  }
  if (mod == -1) {
    cout << 0 << '\n';
    return 0;
  }

  if (mod == 0) {
    ans = ans - cnt + 2;
  } else {
    ans = ans - cnt + 1;
  }
  cout << ans << '\n';
}
