#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long count = 0;
  long long cc = 0;
  long long t = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < n; i++) {
    while (a.at(i) != b.at(i)) {
      if (i == 0) {
        t = a.at(n - 1) + a.at(0) + a.at(1);
        a.at(0) = t;
        count++;
      } else if (i == n - 1) {
        t = a.at(n - 1) + a.at(n - 2) + a.at(0);
        a.at(n - 1) = t;
        count++;
      } else {
        t = a.at(i - 1) + a.at(i) + a.at(i + 1);
        a.at(i) = t;
        count++;
      }
      if (count > 1000000000) {
        cout << "-1" << endl;
        exit(0);
      }
    }
    cc += count;
    count = 0;
  }
  cout << cc << endl;
}
