#include <bits/stdc++.h>
using namespace std;
int n, num[2005], pos[2005];
vector<pair<int, int> > swaps;
int find(int p) {
  int y = p + 1;
  while (y < n && num[y] > p) y++;
  return y;
}
int main() {
  int ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < (int)n; i++) {
    scanf("%d", &num[i]);
    pos[num[i]] = i;
  }
  for (int i = 0; i < (int)n; i++) {
    int a;
    scanf("%d", &a);
    num[pos[a]] = i;
  }
  for (int i = 0; i < (int)n; i++) pos[num[i]] = i;
  vector<vector<int> > vec;
  for (int i = n - 1; i >= 0; i--) {
    int x = pos[i];
    while (x < i) {
      int y = find(x);
      swap(num[x], num[y]);
      swap(pos[num[x]], pos[num[y]]);
      swaps.push_back(make_pair(x + 1, y + 1));
      ans += (y - x);
      x = y;
    }
  }
  printf("%d\n", ans);
  printf("%d\n", swaps.size());
  for (int i = 0; i < (int)swaps.size(); i++)
    printf("%d %d\n", swaps[i].first, swaps[i].second);
  return 0;
}
