#include <bits/stdc++.h>

#define long long long int
using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    vector<int> res;
    bool ok = true;
    for (int i = 0; i < n; i++) {
        int x = b[i];
        int j = 0;
        while (a[j] != x) {
            j++;
        }
        while (j > i) {
            res.push_back(j);
            if (abs(a[j] - a[j - 1]) == 1) {
                ok = false;
            }
            swap(a[j - 1], a[j]);
            j--;
        }
    }
    if (!ok) {
        cout << -1;
    } else {
        cout << res.size() << "\n";
        for (int x : res) cout << x << " ";
    }



    return 0;
}