#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define light ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vp(v)  for(auto it = v.begin(); it != v.end(); it++)  cout << *it << " "; cout<<endl;


int main()
{   
    light
    ll tx;
    cin>>tx;
    ll h1, h2 , t;
    string s1 , s2 , ts ;
    cin>>s1>>h1;
    cin>>s2>>h2;
    if( h1 < h2){
        t = h1 ;
        ts = s1;
        h1 = h2 ;
        s1 = s2 ;
        h2 = t;
        s2 = ts;
    }
    for(ll i =2; i<tx; i++){
        ll he; 
        string  m ;
        cin>>m>>he; 
        if( he > h1 ){
            t = h1 ;
            ts = s1;
            h1 = he ;
            s1 = m ;
            h2 = t;
            s2 = ts;
        }
        else if( h1 > he && h2 < he){
            h2 = he ;
            s2 = m;
        }
    }

    cout<<s2<<endl;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <string>
#include <iomanip>
#include <locale>
#include <list>
#include <bitset>
#include <tuple>
#include <fstream>
using namespace std;
 
#define FORN(i,m,n) for(int i=(m); i<int(n); ++i)
#define PRINTARR(a,n) FORN(i,0,n) cout<<a[i]<<" "; cout<<endl
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
 
typedef long long ll;
const int ms = 50;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n; cin>>n;
  ll ans = 0;
  FORN(i,0,n){
    ll a, b;
    cin>>a>>b;
    ans += ((b - a + 1) * (a + b)) >> 1;
  }
  cout<<ans<<endl;
}