#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define ll long long
#define pr pair<int,int>
#define N 100005
#define mod 1000000007
#define INF 2147483647
using namespace std;
int main() {
	IOS;
    int n;
    string t;
    cin>>n>>t;
    if(n==1){
        if(t=="1"){
            cout<<20000000000;
        }
        else cout<<10000000000;
        return 0;
    }
    bool los=0;
    int cnt1=0,cnt0=0;
    bool hs0=0;
    for(int i=0;i<n;i++){
        if(t[i]=='0'){
            if(hs0&&cnt1!=2)los=1;
            hs0=1;
            cnt1=0;
            cnt0++;
        }
        else cnt1++,cnt0=0;
        if(cnt1>2||cnt0>1)los=1;
        if(los)break;
    }
    if(los)cout<<0;
    else{
        ll len=10000000000;
        ll ans=n;
        if(t[0]=='0'){
            ans=(2+n)/3+((n+2)%3!=0);

        }
        else if(t[1]=='0'){
            ans=(1+n)/3+((n+1)%3!=0);
        }
        else{
            ans=n/3+(n%3!=0);
        }
        cout<<len-ans+1;
    }
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}
#ifdef LOCAL
void _debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void _debug_out(Head H, Tail... T) { cerr << " " << to_string(H); _debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", _debug_out(__VA_ARGS__)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 42
#define eprintf(...) 42
#endif

int main() {
  int n; string t; cin >> n >> t;
  if(n == 1) {
    if(t[0] == '0') cout <<  (ll)1e10 << endl;
    else cout <<  2 * (ll)1e10 << endl;
    return 0;
  }

  if(n==2) {
    if(t=="11") cout <<  (ll)1e10 << endl;
    if(t=="10") cout <<  (ll)1e10 << endl;
    if(t=="01") cout <<  (ll)(1e10)-1 << endl;
    if(t=="00") cout << 0 << endl;
    return 0;
  }

  auto ttt = t.substr(0,3);
  if(!(ttt=="110" || ttt =="101" || ttt=="011")) {
    cout << 0 << endl;
    return 0;
  }
  for(int i=0; i<n-3; i++) {
    if(t[i] != t[i+3]) {
      cout << 0 << endl;
      return 0;
    }
  }

  int zero = 0;
  for(auto c:t) zero += (c=='0');
  cerr << zero << endl;
  ll ans = (ll)1e10 - zero;
  if(t.back() == '0') ans++;
  cout << ans << endl;
}
