#include using namespace std; using ll=long long; using ld=long double; using P=pair; #define MOD 1000000007ll #define INF 1000000000ll #define EPS 1e-10 #define FOR(i,n,m) for(ll i=n;i<(ll)m;i++) #define REP(i,n) FOR(i,0,n) #define DUMP(a) REP(d,a.size()){cout< 0; x -= x & -x) ret += bit[x]; return ret; } void init() { for(ll i=0; i < N; i++) bit[i] = 0; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin>>n; vector a(n); REP(i,n) cin>>a[i]; vector l(n); vector r(n); REP(i,n) cin>>l[i]>>r[i]; ll ans=0; vector b(n); priority_queue,greater

> q; REP(i,n) { while(!q.empty()&&(q.top()).first