#include using namespace std; int first[150000]; int second[150000]; int third[150000]; bool goodOrder(int a, int b) { if(second[a] < second[b] && third[a] < third[b]) return true; return false; } void inicializace(int n) { for(int i = 0; i < n; i++) { int tmp; cin >> tmp; second[tmp] = i; } for(int i = 0; i < n; i++) { int tmp; cin >> tmp; third[tmp] = i; } } int main() { int n; cin >> n; while(n != 0) { for(int i = 0; i < n; i++) { cin >> first[i]; } inicializace(n); long long count = 0; for(int i = 0; i < n - 1; i++) { for(int j = i + 1; j < n; j++) { if(goodOrder(first[i], first[j])) count++; } } cout << count << endl; cin >> n; } return 0; }