#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int ana[n + 1];
  int pos[n + 1];
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    pos[i] = x;
  }
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    ana[x] = i;
  }
  vector<int> A, B;
  int r = 0;
  for (int u = 0; u <= n / 2; ++u) {
    for (int i = n - 1; i > 0; --i) {
      if (ana[pos[i]] == i) continue;
      int k = i;
      for (int j = k + 1; j <= n; ++j) {
        if (ana[pos[j]] == j) continue;
        int x = pos[k];
        int y = pos[j];
        if (ana[x] >= j and ana[y] <= k) {
          pos[k] = y;
          pos[j] = x;
          A.push_back(k);
          B.push_back(j);
          r += abs(k - j);
          k = j;
          break;
        }
      }
    }
    for (int i = 1; i < n; ++i) {
      if (ana[pos[i]] == i) continue;
      int k = i;
      for (int j = k + 1; j <= n; ++j) {
        if (ana[pos[j]] == j) continue;
        int x = pos[k];
        int y = pos[j];
        if (ana[x] >= j and ana[y] <= k) {
          pos[k] = y;
          pos[j] = x;
          A.push_back(k);
          B.push_back(j);
          r += abs(k - j);
          k = j;
          break;
        }
      }
    }
  }
  cout << r << endl;
  cout << A.size() << endl;
  for (int i = 0; i < A.size(); ++i) printf("%d %d\n", A[i], B[i]);
}
