#include <bits/stdc++.h>
using namespace std;
struct LINE {
  int start;
  int end;
};
int ans = 0;
vector<int> res;
string shift(string s, int p1, int p2) {
  char t;
  for (int f = p2; f > p1; f--) {
    ans++;
    res.push_back(f);
    t = s[f];
    s[f] = s[f - 1];
    s[f - 1] = t;
  }
  return s;
}
int main() {
  string s, t;
  int a1[27];
  int a2[27];
  for (int i = 0; i < 27; i++) {
    a2[i] = 0;
    a1[i] = 0;
  }
  getline(std::cin, s);
  getline(std::cin, s);
  getline(std::cin, t);
  for (int i = 0; i < s.length(); i++) {
    a1[((int)s[i]) - 97]++;
  }
  for (int i = 0; i < t.length(); i++) {
    a2[((int)t[i]) - 97]++;
  }
  for (int i = 0; i < 27; i++) {
    if (a1[i] != a2[i]) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == t[i]) continue;
    int a = s.find(t[i], i);
    s = shift(s, i, a);
  }
  cout << ans << "\n";
  for (int i = 0; i < res.size(); i++) {
    cout << res[i] << " ";
  }
  return 0;
}
