B. Obtaining the String

You are given two strings ss and tt. Both strings have length nn and consist of lowercase Latin letters. The characters in the strings are numbered from 11 to nn.

You can successively perform the following move any number of times (possibly, zero):

  • swap any two adjacent (neighboring) characters of ss (i.e. for any i={1,2,…,n−1}i={1,2,…,n−1} you can swap sisi and si+1)si+1).

You can't apply a move to the string tt. The moves are applied to the string ss one after another.

Your task is to obtain the string tt from the string ss. Find any way to do it with at most 104104 such moves.

You do not have to minimize the number of moves, just find any sequence of moves of length 104104 or less to transform ss into tt.

Input

The first line of the input contains one integer nn (1≤n≤501≤n≤50) — the length of strings ss and tt.

The second line of the input contains the string ss consisting of nn lowercase Latin letters.

The third line of the input contains the string tt consisting of nn lowercase Latin letters.

Output

If it is impossible to obtain the string tt using moves, print "-1".

Otherwise in the first line print one integer kk — the number of moves to transform ss to tt. Note that kk must be an integer number between 00 and 104104 inclusive.

In the second line print kk integers cjcj (1≤cj<n1≤cj<n), where cjcj means that on the jj-th move you swap characters scjscjand scj+1scj+1.

If you do not need to apply any moves, print a single integer 00 in the first line and either leave the second line empty or do not print it at all.

Examples

input

Copy

6
abcdef
abdfec

output

Copy

4
3 5 4 5 

input

Copy

4
abcd
accd

output

Copy

-1

题意:给出长度为n的两个字符串,问最少经过几次两个相邻字符的交换使得a串变成b串。

类比冒泡排序的算法,在找到一个ab不相同的字符时从当前位置开始交换,直到此处字符相同。

代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<queue>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long

int main()
{
	vector<int >v;
	int n,i,j,k,s[150]={0};
	string a,b;
	cin>>n;
	cin>>a>>b;
	for(i=0;i<n;i++)    //存储字符及数量,判断ab字符串是否可能相等
	{
		s[a[i]]++;
		s[b[i]]--;
	}
	for(i=0;i<150;i++)
	{
		if(s[i]!=0)
		{
			cout<<"-1"<<endl;
			return 0;
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=i;i<n;j++)
		{
			if(b[i]==a[j])
			{
				for(k=j;k>i;k--)
				{
					swap(a[k],a[k-1]);
					//cout<<i<<" "<<j<<" "<<k<<endl;
					v.push_back(k);
				}
				break;
			}
		}
	}
	cout<<v.size()<<endl;
	for(i=0;i<v.size();i++)
	cout<<v[i]<<" ";
	return 0;
}