#include <bits/stdc++.h>
using namespace std;
long long a[200], b[200];
string s, s2;
int main() {
  long long i, j, k, p, q, m, n;
  cin >> n;
  cin >> s >> s2;
  for (i = 0; i < n; i++) {
    a[s[i]]++;
  }
  for (i = 0; i < n; i++) {
    b[s2[i]]++;
  }
  for (i = 97; i <= 122; i++) {
    if (a[i] != b[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<long long> v;
  k = 0;
  for (i = 0; i < n; i++) {
    if (s[i] != s2[i]) {
      for (j = i; j < n; j++) {
        if (s[j] == s2[i]) {
          break;
        }
      }
      for (; j > i; j--) {
        k++;
        v.push_back(j);
        swap(s[j], s[j - 1]);
      }
    }
  }
  cout << k << endl;
  for (i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  return 0;
}
