#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    ll n;
    cin >> n;
    ll a,b;
    ll total = 0;
    rep(i,n){
        cin >> a >> b;
        total += (b*(b+1)/2) - (a*(a-1))/2;
    }
    cout << total << endl;
    return 0;
}
#pragma Ofast
//#pragma GCC optimize("Ofast,no-stack-protector")
#include<bits/stdc++.h>
#define int long long
#define float double
using namespace std;
signed main(){
srand(time(NULL));
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int a;
cin>>a;
string b;
cin>>b;
bool fail=0;
int suc=-1;
int three=3;
for(int ii=0;ii<3;ii++){
    fail=0;
for(int i=ii;i<a;i++){
    if(i%3==2-ii){
        //cout<<i<<" "<<b[i]<<" "<<0<<endl;
        if(b[i]!='0'){
            fail=1;
            break;
        }
    }
    else{
        //cout<<i<<" "<<b[i]<<" "<<1<<endl;
        if(b[i]!='1'){

            fail=1;
            break;
        }
    }
}
if(fail==0){
    suc=ii;
    break;
}
}
if(suc==-1){
    cout<<0<<endl;
}
else if(b=="111"){
    cout<<0<<endl;
}
else if(b=="00"||b=="000"||b=="010"||b=="100"||b=="001"){
    cout<<0<<endl;
}
else if(a==1){
    if(b=="1")
        cout<<20000000000<<endl;
    if(b=="0"){
        cout<<10000000000<<endl;
    }
}
else{
    a+=suc;
    //cout<<a<<endl;
    suc=(a+2)/3;
    cout<<10000000000-suc+1<<endl;
}

return 0;
}


