#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ans;
int a[2011], b[2011], cur_pos[2011], wanted_pos[2011];
int main() {
  int n, min_ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    cur_pos[a[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", b + i);
    wanted_pos[b[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    int x = b[i];
    if (cur_pos[x] == i) continue;
    for (int j = cur_pos[x]; j >= i; j--) {
      int y = a[j];
      int final = wanted_pos[y];
      if (y == x) continue;
      if (cur_pos[x] >= cur_pos[y] && cur_pos[x] <= final) {
        ans.push_back(make_pair(cur_pos[x], j));
        swap(a[j], a[cur_pos[x]]);
        min_ans += abs(cur_pos[x] - cur_pos[y]);
        cur_pos[y] = cur_pos[x];
        cur_pos[x] = j;
      }
    }
  }
  printf("%d\n%d\n", min_ans, (int)ans.size());
  for (pair<int, int> i : ans) printf("%d %d\n", i.first + 1, i.second + 1);
  return 0;
}
