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