{"trustable":false,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n section pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"Problem Statement","value":{"format":"MD","content":"毕加索的传人,抽象派大师,香风智乃收到了一幅画!\n这幅画可以抽象为一个长度为 n 的仅包含小写字母的字符串。\n作为抽象派大师,她想改一改这幅画(记为 S_0)。\n智乃可以创作若干幅新的画,其中新的画(记为第 j 幅画)的第 i 个位置可以和上一幅画的第 i 个位置画相同颜色,或者和这幅画的第 i-1 个位置画相同颜色,即 S_j(i)\u003dS_{j-1}(i) 或 S_j(i-1)。\n智乃想通过这种方式,创造出一幅画,使得其与另一幅画 T 一样。\n由于智乃忙着泡咖啡,于是想请你帮忙她算一下她最少要新创作多少幅画。"}},{"title":"Constraints","value":{"format":"MD","content":"1 \\leq N \\leq 10^6\nS_0 和 T 的长度均为 N。\n"}},{"title":"Input","value":{"format":"MD","content":"第一行一个正整数 N。\n第二行一个字符串 S_0。\n第三行一个字符串 T。"}},{"title":"Output","value":{"format":"MD","content":"输出一个最小的 i 使得 S_i\u003dT。如果这样的 i 不存在,那么输出 `-1`。"}},{"title":"Sample Input 1","value":{"format":"MD","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e5\nedcba\neeecc\n\u003c/pre\u003e"}},{"title":"Sample Output 1","value":{"format":"MD","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e2\n\u003c/pre\u003e \nS_0\u003dedcba,S_1\u003deeccc,S_2\u003deeecc"}},{"title":"Sample Input 2","value":{"format":"MD","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e4\nacbd\nacbd\n\u003c/pre\u003e"}},{"title":"Sample Output 2","value":{"format":"MD","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e0\n\u003c/pre\u003e"}},{"title":"Sample Input 3","value":{"format":"MD","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e4\ncacc\nccac\n\u003c/pre\u003e"}},{"title":"Sample Output 3","value":{"format":"MD","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e2\n\u003c/pre\u003e"}},{"title":"Sample Input 4","value":{"format":"MD","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e5\nabcde\nccccc\n\u003c/pre\u003e"}},{"title":"Sample Output 4","value":{"format":"MD","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e-1\n\u003c/pre\u003e"}}]}