#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
long long n, i, j, a[26], b[26], pos;
vector<long long> v;
string t, s;
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  cin >> s;
  cin >> t;
  for (i = 0; i < n; i++) {
    a[s[i] - 'a']++;
  }
  for (i = 0; i < n; i++) {
    b[t[i] - 'a']++;
  }
  for (i = 0; i < 26; i++) {
    if (a[i] != b[i]) {
      cout << "-1" << '\n';
      return 0;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = i; j < n; j++) {
      if (s[j] == t[i]) {
        pos = j;
        break;
      }
    }
    pos--;
    while (pos != i - 1) {
      v.push_back(pos + 1);
      swap(s[pos], s[pos + 1]);
      pos--;
    }
  }
  cout << v.size() << '\n';
  for (i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << '\n';
  return 0;
}
