#include #include #include #include #define REP(i,a,b) for(i=a;i> n; rep(i,n) { cin >> a[i] >> b[i]; if(a[i]+b[i]*4 > max) max = a[i]+b[i]*4; } rep(i,n) { int tmp = max - (a[i]+b[i]*4); if( tmp % 2 == 0) cnt += tmp/2; else break; } if(i != n) printf("-1\n"); else printf("%llu\n",cnt); return 0; }