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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define irreps(i, m, n) for (long long i = ((long long)(n)-1); i > (long long)(m); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) (long long)(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

 

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  string t; cin>>t;
  
  
  if(n==1){
    ll ans=10000000000;
    if(t=="0") cout<<ans<<endl;
    else cout<<ans*2<<endl;
  }else if(n==2){
    ll ans=10000000000;
    if(t=="11") cout<<ans<<endl;
    else if(t=="00") cout<<0<<endl;
    else if(t=="10") cout<<ans<<endl;
    else if(t=="01") cout<<ans-1<<endl;
  }else{
    bool flg=1;
    char cycle[]={'1','1','0'};
    
    ll base=10000000000, rem=0;
    base*=3;
    if(t.substr(0,3)=="110"){
      irep(i,3,n) if(cycle[i%3]!=t[i]) flg=0;
    }else if(t.substr(0,2)=="10"){
      rem=1;
      irep(i,2,n) if(cycle[(i-2)%3]!=t[i]) flg=0;
    }else if(t.substr(0,1)=="0"){
      rem=2;
      irep(i,1,n) if(cycle[(i-1)%3]!=t[i]) flg=0;
    }else{
      cout<<0<<endl;
      return 0;
    }
    if(!flg) cout<<0<<endl;
    else{
      ll x=(base-n-rem)/3;
      cout<<x+1<<endl;
      // rem=rem;
      // cout<<rem<<endl;
    }
  }
  
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;


int n;
char s[200010];
long long totalCount;

long long getStartPos() {
	if ((s[0] == '1') && (s[1] == '1') && (s[2] == '0')) {
		return 0;
	} else if ((s[0] == '1') && (s[1] == '0') && (s[2] == '1')) {
		return 1;
	} else if ((s[0] == '0') && (s[1] == '1') && (s[2] == '1')) {
		return 2;
	}
	
	
	return -1;
}

int main()
{
	scanf("%d\n", &n);
	scanf("%s\n", s);
	totalCount = 10000000000L;
	
	if (n == 1) {
		long long zeroCount = 10000000000L;
		long long oneCount = 20000000000L;
		
		if (s[0] == '0') {
			printf("%lld\n", zeroCount);
		} else {
			printf("%lld\n", oneCount);
		}
		
		return 0;
	}
	
	if (n == 2) {
		if ((s[0] == '0') && (s[1] == '0')) {
			printf("0\n");
		} else if ((s[0] == '0') && (s[1] == '1')) {
			printf("%lld\n", totalCount - 1);
		} else {
			printf("%lld\n", totalCount);
		}
		
		return 0;
	}
	
	for (int i = 3 ; i < n ; i++) {
		if (s[i] != s[i - 3]) {
			printf("0\n");
			return 0;
		}
	}
	
	long long startPos = getStartPos();
	long long endPos = startPos + n - 1;
	
	if (startPos == -1) {
		printf("0\n");
		return 0;
	}
	
	long long startSect = startPos / 3;
	long long endSect = endPos / 3;
	
	long long ans = totalCount - endSect;
	
	printf("%lld\n", ans);
	
	return 0;
}
