#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
template <class T>
int upb(V<T> &v, const T &x) { return upper_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&...tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 998244353LL;
//@docs Docs/BinaryIndexedTree.md
template <class T>
struct BinaryIndexedTree {
    int n;
    vector<T> dat;
    BinaryIndexedTree(const int &n) : n(n + 1), dat(n + 1) {}
    void add(int k, const T &x) {
        for (++k; k < n; k += k & -k) dat[k] += x;
    }
    T get(int k) {
        T res = 0;
        for (++k; k > 0; k -= k & -k) res += dat[k];
        return res;
    }
    inline T get(const int &l, const int &r) { //0-indexed [l,r)
        return get(r - 1) - get(l - 1);
    }
};
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    V<ll> a(n), b(n);
    read(a);
    read(b);
    map<ll, int> id;
    V<V<int>> pos(n + 1);
    V<int> is(n + 1);
    int idx = 0;
    for (int i = 0; i < n; i++) {
        a[i] += i;
        b[i] += i;
    }
    V<ll> c = a, d = b;
    sort(all(c));
    sort(all(d));
    if (c != d) {
        cout << -1 << newl;
        return 0;
    }
    //転倒数
    map<P, int> mp;
    map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        if (!cnt.count(b[i])) {
            cnt[b[i]] = 0;
        }
        cnt[b[i]]++;
        mp[P(b[i], cnt[b[i]])] = i;
    }
    cnt.clear();
    V<ll> t(n);
    BinaryIndexedTree<ll> bit(n + 10);
    ll res = 0;
    for (int i = 0; i < n; i++) {
        if (!cnt.count(a[i])) {
            cnt[a[i]] = 0;
        }
        cnt[a[i]]++;
        t[i] = mp[P(a[i], cnt[a[i]])];
        res += bit.get(n + 1) - bit.get(t[i]);
        bit.add(t[i], 1);
    }
    cout << res << newl;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;

bool comp(string a, string b)
{
    string l = a+b;
    string m = b+a;
    if(l>m)
    {
        return true;
    }
    else
        return false;
}
int main()
{
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  int cnt[n+1] = {0};
  bool valid = true;
  int numbersVisited = 0;
  for(int i=0;i<n;i++)
  {
      int val = arr[i];
      if(cnt[val] != 0)
      {
          valid = false;
          break;
      }
      else
      {
          cnt[val] = 1;
          numbersVisited++;
      }
  }
  if(valid && numbersVisited == n)
  {
      cout<<"Yes\n";
  }
  else
    cout<<"No\n";
}
