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

bool checkValidStr(int N, string T) {
  string startsWith = T.substr(0, 3);
  if(startsWith == "110") {
    for(int i = 0; i < N; i++) {
      char c = T.at(i);
      int rest = i % 3;
      if(rest == 0 || rest == 1) {
        if(c != '1') {
          return false;
        }
      } else {
        if(c != '0') {
          return false;
        }
      }
    }
  }else if(startsWith == "101") {
    for(int i = 0; i < N; i++) {
      char c = T.at(i);
      int rest = i % 3;
      if(rest == 0 || rest == 2) {
        if(c != '1') {
          return false;
        }
      } else {
        if(c != '0') {
          return false;
        }
      }
    }
  } else if(startsWith == "011") {
    for(int i = 0; i < N; i++) {
      char c = T.at(i);
      int rest = i % 3;
      if(rest == 1 || rest == 2) {
        if(c != '1') {
          return false;
        }
      } else {
        if(c != '0') {
          return false;
        }
      }
    }
  }
  return true;
}

int64_t count110(int N, string T) {
  if(N == 1) {
    if(T == "0") {
      return pow(10, 10);
    } else {
      return pow(10, 10) * 2;
    }
  }
  if(N == 2) {
    if(T == "00") {
      return 0;
    } else if(T == "01") {
      return pow(10, 10) - 1;
    } else {
      return pow(10, 10); // "11"のみ
    }
  }
  if(!checkValidStr(N, T)) {
    return 0;
  }
  string startsWith = T.substr(0, 3);
  int64_t result = 0;
  if(startsWith == "110") {
    int rest = (N - 1) / 3;
    result = pow(10,10) - rest;
  }else if(startsWith == "101") {
    int rest = (N - 3) / 3;
    result = pow(10,10) - 1 - rest;
  } else if(startsWith == "011") {
    int rest = (N - 2) / 3;
    result = pow(10,10) - 1 - rest;
  }
  return result;
}

int main()
{
  int N;
  cin >> N;
  string T;
  cin >> T;
  int64_t count = count110(N, T);
  cout << count << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 998244353
#define all(a) a.begin(),a.end()
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(auto x:v) cout<<" "<<x; cout<<endl;
ll power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int main(){ 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll tmp=1e10;
	if(n==1){
		if(s=="1")
			cout<<tmp*2<<endl;
		else
			cout<<tmp<<endl;
		return 0;
	}
	if(n==2){
		if(s=="01"){
			cout<<tmp-1<<endl;
		}
		else if(s=="10")
			cout<<tmp<<endl;
		else if(s=="11")	
			cout<<tmp<<endl;
		else
			cout<<0<<endl;
		return 0;
	}
	int f=0;
	string t=s.substr(0,3);
	for(int i=0;i<n-3;i+=3){
		if(s.substr(i,3)!=t)
			f=1;
	}
	ll ans=1e10;
	ans*=3LL;
	string end=s.substr(n-2,2);
	if(t=="011"&&!f){
		ans-=2;
	}
	else if(t=="101"&&!f){
		ans-=1;
	}
	else if(t=="110"&&!f){
	}
	else{ 	
		cout<<0<<endl;
		return 0;
	}
	if(end=="01"){
		ans-=2;
	}
	else if(end=="11"){
		ans-=1;
	}
	else{
	}
	ans=(ans-n)/3LL;
	ans++;
	cout<<ans<<endl;
}

