#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ms(x, y) memset(x, y, sizeof x)
#define sp ,' ',
#define el ,'\n'
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using l2 = array<ll, 2>;
using l3 = array<ll, 3>;
template<typename... Args>
inline void out(Args... args) {
(cout << ... << args);
}
struct r {
template<typename T>
inline r& operator,(T& x) {
cin >> x;
return *this;
}
} in;
#define in in,
int n, h, k, hmx;
ll fw[100005], ans;
l2 sails[100005];
map<ll, ll> mp;
void update(int i, ll val) {
for (; i <= 100000; i = i | (i+1)) fw[i] += val;
}
ll query(int i) {
ll ret = 0;
for (; i >= 0; i = (i & (i+1)) - 1) ret += fw[i];
return ret;
}
void solve() {
cin >> n;
for (int i = 0; i < n; i++) {
int h, k; cin >> h >> k;
hmx = max(hmx, h);
update(h-k, 1);
update(h, -1);
}
for (int i = 0; i < hmx; i++) {
ll cur = query(i);
for (auto it = mp.begin(); it != mp.end();) {
auto &[val, cnt] = *it;
if (cur <= val) break;
ll nx = min(cur-val, cnt);
cur -= nx;
cnt -= nx;
mp[val+1] += nx;
if (cnt == 0) it = mp.erase(it);
else it++;
}
if (mp.empty() || cur <= mp.begin()->first) mp[cur]++;
}
for (auto [val, cnt]: mp) ans += val * (val - 1) / 2 * cnt;
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
// in(t);
while (t--) solve();
}