#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000;
string s, t, sorts, sortt;
int n;
int main() {
  cin >> n;
  cin >> s;
  cin >> t;
  sorts = s;
  sort(sorts.begin(), sorts.end());
  sortt = t;
  sort(sortt.begin(), sortt.end());
  if (sortt == sorts) {
    int k = 0;
    int countt = 0;
    vector<int> res;
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        if (t[i] == s[j]) {
          k = j;
        }
      }
      for (int j = k - 1; j >= i; j--) {
        swap(s[j], s[j + 1]);
        countt++;
        res.push_back(j + 1);
      }
    }
    cout << countt << endl;
    for (int i = 0; i < res.size(); i++) {
      cout << res[i] << " ";
    }
  } else {
    cout << -1 << endl;
  }
  return 0;
}
