#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, i, j, sum = 0, temp;
  cin >> n;
  int sf[26] = {}, tf[26] = {};
  string s, t;
  cin >> s >> t;
  for (i = 0; i < n; i++) {
    sf[s[i] - 'a']++;
    tf[t[i] - 'a']++;
  }
  for (i = 0; i < 26; i++)
    if (sf[i] != tf[i]) {
      cout << "-1";
      return 0;
    }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (t[j] == s[i]) {
        s[i] = j;
        t[j] = 0;
        break;
      }
    }
  }
  vector<int> v(&s[0], &s[0] + n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < n - 1; j++) {
      if (v[j] > v[j + 1]) {
        sum++;
        temp = v[j];
        v[j] = v[j + 1];
        v[j + 1] = temp;
      }
    }
  }
  cout << sum << "\n";
  for (i = 0; i < n; i++) {
    for (j = 0; j < n - 1; j++) {
      if (s[j] > s[j + 1]) {
        cout << j + 1 << " ";
        temp = s[j];
        s[j] = s[j + 1];
        s[j + 1] = temp;
      }
    }
  }
}
