#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
 
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; }
 
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>=n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
 
const vector<int> dx = {1, 1,  1, 0,  0, 0, -1, -1, -1};
const vector<int> dy = {1, 0, -1, 1, -1, 0,  1,  0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
 
const int MAX = 1000000;
const int MOD = 1000000007;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }

int main(){
  int n;
  ll ans = 0;
  cin >> n;
  rep(i, 0, n){
      ll a, b;
      cin >> a >> b;
      ans += (a+b)*(b-a+1)/2;
  }
  cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (int)(n) ; i++)

int main() {
    int n; cin>>n;
    vector<ll> a(n), ac(n), mx(n);
    rep(i, n) {
        cin >> a[i];
        if(i==0) {
            ac[i]=a[i];
            mx[i]=ac[i];
        }
        else {
            ac[i]+=ac[i-1]+a[i];
            mx[i]=max(mx[i-1], ac[i]);
        }
    }
    ll co=0, comx=0;
    rep(i, n) {
        comx=max(comx, co+mx[i]);
        co += ac[i];
        comx=max(comx, co);
    }
    cout << comx << endl;
}