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

int main() {
   int N;
   string T;
   cin >> N >> T;
   long long ans=10000000000;
   if (N==1) {
       if (T!="0")  ans*=2;
   }
   else if (N==2) {
       if (T=="00") ans=0;
       else if (T=="01") ans--;
   }
   else if (N==3) {
       if (T=="101" || T=="011") ans--;
       else if (T!="110") ans=0;
   }
   else if (N==4) {
       if (T=="1101" || T=="1011" || T=="0110")  ans--;
       else ans=0;
   }
   else {
       string x="",y="";
       long long count=0,p=-1;
       for (int i=0; i<3; i++) {
           if (T.substr(i,3)=="110") p=i;
       }
       if (p==-1) ans=0;
       else {
           int z;
           for (int i=p; i+2<N; i+=3) {
               if (T.substr(i,3)=="110") count++;
               else {
                   count=-1;ans=0;break;
               }
               z=i+3;
           }
           if (count>0) {
               if (p>0) x=T.substr(0,p);
               if (z<N) y=T.substr(z);
               if ((x=="" || x=="10" || x=="0") && (y=="" || y=="1" || y=="11")) {
                   if (x=="" && y=="") ans=ans-count+1;
                   else if (x!="" && y!="") ans=ans-count-1;
                   else ans-=count;
               }
               else ans=0;
           }
       }
   }
   cout << ans << endl;
}
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--)
#define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on
struct in {
    template <class T> operator T() {
        T t;
        std::cin >> t;
        return t;
    }
};
void out() { std::cout << "\n"; }
template <class Head, class... Tail> void out(Head&& h, Tail&&... t) {
    std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...);
}
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }
template <class T> using V = std::vector<T>;

/**
 *    author:  knshnb
 *    created: Sat Dec  5 21:06:29 JST 2020
 **/

std::string t = "110";
signed main() {
    Int n = in();
    std::string s = in();
    Int ans = 0;
    REP(offset, 3) {
        bool ok = true;
        REP(i, n) {
            if (s[i] != t[(i + offset) % 3]) ok = false;
        }
        if (!ok) continue;
        ans += (Int)1e10 - (n + offset - 1) / 3;
    }
    out(ans);
}
