PivotOJ

Decrypting Zodiac

시간 제한: 8000ms메모리 제한: 1024MB출처: GCPC 2021BOJ 25248

문제

Original message from Zodiac

In the late 1960s, a serial killer committed his monstrous deeds. He was neither caught nor was he identified and due to a series of cryptic letters he sent to the press he was called Zodiac. It was assumed that those letters contain the killer's real name, but even to this day not all of them have been decrypted. One of the reasons for this is that the encrypted messages contain mistakes. It is not known if Zodiac made those mistakes on purpose to make the decryption harder.

For one of his first letters he used the following two step encryption scheme.2 First, he applied a Caesar cipher which means that he replaced each letter with the one that comes kk steps later in the alphabet, where kk is a fixed number between 0 and 25 inclusive. Note that for this step it is assumed that after z the alphabet starts again with a. In the second step, he cut the message into two parts at an arbitrary position and swapped the parts. It is allowed for one of the two parts to be empty, in which case the message did not change during this second step.

Normally, a simple brute force search could be used to decrypt the message. However, to do this, one needs to automatically check if a message makes sense. Since Zodiac might have made some mistakes during the first step of the encryption, this is not easy to decide.

For this reason, you decided to try another approach. You want to try meaningful candidate sentences and encrypt them and then count how many mistakes would be required to make them match with Zodiac's encrypted message.


2He did in fact not.

입력

The input consists of:

  • One line with a single integer nn (1n1.5105)(1\leq n \leq 1.5\cdot10^5), the length of the messages.
  • Two lines each with one string of length nn. The first string is the encrypted message and the second string is your guess for the decrypted message.

Both strings consist of lowercase letters a-z only.

출력

Output a single integer, the minimal number of mistakes Zodiac must have made during the encryption, assuming you correctly guessed the decrypted message.

힌트

In the first sample the message can be encrypted by Caesar shifting each letter by four, resulting in dshmeg. After this, all letters match except for the second and sixth.

In the second example we can Caesar shift by zero, then split the message in the middle and swap both halves. After this, there is only a single mismatch: s\leftrightarrowc.

In the third example the message can be encrypted by Caesar shifting by three in the first step, resulting in the message wklvlvdvdpsoh. Then, the first two letters can be cut off and swapped with the rest of the string to create lvlvdvdpsohwk. After this, only two letters will differ: p\leftrightarrowq and n\leftrightarrowh.

예제

예제 1

입력
6
drhmex
zodiac
출력
2

예제 2

입력
8
dicepara
paradise
출력
1

예제 3

입력
13
lvlvdvdqsonwk
thisisasample
출력
2
코드를 제출하려면 로그인하세요.