#include <bits/stdc++.h>
using namespace std;
inline void prep() {
  cin.tie(0);
  cin.sync_with_stdio(0);
};
const int mod = (int)1e9 + 7;
const int MX = (int)2e5 + 20;
int main() {
  prep();
  srand(time(0));
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < 26; ++i)
    if (count(s.begin(), s.end(), 'a' + i) !=
        count(t.begin(), t.end(), 'a' + i))
      return puts("-1"), 0;
  vector<int> res;
  for (int i = 0; i < n; ++i) {
    int idx = i;
    for (int j = i; j < n; ++j) {
      if (s[j] == t[i]) {
        idx = j;
        break;
      }
    }
    while (idx != i) {
      res.push_back(idx);
      swap(s[idx], s[idx - 1]);
      idx--;
    }
  }
  cout << res.size() << '\n';
  for (auto x : res) cout << x << " ";
  return 0;
}
