CF1151A.Maxim and Biology

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Maxim and Biology

Today in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let's call the genome the string "ACTG".

Maxim was very boring to sit in class, so the teacher came up with a task for him: on a given string ss consisting of uppercase letters and length of at least 44, you need to find the minimum number of operations that you need to apply, so that the genome appears in it as a substring. For one operation, you can replace any letter in the string ss with the next or previous in the alphabet. For example, for the letter "D" the previous one will be "C", and the next — "E". In this problem, we assume that for the letter "A", the previous one will be the letter "Z", and the next one will be "B", and for the letter "Z", the previous one is the letter "Y", and the next one is the letter "A".

Help Maxim solve the problem that the teacher gave him.

A string aa is a substring of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Input

The first line contains a single integer nn (4n504 \leq n \leq 50) — the length of the string ss.

The second line contains the string ss, consisting of exactly nn uppercase letters of the Latin alphabet.

Output

Output the minimum number of operations that need to be applied to the string ss so that the genome appears as a substring in it.

Note

In the first example, you should replace the letter "Z" with "A" for one operation, the letter "H" — with the letter "G" for one operation. You will get the string "ACTG", in which the genome is present as a substring.

In the second example, we replace the letter "A" with "C" for two operations, the letter "D" — with the letter "A" for three operations. You will get the string "ZACTG", in which there is a genome.

Samples

4
ZCTH
2
5
ZDATG
5
6
AFBAKC
16

在线编程 IDE

建议全屏模式获得最佳体验