| CerealCodes III Novice Division |
|---|
| Finished |
You are given two strings $$$s$$$ and $$$t$$$ of lowercase English letters each of length $$$n.$$$
For every lowercase English letter, let its value be the number of letters between it and a in the ordered alphabet (e.g. the value of a is 0, value of z is 25).
We call the reverse of a letter with value $$$val$$$ to be the letter with value $$$25-val$$$ (e.g. the reverse of a is z, the reverse of c is z).
We call the opposite of a letter with value $$$val$$$ to be the letter with value equivalent to $$$val+13\pmod{26}$$$ (e.g. the opposite of a is n, the opposite of m is b).
In one move, you choose a contiguous range of letters in $$$s$$$ and replace each letter in the range with its reverse, or replace each letter in the range with its opposite.
Determine the minimum number of moves it will take to transform $$$s$$$ into $$$t,$$$ or output $$$-1$$$ if it is not possible.
The first line contains an integer $$$n$$$ $$$(1\le n\le 10^6)$$$ — the length of the two strings.
The second line contains a string $$$s$$$ of length $$$n,$$$ consisting of lowercase English letters.
The third line contains a string $$$t$$$ of length $$$n,$$$ consisting of lowercase English letters.
Output a single integer, representing the minimum number of moves to transform $$$s$$$ into $$$t,$$$ or $$$-1$$$ if it is not possible.
5abcdeabcde
0
5aaaaaznmnm
4
1ab
-1
5ngomcmtyzk
3
7ptacnldcgacmlj
4
7ugrcnkmsgvcapz
5
| Name |
|---|


