CF936C.Lock Puzzle

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Welcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find the solution of the problem of discrete logarithm!

Of course, there is a code lock is installed on the safe. The lock has a screen that displays a string of nn lowercase Latin letters. Initially, the screen displays string ss . Whitfield and Martin found out that the safe will open when string tt will be displayed on the screen.

The string on the screen can be changed using the operation «shift xx ». In order to apply this operation, explorers choose an integer xx from 0 to nn inclusive. After that, the current string p=αβp=αβ changes to βRαβ^{R}α , where the length of ββ is xx , and the length of αα is nxn-x . In other words, the suffix of the length xx of string pp is reversed and moved to the beginning of the string. For example, after the operation «shift 44 » the string «abcacb» will be changed with string «bcacab », since α=α= ab, β=β= cacb, βR=β^{R}= bcac.

Explorers are afraid that if they apply too many operations «shift», the lock will be locked forever. They ask you to find a way to get the string tt on the screen, using no more than 61006100 operations.

输入格式

The first line contains an integer nn , the length of the strings ss and tt ( 1<=n<=20001<=n<=2000 ).

After that, there are two strings ss and tt , consisting of nn lowercase Latin letters each.

输出格式

If it is impossible to get string tt from string ss using no more than 6100 operations «shift», print a single number 1-1 .

Otherwise, in the first line output the number of operations kk ( 0<=k<=61000<=k<=6100 ). In the next line output kk numbers xix_{i} corresponding to the operations «shift xix_{i} » ( 0<=xi<=n0<=x_{i}<=n ) in the order in which they should be applied.

输入输出样例

  • 输入#1

    6
    abacbb
    babcba
    

    输出#1

    4
    6 3 2 3
    
  • 输入#2

    3
    aba
    bba
    

    输出#2

    -1
    
首页