#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #define rep(i,n) for(int i=0;i<(n);i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) ((int)(x).size()) #define pb push_back using ll = long long; using namespace std; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> N; vector A(N),B(N); vector chk(2,0); rep(i,N){ cin >> A[i] >> B[i]; chk[(A[i]+B[i]*4)%2]=1; } if(chk[0]&&chk[1]) cout << -1 << endl; else{ int mx=0; rep(i,N) chmax(mx,A[i]+B[i]*4); ll ans = 0; rep(i,N) ans += (mx-(A[i]+B[i]*4))/2; cout << ans << endl; } return 0; }