#include <bits/stdc++.h>
using namespace std;
void swap(char *a, char *b) {
  char temp = *a;
  *a = *b;
  *b = temp;
}
int main() {
  long long n;
  cin >> n;
  string second;
  cin >> second;
  string t;
  cin >> t;
  map<char, int> m;
  for (int i = 0; i < n; i++) {
    m[second[i]]++;
    m[t[i]]--;
  }
  bool ok = true;
  for (auto i : m) {
    if (i.second != 0) ok = false;
  }
  if (!ok) {
    cout << "-1" << endl;
  } else {
    int count = 0;
    vector<int> ans;
    int j = 0;
    while (j < n) {
      int i = j;
      while (second[i] != t[j]) {
        i++;
      }
      for (int k = i - 1; k >= j; k--) {
        count++;
        ans.push_back(k + 1);
        swap(&second[k], &second[k + 1]);
      }
      j++;
    }
    cout << count << endl;
    for (auto i : ans) cout << i << " ";
  }
}
