#include #include int main() { int i; int a, b; int max; int fullwidths = 0; int n; int sum[1001]; //sum[0]は使わない scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d %d", &a, &b); sum[i] = a + 4 * b; } max = sum[1]; for (i = 2; i <= n; i++) { if (abs(sum[i - 1] - sum[i]) % 2 == 1) { printf("-1\n"); return 0; } else if (sum[i] > max) { fullwidths += (sum[i] - max) / 2 * (i - 1); max = sum[i]; } else { fullwidths += (max - sum[i]) / 2; } } printf("%d\n", fullwidths); return 0; }