#include <bits/stdc++.h>
using namespace std;
char str1[55], str2[55];
int n;
int buck1[27], buck2[27];
int k;
int op[10005];
int main() {
  cin >> n;
  cin >> str1 >> str2;
  for (int i = 0; i < n; i++) {
    buck1[str1[i] - 'a']++;
  }
  for (int i = 0; i < n; i++) {
    buck2[str2[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (buck1[i] != buck2[i]) {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (str1[i] != str2[i]) {
      int j = i;
      while (str1[j] != str2[i]) j++;
      for (; j > i; j--) {
        swap(str1[j], str1[j - 1]);
        op[k++] = j;
      }
    }
  }
  cout << k << endl;
  for (int i = 0; i < k; i++) {
    cout << op[i] << ' ';
  }
  cout << endl;
  return 0;
}
