#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define FOR(i, a, b) for (ll i=a; i<(b); i++)
#define FORD(i, a, b) for (int i=a-1; i>=(b); i--)


void solve () {
    ll ans = 0;
    ll n;
    cin >> n;
    vector<ll> a(n);
    FOR(i, 0, n) cin >> a[i];
    FOR(i, 0, n) {
        ll tmp;
        cin >> tmp;
        a[i] *= tmp;
        ans += a[i];
    }
    if(ans==0)
    cout << "Yes\n";
    else 
    cout << "No\n";
}

int main () 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    
    return 0;
}
//$ sudo g++ -o name name.cpp
//$ ./name
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define vvi vector<vector<int>>
#define Pii pair<int,int>
#define SS second 
#define F first
const int mod = 998244353;
#define ld long double
#define sp fixed<<setprecision(9)
const int inf =1e18+7;
using namespace std;

#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

// int a[1000000],fenw[1000000];

// int query(int k){

//     int s=0;
//     while(k>=1){
//         s+=fenw[k];
//         k-=(k&-k);
//     }
//     return s;
// }

// void update(int k,int x,int n){

//     while(k<=n){
//         fenw[k]+=x;
//         k+=(k&-k);
//     }
// }


int powmod(int x, int n, int md){
    int ans=1;
    while(n){
        if(n&1)
            ans=(ans*x)%md;
        n/=2;
        x=(x*x)%md;
    }
    return ans;
}


int merge(int arr[],int temp[],int left,int mid,int right){
    int i,j,k;
    int inv_count=0;
    i=left,j=mid,k=left;
    while(i<mid and j<=right){
        if(arr[i]<=arr[j]){
            temp[k++]=arr[i++];
        }else{
            temp[k++]=arr[j++];
            inv_count+=mid-i;
        }
    }
    while(i<mid){
        temp[k++]=arr[i++];
    }
    while(j<=right){
        temp[k++]=arr[j++];
    }
    for(i=left;i<=right;i++){
        arr[i]=temp[i];
    }
    return inv_count;
}



int merge_sort(int arr[],int temp[],int left,int right){
    int mid,inv_count=0;
    if(right>left){

        mid=(left+right)/2;

        inv_count+=merge_sort(arr,temp,left,mid);
        inv_count+=merge_sort(arr,temp,mid+1,right);

        inv_count+=merge(arr,temp,left,mid+1,right);
    }
    return inv_count;
}


void solve(int test){
    
    int n;
    cin>>n;
    int a[n];
    int b[n];
    vector<vector<int>> v1,v2;
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]+=i;
        v1.pb({a[i],i});
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        b[i]+=i;
        v2.pb({b[i],i});
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    int v[n],temp[n];
    for(int i=0;i<n;i++){
        if(v1[i][0]!=v2[i][0]){
            cout<<-1;
            return;
        }
        v[v1[i][1]]=v2[i][1];
    }
    cout<<merge_sort(v,temp,0,n-1);


}

int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //double    pi=3.14159265358979323846;
    //sieve();
    //precompute();
    int t=1;
    //cin>>t;
    int test=1;
    while(t--){
        solve(test);
        test++;
    }
    
    return 0;
    
}//Ardhendu Reja , JGEC


