#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
struct poi {
  int X;
  int Y;
  int Z;
  bool operator<(const poi& R) const {
    return X == R.X ? Y == R.Y ? Z < R.Z : Y < R.Y : X < R.X;
  }
};
long long GCD(long long a, long long b) {
  return (b == 0) ? (a) : (GCD(b, a % b));
}
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int s[26], t[26];
int main() {
  int N;
  string S, T;
  cin >> N;
  cin >> S >> T;
  if (S == T) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    s[S[i] - 'a']++;
    t[T[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (s[i] != t[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  string a = S, b = T;
  S = b;
  T = a;
  vector<int> V;
  for (int i = 0; i < N; i++) {
    int n = i;
    while (S[i] != T[n]) {
      n++;
    }
    for (int j = n - 1; j >= i; j--) {
      swap(T[j], T[j + 1]);
      V.push_back(j);
    }
  }
  cout << V.size() << endl;
  for (int i = 0; i < V.size(); i++) {
    if (i) {
      cout << " ";
    }
    cout << V[i] + 1;
  }
  cout << endl;
  return 0;
}
