#include #include #include #include #include #include #include #include #include // require sort next_permutation count __gcd reverse etc. #include // require abs exit atof atoi #include // require scanf printf #include #include // require accumulate #include // require fabs #include #include #include #include // require setw #include // require stringstream #include // require memset #include // require tolower, toupper #include // require freopen #include // require srand #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() #define each(i,c) for(auto i=(c).begin();i!=(c).end();++i) #define exist(s,e) ((s).find(e)!=(s).end()) #define clr(a) memset((a),0,sizeof(a)) #define nclr(a) memset((a),-1,sizoef(a)) #define sz(s) (int)((s).size()) #define INRANGE(x,s,e) ((s)<=(x) && (x)<(e)) #define pb push_back #define MP(x,y) make_pair((x),(y)) #define INF 1<<28 using namespace std; typedef long long ll; typedef pair P; int main() { ios_base::sync_with_stdio(0); int N; cin >> N; vector a(N, 0 ), b (N, 0 ); rep (i, N ){ cin >> a[i] >> b[i]; } // end rep int mins = INF, maxs = 0; bool ok = true; rep (i, N ){ int curr = a[i] + 4*b[i]; mins = min (mins, curr ); maxs = max (maxs, curr ); } // end rep int diff = maxs - mins; if (diff % 2 != 0 ) ok = false; ll res = 0LL; if (ok ){ rep (i, N ){ int curr = diff + mins - (a[i] + 4*b[i] ); if (curr % 2 != 0 ) ok = false; res = res + (ll)curr/2LL; } // end rep } // end if cout << (ok ? res : -1 ) << endl; return 0; }