#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define INF (1<<29) #define LINF (1LL<<60) #define EPS (1e-10) #define PI 3.1415926535897932384626433832795028 typedef long long Int; typedef pair P; typedef long double Real; typedef complex CP; void ok(){ cout << "Yes" << endl; exit(0); } void ng(){ cout << "-1" << endl; exit(0); } Int n; Int a[110000], b[110000]; Int ans; int main(){ cin >> n; Int suma = 0, sumb = 0; for(int i = 0;i < n;i++){cin >> a[i];suma += a[i];} for(int i = 0;i < n;i++){cin >> b[i];sumb += b[i];} if(n == 2){ if(suma != sumb)ng(); cout << abs(a[0] - b[0]) << endl; return 0; } if((suma - sumb) % (n-2) != 0)ng(); if(suma < sumb)ng(); int cnt = (suma - sumb) / (n-2); for(int i = 0;i < n;i++){ int dif = b[i] - (a[i] - cnt); if(dif % 2 == 1)ng(); ans += dif / 2; } cout << ans << endl; return 0; }