#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, sum = 0; cin >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    vector<pair<ll, ll>> ab(n, {0, 0});
    rep(i, n){
        ab[i].first = a[i]+b[i];
        ab[i].second = i;
    }
    sort(all(ab), greater<pair<ll, ll>>());
    rep(i, n){
        if(i%2 == 0) sum += a[ab[i].second];
        else sum -= b[ab[i].second];
    }
    cout << sum << endl;
}
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int n;
	cin >> n;
	vector<vector<P>>lis(n);
	rep(i, n) {
		int a;
		cin >> a;
		rep(j, a) {
			int x, y;
			cin >> x >> y;
			x--;
			lis[i].push_back(P(x, y));
		}
	}
	int ans(0);
	for (int bit = 0; bit < (1 << n); ++bit) {
		int c = 0;
		int can = 0;
		rep(i, n) {
			int cnt(0);
			int a = lis[i].size();
			if (!(bit >> i & 1))continue;
			can++;
			rep(j, lis[i].size()) {
				int x = lis[i][j].first; int y = lis[i][j].second;
				if ((bit >> x & 1) && y != 1)cnt++;
				if (!(bit >> x & 1) && y == 1)cnt++;
			}
			if (cnt >= 1)c = -1;
		}
		//cout << bit << can << endl;
		if (c != -1) {
			ans = max(can, ans);
		}
		
	}
	cout << ans;
	return 0;
}
