#pragma GCC optimize("Ofast")
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <cmath>
#include <iomanip>
#include <string>
#include <deque>
#include <assert.h>
#include <random>
#include <ctime>
#include <unordered_map>
#include <complex>
#include <chrono>

#define pnode node*

using namespace std;

typedef long long ll;
typedef long double ld;

ll n;
string t;

void zer() {
    cout << 0 << "\n";
    exit(0);
}

void solve(){
	cin >> n;
    cin >> t;
    ll ten = 10'000'000'000;
    if (t == "1") {
        cout << 2 * ten << "\n";
        return;
    } else if (t == "11") {
        cout << ten << "\n";
        return;
    }
    ll fst = -1;
    for (ll i = 0; i < t.size(); ++i) {
        if (t[i] == '0') {
            fst = i;
            break;
        }
    }
    if (fst == -1) {
        zer();
    }
    vector < ll > z(t.size());
    for (ll shft = 0; shft <= t.size(); ++shft) {
//		cerr << shft << "\n";
        ll l = fst - 3 * shft;
        ll r = fst + 3 * shft;
        if (l >= 0) {
            if (t[l] == '1') {
                zer();
            } else {
            	z[l] = 1;
            }
        }
        if (r < t.size()) {
            if (t[r] == '1') {
				zer();
            } else {
            	z[r] = 1;
            }
        }
    }
//    for (ll i = 0; i < z.size(); ++i) {
//		cerr << z[i] << " ";
//    }
//    cerr << "\n";
    for (ll i = 0; i < t.size(); ++i) {
        if (!z[i] && t[i] == '0') {
            zer();
        }
    }
    ll sz = t.size();
    if (t.size() >= 2 && t[0] == '1' && t[1] == '1') {
		sz -= 2;
    } else if (t[0] == '1') {
        sz--;
    }
    ll res = (3 * ten - 2 - sz) / 3 + 1;
    cout << res << "\n";
}

signed main(){
    ll t = 1;
    ios_base::sync_with_stdio(0);
    srand(time(0));
    cin.tie(0);
    cout.tie(0);
    cout << fixed;
    cout << setprecision(20);
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
    #endif
    while(t--){
        solve();
    }
}

//#####   #####   #####   #####   #####   #       #####   #   #//
//#   #   #   #   #       #       #   #   #       #   #   ## ##//
//#####   #####   #####   #       #####   #       #####   # # #//
//##      #   #       #   #       #   #   #       #   #   #   #//
//# #     #   #       #   #       #   #   #       #   #   #   #//
//#  #    #   #       #   #       #   #   #       #   #   #   #//
//#   #   #   #   #####   #####   #   #   #####   #   #   #   #//


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ppb pop_back
#define cs(n) cout<<n<<" "
#define cn(n) cout<<n<<"\n"
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define rrep(i,j,k) for(ll i=j;i>=k;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define deb(x) cout << #x << " " << x << endl;
template<typename... T>
void read(T&... args) {
	((cin >> args), ...);
}
template<typename... T>
void write(T&&... args) {
	((cout << args << " "), ...);
}
template<typename... T>
void writen(T&&... args) {
	((cout << args << "\n"), ...);
}
ll bin(ll a, ll b, ll mod)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
		return bin((a * a) % mod , b / 2 , mod) % mod;
	return ((a % mod) * (bin((a * a) % mod , b / 2 , mod) % mod)) % mod;
}
void solve()
{
	ll n;
	read(n);
	ll ans = 0;
	rep(i, 0, n) {
		ll a, b;
		read(a, b);
		ans += b * (b + 1) / 2;
		ans -= a * (a - 1) / 2;
	}
	cout << ans;
} int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif
	fastio;
	ll t;
	t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
	}
#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
	return 0;
}