#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int n;
  scanf("%d", &n);
  vector<int> a(n + 1), b(n + 1);
  vector<int> pos_in_a(n + 1), pos_in_b(n + 1);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pos_in_a[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    pos_in_b[b[i]] = i;
  }
  vector<pair<int, int> > ans;
  int k = 0;
  int cost = 0;
  for (int i = n; i >= 1; i--) {
    while (a[i] != b[i]) {
      int j = pos_in_a[b[i]];
      for (int t = j + 1; t <= i; t++) {
        if (pos_in_b[a[t]] <= j) {
          swap(a[j], a[t]);
          pos_in_a[a[t]] = t;
          pos_in_a[a[j]] = j;
          k++;
          ans.push_back(make_pair(j, t));
          cost += t - j;
          break;
        }
      }
    }
  }
  printf("%d\n", cost);
  printf("%d\n", k);
  for (int i = 0; i < ans.size(); i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
