#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long n;
  string s, t;
  cin >> n >> s >> t;
  long long s1[55], a[40000];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (s[j] == t[i]) {
        s[j] = '\0';
        s1[j + 1] = i + 1;
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (s[i] != '\0') {
      cout << -1;
      return 0;
    }
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - 1; j++) {
      if (s1[j] >= s1[j + 1]) {
        sum++;
        long long temp = s1[j];
        s1[j] = s1[j + 1];
        s1[j + 1] = temp;
        a[sum] = j;
      }
    }
  }
  cout << sum << endl;
  for (int i = 1; i <= sum; i++) cout << a[i] << " ";
}
