#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> p(n), target(n), where(n);
    for (int &x : p) {
        cin >> x;
        --x;
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        target[x - 1] = i;
    }
    for (int i = 0; i < n; i++) {
        p[i] = target[p[i]];
        where[p[i]] = i;
    }
    ll cost = 0;
    vector<pair<int, int>> ops;
    for (int i = 0; i < n; i++) {
        int j = where[i];
        for (int k = j - 1; k >= i; k--)
            if (p[k] >= j) {
                cost += j - k;
                ops.push_back({k + 1, j + 1});
                swap(p[k], p[j]);
                where[p[k]] = k;
                where[p[j]] = j;
                j = k;
            }
    }
    cout << cost << '\n' << ops.size() << '\n';
    for (auto [i, j] : ops)
        cout << i << ' ' << j << '\n';
}
