#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long INF64 = 9e18;
const long double EPS = 1e-9;
const long double PI = 3.14159265358979310000;
const long long MD = 535355424;
const long long T = 25342;
const int N = 200001;
const int M = 10001;
int n;
pair<pair<int, int>, int> a[N];
int d[N], p[N], pos[N], b[N];
vector<pair<int, int> > ans;
int main() {
  cin >> n;
  for (int i = 0; i < int(n); i++) {
    cin >> a[i].first.second;
    a[i].second = i;
  }
  for (int i = 0; i < int(n); i++) {
    cin >> a[i].first.first;
    b[a[i].first.first] = i;
  }
  for (int i = 0; i < int(n); i++) {
    d[i] = b[a[i].first.second] + 1;
    p[i] = a[i].second;
    pos[d[i]] = i;
  }
  int sum = 0;
  for (int i = n; i >= 1; i--)
    if (pos[i] + 1 < i) {
      int j = pos[i] + 1;
      while (j < n)
        if (d[j] <= pos[i] + 1) {
          sum += j - pos[i];
          ans.push_back(make_pair(p[pos[i]], p[j]));
          d[pos[i]] = d[j];
          pos[d[j]] = pos[i];
          pos[i] = j;
          d[j] = i;
          j++;
        } else
          j++;
    }
  cout << sum << endl;
  cout << int((ans).size()) << endl;
  for (int i = 0; i < int(int((ans).size())); i++)
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
  return 0;
}
