Importance of time problem code

#include
#include
using namespace std;
int main()
{
queueq;
int n,i,a,ans=0,c;
cin>>n;
int b[n];
for(i=0;i<n;i++)
{
cin>>a;
q.push(a);
}
for(i=0;i<n;i++)
cin>>b[i];
for(i=0;i<n;i++)
{
if(b[i]==q.front())
{
ans=ans+1;
q.pop();
}
else
{
while(b[i]!=q.front())
{
c=q.front();
q.push©;
q.pop();
ans++;
}
}
}
cout<< ans;
return 0;
}


above is my code.
Sample testcase is passed.
But on submission output is showing wrong answer.
Please highlight the erroe in above code.

hi amit
your code is not producing correct output for the following input
30
5 29 12 16 25 17 18 30 27 10 4 23 20 3 1 24 26 19 14 9 6 22 8 13 15 21 28 7 11 2
17 20 6 18 21 5 22 24 28 7 23 3 27 19 10 30 15 25 12 16 2 1 11 9 4 8 29 14 13 26

expected output: 226
your output: 436