#include <bits/stdc++.h>
using namespace std;
long long int search(string &s, char c, long long int i) {
  for (long long int j = i; j < s.length(); j++) {
    if (s[j] == c) {
      return j;
    }
  }
}
void swap(string &s, long long int i, long long int j) {
  char temp = s[i];
  s[i] = s[j];
  s[j] = temp;
}
int main() {
  ios::sync_with_stdio(false);
  long long int n;
  cin >> n;
  string s, t, S, T;
  cin >> s >> t;
  S = s;
  T = t;
  sort(S.begin(), S.end());
  sort(T.begin(), T.end());
  if (S != T) {
    cout << "-1";
  } else {
    vector<long long int> vec;
    char x, y;
    long long int ind;
    for (long long int i = 0; i < s.length(); i++) {
      x = t[i];
      ind = search(s, x, i);
      for (long long int j = ind - 1; j >= i; j--) {
        vec.push_back(j + 1);
        swap(s, j, j + 1);
      }
    }
    cout << vec.size() << endl;
    for (long long int i = 0; i < vec.size(); i++) {
      cout << vec[i] << " ";
    }
  }
  return 0;
}
