#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

typedef pair<ll, ll> P;

int main()
{
  ll n; cin>>n;
  vector<ll> a(n);
  vector<ll> b(n);
  vector<P> c(n);
  rep(i, n) {
    cin>>a[i]>>b[i];
    c[i] = make_pair(a[i]+b[i], i);
  }
  sort(c.rbegin(),c.rend());

  ll x=0, y=0;
  rep(i, n) {
    if (i%2) y += b[c[i].second];
    else x += a[c[i].second];
  }

  cout << x-y << endl;

  return 0;
}

#include <iostream>
#include <cstring>
using namespace std;

#define N 8


bool col[N],hi[2*N-1],mi[2*N+1];
int row[N];
void point(int y,int x){

  row[y] = x;
  col[x] = false;
  hi[x+y] = false;
  mi[y-x+N-1] = false;

}

void del(int y, int x){

  row[y] = -1;
  col[x] = true;
  hi[x+y] = true;
  mi[y-x+N-1] = true;

}

void print_ans(){
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(row[i] == j) cout << "Q";
      else cout << ".";
    }
    cout << endl;
  }
}

bool is_ok(int y,int x){
  return row[y] == -1 && col[x] == true && hi[x+y] == true && mi[y-x+N-1];
}

void dfs(int r){
  if(r == 8){//??´??????
    print_ans();
    return ;
  }
  if(row[r] != -1){
    dfs(r+1);
  }
  else{
    for(int i=0; i<8; i++){
      if(is_ok(r,i) == true){
	point(r,i);
	dfs(r+1);
	del(r,i);
      }
    }
  }
  return;
}


int main(){

  int k; cin >> k;
  
  memset(row,-1,sizeof(row));
  memset(col,true,sizeof(col));
  memset(hi,true,sizeof(hi));
  memset(mi,true,sizeof(mi));
  
  for(int i=0; i<k; i++){
    int x,y; cin >> y >> x;
    row[y] = x;
    col[x] = false;
    hi[x+y] = false;
    mi[y-x+N-1] = false;
  }
  
  dfs(0);

}