#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

using namespace std;

int main()
{
    int n;
    cin >> n;

    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    ll ans = 0;
    ll nc = 0;
    ll sum = 0;
    ll m = 0;
    for (int i = 1; i <= n; i++) {
        sum = sum + a.at(i - 1);
        m = max(m, sum);
        ans = max(ans, nc + m);
        nc += sum;
    }

    cout << ans << endl;

    return 0;
}
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N, M, K, H, W, A, B, C, D;
string S;
const ll INF = 1LL<<60;

int main(){
    cin>>N;
    ll res(0);
    rep(i, N){
        cin>>A>>B;
        res += (A + B) * (B - A + 1) / 2;
    }
    cout<<res<<endl;
}
