#include<iostream>
#include<vector>
#include<map>

using namespace std;

int main() {
	
	int n;
	cin >> n;
	
	vector<int> x(n);
	vector<int> y(n);
	vector<int> z(n);
	
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> y[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> z[i];
	}
	
	map<int, int> a; //mapa[recept] = broj scenaria za to jelo
	map<int, int> b; //mapa[jelo] = vektor indeksa recepata
	
	for (int i = 1; i <= n; i++) {
		a[i] = 0;
	}
	
	for (int i = 0; i < n; i++) {
		a[z[i]]++;
	}
	
	for (int i = 1; i <= n; i++) {
		b[i] = 0;
	}
	
	for (int i = 0; i < n; i++) {
		b[x[i]]++;
	}
	
	/*for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if(y[j - 1] == i) {
					cout << b[i] << ' ' << a[j] << endl;
					b[i] += a[j];
				}
			}
	}
	*/
	
	for (int i = 1; i <= n; i++) {
		cout << a[i] << ' ' << b[i] << endl;
	}
	
	int rez = 0;
	
	for (int i = 1; i < n; i++) {
		rez += b[i] * a[i];
	}
	
	cout << endl;
	
	cout << rez << '\n';
	
	return 0;
}

/*
4
1 1 4 3
3 1 3 4
1 3 2 2
 
5
1 1 1 1 1
2 1 5 5 5
2 1 2 3 3
*/