/*
// Sample code to perform I/O:
#include <iostream>
using namespace std;
int main() {
int num;
cin >> num; // Reading input from STDIN
cout << "Input number is " << num << endl; // Writing output to STDOUT
}
// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
*/
// Write your code here
#include<bits/stdc++.h>
#include<queue>
using namespace std;
int main(){
int n;cin>>n;
queue<int>order;
int num;
for(int i=0;i<n;i++){
cin>>num;
order.push(num);
}
queue<int>ideal;
for(int i=0;i<n;i++){
cin>>num;
ideal.push(num);
}
int operaciones=0;
while(ideal.size()){
int quiero=ideal.front();
int soy=order.front();
order.pop();
if(quiero != soy) order.push(soy);
if(quiero == soy) ideal.pop();
operaciones++;
}
cout<<operaciones<<endl;
return 0;
}
Language: C++17