#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int N, a, b, sum[1005] = {}; cin >> N; for(int i = 0; i < N; i++) { cin >> a >> b; sum[i] = a + 4 *b; } sort(sum, sum+N); int cnt = 0; for (int i = 0; i < N-1; i++) { if ( (sum[N - 1] - sum[i]) % 2 == 0) { cnt += (sum[N - 1] - sum[i])/2; } else { cout <<-1<< endl; return 0; } } cout << cnt << endl; return 0; }