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

#define For(i,n) for(int i = 0; i < n; i++)
#define For1(i,n) for(int i = 1; i < n; i++)
#define Forn(i,n) for(int i = n-1; i >=0 ; i--)
#define FOR(i,f,n) for(int i = f; i < n; i++)
#define FORN(i,n,f) for(int i = n; i >= f; i--)
#define Forit(it,v) for(auto it = v.begin(); it != v.end(); it++)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define sz size()
#define dbg(a) For(i,a.sz){cout<<a[i]<<' ';}cout<<'\n';
#define Sort(a) sort(a.begin(), a.end());
#define Rev(a) reverse(a.begin(), a.end());
typedef long long int ll;
typedef pair<ll, ll> pl;
typedef pair<int,int> pi;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pl> vpl;
typedef vector<pi> vpi;
typedef vector<vll> vvll;
const int mod = 1e9+7;
const int NF = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
ll gcd(ll a, ll b){
    while( a!=0 and b!=0 )
    {
        if( a >= b ) a = a%b;
        else if( b > a ) b = b%a;
    }
    
    if( a >= b ) return a;
    else return b;
    
}

//FastExpo
ll fast_pow(ll base, ll p){
    ll a =1;
    while(p>0){
        if(p%2==0){
            p /=2;
            base *=base;
        }
        else{
            p --;
            a = a * 1LL * base;
        }
        a %= mod;
        base %=mod;
    }
    return a;
}

ll t,n,m,k,idx,ct1,ct0;

void solve() {
    cin>>n;
    vll a(n,0);
    map<ll, ll> ct;
    ll tmp = 0, res = 0;
    //    vll T;
    For(i,n){
        cin>>a[i];
        if(i%2){tmp+=a[i];}
        else{tmp -= a[i];}
        if(tmp == 0){res++;}
        ll tm = ct[tmp];
        if(tm>=1 && i!=0){
            res+=tm;
        }
        ct[tmp]++;
    }
    //    dbg(T);
    cout<<res<<'\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    //    cin >> t;
    
    //    k = t;
    t = 1;
    while (t--) {
        //        cout<<"Case #"<<k-t<<": ";
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
// #define LOCAL // 提出時はコメントアウト
#define DEBUG_

typedef long long ll;
const double EPS = 1e-9;
const ll INF = ((1LL<<62)-(1LL<<31));
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;
template<typename T> using uset = unordered_set<T>;
template<typename T, typename U> using mapv = map<T,vector<U>>;
template<typename T, typename U> using umap = unordered_map<T,U>;

#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define sz(x) (ll)x.size()
ll llceil(ll a,ll b) { return (a+b-1)/b; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); }

///// DEBUG
#define DUMPOUT cerr
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<typename T,typename U>ostream&operator<<(ostream&os,pair<T,U>&pair_var){os<<"("<<pair_var.first<<", "<<pair_var.second<<")";return os;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");}
os<<"}";return os;}
template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;}
os<<"}";return os;}
template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;}
os<<"}";return os;}
void dump_func(){DUMPOUT<<endl;}
template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";}
dump_func(std::move(tail)...);}
#ifndef LOCAL
#undef DEBUG_
#endif
#ifdef DEBUG_
#define DEB
#define dump(...)                                                          \
DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
        << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
        << endl                                                            \
        << "    ",                                                         \
    dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

//////////

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int main() {
    #ifdef LOCAL
    ifstream in("../../Atcoder/input.txt");
    cin.rdbuf(in.rdbuf());
    #endif

    ll N;
    cin>>N;

    vector<pairl> A(N);
    vecl B(N), P(N);

    vecl holder(N); // holder[i]: 荷物iを持ってる人
    rep(i,N) cin>>A[i].first, A[i].second = i;
    rep(i,N) cin>>B[i];
    rep(i,N) cin>>P[i], holder[--P[i]] = i; // P[i]: 人iが持ってる荷物


    sort(ALL(A));
    rep(i,N) {
        auto [a,j] = A[i];
        ll item = P[j];
        if (item != j && a <= B[item]) {
            cout << -1 << endl;
            return 0;
        }
    }

    vector<pairl> ans;
    rep(i,N) {
        auto [a,ii] = A[i]; // 人: ii
        ll p = holder[ii]; // 荷物iiをもつ人: p
        if (ii == p) continue;

        swap(holder[ii], holder[P[ii]]);
        swap(P[ii],P[p]);
        ans.emplace_back(ii, p);
    }

    cout << sz(ans) << endl;
    rep(i,sz(ans)) {
        auto [x,y] = ans[i];
        cout << ++x << " " << ++y << endl;
    }


    return 0;
}
