#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
int main() {
	int n, a, b;
	ll s = 0, sb = 0;
	cin >> n;
	vector<int> v(n);
	rep(i, 0, n)cin >> a >> b, v[i] = a + b, sb += (ll)b;
	sort(all(v));
	for (int i = v.size() - 1; i >= 0; i -= 2)s += (ll)v[i];
	printf("%lld\n", s - sb);
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  vector<int> cur (n);
  for (int i = 0; i < n; i++) {
    cin >> cur[i];
  }

  sort(cur.begin(), cur.end());

  int ans = 0;
  for (int k = 30; k >= 1; k--) {
    int target = 1 << k;

    vector<int> nxtl;
    vector<int> nxtr;
    
    int lptr = 0, rptr = cur.size() - 1;
    while (lptr <= rptr) {
      if (lptr == rptr) {
        nxtl.push_back(cur[lptr]);
        break;
      } else if (cur[lptr] + cur[rptr] == target) {
        ans++;
        lptr++;
        rptr--;
      } else if (cur[lptr] + cur[rptr] < target) {
        nxtl.push_back(cur[lptr]);
        lptr++;
      } else if (cur[lptr] + cur[rptr] > target) {
        nxtr.push_back(cur[rptr]);
        rptr--;
      }
    }

    reverse(nxtr.begin(), nxtr.end());
    for (int u : nxtr) {
      nxtl.push_back(u);
    }

    cur = nxtl;
  }

  cout << ans << endl;
}
