#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:133217728")
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000007;
const int MAX = 10000;
int n;
int s[MAX], p[MAX];
vector<pair<int, int> > v;
long long sol = 0;
int must[MAX];
void show() {
  cout << " show ";
  for (int i = (0); i < (n); ++i) cout << p[i] << " ";
  cout << endl;
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    cin >> p[i];
  }
  for (int i = (0); i < (n); ++i) {
    cin >> s[i];
    must[s[i]] = i;
  }
  for (;;) {
    int j = 1;
    for (int i = (0); i < (n); ++i) {
      if (must[p[i]] == i) continue;
      while (j < n && (j <= i || must[p[j]] == j)) ++j;
      if (j == n) break;
      if (must[p[i]] >= j && must[p[j]] <= i) {
        sol += abs(i - j);
        v.push_back(make_pair(i + 1, j + 1));
        swap(p[i], p[j]);
      }
    }
    j = n - 2;
    for (int i = (n)-1; i >= (0); --i) {
      if (must[p[i]] == i) continue;
      while (j >= 0 && (j >= i || must[p[j]] == j)) --j;
      if (j < 0) break;
      if (must[p[i]] <= j && must[p[j]] >= i) {
        sol += abs(i - j);
        v.push_back(make_pair(i + 1, j + 1));
        swap(p[i], p[j]);
      }
    }
    bool ok = true;
    for (int i = (0); i < (n); ++i)
      if (must[p[i]] != i) {
        ok = false;
        break;
      }
    if (ok) break;
  }
  printf("%d\n", sol);
  printf("%d\n", v.size());
  for (int i = (0); i < (v.size()); ++i)
    printf("%d %d\n", v[i].first, v[i].second);
  return 0;
}
