#include <bits/stdc++.h>
using namespace std;
const long long init = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> ans;
  string xx = "a";
  string s, t;
  cin >> s >> t;
  vector<int> c1(27, 0), c2(27, 0);
  for (int i = 0; i < n; ++i) {
    c1[s[i] - 'a' + 1]++;
    c2[t[i] - 'a' + 1]++;
  }
  for (int i = 0; i < 27; ++i) {
    if (c1[i] != c2[i]) {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (s[i] == t[i])
      continue;
    else {
      int cur;
      for (int j = i; j < n; ++j) {
        if (s[j] == t[i]) {
          cur = j;
          break;
        }
      }
      for (int j = cur - 1; j >= i; --j) {
        xx[0] = s[j];
        s[j] = s[j + 1];
        s[j + 1] = xx[0];
        ans.push_back(j + 1);
      }
    }
  }
  long long answer = ans.size();
  if (answer <= 10000) {
    cout << ans.size() << endl;
    for (int i = 0; i < answer; ++i) {
      cout << ans[i] << " ";
    }
    if (answer > 0) cout << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
