#include #include #include #include #include #include #include #include #include #include using namespace std; int main(){ int n, max1 = -1, sum1 = 0, oe = -1; cin >> n; for (int i = 0; i < n; i++){ int a, b, tmp; cin >> a >> b; if (i == 0) oe = a%2; tmp = a + b*4; if(a%2 != oe){ cout << -1 << endl; return 0; } else { max1 = max(max1, tmp); sum1 += tmp; } } cout << (max1*n - sum1)/2 << endl; }