CF1015B.Obtaining the String

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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,,n1}i = \{1, 2, \dots, n - 1\} you can swap sis_i and si+1)s_{i + 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 10410^4 such moves.

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

输入格式

The first line of the input contains one integer nn ( 1n501 \le n \le 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.

输出格式

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 10410^4 inclusive.

In the second line print kk integers cjc_j ( 1cj<n1 \le c_j < n ), where cjc_j means that on the jj -th move you swap characters scjs_{c_j} and scj+1s_{c_j + 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.

输入输出样例

  • 输入#1

    6
    abcdef
    abdfec
    

    输出#1

    4
    3 5 4 5 
    
  • 输入#2

    4
    abcd
    accd
    

    输出#2

    -1
    

说明/提示

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

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

首页