#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define all(v) (v).begin(),(v).end()
#define all_rev(v) (v).rbegin(),(v).rend()
#define debug(x) cout << #x << ": " << x << '\n';
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)

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; }

using namespace std;
using ll = long long;
using P = pair<int,int>;
using PL = pair<ll, ll>;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  //cin.tie(0);ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15);
  ll x = 10000000000;

  int n;
  string t;
  cin >> n >> t;

  for (int i = 2; i < t.size(); i++) {
    if (t[i - 2] == '1') {
      if (t[i - 1] == '1') {
        if (t[i] != '0') {
          cout << 0 << endl;
          exit(0);
        }
      } else if (t[i - 1] == '0') {
        if (t[i] != '1') {
          cout << 0 << endl;
          exit(0);
        }
      }
    } else if (t[i - 2] == '0') {
      if (t[i - 1] == '1' && t[i] == '1') {
        continue;
      } else {
        cout << 0 << endl;
        exit(0);
      }
    }
  }

  if (t == "1") {
    cout << 2 * x << endl;
  }else if (t == "00") {
    cout << 0 << endl;
  } else if (t == "11" || t == "0" || t == "10") {
    cout << x << endl;
  } else {
    if (t[0] == '0') {
      // 0110110 -> 110110
      t = t.substr(1);
      x--;
    } else if (t[0] == '1' && t[1] == '0') {
      // 10110110 -> 110110
      t = t.substr(2);
      x--;
    }

    if (t.size() > 2) {
      x = (x - (t.size() / 3)) + 1;
      if (t.size() % 3) x--;
    }
    cout << x << endl;
  }

  return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cerr<<#x<<" = "<<x<<endl

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    li n;

    cin>>n;

    li a[n];

    map<li,li> cnt;

    f(i,0,n-1)
    {
        cin>>a[i];

        cnt[a[i]]++;
    }

    map<li,li> cnt2;

    li ans=0;

    f(i,0,n-1)
    {
        cnt2[a[i]]++;

        ans+= n-i-1-(cnt[a[i]]-cnt2[a[i]]);
    }

    cout<<ans;
}

int main()
{    
    //remove this in kickstart

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li t=1;

    // cin>>t;

    f(i,1,t)
    {
        // cout<<"Case #"<<i<<": ";

        solve();
    }

    return 0;
}