#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define mp make_pair #define pb push_back #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector vb; typedef vector vi; typedef vector vvb; typedef vector vvi; typedef pair pii; const int INF=1<<29; const double EPS=1e-9; const int dx[]={1,0,-1,0},dy[]={0,-1,0,1}; int main(int argc, char const *argv[]) { int N; std::vector haba; cin >> N; for (int i = 0; i < N; ++i) { int temp1, temp2; cin >> temp1 >> temp2; haba.push_back(temp1 + temp2 * 4); //cout << "DEBUG : " << haba[i] << endl; } long long int ans = 0; int max = 0; int odd = haba[0] % 2; for (int i = 0; i < N; ++i) { if (odd != haba[i] % 2) { cout << "-1" << endl; return 0; } max = std::max(max, haba[i]); } for (int i = 0; i < N; ++i) { ans += (max - haba[i]) / 2; //cout << "DEBUG : " << (max - haba[i]) / 2 << endl; } cout << ans << endl; return 0; }