#define _USE_MATH_DEFINES #include using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector a(n), b(n); long long sum_a = 0, sum_b = 0; for (auto& x : a) { cin >> x; sum_a += x; } for (auto& x : b) { cin >> x; sum_b += x; } if (n >= 3) { if (sum_a < sum_b || (sum_a - sum_b) % (n - 2) != 0) { cout << -1 << endl; return 0; } long long opr = (sum_a - sum_b) / (n - 2); for (auto& x : a) { x -= opr; } long long cnt = 0; for (int i = 0; i < n; i++) { if (a[i] > b[i] || (b[i] - a[i]) % 2 != 0) { cout << -1 << endl; return 0; } cnt += (b[i] - a[i]) / 2; } cout << (opr == cnt ? opr : -1) << endl; } else { cout << ((a[0] - b[0]) == (b[1] - a[1]) ? abs(a[0] - b[0]) : -1) << endl; } return 0; }