#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n; cin >> n;
    string s1 , s2; cin >> s1 >> s2;
    map<char,int> m1;
    map<char,int> m2;
    for(int i = 0; i < s1.size(); i++){
        m1[s1[i]] += 1;
        m2[s2[i]] += 1;
    }
    if(s1 == s2){
        cout << 0;
        return 0;
    }
    bool check = false;
    for(int i = 0 ; i  < s1.size(); i++){
        if(m1[s1[i]] == m2[s1[i]]) check = true;
        else{
            check = false;
            cout << -1;
            return 0;
        }
    }
    vector<int> vi;
    int a[50000];
    int q = 0;
    for(int i = 0; i < s2.size(); i++){
        for(int j = i; j < s1.size(); j++){
            if(s2[i] == s1[j]){
                while(i != j){
                    a[q] = j;
                    q++;
                    char w = s1[j - 1];
                    s1[j - 1] = s1[j];
                    s1[j] = w;
                    j--;
                }
            }
        }
    }
    int cnt = 0;
    for(int i = 0; i < 50000; i++){
        if(a[i] != 0){
            cnt++;
        }
        else{
             break;
        }
    }
    cout << cnt << endl;
    for(int i = 0; i < 50000; i++){
        if(a[i] != 0){
        cout << a[i] << " ";
        }
        else{
             return 0;
        }
    }

}


#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define endl "\n"
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string raw;
	int ans=0;
	int tmp,maxi=INT_MIN,mini=INT_MIN;
	vector<int> v;
	string s,t;
	int n;
	cin>>n;
	cin>>s>>t;
	string ca,cb;
	ca = s;
	cb = t;
	sort(all(ca));
	sort(all(cb));
	if(ca!=cb){
		cout<<-1<<endl;
		return 0;
	}
	for (int i = 0; i < s.size(); ++i)
	{
		if(s[i]==t[i]){
			continue;
		}
		else{
			for (int j = i; j < s.size()-1; ++j)
			{
				// cout<<s<<"->";
				char tmp = s[j];
				s[j] = s[j+1];
				s[j+1] = tmp;
				v.pb(j+1);
				// cout<<s<<endl;
				if(s[j+1]==t[j+1]){
					// cout<<"STOP"<<endl;
					i=-1;
					break;
				}
			}
		}
	}
	cout<<v.size()<<endl;
	for (int i = 0; i < v.size(); ++i)
	{
		cout<<v[i]<<" ";
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define endl "\n"
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string raw;
	int ans=0;
	int tmp,maxi=INT_MIN,mini=INT_MIN;
	vector<int> v;
	string s,t;
	int n;
	cin>>n;
	cin>>s>>t;
	string ca,cb;
	ca = s;
	cb = t;
	sort(all(ca));
	sort(all(cb));
	if(ca!=cb){
		cout<<-1<<endl;
		return 0;
	}
	for (int i = 0; i < s.size(); ++i)
	{
		if(s[i]==t[i]){
			continue;
		}
		else{
			for (int j = i; j < s.size()-1; ++j)
			{
				// if()
				swap(s[j],s[j+1]);
				v.pb(j+1);
				if(s[j+1]==t[j+1]) break;
			}
		}
	}
	cout<<v.size()<<endl;
	for (int i = 0; i < v.size(); ++i)
	{
		cout<<v[i]<<" ";
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long int
#define endl "\n"
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string raw;
	int ans=0;
	int tmp,maxi=INT_MIN,mini=INT_MAX;
	vector<int> v;
	multiset<int> chc;
	int tanda[100001][3]={0};
	int n,m;
	cin>>n>>m;
	for (int i = 1; i <= n; ++i)
	{
		cin>>tmp;
		tanda[tmp][0]++;
		if(tanda[tmp][0]==2){
			puts("0");
			return 0;
		}
		if((tmp&m) != tmp){
			tanda[tmp&m][1]++;
		}
	}
	for (int i = 0; i <= 100000; ++i)
	{
		if(tanda[i][0]==1 and tanda[i][1]>=1){
			puts("1");
			return 0;
		}
	}
	for (int i = 0; i <= 100000; ++i)
	{
		if(tanda[i][1]>=2){
			puts("2");
			return 0;
		}
	}
	puts("-1");

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define endl "\n"
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string raw;
	int ans=0;
	int tmp,maxi=INT_MIN,mini=INT_MIN;
	vector<int> v;
	string s,t;
	int n;
	cin>>n;
	cin>>s>>t;
	string ca,cb;
	ca = s;
	cb = t;
	sort(all(ca));
	sort(all(cb));
	if(ca!=cb){
		cout<<-1<<endl;
		return 0;
	}
	long long int save = -1;
	for (long long int  i = 0; i < s.size(); ++i)
	{

		// cout<<t<<"->";
		// cout<<s<<endl;
		if(s[i]==t[i]){
			save = i;
			continue;
		}
		else{
			for (long long int  j = i; j < s.size()-1; ++j)
			{
				// cout<<s<<"->";
				char tmp = s[j];
				s[j] = s[j+1];
				s[j+1] = tmp;
				v.pb(j+1);
				// cout<<s<<endl;
				if(s[j+1]==t[j+1]){
					// cout<<"STOP"<<endl;
					i=save;
					break;
				}
				if(v.size()>10000) break;
			}
		}

		if(v.size()>10000) break;
	}

	if(v.size()>10000){
		cout<<-1<<endl;
		return 0;
	}
	cout<<v.size()<<endl;
	for (int i = 0; i < v.size(); ++i)
	{
		cout<<v[i]<<" ";
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define endl "\n"
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string raw;
	int ans=0;
	int tmp,maxi=INT_MIN,mini=INT_MIN;
	vector<int> v;
	vector<int> dt[100];
	string s,t;
	int n;
	cin>>n;
	cin>>s>>t;

	for (int i = 0; i < t.size(); ++i)
	{
		dt[t[i]-'a'].pb(i);
	}
	for (int i = 0; i < t.size(); ++i)
	{
		sort(all(dt[t[i]-'a']));
	}
	string ca,cb;
	ca = s;
	cb = t;
	sort(all(ca));
	sort(all(cb));
	if(ca!=cb){
		cout<<-1<<endl;
		return 0;
	}
	for (int i = n-1; i >=0; --i)
	{
		if(s[i]==t[i]){
			continue;
		}
		else{
			for (int j = 0; j < s.size(); ++j)
			{
				if(s[j] == t[i]){
					for (int k = j; k <i; ++k)
					{
						swap(s[k],s[k+1]);
						v.pb(k+1);
					}
					break;
				}
			}
		}
	}
	cout<<v.size()<<endl;
	for (int i = 0; i < v.size(); ++i)
	{
		cout<<v[i]<<" ";
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define endl "\n"
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string raw;
	int ans=0;
	int tmp,maxi=INT_MIN,mini=INT_MIN;
	vector<int> v;
	string s,t;
	int n;
	cin>>n;
	cin>>s>>t;
	string ca,cb;
	ca = s;
	cb = t;
	sort(all(ca));
	sort(all(cb));
	if(ca!=cb){
		cout<<-1<<endl;
		return 0;
	}
	for (int i = 0; i < s.size(); ++i)
	{
		if(s[i]==t[i]){
			continue;
		}
		else{
			for (int j = i; j < s.size()-1; ++j)
			{
				// cout<<s<<"->";
				swap(s[j],s[j+1]);
				v.pb(j+1);
				// cout<<s<<endl;
				if(s[j+1]==t[j+1]){
					// cout<<"STOP"<<endl;
					i=-1;
					break;
				}
			}
		}
	}
	cout<<v.size()<<endl;
	for (int i = 0; i < v.size(); ++i)
	{
		cout<<v[i]<<" ";
	}

	return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mi 1e18
using namespace std;
int cmp(int x,int y){return x>y;}
string s,t;
int a[28],b[28],ans,k;
vector <int> v;
vector <int>::iterator it;
int main()
{ int n;
    cin>>n>>s>>t;
   for(int i=0;i<n;i++)
   {int p=0;
       for(int x=i;x<n;x++)
        if(s[x]==t[i]) {p=x;}
       if(p<s.size() && p>=i) {ans+=abs(i-p);
        for(int j=p;j>i;j--)
        {
          swap(s[j],s[j-1]);
          v.push_back(j);
        }
       // cout<<i<<' '<<p<<' '<<s<<' '<<t<<endl;
       }
       else {cout<<-1;return 0;}
   }
   if(ans<10001)
   {
    cout<<ans<<endl;
   for(it=v.begin();it!=v.end();++it)
    cout<<*it<<' ';
   }
   else cout<<-1;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mi 1e18
using namespace std;
int cmp(int x,int y){return x>y;}
string s,t;
int a[28],b[28],ans,k;
vector <int> v;
vector <int>::iterator it;
int main()
{ int n;
    cin>>n>>s>>t;
    for(int i=0;i<n;i++)
    {
      a[s[i]-64]++;
      b[t[i]-64]++;
    }
   for(int i=0;i<n;i++)
   {
       int p=s.find(t[i]);
       if(p<s.size() && p>=i) {ans+=abs(i-p);
        for(int j=p;j>i;j--)
        {
          swap(s[j],s[j-1]);
          v.push_back(s[j]-(int)'a'+1);
        }
       // cout<<i<<' '<<p<<' '<<s<<' '<<t<<endl;
       }
       else {cout<<-1;return 0;}
   }
   if(ans<10001)
   {
    cout<<ans<<endl;
   for(it=v.begin();it!=v.end();++it)
    cout<<*it<<' ';
   }

}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mi 1e18
using namespace std;
int cmp(int x,int y){return x>y;}
string s,t;
int a[28],b[28],ans,k;
vector <int> v;
vector <int>::iterator it;
int main()
{ int n;
    cin>>n>>s>>t;
   for(int i=0;i<n;i++)
   {int p=0;
       for(int x=i;x<n;x++)
        if(s[x]==t[i]) {p=x;break;}
       if(p<s.size() && p>=i) {ans+=abs(i-p);
        for(int j=p;j>i;j--)
        {
          swap(s[j],s[j-1]);
          v.push_back(j);
        }
       // cout<<i<<' '<<p<<' '<<s<<' '<<t<<endl;
       }
       else {cout<<-1;return 0;}
   }
   if(ans<10001)
   {
    cout<<ans<<endl;
   for(it=v.begin();it!=v.end();++it)
    cout<<*it<<' ';
   }
   else cout<<-1;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mi 1e18
using namespace std;
int cmp(int x,int y){return x>y;}
string s,t;
int a[28],b[28],ans,k;
vector <int> v;
vector <int>::iterator it;
int main()
{ int n;
    cin>>n>>s>>t;
   for(int i=0;i<n;i++)
   {
       int p=s.find(t[i]);
       if(p<s.size() && p>=i) {ans+=abs(i-p);
        for(int j=p;j>i;j--)
        {
          swap(s[j],s[j-1]);
          v.push_back(j);
        }
       // cout<<i<<' '<<p<<' '<<s<<' '<<t<<endl;
       }
       else {cout<<-1;return 0;}
   }
   if(ans<10001)
   {
    cout<<ans<<endl;
   for(it=v.begin();it!=v.end();++it)
    cout<<*it<<' ';
   }

}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mi 1e18
using namespace std;
int cmp(int x,int y){return x>y;}
string s,t;
int a[28],b[28],ans,k;
vector <int> v;
vector <int>::iterator it;
int main()
{ int n;
    cin>>n>>s>>t;
   for(int i=0;i<n;i++)
   {int p=0;
       for(int x=i;x<n;x++)
        if(s[x]==t[i]) {p=x;break;}
       if(p<s.size() && p>=i) {ans+=abs(i-p);
        for(int j=p;j>i;j--)
        {
          swap(s[j],s[j-1]);
          v.push_back(j);
        }
       // cout<<i<<' '<<p<<' '<<s<<' '<<t<<endl;
       }
       else {cout<<-1;return 0;}
   }
   if(ans<10001)
   {
    cout<<ans<<endl;
   for(it=v.begin();it!=v.end();++it)
    cout<<*it<<' ';
   }
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mi 1e18
using namespace std;
int cmp(int x,int y){return x>y;}
string s,t;
int a[28],b[28],ans,k;
vector <int> v;
vector <int>::iterator it;
int main()
{ int n;
    cin>>n>>s>>t;
    s="#"+s;
    t="#"+t;
   for(int i=1;i<=n;i++)
   {int p=0;
       for(int x=i;x<=n;x++)
        if(s[x]==t[i]) {p=x;break;}
       if(p<s.size() && p>=i) {ans+=abs(i-p);
        for(int j=p;j>i;j--)
        {
          swap(s[j],s[j-1]);
          v.push_back(j-1);
        }
       // cout<<i<<' '<<p<<' '<<s<<' '<<t<<endl;
       }
       else {cout<<-1;return 0;}
   }
   if(ans<10001)
   {
    cout<<ans<<endl;
   for(it=v.begin();it!=v.end();++it)
    cout<<*it<<' ';
   }
   else cout<<-1;
}


#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define ll long long
#define vll vector<long long>
#define vc vector<char>
#define vi vector<int>
#define pb push_back
#define LOOP(n) for(int i=0; i<n; ++i)

using namespace std;

bool checkzero(string s1, string s2)
{
	for (int i = 0; i < s1.size(); ++i)
	{
		bool flag = true;
		for(int j=0; j<s2.size(); ++j)
		{
			if(s1[i] == s2[j])
			{
				flag = false;
				s2[j] = 'A';
				break;
			}
		}
		if(flag) return true;
	}
	return false;
}

int main()
{
	ll n; string s; string t;
	cin>>n>>s>>t;
	vll ans;
	if(checkzero(s,t)) cout<<"-1";
	else
	{
		for(int i=0; i<n; ++i)
		{
			if(s[i]==t[i]) continue;
			ll pos = -1;
			for(ll j=i+1; j<n; ++j)
			{
				if(s[j] == t[i])
				{
					pos = j;
					break;
				}
			}
			for(ll j=pos-1; j>=i; --j)
			{
				ans.pb(j+1);
				swap(s[j],s[j+1]);
			}
		}
		cout<<ans.size()<<endl;
		for (ll i = 0; i < ans.size(); ++i)
		{
			cout<<ans[i]<<" ";
		}
	}
	return 0;
}


#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define ll long long
#define vll vector<long long>
#define vc vector<char>
#define vi vector<int>
#define pb push_back
#define LOOP(n) for(int i=0; i<n; ++i)

using namespace std;

bool checkzero(string s1, string s2)
{
	for (int i = 0; i < s1.size(); ++i)
	{
		bool flag = true;
		for(int j=0; j<s2.size(); ++j)
		{
			if(s1[i] == s2[j])
			{
				flag = false;
				s2[j] = 'A';
				break;
			}
		}
		if(flag) return true;
	}
	return false;
}

int main()
{
	ll n; string s; string t;
	cin>>n>>s>>t;
	vll ans;
	if(checkzero(s,t)) cout<<"-1";
	else
	{
		for(int i=0; i<n; ++i)
		{
			if(s[i]==t[i]) continue;
			ll pos = -1;
			for(int j=0; j<n; ++j)
			{
				if(s[i] == t[j])
				{
					pos = j;
					break;
				}
			}
			for(int j=i; j<pos; ++j)
			{
				ans.pb(j+1);
				swap(s[i],s[j]);
			}
		}
		cout<<ans.size()<<endl;
		for (int i = 0; i < ans.size(); ++i)
		{
			cout<<ans[i]<<" ";
		}
	}
	return 0;
}


#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define ll long long
#define vll vector<long long>
#define vc vector<char>
#define vi vector<int>
#define pb push_back
#define LOOP(n) for(int i=0; i<n; ++i)

using namespace std;

bool checkzero(string s1, string s2)
{
	ll l1 = s1.length();
	for(int i=0; i<l1; ++i)
	{
		bool flag = false;
		for (int j = 0; j < l1; ++j)
		{
			if(s2[j] == s1[i])
			{
				flag = true;
				s2[j] = 'A';
				break;
			}
		}
		if(flag == false)
		{
			return false;
			break;
		}
	}
	return true;
}
vll final;
void swapping(string& str, ll p1, ll p2)
{
	for (int i = p1; i < p2; ++i)
	{
		final.pb(i+1);
		swap(str[i], str[i+1]);
	}
}

void process(string s1, string s2)
{
	ll len = s1.length();
	for (int i = 0; i < len; ++i)
	{
		if(s1[i] != s2[i])
		{
			for(int j=0; j<len; ++j)
			{
				if(i!=j && s2[j]==s1[i])
				{
					s2[j] = 'A';
					if(i>j) swapping(s1,j,i);
					else swapping(s1,i,j);
				}
			}
		}
	}
}

int main()
{
	ll n; cin>>n;
	string s1; string s2;
	cin>>s1>>s2;
	if(checkzero(s1,s2)==0)
	{
		cout<<"-1";
	}
	else
	{
		process(s1,s2);
        if(final.size()>10000) {cout<<"-1";return 0;}
		cout<<final.size()<<endl;
		for (int i = 0; i < final.size(); ++i)
		{
			cout<<final[i]<<' ';
		}
	}
	return 0;
}


#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define ll long long
#define vll vector<long long>
#define vc vector<char>
#define vi vector<int>
#define pb push_back
#define LOOP(n) for(int i=0; i<n; ++i)

using namespace std;

int main()
{
	ll n; cin>>n;
	ll m; cin>>m;
	ll a[10005], b[100005];
	ll su=0; ll so=0;
	for (ll i = 0; i < n; ++i)
	{
		cin>>a[i]>>b[i];
		su = su+a[i];
		so = so + b[i];
	}
	ll diff = su-m;
	if(su<=m) cout<<0;
	else if(so>m) cout<<"-1";
	else
	{
		ll ans[100005];
		for (ll i = 0; i < n; ++i)
		{
			ans[i] = a[i]-b[i];
		}
		sort(ans,ans+n);
		ll val = 0; ll cnt =0;
		for (ll i = n-1; i >=0; --i)
		{
			val = val + ans[i];
			++cnt;
			if(val >= diff)
			{
				break;
			}
		}
        cout<<cnt;
	}
	return 0;
}


#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define ll long long
#define vll vector<long long>
#define vc vector<char>
#define vi vector<int>
#define pb push_back
#define LOOP(n) for(int i=0; i<n; ++i)

using namespace std;

bool checkzero(string s1, string s2)
{
	for (int i = 0; i < s1.size(); ++i)
	{
		bool flag = true;
		for(int j=0; j<s2.size(); ++j)
		{
			if(s1[i] == s2[j])
			{
				flag = false;
				s2[j] = 'A';
				break;
			}
		}
		if(flag) return true;
	}
	return false;
}

int main()
{
	ll n; string s; string t;
	cin>>n>>s>>t;
	vll ans;
	if(checkzero(s,t)) cout<<"-1";
	else
	{
		for(int i=0; i<n; ++i)
		{
			if(s[i]==t[i]) continue;
			ll pos = -1;
			for(int j=i+1; j<n; ++j)
			{
				if(s[j] == t[i])
				{
					pos = j;
					break;
				}
			}
			for(int j=i; j<=pos; ++j)
			{
				ans.pb(j+1);
				swap(s[i],s[j]);
			}
		}
		cout<<ans.size()<<endl;
		for (int i = 0; i < ans.size(); ++i)
		{
			cout<<ans[i]<<" ";
		}
	}
	return 0;
}


#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define ll long long
#define vll vector<long long>
#define vc vector<char>
#define vi vector<int>
#define pb push_back
#define LOOP(n) for(int i=0; i<n; ++i)

using namespace std;

bool checkzero(string s1, string s2)
{
	for (int i = 0; i < s1.size(); ++i)
	{
		bool flag = true;
		for(int j=0; j<s2.size(); ++j)
		{
			if(s1[i] == s2[j])
			{
				flag = false;
				s2[j] = 'A';
				break;
			}
		}
		if(flag) return true;
	}
	return false;
}

int main()
{
	ll n; string s; string t;
	cin>>n>>s>>t;
	vll ans;
	if(checkzero(s,t)) cout<<"-1";
	else
	{
		for(int i=0; i<n; ++i)
		{
			if(s[i]==t[i]) continue;
			ll pos = -1;
			for(int j=i+1; j<n; ++j)
			{
				if(s[j] == t[i])
				{
					pos = j;
					break;
				}
			}
			for(int j=i; j<=pos; ++j)
			{
				ans.pb(j+1);
				swap(s[i],s[j]);
			}
		}
		cout<<s<<endl;
		cout<<ans.size()<<endl;
		for (int i = 0; i < ans.size(); ++i)
		{
			cout<<ans[i]<<" ";
		}
	}
	return 0;
}


#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define ll long long
#define vll vector<long long>
#define vc vector<char>
#define vi vector<int>
#define pb push_back
#define LOOP(n) for(int i=0; i<n; ++i)

using namespace std;

bool checkzero(string s1, string s2)
{
	ll l1 = s1.length();
	for(int i=0; i<l1; ++i)
	{
		bool flag = false;
		for (int j = 0; j < l1; ++j)
		{
			if(s2[j] == s1[i])
			{
				flag = true;
				s2[j] = 'A';
				break;
			}
		}
		if(flag == false)
		{
			return false;
			break;
		}
	}
	return true;
}
vll final;
void swapping(string& str, ll p1, ll p2)
{
	for (int i = p1; i < p2; ++i)
	{
		final.pb(i+1);
		swap(str[i], str[i+1]);
	}
}

void process(string s1, string s2)
{
	ll len = s1.length();
	for (int i = 0; i < len; ++i)
	{
		if(s1[i] != s2[i])
		{
			for(int j=0; j<len; ++j)
			{
				if(i!=j && s2[j]==s1[i])
				{
					s2[j] = 'A';
					if(i>j) swapping(s1,j,i);
					else swapping(s1,i,j);
				}
			}
		}
	}
}

int main()
{
	ll n; cin>>n;
	string s1; string s2;
	cin>>s1>>s2;
	if(checkzero(s1,s2)==false)
	{
		cout<<"-1";
	}
	else
	{
		process(s1,s2);
		cout<<final.size()<<endl;
		for (int i = 0; i < final.size(); ++i)
		{
			cout<<final[i]<<' ';
		}
	}
	return 0;
}


#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define ll long long
#define vll vector<long long>
#define vc vector<char>
#define vi vector<int>
#define pb push_back
#define LOOP(n) for(int i=0; i<n; ++i)

using namespace std;

bool checkzero(string s1, string s2)
{
	for (int i = 0; i < s1.size(); ++i)
	{
		bool flag = true;
		for(int j=0; j<s2.size(); ++j)
		{
			if(s1[i] == s2[j])
			{
				flag = false;
				s2[j] = 'A';
				break;
			}
		}
		if(flag) return true;
	}
	return false;
}

int main()
{
	ll n; string s; string t;
	cin>>n>>s>>t;
	vll ans;
	if(checkzero(s,t)) cout<<"-1";
	else
	{
		for(int i=0; i<n; ++i)
		{
			if(s[i]==t[i]) continue;
			ll pos = -1;
			for(ll j=i+1; j<n; ++j)
			{
				if(s[j] == t[i])
				{
					pos = j;
					break;
				}
			}
			for(ll j=pos-1; j>=i; --j)
			{
				ans.pb(j+1);
				swap(s[j],s[j+1]);
			}
		}
		cout<<s<<endl;
		cout<<ans.size()<<endl;
		for (ll i = 0; i < ans.size(); ++i)
		{
			cout<<ans[i]<<" ";
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int>ans;
    string s1 = s;
    sort(s1.begin(), s1.end());
    string t1 = t;
    sort(t1.begin(), t1.end());
    if(t1 != s1)
    {
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<n-1; i++)
    {
        int idx=i;
        while(s[idx]!=t[idx] && idx+1<n)
        {
            ans.push_back(idx+1);
            swap(s[idx],s[idx+1]);
            idx++;
        }
    }
    //cout<<s<<endl;
    cout<<ans.size()<<'\n';
    for(int z: ans)cout<<z<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int>ans;
    string s1 = s;
    sort(s1.begin(), s1.end());
    string t1 = t;
    sort(t1.begin(), t1.end());
    if(t1 != s1)
    {
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<n-1; i++){
        int idx=i;
        while(s[idx]!=t[i] && idx+1<n){
            ans.push_back(idx+1);
            swap(s[idx],s[idx+1]);
            idx++;
        }
    }
    //cout<<s<<endl;
    cout<<ans.size()<<'\n';
    for(int z: ans)cout<<z<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int>ans;
    string s1 = s;
    sort(s1.begin(), s1.end());
    string t1 = t;
    sort(t1.begin(), t1.end());
    if(t1 != s1)
    {
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<n-1; i++){
        int idx=i;
        while(s[idx]!=t[i] && idx+1<n){
            ans.push_back(idx+1);
            swap(s[idx],s[idx+1]);
            idx++;
        }
    }
    cout<<s<<endl;
    cout<<ans.size()<<'\n';
    for(int z: ans)cout<<z<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int>ans;
    string s1 = s;
    sort(s1.begin(), s1.end());
    string t1 = t;
    sort(t1.begin(), t1.end());
    if(t1 != s1)
    {
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<n-1; i++)
    {
        int idx=i;
        while(s[idx]!=t[i] && idx+1<n)
        {
            idx++;
        }
        for(int j = idx;j>i; j--){
            swap(s[j],s[j-1]);
            ans.push_back(j-1);
        }
    }
//    cout<<s<<endl;
    cout<<ans.size()<<'\n';
    for(int z: ans)cout<<z<<" ";
    return 0;
}
/*
3
bac
cab
*/


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int>ans;
    string s1 = s;
    sort(s1.begin(), s1.end());
    string t1 = t;
    sort(t1.begin(), t1.end());
    if(t1 != s1)
    {
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<n-1; i++)
    {
        int idx=i;
        while(s[idx]!=t[idx])
        {
            cout<<i<<" "<<s[idx]<<" "<<t[i]<<endl;
            ans.push_back(idx+1);
            swap(s[idx],s[idx+1]);
            idx++;
        }
    }
    //cout<<s<<endl;
    cout<<ans.size()<<'\n';
    for(int z: ans)cout<<z<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int>ans;
    string s1 = s;
    sort(s1.begin(), s1.end());
    string t1 = t;
    sort(t1.begin(), t1.end());
    if(t1 != s1)
    {
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<n-1; i++)
    {
        int idx=i;
        while(s[idx]!=t[i] && idx+1<n)
        {
            idx++;
        }
        for(int j = idx;j>i; j--){
            swap(s[j],s[j-1]);
            ans.push_back(j);
        }
    }
//    cout<<s<<endl;
    cout<<ans.size()<<'\n';
    for(int z: ans)cout<<z<<" ";
    return 0;
}
/*
3
bac
cab
*/


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int>ans;
    string s1 = s;
    sort(s1.begin(), s1.end());
    string t1 = t;
    sort(t1.begin(), t1.end());
    if(t1 != s1)
    {
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<n-1; i++)
    {
        int idx=i;
        int u = i;
        while(s[idx]!=t[u] && idx+1<n)
        {
            ans.push_back(idx+1);
            swap(s[idx],s[idx+1]);
            idx++;
            i = -1;
        }
    }
    //cout<<s<<endl;
    cout<<ans.size()<<'\n';
    for(int z: ans)cout<<z<<" ";
    return 0;
}
/*
3
bac
cab
*/


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int>ans;
    string s1 = s;
    sort(s1.begin(), s1.end());
    string t1 = t;
    sort(t1.begin(), t1.end());
    if(t1 != s1)
    {
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<n-1; i++)
    {
        int idx=i;
        while(s[idx]!=t[idx])
        {
            ans.push_back(idx+1);
            swap(s[idx],s[idx+1]);
            idx++;
        }
    }
    //cout<<s<<endl;
    cout<<ans.size()<<'\n';
    for(int z: ans)cout<<z<<" ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	int a[26];
	int b[26];
	for(int e=0;e<26;e++){
	    a[e]=0;
	    b[e]=0;
	}
	for(int r=0;r<n;r++){
	    a[(int)s[r]-'a']++;
	    b[(int)t[r]-'a']++;
	}
	int g=1;
	for(int d=0;d<26;d++)if(a[d]!=b[d]){g=0;break;}
	if(g==0)cout<<"-1";
	else{
	vector<int> v;
	int cnt=0;
	int o=0;
	int df=1;
	while(df==1){
	    if(s[o]!=t[o]){
	            for(int m=n-1;m>o;m--){
	                if(t[m]==s[o]){
	                    for(int l=o;l<m;l++){
	                    cnt++;
	                    v.push_back(l+1);
	                    char temp;
	                    temp=s[l];
	                    s[l]=s[l+1];
	                    s[l+1]=temp;
	                    }
	                    break;
	                }
	            }
	        }
	    int d=1;
	    for(int g=0;g<n;g++){
	        if(s[g]!=t[g]){d=0;break;}
	    }
	    if(d==1)df=0;
	    o++;
	    if(o==n)o=0;
	}
    cout<<cnt<<"\n";
	for(int s=0;s<v.size();s++)cout<<v[s]<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	int a[26];
	int b[26];
	for(int e=0;e<26;e++){
	    a[e]=0;
	    b[e]=0;
	}
	for(int r=0;r<n;r++){
	    a[(int)s[r]-'a']++;
	    b[(int)t[r]-'a']++;
	}
	int g=1;
	for(int d=0;d<26;d++)if(a[d]!=b[d]){g=0;break;}
	if(g==0)cout<<"-1";
	else{
	vector<int> v;
	int cnt=0;
	int o=0;
	int df=1;
	while(df==1){
	    if(s[o]!=t[o]){
	            for(int m=o+1;m<n;m++){
	                v.push_back(m);
	                cnt++;
	                if(t[m]==s[o]){
	                    for(int l=o;l<m;l++){
	                    char temp;
	                    temp=s[l];
	                    s[l]=s[l+1];
	                    s[l+1]=temp;
	                    }
	                    break;
	                }
	            }
	    }
	    int d=1;
	    for(int g=0;g<n;g++){
	        if(s[g]!=t[g]){d=0;break;}
	    }
	    if(d==1)df=0;
	    o++;
	    if(o==n)o=0;
	}
	cout<<cnt<<"\n";
	for(int s=0;s<v.size();s++)cout<<v[s]<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	int a[26];
	int b[26];
	for(int e=0;e<26;e++){
	    a[e]=0;
	    b[e]=0;
	}
	for(int r=0;r<n;r++){
	    a[(int)s[r]-'a']++;
	    b[(int)t[r]-'a']++;
	}
	int g=1;
	for(int d=0;d<26;d++)if(a[d]!=b[d]){g=0;break;}
	if(g==0)cout<<"-1";
	else{
	vector<int> v;
	int cnt=0;
	int o=0;
	int df=1;
	while(df==1){
	    if(s[o]!=t[o]){
	            for(int m=o+1;m<n;m++){
	                v.push_back(m);
	                cnt++;
	                if(t[m]==s[o]){
	                    for(int l=o;l<m;l++){
	                    char temp;
	                    temp=s[l];
	                    s[l]=s[l+1];
	                    s[l+1]=temp;
	                    }
	                    break;
	                }
	            }
	        }
	    int d=1;
	    for(int g=0;g<n;g++){
	        if(s[g]!=t[g]){d=0;break;}
	    }
	    if(d==1)df=0;
	    o++;
	    if(o==n)o=0;
	}
		 cout<<cnt<<"\n";
	    for(int s=0;s<v.size();s++)cout<<v[s]<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	int a[26]={0};
	int b[26]={0};
	for(int r=0;r<n;r++){
	    a[(int)s[r]-'a']++;
	    b[(int)t[r]-'a']++;
	}
	int g=1;
	for(int d=0;d<26;d++)if(a[d]!=b[d]){g=0;break;}
	if(g==0)cout<<"-1";
	else{
	vector<int> v;
	int cnt=0;
	int o=0;
	int df=1;
	while(df==1){
	    if(s[o]!=t[o]){
	        int fl=0;
	        for(int k=o-1;k>=0;k--){
	            if(t[k]==s[o]){
	                fl=1;
	                cnt+=k-o;
	                for(int l=o-1;l>=k;l++)v.push_back(l+1);
	                for(int l=o-1;l>=k;l--){
	                    char temp;
	                    temp=s[l];
	                    s[l]=s[l+1];
	                    s[l+1]=temp;
	                }
	                break;
	            }
	        }
	        if(fl==0){
	            for(int m=o+1;m<n;m++){
	                v.push_back(m);
	                cnt++;
	                if(t[m]==s[o]){
	                    for(int l=o;l<m;l++){
	                    char temp;
	                    temp=s[l];
	                    s[l]=s[l+1];
	                    s[l+1]=temp;
	                    }
	                    break;
	                }
	            }
	        }
	    }
	    int d=1;
	    for(int g=0;g<n;g++){
	        if(s[g]!=t[g]){d=0;break;}
	    }
	    if(d==1)df=0;
	    o++;
	    if(o==n)o=0;
	}
	cout<<cnt<<"\n";
	for(int s=0;s<v.size();s++)cout<<v[s]<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	int a[26];
	int b[26];
	for(int e=0;e<26;e++){
	    a[e]=0;
	    b[e]=0;
	}
	for(int r=0;r<n;r++){
	    a[(int)s[r]-'a']++;
	    b[(int)t[r]-'a']++;
	}
	int g=1;
	for(int d=0;d<26;d++)if(a[d]!=b[d]){g=0;break;}
	if(g==0)cout<<"-1";
	else{
	vector<int> v;
	int cnt=0;
	int o=0;
	int df=1;
	while(df==1){
	    if(s[o]!=t[o]){
	            for(int m=o+1;m<n;m++){
	                if(s[m]==t[o]){
	                    for(int l=m-1;l>=o;l--){
	                    cnt++;
	                    v.push_back(l+1);
	                    char temp;
	                    temp=s[l];
	                    s[l]=s[l+1];
	                    s[l+1]=temp;
	                    }
	                    break;
	                }
	            }
	        }
	    int d=1;
	    for(int g=0;g<n;g++){
	        if(s[g]!=t[g]){d=0;break;}
	    }
	    if(d==1)df=0;
	    o++;
	    if(o==n)o=0;
	}
    cout<<cnt<<"\n";
	for(int s=0;s<v.size();s++)cout<<v[s]<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	int a[26];
	int b[26];
	for(int e=0;e<26;e++){
	    a[e]=0;
	    b[e]=0;
	}
	for(int r=0;r<n;r++){
	    a[(int)s[r]-'a']++;
	    b[(int)t[r]-'a']++;
	}
	int g=1;
	for(int d=0;d<26;d++)if(a[d]!=b[d]){g=0;break;}
	if(g==0)cout<<"-1";
	else{
	vector<int> v;
	int cnt=0;
	int o=0;
	int df=1;
	while(df==1){
	    if(s[o]!=t[o]){
	        int fl=0;
	        for(int k=o-1;k>=0;k--){
	            if(t[k]==s[o]){
	                fl=1;
	                cnt+=k-o;
	                for(int l=o-1;l>=k;l--)v.push_back(l+1);
	                for(int l=o-1;l>=k;l--){
	                    char temp;
	                    temp=s[l];
	                    s[l]=s[l+1];
	                    s[l+1]=temp;
	                }
	                break;
	            }
	        }
	        if(fl==0){
	            for(int m=o+1;m<n;m++){
	                v.push_back(m);
	                cnt++;
	                if(t[m]==s[o]){
	                    for(int l=o;l<m;l++){
	                    char temp;
	                    temp=s[l];
	                    s[l]=s[l+1];
	                    s[l+1]=temp;
	                    }
	                    break;
	                }
	            }
	        }
	    }
	    int d=1;
	    for(int g=0;g<n;g++){
	        if(s[g]!=t[g]){d=0;break;}
	    }
	    if(d==1)df=0;
	    o++;
	    if(o==n)o=0;
	}
	cout<<cnt<<"\n";
	for(int s=0;s<v.size();s++)cout<<v[s]<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define sf              scanf
#define pf              printf
#define cases           ll T;cin>>T;for(int TC=1;TC<=T;TC++)
#define pi              3.1415926535897932384626433832795l
#define ignore          cin.ignore();
#define mem(n,i)        memset(n,i,sizeof n);
#define precision(n)    cout<<fixed<<setprecision(n);
#define bug()           cerr<<"**********\n";
#define pb              push_back
#define MOD             1000000007
#define cout(x)         cout<<"Case "<<TC<<": "<<x<<endl
#define EPS             1e-9
#define mp              make_pair
int values[1000];
int main()
{
    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;
    for(int i=0;i<n;i++)
        values[t[i]]=i+1;
    vector <int> v;
    int count=0;
    for(int i=0;i<n-1;i++)
    {
        for (int j = 0; j < n-i-1; j++)
        {
            if(values[s[j]]==0)
            {
                cout<<"-1"<<endl;
                return 0;
            }

            else if (values[s[j]] >values[s[j+1]]){
                count++;
                swap(s[j],s[j+1]);
                v.push_back(j+1);
            }
        }
    }
    cout<<count<<endl;
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";

}


#include <bits/stdc++.h>
using namespace std;
#define sf              scanf
#define pf              printf
#define cases           ll T;cin>>T;for(int TC=1;TC<=T;TC++)
#define pi              3.1415926535897932384626433832795l
#define ignore          cin.ignore();
#define mem(n,i)        memset(n,i,sizeof n);
#define precision(n)    cout<<fixed<<setprecision(n);
#define bug()           cerr<<"**********\n";
#define pb              push_back
#define MOD             1000000007
#define cout(x)         cout<<"Case "<<TC<<": "<<x<<endl
#define EPS             1e-9
#define mp              make_pair
int values[100000];
int my1[100000];
int my2[100000];
int main()
{
    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;
    char x='a';
    for(int i=97,j=1;i<=122;i++,j+=50){
        my1[x]=j;
        my2[x]=j;
        x++;
    }
    vector <int> s1,t1;
    for(int i=0;i<n;i++)
    {
        s1.pb(my1[s[i]]);
        my1[s[i]]++;
    }
    for(int i=0;i<n;i++)
    {
        t1.pb(my2[t[i]]);
        my2[t[i]]++;
    }
    for(int i=0;i<n;i++)
        values[t1[i]]=i+1;

    vector <int> v;
    for(int i=0;i<n-1;i++)
    {
        for (int j = 0; j < n-i-1; j++)
        {
            if(values[s1[j]]==0)
            {
                cout<<"-1"<<endl;
                return 0;
            }

            else if (values[s1[j]] >values[s1[j+1]]){
                swap(s1[j],s1[j+1]);
                v.push_back(j+1);
            }
        }
    }
    cout<<v.size()<<endl;
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
#define sf              scanf
#define pf              printf
#define cases           ll T;cin>>T;for(int TC=1;TC<=T;TC++)
#define pi              3.1415926535897932384626433832795l
#define ignore          cin.ignore();
#define mem(n,i)        memset(n,i,sizeof n);
#define precision(n)    cout<<fixed<<setprecision(n);
#define bug()           cerr<<"**********\n";
#define pb              push_back
#define MOD             1000000007
#define cout(x)         cout<<"Case "<<TC<<": "<<x<<endl
#define EPS             1e-9
#define mp              make_pair
int values[100000];
int my1[100000];
int my2[100000];
int main()
{
    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;
    string w,r;
    w=s;
    r=t;
    sort(w.begin(),w.end());
     sort(r.begin(),r.end());
     if(w!=r)
     {
         cout<<"-1"<<endl;
         return 0;
     }

    char x='a';
    for(int i=97,j=1;i<=122;i++,j+=50){
        my1[x]=j;
        my2[x]=j;
        x++;
    }
    vector <int> s1,t1;
    for(int i=0;i<n;i++)
    {
        s1.pb(my1[s[i]]);
        my1[s[i]]++;
    }
    for(int i=0;i<n;i++)
    {
        t1.pb(my2[t[i]]);
        my2[t[i]]++;
    }
    //for(int i=0;i<n;i++)
      // values[t1[i]]=i+1;
    //for(int i=0;i<n;i++)
      // cout<<s1[i]<<" ";
    //cout<<endl;
    for(int i=0;i<n;i++)
       cout<<t1[i]<<" ";
    cout<<endl;

    vector <int> v;

    for(int i=0;i<n-1;i++)
    {
        for (int j = 0; j < n-i-1; j++)
        {
            if(values[s1[j]]==0)
            {
                cout<<"-1"<<endl;
                return 0;
            }

            else if (values[s1[j]] >values[s1[j+1]]){
                swap(s1[j],s1[j+1]);
                v.push_back(j+1);
            }
        }
    }

    cout<<v.size()<<endl;
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";

}


#include <bits/stdc++.h>
using namespace std;
#define sf              scanf
#define pf              printf
#define cases           ll T;cin>>T;for(int TC=1;TC<=T;TC++)
#define pi              3.1415926535897932384626433832795l
#define ignore          cin.ignore();
#define mem(n,i)        memset(n,i,sizeof n);
#define precision(n)    cout<<fixed<<setprecision(n);
#define bug()           cerr<<"**********\n";
#define pb              push_back
#define MOD             1000000007
#define cout(x)         cout<<"Case "<<TC<<": "<<x<<endl
#define EPS             1e-9
#define mp              make_pair
int values[100000];
int my1[100000];
int my2[100000];
int main()
{
    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;

    string  temp1=s,temp2=t;
    sort(temp1.begin(),temp1.end());
    sort(temp2.begin(),temp2.end());
    if(temp1!=temp2)
    {
        cout<<"-1"<<endl;
        return 0;
    }

    char x='a';
    for(int i=97,j=1;i<=122;i++,j+=50){
        my1[x]=j;
        my2[x]=j;
        x++;
    }
    vector <int> s1,t1;

    for(int i=0;i<n;i++)
    {
        s1.pb(my1[s[i]]);
        my1[s[i]]++;
    }
    for(int i=0;i<n;i++)
    {
        t1.pb(my2[t[i]]);
        my2[t[i]]++;
    }
    for(int i=0;i<n;i++)
        values[t1[i]]=i+1;

    vector <int> v;

    for(int i=0;i<n-1;i++)
    {
        for (int j = 0; j < n-i-1; j++)
        {
             if (values[s1[j]] >values[s1[j+1]]){
                swap(s1[j],s1[j+1]);
                v.push_back(j+1);
            }
        }
    }
    cout<<v.size()<<endl;
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
#define sf              scanf
#define pf              printf
#define cases           ll T;cin>>T;for(int TC=1;TC<=T;TC++)
#define pi              3.1415926535897932384626433832795l
#define ignore          cin.ignore();
#define mem(n,i)        memset(n,i,sizeof n);
#define precision(n)    cout<<fixed<<setprecision(n);
#define bug()           cerr<<"**********\n";
#define pb              push_back
#define MOD             1000000007
#define cout(x)         cout<<"Case "<<TC<<": "<<x<<endl
#define EPS             1e-9
#define mp              make_pair
int values[100000];
int my1[100000];
int my2[100000];
int main()
{
    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;
    string w,r;
    char x='a';
    for(int i=97,j=1;i<=122;i++,j+=50){
        my1[x]=j;
        my2[x]=j;
        x++;
    }
    vector <int> s1,t1;
    for(int i=0;i<n;i++)
    {
        s1.pb(my1[s[i]]);
        my1[s[i]]++;
    }
    for(int i=0;i<n;i++)
    {
        t1.pb(my2[t[i]]);
        my2[t[i]]++;
    }
    for(int i=0;i<n;i++)
        values[t1[i]]=i+1;
    //for(int i=0;i<n;i++)
      // cout<<s1[i]<<" ";
    //cout<<endl;
    //for(int i=0;i<n;i++)
      // cout<<t1[i]<<" ";
    //cout<<endl;

    vector <int> v;

    for(int i=0;i<n;i++)
    {
        for (int j = 0; j <= n-i-1; j++)
        {

            if(values[s1[j]]==0)
            {
                cout<<"-1"<<endl;
                return 0;
            }

            else if (values[s1[j]] >values[s1[j+1]]){
                swap(s1[j],s1[j+1]);
                v.push_back(j+1);
            }
        }
    }

    cout<<v.size()<<endl;
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";

}


#include <bits/stdc++.h>
using namespace std;
#define sf              scanf
#define pf              printf
#define cases           ll T;cin>>T;for(int TC=1;TC<=T;TC++)
#define pi              3.1415926535897932384626433832795l
#define ignore          cin.ignore();
#define mem(n,i)        memset(n,i,sizeof n);
#define precision(n)    cout<<fixed<<setprecision(n);
#define bug()           cerr<<"**********\n";
#define pb              push_back
#define MOD             1000000007
#define cout(x)         cout<<"Case "<<TC<<": "<<x<<endl
#define EPS             1e-9
#define mp              make_pair
int values[100000];
int my1[100000];
int my2[100000];
int main()
{
    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;
    string w,r;
    w=s;
    r=t;
    sort(w.begin(),w.end());
     sort(r.begin(),r.end());
     if(w!=r)
     {
         cout<<"-1"<<endl;
         return 0;
     }

    char x='a';
    for(int i=97,j=1;i<=122;i++,j+=50){
        my1[x]=j;
        my2[x]=j;
        x++;
    }
    vector <int> s1,t1;
    for(int i=0;i<n;i++)
    {
        s1.pb(my1[s[i]]);
        my1[s[i]]++;
    }
    for(int i=0;i<n;i++)
    {
        t1.pb(my2[t[i]]);
        my2[t[i]]++;
    }
    for(int i=0;i<n;i++)
        values[t1[i]]=i+1;
    //for(int i=0;i<n;i++)
      // cout<<s1[i]<<" ";
    //cout<<endl;
    //for(int i=0;i<n;i++)
      // cout<<t1[i]<<" ";
    //cout<<endl;

    vector <int> v;

    for(int i=0;i<n-1;i++)
    {
        for (int j = 0; j < n-i-1; j++)
        {
            if(values[s1[j]]==0)
            {
                cout<<"-1"<<endl;
                return 0;
            }

            else if (values[s1[j]] >values[s1[j+1]]){
                swap(s1[j],s1[j+1]);
                v.push_back(j+1);
            }
        }
    }

    cout<<v.size()<<endl;
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;

int find(char q,string g)
{
	int u,i;

	u = g.length();

	for(i=0;i<u;i++)
	{
		if(g[i] == q)
		{
			return i;
		}
	}

	return -1;
}

bool check(char a,char b)
{
	if(a==b)
	return true;
	else
	return false;
}

int main()
{
	string s1,s2;
	int n,count=0,flag =0,boss = 0,poi = 0,j,i;

	int var;

	vector<int> v1;

	cin>>n;
	cin>>s1>>s2;

	while(flag<=n)
	{
		if(!(check(s1[poi],s2[poi])))
		{
		var = find(s2[poi],s1);

				if(var == -1)
				{
					boss=1;
					break;
				}

				swap(s1[var],s1[poi]);

				if(s1==s2)
				break;

				for(j = var;j>=poi;j--)
				{
					v1.push_back(j+1);
				}
				poi++;
				flag++;
		}
		else
		{
			poi++;
		}
		count++;
		if(count>10000)
		{
			boss = 1;
			break;
		}
	}

	if(boss == 1)
	{
		cout<<-1;
	}
	else
	{

		cout<<v1.size()<<endl;

		for(i=0;i<v1.size();i++)
		{
			cout<<v1[i]<<" ";
		}
	}

}


#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
bool compare(string s1 , string s2){
	if(s1==s2)
	return true;
	else
	return false;
}
bool check(char a , char b){
	if(a==b)
	return true;
	else
	return false;
}
int main(){
	int n;
	string s1 , s2;
	cin>>n;
	cin>>s1>>s2;
	//cout<<s1<<endl;
	int flag =0,flag1=1;
	int t=0;
	vector<int> v;
	while(flag<=n){
		for(int i=flag;i<n-1;i++){
			if(check(s1[i],s2[i])){
				flag++;
			}
			else
			{
				swap(s1[i],s1[i+1]);
				v.push_back(i+1);
				if(check(s1[i],s2[i])){
					flag++;
				}
			}
		}
		cout<<s1<<endl;
		if(compare(s1,s2))
		break;
		t++;
		if(t>=10000){
		flag1=0;
		break;
	}
	cout<<"t "<<t<<endl;
	}
	if(flag1==0)
	cout<<-1;
	else{
		cout<<"else kulla irukkan "<<endl;
		cout<<v.size()<<endl;
		for(int i=0;i<v.size();i++)
		cout<<v[i]<<" ";
	}
	cout<<s1;

}


#include<bits/stdc++.h>
using namespace std;

int find(char q,string g)
{
	int u,i;

	u = g.length();

	for(i=0;i<u;i++)
	{
		if(g[i] == q)
		{
			return i;
		}
	}

	return -1;
}

bool check(char a,char b)
{
	if(a==b)
	return true;
	else
	return false;
}

int main()
{
	string s1,s2,m;
	int n,count=0,flag =0,boss = 0,poi = 0,j,i;

	int var;												//transform s1 -> s2

	vector<int> v1;

	cin>>n;
	cin>>s1>>s2;

	m = s1;

	while(flag<=n)
	{
		if(!(check(s1[poi],s2[poi])))
		{

		var = find(s2[poi],m);      		//s2 for comparison - s1 to find that character

				if(var == -1 && poi<n)
				{

					boss=1;
					break;
				}

				swap(s1[var],s1[poi]);

				swap(m[var],m[poi]);

				m[poi] = '0';

				for(j = var;j>=poi;j--)
				{
					v1.push_back(j+1);
				}
				poi++;
				flag++;

				if(s1==s2)
				break;
		}
		else
		{
			m[poi] = '0';
			poi++;

		}
		count++;
		if(count>10000)
		{
			boss = 1;
			break;
		}

	}

	if(boss == 1)
	{
		cout<<-1;
	}
	else
	{

		cout<<v1.size()<<endl;

		for(i=0;i<v1.size();i++)
		{
			cout<<v1[i]<<" ";
		}
	}

}


#include<bits/stdc++.h>
using namespace std;

int find(char q,string g)
{
	int u,i;

	u = g.length();

	for(i=0;i<u;i++)
	{
		if(g[i] == q)
		{
			return i;
		}
	}

	return -1;
}

bool check(char a,char b)
{
	if(a==b)
	return true;
	else
	return false;
}

int main()
{
	string s1,s2,m;
	int n,count=0,flag =0,boss = 0,poi = 0,j,i;

	int var;												//transform s1 -> s2

	vector<int> v1;

	cin>>n;
	cin>>s1>>s2;

	m = s1;

	while(flag<=n)
	{
		if(!(check(s1[poi],s2[poi])))
		{

		var = find(s2[poi],m);      		//s2 for comparison - s1 to find that character

				if(var == -1 && poi<n)
				{
					boss=1;
					break;
				}

				swap(s1[var],s1[poi]);

				swap(m[var],m[poi]);

				m[poi] = '0';

				for(j = var;j>poi;j--)
				{
					v1.push_back(j);
				}
				poi++;
				flag++;

				if(s1==s2)
				break;
		}
		else
		{
			m[poi] = '0';
			poi++;

		}
		count++;
		if(count>10000)
		{
			boss = 1;
			break;
		}

	}

	if(boss == 1)
	{
		cout<<-1;
	}
	else
	{

		cout<<v1.size()<<endl;

		for(i=0;i<v1.size();i++)
		{
			cout<<v1[i]<<" ";
		}
	}

}


#include<bits/stdc++.h>
using namespace std;

int find(char q,string g)
{
	int u,i;

	u = g.length();

	for(i=0;i<u;i++)
	{
		if(g[i] == q)
		{
			return i;
		}
	}

	return -1;
}

bool check(char a,char b)
{
	if(a==b)
	return true;
	else
	return false;
}

int main()
{
	string s1,s2,m;
	int n,count=0,flag =0,boss = 0,poi = 0,j,i;

	int var;												//transform s1 -> s2

	vector<int> v1;

	cin>>n;
	cin>>s1>>s2;

	m = s1;

	while(flag<=n)
	{
		if(!(check(s1[poi],s2[poi])))
		{

		var = find(s2[poi],m);      		//s2 for comparison - s1 to find that character

				if(var == -1 && poi<n)
				{

					boss=1;
					break;
				}

				for(j = var;j>poi;j--)
				{
					swap(s1[j],s1[j-1]);
					swap(m[j],m[j-1]);
					v1.push_back(j);
				}
				m[poi] = '0';
				poi++;
				flag++;

				if(s1==s2)
				break;
		}
		else
		{
			m[poi] = '0';
			poi++;

		}
		count++;
		if(count>10000)
		{
			boss = 1;
			break;
		}

	}

	if(boss == 1)
	{
		cout<<-1;
	}
	else
	{
		cout<<v1.size()<<endl;

		for(i=0;i<v1.size();i++)
		{
			cout<<v1[i]<<" ";
		}
	}

}


#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
bool compare(string s1 , string s2){
	if(s1==s2)
	return true;
	else
	return false;
}
bool check(char a , char b){
	if(a==b)
	return true;
	else
	return false;
}
int main()
{
	int n;
	string s1 , s2;
	cin>>n;
	cin>>s1>>s2;

	int flag =0,flag1=1;
	int t=0;
	vector<int> v;
	while(flag<=n)
	{
		for(int i=flag;i<n-1;i++)
		{
			if(check(s1[i],s2[i]))
			{
				flag++;
			}
			else
			{
				swap(s1[i],s1[i+1]);
				v.push_back(i+1);
				if(check(s1[i],s2[i]))
				{
					flag++;
				}
			}
		}

		if(compare(s1,s2))
		break;
		t++;
		if(t>=10000)
		{
		flag1=0;
		break;
		}

	}
	if(flag1==0)
	cout<<-1;
	else
	{

		cout<<v.size()<<endl;
		for(int i=0;i<v.size();i++)
		cout<<v[i]<<" ";
	}

}


#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
bool compare(string s1 , string s2){
	if(s1==s2)
	return true;
	else
	return false;
}
bool check(char a , char b){
	if(a==b)
	return true;
	else
	return false;
}
int main(){
	int n;
	string s1 , s2;
	cin>>n;
	cin>>s1>>s2;
	vector<int>vec;
	int count =0;
	for(int i=0;i<n;i++){
		if(check(s1[i],s2[i]))
		continue;
		else{
		swap(s1[i],s1[i+1]);
		vec.push_back(i+1);
		count++;
		}
		//cout<<s1<<endl;
	}
	for(int i=n-1;i>=0;i--){
		if(check(s1[i],s2[i]))
		continue;
		else{
		swap(s1[i],s1[i-1]);
		vec.push_back(i+1);
		count++;
		}
	}
	if(count>=n)
	cout<<-1;
	else{
	cout<<count<<endl;
	for(int i=0;i<vec.size();i++)
	cout<<vec[i]<<" ";
	}
}


#include <bits/stdc++.h>

using namespace std;
int main() {
	int n,ans[100000],cnt=0;
	string s, t;
	cin>>n>>s>>t;
	for(int i=0;i<n;++i){
		if(s[i]==t[i]) continue;
		int pos=-1;
		for(int j=i+1;j<n;++j){
			if(s[j]==t[i]){
			    pos=j;
			    break;
			}
		}
		if(pos==-1){
			cout<<-1<<endl;
			return 0;
		}
		for(int j=pos-1;j>=i;--j){
			swap(s[j],s[j+1]);
			ans[cnt++]=j;
		}
	}
	assert(s == t);
	cout<<cnt<<endl;
	for(int i=0;i<cnt;i++) cout<<ans[i]+1<<" ";
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,i,j,a,b,k,save[100000],cnt=0;
	char s[50],t[50];
	bool ok=false;
	cin>>n;
	cin>>s>>t;
	a=n-1;
	for(i=a;i>=0;i--){
		if(s[i]!=t[i]){
			for(j=i-1;j>=0;j--){
				if(s[j]==t[i]){
					ok=true;
					b=j+1;
					for(k=b;k<=i;k++){
						save[cnt++]=k;
						swap(s[k],s[k-1]);
					}
					break;
				}
			}
			if(!ok){
				cout<<"-1";
				return 0;
			}
			ok=false;
		}
	}
	if(strcmp(s,t)!=0){
		cout<<"-1";
		return 0;
	}
	cout<<s<<endl<<cnt<<endl;
	for(i=0;i<cnt;i++) cout<<save[i]<<" ";
}


#include <bits/stdc++.h>

using namespace std;
int main() {
	int n,ans[100000],cnt=0;
	string s,t;
	cin>>n>>s>>t;
	for(int i=0;i<n;++i){
		if(s[i]==t[i]) continue;
		int pos=-1;
		for(int j=i+1;j<n;++j){
			if(s[j]==t[i]){
			    pos=j;
			    break;
			}
		}
		if(pos==-1){
			cout<<-1<<endl;
			return 0;
		}
		for(int j=pos-1;j>=i;--j){
			swap(s[j],s[j+1]);
			ans[cnt++]=j;
		}
	}
	cout<<cnt<<endl;
	for(int i=0;i<cnt;i++) cout<<ans[i]+1<<" ";
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,i,j,a,b,k,save[100000],cnt=0;
	char s[50],t[50];
	bool ok=false;
	cin>>n;
	cin>>s>>t;
	a=n-1;
	for(i=a;i>=0;i--){
		if(s[i]!=t[i]){
			for(j=i-1;j>=0;j--){
				if(s[j]==t[i]){
					ok=true;
					b=j+1;
					for(k=b;k<=i;k++){
						save[cnt++]=k;
						swap(s[k],s[k-1]);
					}
					break;
				}
			}
			if(!ok){
				cout<<"-1";
				return 0;
			}
			ok=false;
		}
	}
	if(strcmp(s,t)!=0){
		cout<<"-1";
		return 0;
	}
	cout<<cnt<<endl;
	for(i=0;i<cnt;i++) cout<<save[i]<<" ";
}


#include<bits/stdc++.h>

using namespace std;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,i,j,a,b,k,save[100000],cnt=0;
	char s[50],t[50];
	bool ok=false;
	cin>>n;
	cin>>s>>t;
	a=n-1;
	for(i=a;i>=0;i--){
		if(s[i]==t[i]) continue;
			for(j=i-1;j>=0;j--){
				if(s[j]==t[i]){
					ok=true;
					for(k=j;k<i;k++){
						save[cnt++]=k+1;
						swap(s[k],s[k+1]);
					}
					break;
				}
			}
			if(!ok){
				cout<<"-1";
				return 0;
			}
		ok=false;
	}
	if(strcmp(s,t)!=0){
		cout<<"-1";
		return 0;
	}
	cout<<cnt<<endl;
	for(i=0;i<cnt;i++) cout<<save[i]<<" ";
}


#include<bits/stdc++.h>

using namespace std;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,i,j,a,b,k,save[100000],cnt=0;
	char s[50],t[50];
	cin>>n;
	cin>>s>>t;
	a=n-1;
	for(i=a;i>=0;i--){
		if(s[i]!=t[i]){
			for(j=i-1;j>=0;j--){
				if(s[j]==t[i]){
					b=j+1;
					for(k=b;k<=i;k++){
						save[cnt++]=k;
						swap(s[k],s[k-1]);
					}
					break;
				}
			}
		}
	}
	if(cnt==0){
		cout<<"-1";
		return 0;
	}
	cout<<cnt<<endl;
	for(i=0;i<cnt;i++) cout<<save[i]<<" ";
}


#include<bits/stdc++.h>

using namespace std;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,i,j,a,b,k,save[100000],cnt=0;
	char s[50],t[50];
	cin>>n;
	cin>>s>>t;
	a=n-1;
	for(i=a;i>=0;i--){
		if(s[i]==t[i]) continue;
			for(j=i-1;j>=0;j--){
				if(s[j]==t[i]){
					for(k=j;k<i;k++){
						save[cnt++]=k+1;
						swap(s[k],s[k+1]);
					}
					break;
				}
			}
	}
	if(strcmp(s,t)!=0){
		cout<<"-1";
		return 0;
	}
	cout<<cnt<<endl;
	for(i=0;i<cnt;i++) cout<<save[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
double eps =1e-9;
long long mo =1000000009 ;
long long power(long long  a, long long  b)
{
    if (b == 0) return 1;
    if (b == 1) return a%mo;
    if (b % 2 == 0) return power((a*a)%mo, b / 2)%mo;
    else return (a * power((a * a)%mo, (b - 1) / 2))%mo;
}

int main()
 {  ios_base::sync_with_stdio(0);cin.tie(0);
int n ;
cin>>n;
string s,t;
cin>>s>>t;
vector<int>v;
string t1=s,t2=t;
sort(t1.begin(),t1.end());
sort(t2.begin(),t2.end());
if (t1!=t2)
{
    cout<<-1 ; return 0;
}
while(1)
{
    for(int i=n-1 ; i>0 ; i--)
{
 if (s[i]!=t[i]) {
    char d=s[i];
    s[i]=s[i-1];
    s[i-1]=d;
    v.push_back(i);
 }

}
for(int i=0 ; i<n ; i++)
{
 if (i!=n-1&&s[i]!=t[i]) {
    char d=s[i];
    s[i]=s[i+1];
    s[i+1]=d;
    v.push_back(i+1);
 }

}

if (s==t||v.size()>10000) break;
}

if (s!=t) {cout<<-1 ; return 0;}
cout<<v.size()<<endl;
for(int i=0 ; i<v.size() ; i++) cout<<v[i]<<" ";

return 0;
}


#include <bits/stdc++.h>
using namespace std;
double eps =1e-9;
long long mo =1000000009 ;
long long power(long long  a, long long  b)
{
    if (b == 0) return 1;
    if (b == 1) return a%mo;
    if (b % 2 == 0) return power((a*a)%mo, b / 2)%mo;
    else return (a * power((a * a)%mo, (b - 1) / 2))%mo;
}

int main()
 {  ios_base::sync_with_stdio(0);cin.tie(0);
int n ;
cin>>n;
string s,t;
cin>>s>>t;
vector<int>v;
string t1=s,t2=t;
sort(t1.begin(),t1.end());
sort(t2.begin(),t2.end());
if (t1!=t2)
{
    cout<<-1 ; return 0;
}
while(1)
{

for(int i=0 ; i<n ; i++)
{
 if (i!=n-1&&s[i]!=t[i]) {
    char d=s[i];
    s[i]=s[i+1];
    s[i+1]=d;
    v.push_back(i+1);
 }

}
if (s==t) break;
}

cout<<v.size()<<endl;
for(int i=0 ; i<v.size() ; i++) cout<<v[i]<<" ";

return 0;
}


#include <bits/stdc++.h>
using namespace std;
double eps =1e-9;
long long mo =1000000009 ;
long long power(long long  a, long long  b)
{
    if (b == 0) return 1;
    if (b == 1) return a%mo;
    if (b % 2 == 0) return power((a*a)%mo, b / 2)%mo;
    else return (a * power((a * a)%mo, (b - 1) / 2))%mo;
}

int main()
 {  ios_base::sync_with_stdio(0);cin.tie(0);
int n ;
cin>>n;
string s,t;
cin>>s>>t;
vector<int>v;
string t1=s,t2=t;
sort(t1.begin(),t1.end());
sort(t2.begin(),t2.end());
if (t1!=t2)
{
    cout<<-1 ; return 0;
}
while(1)
{
for(int i=0 ; i<n ; i++)
{
 if (i!=n-1&&s[i]!=t[i]) {
    char d=s[i];
    s[i]=s[i+1];
    s[i+1]=d;
    v.push_back(i+1);
 }

}
if (s==t) break;

for(int i=n-1 ; i>0 ; i--)
{
 if (s[i]!=t[i]) {
    char d=s[i];
    s[i]=s[i-1];
    s[i-1]=d;
    v.push_back(i);
 }

}
if (s==t) break;
}

cout<<v.size()<<endl;
for(int i=0 ; i<v.size() ; i++) cout<<v[i]<<" ";

return 0;
}


#include <bits/stdc++.h>
#define Fill(ar, val) memset(ar, val, sizeof(ar))
#define pb push_back
#define ll long long
#define ull unsiigned long long
#define sz size()

using namespace std;
int const maxN =100000000;
double eps =1e-9;
long long  mod=1000000007;
vector<pair<ll,ll> > u ;
long long power(long long  a, long long  b)
{
    if (b == 0) return 1;
    if (b == 1) return a%mod;
    if (b % 2 == 0) return power((a*a)%mod, b / 2)%mod;
    else return (a * power((a * a)%mod, (b - 1) / 2))%mod;
}
vector<int>pr;
bool comp[maxN+5];
map<int,int>m;
void seive()
{
 comp[1]=1; comp[0]=1;
 for(int i=4 ; i<=maxN ; i+=2)
    comp[i]=1;
 for(ll i=3 ; i*i<=maxN ;i+=2)
 {

  if (comp[i%maxN]==0)
  { for(ll j=i*i ; j<=maxN ; j+=i )
      comp[j]=1;

  }

 }
 for(ll i=0  ; i<=maxN ; i++)
{if (!comp[i]) {pr.pb(i); if (i-2>0&&!comp[i-2]) { u.pb(make_pair(i-2,i));} }

}
}

struct MyLessString
{
    bool operator () (const string& lhs, const string& rhs) const
    {
        return lhs.size() == rhs.size() ?
                    lhs < rhs : lhs.size() < rhs.size();
    }
};

int main() {
  //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);

int n;
cin>>n;
string s,t;
cin>>s>>t; vector<int>v;
for(int i=0 ; i<n; i++)
{

    if (s[i]!=t[i])
    {   bool ans=0;
        for(int j=i ; j<n ; j++)
        { if (s[j]==t[i])
        { ans=1;
          for(int k=j ; k>i ; k--) {v.pb(k); swap(s[k],s[k-1]);}

        }

        }
    }
}
if (s!=t) cout<<-1;
else
{
    cout<<v.sz<<endl;
    for(int  i=0 ; i<v.sz ; i++) cout<<v[i]<<" ";
}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
double eps =1e-9;
long long mo =1000000009 ;
long long power(long long  a, long long  b)
{
    if (b == 0) return 1;
    if (b == 1) return a%mo;
    if (b % 2 == 0) return power((a*a)%mo, b / 2)%mo;
    else return (a * power((a * a)%mo, (b - 1) / 2))%mo;
}

int main()
 {  ios_base::sync_with_stdio(0);cin.tie(0);
int n ;
cin>>n;
string s,t;
cin>>s>>t;
vector<int>v;
string t1=s,t2=t;
sort(t1.begin(),t1.end());
sort(t2.begin(),t2.end());
if (t1!=t2)
{
    cout<<-1 ; return 0;
}
while(1)
{
for(int i=0 ; i<n ; i++)
{
 if (i!=n-1&&s[i]!=t[i]) {
    char d=s[i];
    s[i]=s[i+1];
    s[i+1]=d;
    v.push_back(i+1);
 }

}
if (s==t) break;

for(int i=n-1 ; i>0 ; i--)
{
 if (s[i]!=t[i]) {
    char d=s[i];
    s[i]=s[i-1];
    s[i-1]=d;
    v.push_back(i);
 }

}
if (s==t||v.size()>10000) break;
}

if (s!=t) {cout<<-1 ; return 0;}
cout<<v.size()<<endl;
for(int i=0 ; i<v.size() ; i++) cout<<v[i]<<" ";

return 0;
}


#include <bits/stdc++.h>
#define Fill(ar, val) memset(ar, val, sizeof(ar))
#define pb push_back
#define ll long long
#define ull unsiigned long long
#define sz size()

using namespace std;
int const maxN =100000000;
double eps =1e-9;
long long  mod=1000000007;
vector<pair<ll,ll> > u ;
long long power(long long  a, long long  b)
{
    if (b == 0) return 1;
    if (b == 1) return a%mod;
    if (b % 2 == 0) return power((a*a)%mod, b / 2)%mod;
    else return (a * power((a * a)%mod, (b - 1) / 2))%mod;
}
vector<int>pr;
bool comp[maxN+5];
map<int,int>m;
void seive()
{
 comp[1]=1; comp[0]=1;
 for(int i=4 ; i<=maxN ; i+=2)
    comp[i]=1;
 for(ll i=3 ; i*i<=maxN ;i+=2)
 {

  if (comp[i%maxN]==0)
  { for(ll j=i*i ; j<=maxN ; j+=i )
      comp[j]=1;

  }

 }
 for(ll i=0  ; i<=maxN ; i++)
{if (!comp[i]) {pr.pb(i); if (i-2>0&&!comp[i-2]) { u.pb(make_pair(i-2,i));} }

}
}

struct MyLessString
{
    bool operator () (const string& lhs, const string& rhs) const
    {
        return lhs.size() == rhs.size() ?
                    lhs < rhs : lhs.size() < rhs.size();
    }
};

int main() {
  //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);

int n;
cin>>n;
string s,t;
cin>>s>>t; vector<int>v;
for(int i=0 ; i<n; i++)
{
bool ans=1;
    if (s[i]!=t[i])
    {
        for(int j=i ; j<n ; j++)
        { if (s[j]==t[i])
        {
          for(int k=j ; k>i ; k--) {v.pb(k); swap(s[k],s[k-1]);  }
            break;
        }

        }
    }
}
if (s!=t) cout<<-1;
else
{
    cout<<v.sz<<endl;
    for(int  i=0 ; i<v.sz ; i++) cout<<v[i]<<" ";
}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
double eps =1e-9;
long long mo =1000000009 ;
long long power(long long  a, long long  b)
{
    if (b == 0) return 1;
    if (b == 1) return a%mo;
    if (b % 2 == 0) return power((a*a)%mo, b / 2)%mo;
    else return (a * power((a * a)%mo, (b - 1) / 2))%mo;
}

int main()
 {  ios_base::sync_with_stdio(0);cin.tie(0);
int n ;
cin>>n;
string s,t;
cin>>s>>t;
vector<int>v;
for(int i=0 ; i<n ; i++)
{
 if (i!=n-1&&s[i]!=t[i]) {
    char d=s[i];
    s[i]=s[i+1];
    s[i+1]=d;
    v.push_back(i+1);
 }

}
for(int i=n-1 ; i>0 ; i--)
{
     if (s[i]!=t[i]) {
    char d=s[i];
    s[i]=s[i-1];
    s[i-1]=d;
    v.push_back(i);
 }

}
for(int i=0 ; i<n ; i++)
{
    if (s[i]!=t[i]) {cout<<-1 ; return 0; }
}
cout<<v.size()<<endl;
for(int i=0 ; i<v.size() ; i++) cout<<v[i]<<" ";

return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool compare_str(char a[], char b[],int n)
{
    int count1[26]={0}, count2[26]={0};

    for(int i=0;i<n;i++)
    {
        count1[a[i]-'a']++;
        count2[b[i]-'a']++;
    }

    for(int i=0;i<26;i++)
    {
        if(count1[i]!=count2[i])
            return false;
    }

    return true;

}
int main()
{
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    int n, cnt=0;
    scanf("%d", &n);

    char s[n+1], t[n+1];
    scanf("%s", s);
    scanf("%s", t);

    vector<int>vec;
    vector<int>::iterator it;

    if((compare_str(s,t,n))==false)
        printf("%d",-1);
    else if(compare_str(s,t,n)==true)
    {
        if((strcmp(s,t))==0)
            printf("%d", 0);
        else
        {
            char temp;
            //int cnt=0;

            while(1)
            {
                for(int i=0;i<n;i++)
                {
                    if(s[i]!=t[i])
                    {
                        int j, k=i;
                        for(j=i+1;j<n-1;j++)
                        {
                            if(s[i]==t[j])
                                    break;
                        }

                    while(k!=j)
                    {
                       //if(k==j)
                            //break;

                        cnt++;
                        temp=s[k];
                        s[k]=s[k+1];
                        s[k+1]=temp;
                        vec.push_back(k+1);
                        k++;

                    }

                    if(strcmp(s,t)==0)
                            break;

                        /*cnt++;
                        temp=s[i];
                        s[i]=s[i+1];
                        s[i+1]=temp;
                        vec.push_back(i+1);*/

                    }
                }
                break;

            }
        }

         printf("%d\n", cnt);

         for(it=vec.begin();it!=vec.end();++it)
         {
             if(it==vec.end()-1)
                cout<<*it;
             else
                cout<<*it<<" ";
         }

        }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool compare_str(char a[], char b[],int n)
{
    int count1[26]={0}, count2[26]={0};

    for(int i=0;i<n;i++)
    {
        count1[a[i]-'a']++;
        count2[b[i]-'a']++;
    }

    for(int i=0;i<26;i++)
    {
        if(count1[i]!=count2[i])
            return false;
    }

    return true;

}
int main()
{
    freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

    int n, cnt=0;
    scanf("%d", &n);

    char s[n], t[n];
    scanf("%s", s);
    scanf("%s", t);

    vector<int>vec;
    vector<int>::iterator it;

    if((compare_str(s,t,n))==false)
        printf("%d",-1);
    else if(compare_str(s,t,n)==true)
    {
        if((strcmp(s,t))==0)
            printf("%d", 0);
        else
        {
            char temp;
            //int cnt=0;

            while(1)
            {
                for(int i=0;i<n;i++)
                {
                    if(s[i]!=t[i])
                    {
                        int j, k=i;
                        for(j=i+1;j<n;j++)
                        {
                            if(s[i]==t[j])
                                    break;
                        }

                    while(k!=j)
                    {
                        cnt++;
                        temp=s[k];
                        s[k]=s[k+1];
                        s[k+1]=temp;
                        vec.push_back(k+1);
                        k++;
                    }

                    if(strcmp(s,t)==0)
                            break;

                        /*cnt++;
                        temp=s[i];
                        s[i]=s[i+1];
                        s[i+1]=temp;
                        vec.push_back(i+1);*/

                    }
                }
                break;

            }
        }

         printf("%d\n", cnt);

         for(it=vec.begin();it!=vec.end();++it)
         {
             if(it==vec.end()-1)
                cout<<*it;
             else
                cout<<*it<<" ";
         }

        }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool compare_str(char a[], char b[],int n)
{
    int count1[26]={0}, count2[26]={0};

    for(int i=0;i<n;i++)
    {
        count1[a[i]-'a']++;
        count2[b[i]-'a']++;
    }

    for(int i=0;i<26;i++)
    {
        if(count1[i]!=count2[i])
            return false;
    }

    return true;

}
int main()
{
    freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

    int n, cnt=0;
    scanf("%d", &n);

    char s[n+1], t[n+1];
    scanf("%s", s);
    scanf("%s", t);

    vector<int>vec;
    vector<int>::iterator it;

    if((compare_str(s,t,n))==false)
        printf("%d",-1);
    else if(compare_str(s,t,n)==true)
    {
        if((strcmp(s,t))==0)
            printf("%d", 0);
        else
        {
            char temp;
            //int cnt=0;

            while(1)
            {
                for(int i=0;i<n;i++)
                {
                    if(s[i]!=t[i])
                    {
                        int j, k=i;
                        for(j=i+1;j<n-1;j++)
                        {
                            if(s[i]==t[j])
                                    break;
                        }

                    while(k!=j)
                    {
                       //if(k==j)
                            //break;

                        cnt++;
                        temp=s[k];
                        s[k]=s[k+1];
                        s[k+1]=temp;
                        vec.push_back(k+1);
                        k++;

                    }

                    if(strcmp(s,t)==0)
                            break;

                        /*cnt++;
                        temp=s[i];
                        s[i]=s[i+1];
                        s[i+1]=temp;
                        vec.push_back(i+1);*/

                    }
                }
                break;

            }
        }

         printf("%d\n", cnt);

         for(it=vec.begin();it!=vec.end();++it)
         {
             if(it==vec.end()-1)
                cout<<*it;
             else
                cout<<*it<<" ";
         }

        }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    int n;
    string s,t;
    vector<int> vec;
    vector<int>::iterator it;

    cin >> n>> s>> t;

    int pos=-1;

    for(int i=0;i<n;++i)
    {
        if(s[i]==t[i])
            continue;

        //int pos=-1;

        for(int j=i+1;j<n;++j)
        {
            if(s[j]==t[i])
            {
                pos=j;
                break;
            }
        }

        if(pos==-1)
        {
            printf("%d\n", -1);
            return 0;
        }

        for(int j=i;j<pos;j++)
        {
            swap(s[j],s[j+1]);
            vec.push_back(j+1);
        }
    }

        cout<<vec.size()<<endl;

        for(it=vec.begin();it!=vec.end();++it)
        {
            if(it==vec.end()-1)
                cout<<*it;
             else
                cout<<*it<<" ";
         }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool compare_str(char a[], char b[],int n)
{
    int count1[26]={0}, count2[26]={0};

    for(int i=0;i<n;i++)
    {
        count1[a[i]-'a']++;
        count2[b[i]-'a']++;
    }

    for(int i=0;i<26;i++)
    {
        if(count1[i]!=count2[i])
            return false;
    }

    return true;

}
int main()
{
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    int n, cnt=0;
    scanf("%d", &n);

    char s[n], t[n];
    scanf("%s", s);
    scanf("%s", t);

    vector<int>vec;
    vector<int>::iterator it;

    if((compare_str(s,t,n))==false)
        printf("%d",-1);
    else if(compare_str(s,t,n)==true)
    {
        if((strcmp(s,t))==0)
            printf("%d", 0);
        else
        {
            char temp;
            //int cnt=0;

            while(1)
            {
                for(int i=0;i<n;i++)
                {
                    if(s[i]!=t[i])
                    {
                        int j, k=i;
                        for(j=i+1;j<n;j++)
                        {
                            if(s[i]==t[j])
                                    break;
                        }

                    while(k!=j)
                    {
                        cnt++;
                        temp=s[k];
                        s[k]=s[k+1];
                        s[k+1]=temp;
                        vec.push_back(k+1);
                        k++;
                    }

                    if(strcmp(s,t)==0)
                            break;

                        /*cnt++;
                        temp=s[i];
                        s[i]=s[i+1];
                        s[i+1]=temp;
                        vec.push_back(i+1);*/

                    }
                }
                break;

            }
        }

         printf("%d\n", cnt);

         for(it=vec.begin();it!=vec.end();++it)
         {
             if(it==vec.end()-1)
                cout<<*it;
             else
                cout<<*it<<" ";
         }

        }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool compare_str(char a[], char b[],int n)
{
    int count1[26]={0}, count2[26]={0};

    for(int i=0;i<n;i++)
    {
        count1[a[i]-'a']++;
        count2[b[i]-'a']++;
    }

    for(int i=0;i<26;i++)
    {
        if(count1[i]!=count2[i])
            return false;
    }

    return true;

}
int main()
{
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    int n, cnt=0;
    scanf("%d", &n);

    char s[n+1], t[n+1];
    scanf("%s", s);
    scanf("%s", t);

    vector<int>vec;
    vector<int>::iterator it;

    if((compare_str(s,t,n))==false)
        printf("%d",-1);
    else if(compare_str(s,t,n)==true)
    {
        if((strcmp(s,t))==0)
            printf("%d", 0);
        else
        {
            char temp;
            //int cnt=0;

            while(1)
            {
                for(int i=0;i<n-1;i++)
                {
                    if(s[i]!=t[i])
                    {
                        int j, k=i;
                        for(j=i+1;j<n-1;j++)
                        {
                            if(s[i]==t[j])
                                    break;
                        }

                    while(k!=j)
                    {
                       //if(k==j)
                            //break;

                        cnt++;
                        temp=s[k];
                        s[k]=s[k+1];
                        s[k+1]=temp;
                        vec.push_back(k+1);
                        k++;

                    }

                    if(strcmp(s,t)==0)
                            break;

                        /*cnt++;
                        temp=s[i];
                        s[i]=s[i+1];
                        s[i+1]=temp;
                        vec.push_back(i+1);*/

                    }
                }
                break;

            }
        }

         printf("%d\n", cnt);

         for(it=vec.begin();it!=vec.end();++it)
         {
             if(it==vec.end()-1)
                cout<<*it;
             else
                cout<<*it<<" ";
         }

        }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    int n;
    string s,t;
    vector<int> vec;
    vector<int>::iterator it;

    cin >> n>> s>> t;

    //int pos=-1;

    for(int i=0;i<n;++i)
    {
        if(s[i]==t[i])
            continue;

        int pos=-1;

        for(int j=i+1;j<n;++j)
        {
            if(s[j]==t[i])
            {
                pos=j;
                break;
            }
        }

        if(pos==-1)
        {
            printf("%d\n", -1);
            return 0;
        }

        for(int j=pos-1;j>=i;--j)
        {
            swap(s[j],s[j+1]);
            vec.push_back(j+1);
        }
    }

    assert(s==t);

        cout<<vec.size()<<endl;

        for(it=vec.begin();it!=vec.end();++it)
        {
            if(it==vec.end()-1)
                cout<<*it;
             else
                cout<<*it<<" ";
         }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool compare_str(char a[], char b[],int n)
{
    int count1[26]={0}, count2[26]={0};

    for(int i=0;i<n;i++)
    {
        count1[a[i]-'a']++;
        count2[b[i]-'a']++;
    }

    /*for(int i=0;i<26;i++)
    {
        printf("%d ", count1[i]);
    }
        printf("\n");
     for(int i=0;i<26;i++)
    {
        printf("%d ", count2[i]);
    }*/

    for(int i=0;i<26;i++)
    {
        if(count1[i]!=count2[i])
            return false;
    }

    return true;

}
int main()
{
    int n, cnt=0;
    scanf("%d", &n);

    char s[n], t[n];
    scanf("%s", s);
    scanf("%s", t);

    vector<int>vec;
    vector<int>::iterator it;

    if((compare_str(s,t,n))==false)
        printf("%d",-1);
    else if(compare_str(s,t,n)==true)
    {
        if((strcmp(s,t))==0)
            printf("%d", 0);
        else
        {
            char temp;
            //int cnt=0;

            while((strcmp(s,t))!=0)
            {
                for(int i=0;i<n;i++)
                {
                    if(s[i]!=t[i])
                    {
                        cnt++;
                        temp=s[i];
                        s[i]=s[i+1];
                        s[i+1]=temp;
                        vec.push_back(i+1);
                    }
                }

            }
        }

         printf("%d\n", cnt);

         for(it=vec.begin();it!=vec.end();++it)
         {
             if(it==vec.end()-1)
                cout<<*it;
             else
                cout<<*it<<" ";
         }

        }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    int n;
    string s,t;
    vector<int> vec;
    vector<int>::iterator it;

    cin >> n>> s>> t;

    int pos=-1;

    for(int i=0;i<n;++i)
    {
        if(s[i]==t[i])
            continue;

        //int pos=-1;

        for(int j=i+1;j<n;++j)
        {
            if(s[j]==t[i])
            {
                pos=j;
                break;
            }
        }

        if(pos==-1)
        {
            printf("%d\n", -1);
            return 0;
        }

        for(int j=pos-1;j>=i;--j)
        {
            swap(s[j],s[j+1]);
            vec.push_back(j+1);
        }
    }

        cout<<vec.size()<<endl;

        for(it=vec.begin();it!=vec.end();++it)
        {
            if(it==vec.end()-1)
                cout<<*it;
             else
                cout<<*it<<" ";
         }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool compare_str(char a[], char b[],int n)
{
    int count1[26]={0}, count2[26]={0};

    for(int i=0;i<n;i++)
    {
        count1[a[i]-'a']++;
        count2[b[i]-'a']++;
    }

    for(int i=0;i<26;i++)
    {
        if(count1[i]!=count2[i])
            return false;
    }

    return true;

}
int main()
{
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    int n, cnt=0;
    scanf("%d", &n);

    char s[n+1], t[n+1];
    scanf("%s", s);
    scanf("%s", t);

    vector<int>vec;
    vector<int>::iterator it;

    if((compare_str(s,t,n))==false)
        printf("%d",-1);
    else if(compare_str(s,t,n)==true)
    {
        if((strcmp(s,t))==0)
            printf("%d", 0);
        else
        {
            char temp;
            //int cnt=0;

            while(1)
            {
                for(int i=0;i<n;i++)
                {
                    if(s[i]!=t[i])
                    {
                        int j, k=i;
                        for(j=i+1;j<n;j++)
                        {
                            if(s[i]==t[j])
                                    break;
                        }

                    while(k!=j)
                    {
                        cnt++;
                        temp=s[k];
                        s[k]=s[k+1];
                        s[k+1]=temp;
                        vec.push_back(k+1);
                        k++;
                    }

                    if(strcmp(s,t)==0)
                            break;

                        /*cnt++;
                        temp=s[i];
                        s[i]=s[i+1];
                        s[i+1]=temp;
                        vec.push_back(i+1);*/

                    }
                }
                break;

            }
        }

         printf("%d\n", cnt);

         for(it=vec.begin();it!=vec.end();++it)
         {
             if(it==vec.end()-1)
                cout<<*it;
             else
                cout<<*it<<" ";
         }

        }

    return 0;
}


                #include <bits/stdc++.h>
                using namespace std;
                #define fio              ios_base::sync_with_stdio(false),cin.tie(NULL)
                #define ll              long long int
                #define ull             unsigned long long int
                #define ld              long double
                #define sb              __builtin_popcount
                #define vi              vector<int>
                #define vl              vector<ll>
                #define vc              vector<char>
                #define ii              pair<int,int>
                #define pq              priority_queue<ii,vector<ii>, greater< ii>>
                #define vii             vector<ii>
                #define viii            vector<tuple<ll,ll,ll>>
                #define sz(a)           int((a).size())
                #define f(a,b)          for(int i=a;i<b;i++)
                #define fr(a,b)         for(int i=a-1;i>=b;i--)
                #define tr(x,m)         for(auto x : m)
                #define in(a,b)         (b.find(a) != string::npos)
                #define minin(a)        *min_element (all(a))
                #define maxin(a)        *max_element(all(a))
                #define bs(l,h,k)       equal_range(l,h,k);
                #define X               first
                #define Y               second
                #define fill(a,x)       memset(a,x,sizeof(a))
                #define pb              push_back
                #define pf              push_front
                #define mp              make_pair
                #define all(v)          v.begin(),v.end()
                #define rall(v)         reverse(v.begin(),v.end())
                #define unq(v)          v.erase(unique(all(v)),v.end())
                #define el              "\n"
                #define mx3(a,b,c)      max(max(a,b),c)
                #define S(v)            accumulate(all(v), (ll)0)
                #define IP(v1,v2)       inner_product(all(v1), v2.begin(), (ll)0)
                const long double PI = atan(1.0)*4.0;
                const ll M = 1e9 + 7;
                const ll INF = 1e18;
                const ld EPS = 0.0000001;
                #define N  100005
                bool cmp(pair<string,int>a,pair<string,int>b){
                   return a.Y>b.Y;
                }
                int pw(int x,int n,int M)
                {
                    if(n==0)
                         return 1;
                     else if(n%2 == 0)        //n is even
                         return pw((x*x)%M,n/2,M);
                     else                             //n is odd
                         return (x*pw((x*x)%M,(n-1)/2,M))%M;
                }

                int main(){
                       fio;
                    int n;cin>>n;
                    string s,t,p,q;cin>>s;
                    cin>>t;
                    p=s;
                    q=t;
                    sort(all(p));
                    sort(all(q));
                    if(s==t){
                        cout<<0<<el;
                        return 0;
                    }
                     if(p!=q){
                        cout<<-1<<el;
                        return 0;
                    }

                        vi v;
                        int ind=0;
                        for(int i=0;i<n-1;i++){
                            if(s[i]!=t[i]){
                                for(int j=i+1;j<n;j++){
                                    if(s[j]==t[i]){
                                        ind=j;
                                        break;
                                    }
                                }
                            }
                            char tmp;
                            for(int j=ind-1;j>=i && j<n;j--){
                                //swap(s[j],s[j-1]);
                                tmp=s[j];
                                s[j]=s[j+1];
                                s[j+1]=tmp;
                                v.pb(j+1);
                            }
                          //  cout<<s<<el;
                         //for(int j=i+1;j<=ind;j++)v.pb(j);
                        }
                       cout<<v.size()<<el;
                      f(0,v.size())cout<<v[i]<<" ";

                       return 0;
                  }


#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
long long int i,j,n,m,k;
string s,t;
long long a1[26]={0};
long long a2[26]={0};
long long int pos=1;
cin>>n;
cin>>s>>t;
for(i=0;i<n;i++)
a1[s[i]-'a']++,a2[t[i]-'a']++;
for(i=0;i<26;i++)
if(a1[i]!=a2[i])
pos=0;
vector<long long> v;
if(pos==0)
cout<<"-1";
else
{
for(i=0;i<n;i++)
{
if(s[i]!=t[i])
{
for(j=i+1;j<n;)
{
if(s[j]==t[i])
break;
j++;
}
long long index1=j;
for(j=index1-1;j>=i;j--)
{
char tmp=s[j];
s[j]=s[j+1];
s[j+1]=tmp;
v.push_back(j+1);
}

}
}
cout<<v.size()<<endl;
for(i=0;i<v.size();i++)
cout<<v[i]<<" ";
}
return 0;
}


                #include <bits/stdc++.h>
                using namespace std;
                #define fio              ios_base::sync_with_stdio(false),cin.tie(NULL)
                #define ll              long long int
                #define ull             unsigned long long int
                #define ld              long double
                #define sb              __builtin_popcount
                #define vi              vector<int>
                #define vl              vector<ll>
                #define vc              vector<char>
                #define ii              pair<int,int>
                #define pq              priority_queue<ii,vector<ii>, greater< ii>>
                #define vii             vector<ii>
                #define viii            vector<tuple<ll,ll,ll>>
                #define sz(a)           int((a).size())
                #define f(a,b)          for(int i=a;i<b;i++)
                #define fr(a,b)         for(int i=a-1;i>=b;i--)
                #define tr(x,m)         for(auto x : m)
                #define in(a,b)         (b.find(a) != string::npos)
                #define minin(a)        *min_element (all(a))
                #define maxin(a)        *max_element(all(a))
                #define bs(l,h,k)       equal_range(l,h,k);
                #define X               first
                #define Y               second
                #define fill(a,x)       memset(a,x,sizeof(a))
                #define pb              push_back
                #define pf              push_front
                #define mp              make_pair
                #define all(v)          v.begin(),v.end()
                #define rall(v)         reverse(v.begin(),v.end())
                #define unq(v)          v.erase(unique(all(v)),v.end())
                #define el              "\n"
                #define mx3(a,b,c)      max(max(a,b),c)
                #define S(v)            accumulate(all(v), (ll)0)
                #define IP(v1,v2)       inner_product(all(v1), v2.begin(), (ll)0)
                const long double PI = atan(1.0)*4.0;
                const ll M = 1e9 + 7;
                const ll INF = 1e18;
                const ld EPS = 0.0000001;
                #define N  100005
                bool cmp(pair<string,int>a,pair<string,int>b){
                   return a.Y>b.Y;
                }
                int pw(int x,int n,int M)
                {
                    if(n==0)
                         return 1;
                     else if(n%2 == 0)        //n is even
                         return pw((x*x)%M,n/2,M);
                     else                             //n is odd
                         return (x*pw((x*x)%M,(n-1)/2,M))%M;
                }

                int main(){
                       fio;
                    int n;cin>>n;
                    string s,t,p,q;cin>>s;
                    cin>>t;
                    p=s;
                    q=t;
                    sort(all(p));
                    sort(all(q));
                    if(s==t){
                        cout<<0<<el;
                        return 0;
                    }
                    else if(p!=q){
                        cout<<-1<<el;
                        return 0;
                    }
                    else{
                        vi v;
                        int ind;
                        for(int i=0;i<n;i++){
                            if(s[i]!=t[i]){
                                for(int j=i+1;j<n;j++){
                                    if(s[j]==t[i]){
                                        ind=j;
                                        break;
                                    }
                                }
                            }
                            char tmp;
                            for(int j=ind-1;j>=i && j<n;j--){
                                //swap(s[j],s[j-1]);
                                tmp=s[j];
                                s[j]=s[j+1];
                                s[j+1]=tmp;
                                v.pb(j+1);
                            }
                          //  cout<<s<<el;
                         //for(int j=i+1;j<=ind;j++)v.pb(j);
                        }
                       cout<<v.size()<<el;
                      f(0,v.size())cout<<v[i]<<" ";
                    }

                       return 0;
                  }


                #include <bits/stdc++.h>
                using namespace std;
                #define fio              ios_base::sync_with_stdio(false),cin.tie(NULL)
                #define ll              long long int
                #define ull             unsigned long long int
                #define ld              long double
                #define sb              __builtin_popcount
                #define vi              vector<int>
                #define vl              vector<ll>
                #define vc              vector<char>
                #define ii              pair<int,int>
                #define pq              priority_queue<ii,vector<ii>, greater< ii>>
                #define vii             vector<ii>
                #define viii            vector<tuple<ll,ll,ll>>
                #define sz(a)           int((a).size())
                #define f(a,b)          for(int i=a;i<b;i++)
                #define fr(a,b)         for(int i=a-1;i>=b;i--)
                #define tr(x,m)         for(auto x : m)
                #define in(a,b)         (b.find(a) != string::npos)
                #define minin(a)        *min_element (all(a))
                #define maxin(a)        *max_element(all(a))
                #define bs(l,h,k)       equal_range(l,h,k);
                #define X               first
                #define Y               second
                #define fill(a,x)       memset(a,x,sizeof(a))
                #define pb              push_back
                #define pf              push_front
                #define mp              make_pair
                #define all(v)          v.begin(),v.end()
                #define rall(v)         reverse(v.begin(),v.end())
                #define unq(v)          v.erase(unique(all(v)),v.end())
                #define el              "\n"
                #define mx3(a,b,c)      max(max(a,b),c)
                #define S(v)            accumulate(all(v), (ll)0)
                #define IP(v1,v2)       inner_product(all(v1), v2.begin(), (ll)0)
                const long double PI = atan(1.0)*4.0;
                const ll M = 1e9 + 7;
                const ll INF = 1e18;
                const ld EPS = 0.0000001;
                #define N  100005
                bool cmp(pair<string,int>a,pair<string,int>b){
                   return a.Y>b.Y;
                }
                int pw(int x,int n,int M)
                {
                    if(n==0)
                         return 1;
                     else if(n%2 == 0)        //n is even
                         return pw((x*x)%M,n/2,M);
                     else                             //n is odd
                         return (x*pw((x*x)%M,(n-1)/2,M))%M;
                }

                int main(){
                       fio;
                    int n;cin>>n;
                    string s,t,p,q;cin>>s>>t;
                    p=s;
                    q=t;
                    sort(all(p));
                    sort(all(q));
                    if(s==t){
                        cout<<0<<el;
                        return 0;
                    }
                    else if(p!=q){
                        cout<<-1<<el;
                        return 0;
                    }
                    else{
                        vi v;
                        int ind;
                        for(int i=0;i<s.length();i++){
                            if(s[i]!=t[i]){
                                for(int j=i+1;j<s.length();j++){
                                    if(s[j]==t[i]){
                                        ind=j;
                                        break;
                                    }
                                }
                            }
                            char tmp;
                            for(int j=ind;j>i;j--){
                                //swap(s[j],s[j-1]);
                                tmp=s[j];
                                s[j]=s[j-1];
                                s[j-1]=tmp;
                                v.pb(j+1);
                            }
                          //  cout<<s<<el;
                         //for(int j=i+1;j<=ind;j++)v.pb(j);
                        }
                       cout<<v.size()<<el;
                      f(0,v.size())cout<<v[i]-1<<" ";
                    }

                       return 0;
                  }


                #include <bits/stdc++.h>
                using namespace std;
                #define fio              ios_base::sync_with_stdio(false),cin.tie(NULL)
                #define ll              long long int
                #define ull             unsigned long long int
                #define ld              long double
                #define sb              __builtin_popcount
                #define vi              vector<int>
                #define vl              vector<ll>
                #define vc              vector<char>
                #define ii              pair<int,int>
                #define pq              priority_queue<ii,vector<ii>, greater< ii>>
                #define vii             vector<ii>
                #define viii            vector<tuple<ll,ll,ll>>
                #define sz(a)           int((a).size())
                #define f(a,b)          for(int i=a;i<b;i++)
                #define fr(a,b)         for(int i=a-1;i>=b;i--)
                #define tr(x,m)         for(auto x : m)
                #define in(a,b)         (b.find(a) != string::npos)
                #define minin(a)        *min_element (all(a))
                #define maxin(a)        *max_element(all(a))
                #define bs(l,h,k)       equal_range(l,h,k);
                #define X               first
                #define Y               second
                #define fill(a,x)       memset(a,x,sizeof(a))
                #define pb              push_back
                #define pf              push_front
                #define mp              make_pair
                #define all(v)          v.begin(),v.end()
                #define rall(v)         reverse(v.begin(),v.end())
                #define unq(v)          v.erase(unique(all(v)),v.end())
                #define el              "\n"
                #define mx3(a,b,c)      max(max(a,b),c)
                #define S(v)            accumulate(all(v), (ll)0)
                #define IP(v1,v2)       inner_product(all(v1), v2.begin(), (ll)0)
                const long double PI = atan(1.0)*4.0;
                const ll M = 1e9 + 7;
                const ll INF = 1e18;
                const ld EPS = 0.0000001;
                #define N  100005
                bool cmp(pair<string,int>a,pair<string,int>b){
                   return a.Y>b.Y;
                }
                int pw(int x,int n,int M)
                {
                    if(n==0)
                         return 1;
                     else if(n%2 == 0)        //n is even
                         return pw((x*x)%M,n/2,M);
                     else                             //n is odd
                         return (x*pw((x*x)%M,(n-1)/2,M))%M;
                }

                int main(){
                       fio;
                    int n;cin>>n;
                    string s,t,p,q;cin>>s>>t;
                    p=s;
                    q=t;
                    sort(all(p));
                    sort(all(q));
                    if(s==t){
                        cout<<0<<el;
                        return 0;
                    }
                    else if(p!=q){
                        cout<<-1<<el;
                        return 0;
                    }
                    else{
                        vi v;
                        int ind;
                        for(int i=0;i<s.length();i++){
                            if(s[i]!=t[i]){
                                for(int j=i+1;j<s.length();j++){
                                    if(s[j]==t[i]){
                                        ind=j;
                                        break;
                                    }
                                }
                            }
                            for(int j=ind;j>i;j--){
                                swap(s[j],s[j-1]);
                                v.pb(j+1);
                            }
                          //  cout<<s<<el;
                         //for(int j=i+1;j<=ind;j++)v.pb(j);
                        }
                       cout<<v.size()<<el;
                      f(0,v.size())cout<<v[i]-1<<" ";
                    }

                       return 0;
                  }