#include <bits/stdc++.h>
using namespace std;
int N, len, cost;
int a[2010], b[2010], t[2010];
class rec {
 public:
  int x, y;
} ans[2000010];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= N; i++) scanf("%d", &b[i]), t[b[i]] = i;
  for (int i = 1; i <= N; i++) a[i] = t[a[i]], b[i] = t[b[i]];
  for (int i = N; i; i--) {
    int x;
    for (int j = 1; j <= N; j++)
      if (a[j] == i) x = j;
    int r = x + 1;
    while (r <= N) {
      if (a[r] <= x) {
        ++len;
        ans[len].x = x;
        ans[len].y = r;
        swap(a[r], a[x]);
        cost += abs(r - x);
        x = r;
      }
      r++;
    }
  }
  printf("%d\n", cost);
  printf("%d\n", len);
  for (int i = 1; i <= len; i++) printf("%d %d\n", ans[i].x, ans[i].y);
}
