#include <bits/stdc++.h>
using namespace std;
typedef struct pr {
  long long first;
  int second;
  bool operator<(const struct pr& rhs) const { return first < rhs.first; }
} pr;
int N;
long long A[200001], B[200001];
int getPrev(int x) { return (x - 1 + N) % N; }
int getNext(int x) { return (x + 1) % N; }
set<pr> tmp;
long long cnt = 0;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < N; i++) {
    if (B[i] < A[i]) {
      cout << -1 << endl;
      return 0;
    }
    if (B[i] != A[i]) tmp.insert({B[i], i});
  }
  while (tmp.size() > 0) {
    auto it = tmp.end();
    it--;
    int id = it->second;
    long long val = it->first;
    tmp.erase(it);
    int prev = getPrev(id);
    int nxt = getNext(id);
    B[id] -= (B[prev] + B[nxt]);
    if (B[id] > A[id]) {
      tmp.insert({B[id], id});
    }
    if (B[id] < A[id]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << cnt << endl;
  return 0;
}
