#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 100;
int V1[MAXN], V2[MAXN], V[MAXN];
pair<int, int> res[MAXN * 10];
int main() {
  int n;
  while (scanf(" %d", &n) != EOF) {
    for (int i = 0; i < n; ++i) scanf(" %d", &V1[i]);
    for (int i = 0; i < n; ++i) scanf(" %d", &V2[i]);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (V1[i] == V2[j]) V[i] = j;
      }
    }
    int ans = 0, tam = 0;
    for (int i = 0; i < n; ++i) {
      int k = -1;
      for (int j = i; j < n; ++j) {
        if (V[j] == i) {
          k = j;
          break;
        }
      }
      while (k != i) {
        for (int j = k - 1; j >= i; j--) {
          if (V[j] >= k) {
            swap(V[j], V[k]);
            res[tam++] = (pair<int, int>(j + 1, k + 1));
            ans += k - j;
            k = j;
            break;
          }
        }
      }
    }
    printf("%d\n", ans);
    printf("%d\n", tam);
    for (int i = 0; i < tam; ++i)
      printf("%d %d\n", res[i].first, res[i].second);
  }
}
