#include #include #pragma GCC optimize("O3") #pragma GCC target("avx") #define ll long long using namespace std; struct P { int x, y; P(){} P(int a, int b) : x(a), y(b){} bool operator< (const P& a) const { return (this->x == a.x)?(this->y < a.y):(this->x < a.x); } }; #define getchar getchar_unlocked inline int in() { int n, c; while ((c = getchar()) < '0') if (c == EOF) return -1; n = c - '0'; while ((c = getchar()) >= '0') n = n * 10 + c - '0'; return n; } const int MAX_N = 300001; int i,n,q; ll ans = 0; int bt[MAX_N], a[MAX_N], r[MAX_N]; P p[2*MAX_N]; void add(int i, int x){ while(i < n+1) bt[i] += x, i += i & -i; } int sum(int i){ int s = 0; while(i > 0) s += bt[i], i -= i & -i; return s; } int main() { n = in(); for(i = 0; i < n; i++){ a[i] = in(); } for(i = 0; i < n; i++){ int l = in(); r[i] = in(); p[i] = P(a[i], n+i); p[n+i] = P(a[i]-l, i); } sort(p, p+2*n); for(i = 0; i < 2*n; i++){ q = p[i].y; if(q >= n){ q -= n; ans += sum(upper_bound(a, a+n, a[q]+r[q]) - a) - sum(q+1); }else{ add(q+1,1); } } printf("%lld\n",ans); return 0; }