#include <bits/stdc++.h>
using namespace std;
int main() {
  int jabba;
  cin >> jabba;
  string a, b;
  cin >> a >> b;
  if (a.length() != b.length()) {
    cout << "-1";
    return 0;
  }
  int f1[26] = {0};
  int f2[26] = {0};
  for (int i = 0; i < a.length(); ++i) {
    f1[a[i] - 'a']++;
    f2[b[i] - 'a']++;
  }
  for (int i = 0; i < 26; ++i) {
    if (f1[i] != f2[i]) {
      cout << "-1";
      return 0;
    }
  }
  vector<int> m;
  int moves = 0;
  for (int i = 0; i < a.length(); ++i) {
    if (a[i] == b[i]) continue;
    int j;
    for (j = i + 1; a[j] != b[i]; ++j)
      ;
    while (a[i] != b[i]) {
      moves++;
      swap(a[j - 1], a[j]);
      moves++;
      m.push_back(j);
      j--;
    }
  }
  if (moves > 10000) {
    cout << "-1";
  } else {
    cout << m.size() << endl;
    for (int i = 0; i < m.size(); ++i) {
      cout << m[i] << " ";
    }
  }
  return 0;
}
