// #define _GLIBCXX_DEBUG // #include #include #include #include using namespace std; #include int N,M; long long ans=0; using S=pair; S op(S l, S r){ return S{l.first+r.first, l.second+r.second}; } S e(void){ return S{0LL,0}; } int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); cout< seg_x(1009),seg_y(1009); cin>>N; for(int i=0;i>x>>y; auto [sum,cnt]=seg_x.get(x); seg_x.set(x, S{sum+x, ++cnt}); tie(sum,cnt)=seg_y.get(y); seg_y.set(y, S{sum+y, ++cnt}); } cin>>M; for(int i=0;i>x>>y; { // smaller auto [sum,cnt]=seg_x.prod(0, x); ans+=x*cnt-sum; // larger tie(sum,cnt)=seg_x.prod(x, 1009); ans+=x*cnt-sum; } { // smaller auto [sum,cnt]=seg_y.prod(0, y); ans+=y*cnt-sum; // larger tie(sum,cnt)=seg_y.prod(y, 1009); ans+=y*cnt-sum; } } cout<