/*
TASK: reverse
LANG: C++
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
#define null NULL
struct node{
  node *l,*r,*par;
  int val,key,sts,rev;
  node(){
   par=l=r=null;
   key=rand();
   rev=sts=0;
        }
};
node *root=null;
void push(node* vr){
  if(vr==null)return;
  if(vr->rev){
   vr->rev=0;
   swap(vr->l,vr->r);
   if(vr->l!=null)(vr->l)->rev^=1;
   if(vr->r!=null)(vr->r)->rev^=1;
             }
}
void update(node* vr){
  if(vr==null)return;
  vr->sts=1;
  if(vr->l!=null)vr->sts+=(vr->l)->sts;
  if(vr->r!=null)vr->sts+=(vr->r)->sts;
  if(vr->l!=null){(vr->l)->par=vr;}
  if(vr->r!=null){(vr->r)->par=vr;}
}
void split(int val,int add,node* vr,node*& l,node*& r){
  if(vr==null){l=r=null;return;}
  push(vr);
  int CV=add+1;
  if(vr->l!=null)CV+=(vr->l)->sts;
  if(val<=CV){
   split(val,add,vr->l,l,vr->l);
   r=vr;
   update(l);update(r);
   if(l!=null)l->par=null;
   if(r!=null)r->par=null;
             }
  else{
   split(val,CV,vr->r,vr->r,r);
   l=vr;
   update(l);update(r);
      }
}
node* merge(node* l,node* r){
  if(l==null || r==null)return (l==null)?r:l;
  push(l);push(r);
  if(l->key > r->key){l->r=merge(l->r,r);update(l);return l;}
  else{r->l=merge(l,r->l);update(r);return r;}
}
node* SET;
void INS(node*& p,int add,node* w){
  if(p==null){p=w;update(p);SET=p;return;}
  push(p);
  int CV=add+1;
  if(p->l!=null)CV+=(p->l)->sts;
  if(w->key>p->key){
   split(w->val,add,p,w->l,w->r);
   p=w;
   update(p);
   SET=p;
   //cout<<SET<<endl;
   //system("pause");
   return;
                   }
  if(w->val<CV)INS(p->l,add,w);
  else INS(p->r,CV,w);
  update(p);
}
node* pos[100010];
void push(int w){
  node* T=new node();
  T->val=w;
  INS(root,0,T);
  //cout<<SET<<endl;
  pos[w]=SET;
}
void dfs(node* vr){
  if(vr==null)return;
  cout<<vr->val<<' '<<vr->rev<<endl;
  cout<<"LEFT\n";
  dfs(vr->l);
  cout<<"END\n";
  cout<<"RIGHT\n";
  dfs(vr->r);
  cout<<"END\n";
}
void SS(node* vr){
  if(vr==null)return;
  SS(vr->l);
  cout<<vr->val<<' '<<vr->key<<endl;
  SS(vr->r);
}
void rev_interval(int f,int t){
  node *l,*m,*r;
  split(f,0,root,l,m);
  int CA=0;if(l!=null)CA=l->sts;
  split(t+1,CA,m,m,r);
  if(m!=null){
   push(m);
   m->rev=1;
             }
  m=merge(m,r);
  root=merge(l,m);
  root->par=null;
}
vector<node* > path;
int get_ID(int w){
  path.clear();
  node* rep=pos[w];
  while(rep!=null){
   path.push_back(rep);
   rep=rep->par;
                  }
  int ID=1;
  for(int i=(int)path.size()-1;i>0;--i){
   push(path[i]);
   //cout<<"!"<<path[i]->val<<endl;
   if(path[i-1]==path[i]->r){
     ++ID;
     if(path[i]->l!=null)ID+=(path[i]->l)->sts;
                            }
                                      }
  push(path[0]);
  if(path[0]->l!=null)ID+=((path[0])->l)->sts;
  return ID;
}
// SOLUTION
int n;
int from[100010],GO[100010];
vector<int> m1,m2;
int main(){
  int i,j,k,l;
  srand(117896513);
  scanf("%d",&n);
  for(i=1;i<=n;++i)push(i);
  //cout<<get_ID(4)<<endl;
  //rev_interval(1,3);
  //dfs(root);
  //for(int i=1;i<=4;++i)cout<<pos[i]<<' '<<pos[i]->par<<endl;
  //cout<<get_ID(4);
  //system("pause");
  for(i=1;i<=n;++i)scanf("%d",&from[i]);
  for(i=1;i<=n;++i){
   scanf("%d",&l);
   GO[l]=i;
                   }
  for(i=1;i<=n;++i)from[i]=GO[from[i]];
  for(i=1;i<=n;++i){
   l=get_ID(from[i]);
   //cout<<from[i]<<' '<<l<<endl;
   //system("pause");
   if(i==l)continue;
   int _f=i,_t=l;
   if(_f>_t)swap(_f,_t);
   m1.push_back(_f);m2.push_back(_t);
   rev_interval(_f,_t);
   //cout<<_f<<' '<<_t<<endl;
   //system("pause");
   //SS(root);
   //system("pause");
                   }
  printf("%d\n",m1.size());
  for(i=(int)(m1.size())-1;i>=0;--i)
   printf("%d %d\n",m1[i],m2[i]);
  return 0;
}
