#include using namespace std; using ll = long long; constexpr char newl = '\n'; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); ll suma = 0; for (int i = 0; i < n; i++) { cin >> a[i]; suma += a[i]; } vector b(n); ll sumb = 0; for (int i = 0; i < n; i++) { cin >> b[i]; sumb += b[i]; } ll diff = suma - sumb; if (n == 2) { cout << (diff == 0 ? abs(a[0] - b[0]) : -1) << newl; return 0; } if (diff < 0 || diff % (n - 2) != 0) { cout << -1 << newl; return 0; } ll cnt = diff / (n - 2); for (int i = 0; i < n; i++) { a[i] -= cnt; } for (int i = 0; i < n; i++) { ll tmp = b[i] - a[i]; if (tmp < 0 || tmp % 2 != 0) { cout << -1 << newl; return 0; } } cout << cnt << newl; return 0; }