#include #include #include using namespace std; bool func(const vector& vec) { vector evenOrOdd; for (size_t i = 0; i < vec.size(); ++i) { if (vec.at(i) % 2 == 0) { evenOrOdd.push_back(0); //even } else { evenOrOdd.push_back(1); //odd } } bool flag = true; //全部evenか全部oddならtrue, 要素ひとつでも違えばfalse for (size_t j = 0; j < (vec.size() - 1); ++j) { if (evenOrOdd.at(j) != evenOrOdd.at(j+1)) { flag = false; } } return flag; } int main() { int n, a, b; cin >> n; vector wa; for (int i = 0; i < n; ++i) { cin >> a >> b; wa.push_back(a + 4 * b); } if (func(wa) == true) { int p = *max_element(wa.begin(), wa.end()); int ans = 0; for (int j = 0; j < n; ++j) { ans += (p - wa.at(j)) / 2; } cout << ans << endl; } else { cout << -1 << endl; } return 0; }