#include <bits/stdc++.h>
using namespace std;
int n, ans = 0;
char arr1[50], arr2[50];
int arr3[1500];
inline int find(int a, char c) {
  int r;
  while (a <= n) {
    if (arr1[a] == c) {
      return a;
    }
    a++;
  }
  if (a = n + 1) return -1;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr1[i];
  for (int i = 1; i <= n; i++) cin >> arr2[i];
  for (int i = 1; i <= n; i++) {
    int j = find(i, arr2[i]);
    if (j == -1) {
      cout << -1;
      return 0;
    } else {
      for (int k = j - 1; k >= i; k--) {
        char c;
        arr3[++ans] = k;
        c = arr1[k], arr1[k] = arr1[k + 1], arr1[k + 1] = c;
      }
    }
  }
  cout << ans << '\n';
  for (int i = 1; i <= ans; i++) cout << arr3[i] << ' ';
  return 0;
}
