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 ssto 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 scjscj and 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

6
abcdef
abdfec

Output

4
3 5 4 5 

Input

4
abcd
accd

Output

-1

Note

In the first example the string ss changes as follows: "abcdef" →→ "abdcef" →→"abdcfe" →→ "abdfce" →→ "abdfec".

In the second example there is no way to transform the string ss into the string ttthrough any allowed moves.

暴搜找对应位置,找到前后交换,记录交换的位置

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{int n;
    string s,t;
    int ans;
    int b[2505];
    cin>>n>>s>>t;
    {int pos=-1;
    ans=0;
    memset(b,0,sizeof(b));
        for(int i=0;i<n;i++)
        { if(s[i]==t[i])
        continue;

          for(int j=i+1;j<n;j++)
          if(s[j]==t[i])
          {
              pos=j;
              break;
          }
          if(pos==-1)
          {printf("-1\n");
          return 0;
          }
          for(int j=pos-1;j>=i;--j)
          {
              swap(s[j],s[j+1]);
              ++ans;
              b[ans]=j;
          }


    }


  if(ans<1e4&&s==t)
 {
    printf("%d\n",ans);
  for(int i=1;i<=ans;i++)
  printf("%d ",b[i]+1);
  printf("\n");

    }
    else
    printf("-1");
    }
    return 0;
}

考虑一下交换任意位置的结果

猜你喜欢

转载自blog.csdn.net/sdauguanweihong/article/details/81432642