#include using namespace std; int main(){ int N; cin >> N; int space[N][2]; for(int i = 0; i < N; i++){ cin >> space[i][0]; cin >> space[i][1]; } int space_odd = space[0][0] % 2; for(int i = 1; i < N; i++){ if(space[i][0] % 2 != space_odd){ cout << -1 << endl; return 0; } } int max_space = 0; for(int i = 0; i < N; i++){ max_space = max(max_space, space[i][0] + space[i][1] * 4); } int ans = 0; for(int i = 0; i < N; i++){ ans += max_space - space[i][0] - space[i][1] * 4; } cout << ans / 2 << endl; }