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 n lowercase Latin letters. Initially, the screen displays string s. Whitfield and Martin found out that the safe will open when string t will be displayed on the screen.

The string on the screen can be changed using the operation «shift x». In order to apply this operation, explorers choose an integer x from 0 to n inclusive. After that, the current string p = αβ changes to βRα, where the length of β is x, and the length of α is n - x. In other words, the suffix of the length x of string p is reversed and moved to the beginning of the string. For example, after the operation «shift 4» the string «abcacb» will be changed with string «bcacab », since α = ab, β = cacb, β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 t on the screen, using no more than 6100 operations.

Input

The first line contains an integer n, the length of the strings s and t (1 ≤ n ≤ 2 000).

After that, there are two strings s and t, consisting of n lowercase Latin letters each.

Output

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

Otherwise, in the first line output the number of operations k (0 ≤ k ≤ 6100). In the next line output k numbers xi corresponding to the operations «shift xi» (0 ≤ xi ≤ n) in the order in which they should be applied.

Examples

Input

6
abacbb
babcba


Output

4
6 3 2 3


Input

3
aba
bba


Output

-1

Source: codeforces | Difficulty: HARD
Tags: String algorithms

Implementation

Constructive algorithms


Solutions:
n = int(input())
t = input()[:n]
s = input()[:n]
ops = []

def shift(k, cur):
	if k == 0:
		return cur
	return cur[:-k - 1:-1] + cur[:-k]

def move_to_front(k, curst):
	if k == n - 1:
		ops.append(1)
		curst = curst[-1] + curst[:-1]
	else:
		ops.append(n - 1)
		ops.append(k)
		ops.append(1)
		curst = curst[k] + curst[:k] + curst[-1:k:-1]
	return curst

def find_char(char, t):
	for (m, cur_c) in enumerate(t[::-1]):
		if cur_c == char:
			return n - m - 1
	return 0
from collections import Counter
scount = Counter(s)
tcount = Counter(t)
ori_t = t
if scount != tcount:
	print(-1)
	exit()
for char in s[::-1]:
	t = move_to_front(find_char(char, t), t)
print(len(ops))
print(*ops)


n = int(input())
s = input()
t = input()
s0 = sorted(list(s))
t0 = sorted(list(t))
if s0 != t0:
	print(-1)
else:
	ans = []
	for i in range(n):
		j = 0
		while s[j] != t[i]:
			j = j + 1
		ans += [n - j - 1, 1, n]
		s = ''.join(reversed(s[:j])) + s[j + 1:] + s[j]
	print(len(ans))
	print(' '.join((str(i) for i in ans)))


n = int(input())
s = input()
t = input()
if sorted(s) != sorted(t):
	print(-1)
else:
	ans = []
	for i in t:
		j = 0
		for j in range(n):
			if i == s[j]:
				break
		ans.append(n - j - 1)
		ans.append(1)
		ans.append(n)
		s = s[j - n - 1:-n - 1:-1] + s[j + 1:] + s[j]
	print(len(ans))
	for i in ans:
		print(i, end=' ')


size = int(input())
start = input()
target = input()
capture = []
first = sorted(start)
second = sorted(target)
if first != second:
	print(-1)
else:
	for x in range(size):
		similar = 0
		while start[similar] != target[x]:
			similar += 1
		capture.append(str(size - similar - 1))
		capture.append(str(1))
		capture.append(str(size))
		start = ''.join(reversed(start[:similar])) + start[similar + 1:] + start[similar]
	print(len(capture))
	print(' '.join(capture))


(n, s, t) = (int(input()), input(), input())
ans = []
for i in range(n):
	cur = 0
	for j in range(n - i):
		if s[j] == t[i]:
			cur = j
			break
	else:
		print(-1)
		raise SystemExit
	ans.extend([n - 1 - cur, 1, n])
	s = s[max(cur - 1, 0):0:-1] + (s[0] if cur != 0 else '') + s[cur + 1:]
print(len(ans))
print(*ans)


n = int(input())
(src, tar) = (input(), input())
ans = []

def shift(s, x):
	ans.append(x)
	return s[-x:][::-1] + s[:-x]
flag = True
for i in range(n):
	index = -1
	for j in range(n - i):
		if src[j] == tar[i]:
			index = j
			break
	if index == -1:
		flag = False
		break
	if index == n - 1:
		continue
	src = shift(src, n - index - 1)
	src = shift(src, 1)
	src = shift(src, n)
if flag:
	ans = [str(x) for x in ans]
	print(len(ans))
	print(' '.join(ans))
else:
	print(-1)


import math
import sys
input = sys.stdin.readline
result = []

def move(s, x):
	result.append(x)
	return s[-1:-1 - x:-1] + s[:len(s) - x]

def getFirst(s, need, size):
	piv = -1
	for i in range(size, len(s)):
		if s[i] == need:
			piv = i
			break
	if piv == -1:
		print(-1)
		exit(0)
	s = move(s, len(s) - piv)
	s = move(s, piv - size)
	s = move(s, size + 1)
	return s
n = int(input())
s = input().strip()
t = input().strip()
(l, r) = (len(s) // 2, len(s) // 2)
s = getFirst(s, t[l], 0)
size = 1
while size < len(s):
	if size % 2 == 1:
		l = l - 1
		s = getFirst(s, t[l], size)
	else:
		r = r + 1
		s = getFirst(s, t[r], size)
	size = size + 1
if s != t:
	s = move(s, len(s))
print(len(result))
print(' '.join(map(str, result)))


ans = []

def op(s, l):
	if l == 0:
		return s
	ans.append(l)
	return s[-l:][::-1] + s[:-l]

def reform(s, a, b, c):
	if b < c:
		s = op(s, len(s) - c - 1)
		s = op(s, c - b + 1)
		s = op(s, len(s) - c + b)
		s = op(s, c - b - 1)
		return s
	else:
		s = op(s, len(s) - b - 1)
		s = op(s, 1)
		s = op(s, b - c)
		s = op(s, n)
		s = op(s, b - c - 1)
		return s
n = int(input())
(s, t) = (input(), input())

def countSig(u):
	d = {}
	for c in u:
		if c in d:
			d[c] += 1
		else:
			d[c] = 1
	return tuple(sorted(d.items()))
if countSig(s) != countSig(t):
	print('-1')
	exit()
if t[0] != s[-1]:
	s = op(s, n - s.index(t[0]) - 1)
a = 1
while a + 2 <= len(s):
	(u, v) = (t[a], t[a + 1])
	if u == v:
		x = s.index(u)
		y = s.index(u, x + 1)
	else:
		x = s.index(u)
		y = s.index(v)
	s = reform(s, a, x, y)
	a += 2
if a < n:
	s = op(s, n - 1)
	s = op(s, 1)
	s = op(s, n)
	a = n
print(len(ans))
print(*ans)


n = int(input())
s = input()
t = input()
if sorted(s) != sorted(t):
	print(-1)
else:
	res = []
	for i in range(n):
		k = 0
		while s[k] != t[i]:
			k += 1
		res += [n - k - 1, 1, n]
		s = ''.join(reversed(s[:k])) + s[k + 1:] + s[k]
	print(len(res))
	print(*res)


def reverse(s, k):
	if not k:
		return s
	return s[-1:-k - 1:-1] + s[:-k]
n = int(input())
s = input()
t = input()
cnt = [0] * 26
for i in s:
	cnt[ord(i) - ord('a')] += 1
for i in t:
	cnt[ord(i) - ord('a')] -= 1
for i in cnt:
	if i != 0:
		print(-1)
		exit(0)
print(n * 3)
for i in t:
	mark = s.find(i)
	print(n - (mark + 1), end=' ')
	print(1, end=' ')
	print(n, end=' ')
	s = reverse(s, n - (mark + 1))
	s = reverse(s, 1)
	s = reverse(s, n)


(n, s, t) = (int(input()), input(), input())
if sorted(s) != sorted(t):
	print(-1)
else:
	ans = []

	def shift(k, cur):
		if k == 0:
			return cur
		return cur[:-k - 1:-1] + cur[:-k]

	def DO_SWAP(x):
		ans.append(x)
		return shift(x, s)
	for i in range(n):
		curr = t[i]
		j = -1
		for k in range(n - i):
			if s[k] == curr:
				j = k
				break
		s = DO_SWAP(n - j - 1)
		s = DO_SWAP(1)
		s = DO_SWAP(n - 1)
	assert s == t
	print(len(ans))
	for x in ans:
		print(x, end=' ')