AtCoder Regular Contest 154
B
New Place
AtCoder
⌀ 1027
原题
← AC →
翻译中…

Problem Statement

翻译中…

You are given strings $S$ and $T$ of length $N$ consisting of lowercase English letters.

翻译中…

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

翻译中…
  • Erase the first character of $S$ and insert the same character at any position of $S$.
翻译中…

Determine whether it is possible to make $S$ equal $T$, and if it is possible, find the minimum number of operations needed.

翻译中…

Constraints

翻译中…
  • $1 \le N \le 2 \times 10^5$
  • $S$ and $T$ are strings of length $N$ consisting of lowercase English letters.
翻译中…

Input

翻译中…

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

翻译中…

N
S
T

翻译中…

Output

翻译中…

If it is impossible to make $S$ equal $T$, print -1. If it is possible, print the minimum number of operations needed.

翻译中…

样例

Input #1
4
abab
abba
Output #1
2
You can make $S$ equal $T$ in two operations, as follows. - Erase the first character of $S$, and insert that character `a` at the end of $S$, making $S$ `baba`. - Erase the first character of $S$, and insert that character `b` between the $2$-nd and $3$-rd characters of $S$, making $S$ `abba`. It is impossible to make $S$ equal $T$ in one or fewer operations, so the answer is $2$.
Input #2
3
arc
cra
Output #2
2
题目信息
题号
arc154_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。