#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
const int N =2000005;
int cnt[20];
bool check(int x) {
	int key[10]={};
	while(x) {
		key[x%10]++;
		x/=10;
	}
	for(int i=0;i<10;++i) {
		if(key[i]>cnt[i])
		return false;
	}
	return true;
} 
int main()
{
	char ch[N];
	scanf("%s",ch);
	getchar();
	int len=strlen(ch);
	for(int i=0;i<len;++i) {
		cnt[ch[i]-'0']++;
	}
	if (len==1) {
		if(ch[0]=='8')
		puts("Yes");
		else
		puts("No");
	}
	else if (len==2) {
		int a=(ch[0]-'0')*10+ch[1]-'0';
		int b=(ch[1]-'0')*10+ch[0]-'0';
		if(a%8==0||b%8==0)
		puts("Yes");
		else
		puts("No");
	}
	else {
		for(int i=104;i<1000;i+=8) {
			if (check(i)) {
				puts("Yes");
				return 0;
			}
		}
		puts("No");
	}
	
	return 0;
}
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <unordered_set>

using namespace std;

class InputReader {
public:
    InputReader() {}
    InputReader(const char *file_name) {
        input_file = fopen(file_name, "r");
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    inline InputReader &operator >>(int &n) {
        while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }
    inline InputReader &operator >>(long long &n) {
        while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }
private:
    FILE *input_file;
    static const int SIZE = 1 << 17;
    int cursor;
    char buffer[SIZE];
    inline void advance() {
        ++ cursor;
        if(cursor == SIZE) {
            cursor = 0;
            fread(buffer, SIZE, 1, input_file);
        }
    }
};

const int MAXN = 200000;

int a[1 + MAXN], b[1 + MAXN], p[1 + MAXN];

bool compare(const int &i, const int &j) {
    return a[i] > a[j];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //ifstream cin("input.txt");
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    vector<int> bad;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        if (p[i] != i) {
            if (b[p[i]] >= a[i]) {
                cout << "-1\n";
                return 0;
            }
            bad.push_back(i);
        }
    }
    sort(bad.begin(), bad.end(), compare);
    vector<pair<int, int> > op;
    for (auto x : bad) {
        while (p[x] != x) {
            int y = p[x];
            op.push_back(make_pair(x, y));
            swap(p[x], p[y]);
        }
    }
    for (int i = 1; i <= n; i++) {
        assert(p[i] == i);
    }
    cout << op.size() << "\n";
    for (auto it : op) {
        cout << it.first << " " << it.second << "\n";
    }
    return 0;
}

