#include #include #include #include #include #include #include #include #include #include #include #include //#include "toollib.h" #define INT_MAX 2147483647 #define Loop(i, n) for(int i = 0; i < (int)n; i++) #pragma warning (disable:4018) using namespace std; typedef long long int lint; //***** Main Program ***** int main() { int N; cin >> N; vector a(N), b(N), sum(N); Loop(i, N) { cin >> a[i] >> b[i]; sum[i] = a[i] + 4 * b[i]; } sort(sum.begin(), sum.end(), greater()); int ret = 0; Loop(i, N) { if ((sum[0] - sum[i]) % 2 == 0) ret += (sum[0] - sum[i]) / 2; else { ret = -1; break; } } cout << ret << endl; return 0; }