Language: C++

#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
#define long long long long
#define two pair<long long,pair<long long,long long> >
set<two>s1,s2;
set<two>::iterator it;
long long a[100003];
long long b[100003];
long long n,j,ans;
int main(){std::ios::sync_with_stdio(false);
cin>>n;
for(long long i=0;i<n;i++){
	cin>>a[i]>>b[i];
	s1.insert({a[i],{b[i],i}});
	s2.insert({b[i],{a[i],i}});
}
j=1LL;
while(j<=n){
	if(j&1){
		it=s1.end();
		it--;
		ans+=(*it).first;
		s1.erase(it);
		it=s2.find({(*it).second.first,{(*it).first,(*it).second.second}});
		s2.erase(it);
	}else{
		it=s2.end();
		it--;
		ans-=(*it).first;
		s2.erase(it);
		it=s1.find({(*it).second.first,{(*it).first,(*it).second.second}});
		s1.erase(it);
	}
	j++;
}
cout<<ans<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
                 *   *   * *   *
                  *   *   *   *
                   *   * *   *
                     *  *   *
					   *  *


*/





Compiler output:
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:5:18: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                  ^~~~
a.cc:6:5: note: in expansion of macro 'two'
    6 | set<two>s1,s2;
      |     ^~~
a.cc:4:14: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |              ^~~~
a.cc:5:23: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                       ^~~~
a.cc:6:5: note: in expansion of macro 'two'
    6 | set<two>s1,s2;
      |     ^~~
a.cc:4:19: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                   ^~~~
a.cc:5:23: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                       ^~~~
a.cc:6:5: note: in expansion of macro 'two'
    6 | set<two>s1,s2;
      |     ^~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:5:23: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                       ^~~~
a.cc:6:5: note: in expansion of macro 'two'
    6 | set<two>s1,s2;
      |     ^~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:5:33: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                 ^~~~
a.cc:6:5: note: in expansion of macro 'two'
    6 | set<two>s1,s2;
      |     ^~~
a.cc:4:14: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |              ^~~~
a.cc:5:38: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                      ^~~~
a.cc:6:5: note: in expansion of macro 'two'
    6 | set<two>s1,s2;
      |     ^~~
a.cc:4:19: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                   ^~~~
a.cc:5:38: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                      ^~~~
a.cc:6:5: note: in expansion of macro 'two'
    6 | set<two>s1,s2;
      |     ^~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:5:38: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                      ^~~~
a.cc:6:5: note: in expansion of macro 'two'
    6 | set<two>s1,s2;
      |     ^~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:5:43: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                           ^~~~
a.cc:6:5: note: in expansion of macro 'two'
    6 | set<two>s1,s2;
      |     ^~~
a.cc:4:14: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |              ^~~~
a.cc:5:48: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                                ^~~~
a.cc:6:5: note: in expansion of macro 'two'
    6 | set<two>s1,s2;
      |     ^~~
a.cc:4:19: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                   ^~~~
a.cc:5:48: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                                ^~~~
a.cc:6:5: note: in expansion of macro 'two'
    6 | set<two>s1,s2;
      |     ^~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:5:48: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                                ^~~~
a.cc:6:5: note: in expansion of macro 'two'
    6 | set<two>s1,s2;
      |     ^~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:5:18: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                  ^~~~
a.cc:7:5: note: in expansion of macro 'two'
    7 | set<two>::iterator it;
      |     ^~~
a.cc:4:14: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |              ^~~~
a.cc:5:23: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                       ^~~~
a.cc:7:5: note: in expansion of macro 'two'
    7 | set<two>::iterator it;
      |     ^~~
a.cc:4:19: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                   ^~~~
a.cc:5:23: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                       ^~~~
a.cc:7:5: note: in expansion of macro 'two'
    7 | set<two>::iterator it;
      |     ^~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:5:23: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                       ^~~~
a.cc:7:5: note: in expansion of macro 'two'
    7 | set<two>::iterator it;
      |     ^~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:5:33: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                 ^~~~
a.cc:7:5: note: in expansion of macro 'two'
    7 | set<two>::iterator it;
      |     ^~~
a.cc:4:14: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |              ^~~~
a.cc:5:38: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                      ^~~~
a.cc:7:5: note: in expansion of macro 'two'
    7 | set<two>::iterator it;
      |     ^~~
a.cc:4:19: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                   ^~~~
a.cc:5:38: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                      ^~~~
a.cc:7:5: note: in expansion of macro 'two'
    7 | set<two>::iterator it;
      |     ^~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:5:38: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                      ^~~~
a.cc:7:5: note: in expansion of macro 'two'
    7 | set<two>::iterator it;
      |     ^~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:5:43: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                           ^~~~
a.cc:7:5: note: in expansion of macro 'two'
    7 | set<two>::iterator it;
      |     ^~~
a.cc:4:14: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |              ^~~~
a.cc:5:48: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                                ^~~~
a.cc:7:5: note: in expansion of macro 'two'
    7 | set<two>::iterator it;
      |     ^~~
a.cc:4:19: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                   ^~~~
a.cc:5:48: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                                ^~~~
a.cc:7:5: note: in expansion of macro 'two'
    7 | set<two>::iterator it;
      |     ^~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:5:48: note: in expansion of macro 'long'
    5 | #define two pair<long long,pair<long long,long long> >
      |                                                ^~~~
a.cc:7:5: note: in expansion of macro 'two'
    7 | set<two>::iterator it;
      |     ^~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:8:1: note: in expansion of macro 'long'
    8 | long long a[100003];
      | ^~~~
a.cc:4:14: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |              ^~~~
a.cc:8:6: note: in expansion of macro 'long'
    8 | long long a[100003];
      |      ^~~~
a.cc:4:19: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                   ^~~~
a.cc:8:6: note: in expansion of macro 'long'
    8 | long long a[100003];
      |      ^~~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:8:6: note: in expansion of macro 'long'
    8 | long long a[100003];
      |      ^~~~
a.cc:4:24: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                        ^~~~
a.cc:9:1: note: in expansion of macro 'long'
    9 | long long b[100003];
      | ^~~~
a.cc:4:14: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |              ^~~~
a.cc:9:6: note: in expansion of macro 'long'
    9 | long long b[100003];
      |      ^~~~
a.cc:4:19: error: 'long long long' is too long for GCC
    4 | #define long long long long
      |                   ^~~~
a.cc:9:6: note: in expansion of macro 'long'