#ARC154B. [ARC154B] New Place

[ARC154B] New Place

Score : 400400 points

Problem Statement

You are given strings SS and TT of length NN consisting of lowercase English letters.

You can repeat the following operation any number of times (possibly zero).

  • Erase the first character of SS and insert the same character at any position of SS.

Determine whether it is possible to make SS equal TT, and if it is possible, find the minimum number of operations needed.

Constraints

  • 1N2×1051 \le N \le 2 \times 10^5
  • SS and TT are strings of length NN consisting of lowercase English letters.

Input

The input is given from Standard Input in the following format:

NN

SS

TT

Output

If it is impossible to make SS equal TT, print -1. If it is possible, print the minimum number of operations needed.

4
abab
abba
2

You can make SS equal TT in two operations, as follows.

  • Erase the first character of SS, and insert that character a at the end of SS, making SS baba.
  • Erase the first character of SS, and insert that character b between the 22-nd and 33-rd characters of SS, making SS abba.

It is impossible to make SS equal TT in one or fewer operations, so the answer is 22.

3
arc
cra
2