{"problem":{"name":"Shik and Copying String","description":{"content":"#nck { width: 30px; height: auto; }Shik's job is very boring. At day $0$, his boss gives him a string $S_0$ of length $N$ which consists of only lowercase English letters. In the $i$\\-th day after day","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"agc007_f"},"statements":[{"statement_type":"Markdown","content":"#nck { width: 30px; height: auto; }Shik's job is very boring. At day $0$, his boss gives him a string $S_0$ of length $N$ which consists of only lowercase English letters. In the $i$\\-th day after day $0$, Shik's job is to copy the string $S_{i-1}$ to a string $S_i$. We denote the $j$\\-th letter of $S_i$ as $S_i[j]$.\nShik is inexperienced in this job. In each day, when he is copying letters one by one from the first letter to the last letter, he would make mistakes. That is, he sometimes accidentally writes down the same letter that he wrote previously instead of the correct one. More specifically, $S_i[j]$ is equal to either $S_{i-1}[j]$ or $S_{i}[j-1]$. (Note that $S_i[1]$ always equals to $S_{i-1}[1]$.)\nYou are given the string $S_0$ and another string $T$. Please determine the smallest integer $i$ such that $S_i$ could be equal to $T$. If no such $i$ exists, please print `-1`.\n\n## Constraints\n\n*   $1 \\leq N \\leq 1,000,000$\n*   The lengths of $S_0$ and $T$ are both $N$.\n*   Both $S_0$ and $T$ consist of lowercase English letters.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$\n$S_0$\n$T$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"agc007_f","tags":[],"sample_group":[["5\nabcde\naaacc","2\n\n$S_0$ = `abcde`, $S_1$ = `aaccc` and $S_2$ = `aaacc` is a possible sequence such that $S_2 = T$."],["5\nabcde\nabcde","0"],["4\nacaa\naaca","2"],["5\nabcde\nbbbbb","\\-1"]],"created_at":"2026-03-03 11:01:14"}}