#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 5;
int mod = 998244353;
int pre[N]{};
void add(int pos){
    pos = N - pos - 1;
    for (int i = pos; i < N; i += i & -i) pre[i]++;
}
int query(int pos){
    pos = N - pos - 1;
    int ans = 0;
    for (int i = pos; i; i -= i & -i) ans += pre[i];
    return ans;
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    int a[n], b[n], tar[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    map<int, queue<int>> v;
    for (int i = 0; i < n; i++){
        cin >> b[i];
        v[b[i] + i].push(i);
    }
    for (int i = 0; i < n; i++){
        if (v[a[i] + i].empty()){
            cout << -1 << '\n';
            return 0;
        }
        tar[i] = v[a[i] + i].front();
        v[a[i] + i].pop();
    }
    ll ans = 0;
    for (int i = 0; i < n; i++){
        //cout << tar[i] - i<< ' ';
        ans += tar[i] + query(tar[i]) - i;
        add(tar[i]);
    }
    cout << ans << '\n';
}
#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	map<int, int> mp;
	mp[0] = 1;
	int sum = 0;
	int c = 1;
	for (int i = 0; i < N; i++) {
		sum += A[i] * c;
		c *= -1;
		res += mp[sum];
		mp[sum]++;
	}
	cout << res << endl;
}