#include <bits/stdc++.h>
using namespace std;
ifstream f("test.in");
ofstream g("test.out");
int n;
string s, t;
bool pos() {
  string a, b;
  a = s;
  b = t;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (int i = 0; i < a.size(); i++)
    if (a[i] != b[i]) return 0;
  return 1;
}
vector<int> act;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> s;
  cin >> t;
  if (!pos()) {
    cout << -1;
    return 0;
  }
  s = ' ' + s;
  t = ' ' + t;
  for (int i = 1; i <= n; i++)
    if (s[i] != t[i]) {
      int poz = 0;
      for (int j = i + 1; j <= n and !poz; j++)
        if (s[j] == t[i]) poz = j;
      while (poz > i) {
        poz--;
        if (poz) {
          act.push_back(poz);
          swap(s[poz], s[poz + 1]);
        }
      }
    }
  if (act.size() <= 1e4) {
    cout << act.size() << '\n';
    for (int i = 0; i < act.size(); i++) cout << act[i] << ' ';
  } else {
    cout << "-1";
  }
  return 0;
}
