#include using namespace std; typedef long long ll; int main() { int n; ll sum = 0; int p; ll mx = 0; for (int i = 0; i < n; i++) { ll a, b; cin >> a >> b; if (i == 0) p = a%2; else if (a%2 != p) { puts("-1"); return 0; } sum += a+4*b; mx = max(mx, a+4*b); } cout << (mx*n - sum) / 2 << endl; return 0; }