// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#ifdef _LOCAL_
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define name(x) #x
#define dump(x) cout << name(x) << " = " << x << endl;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rrep(i,n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define For(i,x) for (auto &i : x)
#define len(x) ll(x.size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) ll(__builtin_popcountll(bit))
#define gcd(a,b) __gcd(a, b)
#define lcm(a,b) a * b / __gcd(a, b)
#define roundup(x,y) (x + y - 1) / y
using ll = long long;
using pii = pair<int,int>;
const long double pi = acos(-1.0);
const ll INF = 4500000000000000000ll;
const int MAX = 1000010;
const int MOD1 = 1000000007;
const int MOD2 = 998244353;
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};
const int di2[8] = {0, 1, 0, -1, 1, 1,-1, -1};
const int dj2[8] = {1, 0,-1, 0, 1, -1, 1, -1};
template <typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <typename T> bool chmin(T &a, T b) {if (b < a) {a = b; return 1;} return 0;}
template <typename T> T bpow(T a, int n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
template <typename T> auto comp(vector<T> a) {sort(all(a)); a.erase(unique(all(a)),a.end()); return a;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T,U> &p) {os << p.first << " " << p.second; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T,U> &mp) {For(p,mp) {os << "[" << p << "]\n";} return os;}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {rep(i,len(v)) {if(i) os << " "; os << v[i];} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T> &st) {int c(0); For(x,st) {if (c) os << " "; os << x; c++;} return os;}
template <typename T> istream &operator>>(istream &i, vector<T> &v) {rep(j,len(v)) i >> v[j]; return i;}
template <typename T, typename U> istream &operator>>(istream &i, pair<T,U> &p) {i >> p.first >> p.second; return i;}



void solve() {
    int n; cin >> n;
    string s; cin >> s;
    string t = "";
    int num = 10000000000;
    rep(i,n/3+2) t += "110";
    bool ok = false;
    rep(i,3) if (t.substr(i,n) == s) ok = true;
    if (!ok) cout << 0 << endl;
    else {
        int c = 0;
        rep(i,n) if (s[i] == '0') c++;
        if (s == "1") cout << 2 * num << endl;
        else if (s[n-1] == '0') cout << num - c + 1 << endl;
        else cout << num - c << endl;
    }
    return;
}

signed main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef _DEBUG
#define show(x)          \
	cerr << #x << " : "; \
	showVal(x)
template <typename T>
void showVal(const T &a) { cerr << a << endl; }
template <typename T>
void showVal(const vector<T> &a) {
	for (const T &v : a) cerr << v << " ";
	cerr << endl;
}
template <typename T>
void showVal(const vector<vector<T>> &a) {
	cerr << endl;
	for (const vector<T> &v : a) showVal(v);
}
#else
#define show(x)
#endif
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<ll> s1(n + 1), s2(n + 1);
	for (int i = 0; i < n; i++) {
		s1[i + 1] = s1[i];
		if (i % 2 == 0) s1[i + 1] += a[i];
		s2[i + 1] = s2[i];
		if (i % 2 == 1) s2[i + 1] += a[i];
	}
	show(s1);
	show(s2);
	map<ll, int> diff;
	for (int i = 0; i < n + 1; i++) {
		diff[s1[i] - s2[i]]++;
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		diff[s1[i] - s2[i]]--;
		ans += diff[s1[i] - s2[i]];
	}
	cout << ans << endl;
	return 0;
}