#include using namespace std; int main() { int64_t n; cin >> n; vector a(n); vector b(n); int64_t as = 0; int64_t bs = 0; for(int64_t i = 0; i < n; i++) { cin >> a[i]; as += a[i]; } for(int64_t i = 0; i < n; i++) { cin >> b[i]; bs += b[i]; } if(as - bs < 0) { cout << -1 << endl; return 0; } if(n == 2) { if(as != bs) cout << -1 << endl; else cout << abs(a[0] - b[0]) << endl; return 0; } if((as - bs) % (n - 2) != 0) { cout << -1 << endl; return 0; } int64_t k = (as - bs) / (n - 2); for(int64_t i = 0; i < n; i++) a[i] -= k; int64_t cnt = 0; for(int64_t i = 0; i < n; i++) { if(a[i] > b[i]) { cout << -1 << endl; return 0; } if((b[i] - a[i]) % 2 != 0) { cout << -1 << endl; return 0; } cnt += (b[i] - a[i]) / 2; } if(k == cnt) cout << k << endl; else cout << -1 << endl; return 0; }