Codeforces Round 553 (Div. 2)
A
Maxim and Biology
Codeforces
1000
原题
←B →
翻译中…

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 $s$ consisting of uppercase letters and length of at least $4$, 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 $s$ 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 $a$ is a substring of a string $b$ if $a$ can be obtained from $b$ 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 $n$ ($4 \leq n \leq 50$) — the length of the string $s$.

翻译中…

The second line contains the string $s$, consisting of exactly $n$ uppercase letters of the Latin alphabet.

翻译中…

Output

翻译中…

Output the minimum number of operations that need to be applied to the string $s$ 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.

翻译中…

样例

Input #1
4
ZCTH
Output #1
2
InputCopy OutputCopy
Input #2
5
ZDATG
Output #2
5
InputCopy OutputCopy
Input #3
6
AFBAKC
Output #3
16
InputCopy OutputCopy
题目信息
题号
1151A
时间限制
1 s
内存限制
256 MB
标签
暴力
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。