#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("YES");}else{puts("NO");} #define MAX_N 200005 int main() { ll n; cin >> n; ll a[n], b[n]; rep(i,n)cin >> a[i]; rep(j,n)cin >> b[j]; int flag = 1; ll sum = 0; rep(i,n)sum += a[i] - b[i]; if(sum < 0) flag = 0; if(n == 2){ if(sum==0){ cout << abs(a[0]-a[1]) << endl; }else{ cout << -1 << endl; } return 0; } if(sum % (n-2) != 0) flag = 0; ll ans = sum / (n-2); rep(i,n)a[i] -= ans; rep(i,n){ if(a[i] > b[i]){ flag = 0; }else if((a[i]-b[i])%2!=0){ flag = 0; } } if(flag){ cout << ans << endl; }else{ cout << -1 << endl; } return 0; }