#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  int a[26], b[26];
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  for (int i = 0; i < n; i++) {
    a[(s[i] - 'a')]++;
    b[(t[i] - 'a')]++;
  }
  bool p = true;
  for (int i = 0; i < 26; i++) {
    if (a[i] == b[i]) {
      continue;
    } else {
      p = false;
      break;
    }
  }
  if (p) {
    int cnt = 0;
    vector<int> moves;
    for (int i = 0; i < n; i++) {
      if (s[i] == t[i]) {
        continue;
      } else {
        int temp = i, j;
        for (j = i; j < n; j++) {
          if (s[j] == t[i]) {
            break;
          } else {
            cnt++;
          }
        }
        for (int k = j - 1; k >= temp; k--) {
          char c = s[k];
          s[k] = s[k + 1];
          s[k + 1] = c;
          moves.push_back(k);
        }
      }
    }
    cout << cnt << endl;
    for (auto it = moves.begin(); it != moves.end(); it++) {
      cout << *it + 1 << " ";
    }
  } else {
    cout << -1;
  }
  return 0;
}
