#include #include #include int main() { int n; std::cin >> n; std::vector space(n, 0), tab(n, 0); for (int i = 0; i < n; i++) { std::cin >> space[i] >> tab[i]; } std::vector width(n, 0); for (int i = 0; i < n; i++) { width[i] = space[i] + 4 * tab[i]; } for (int i = 0; i < n; i++) { if (width[i] % 2 != width[0] % 2) { std::cout << -1 << std::endl; return 0; } } int max = *std::max_element(width.begin(), width.end()); int count = 0; for (int i = 0; i < n; i++) { count += (max - width[i]); } std::cout << count / 2 << std::endl; return 0; }