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 (4≤n≤504≤n≤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.

Examples

input

4
ZCTH

output

2

input

5
ZDATG

output

5

input

6
AFBAKC

output

16

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.

 

 

题意:

给定一个字符串,输出字符串中连续的四位转换成“ACTG”的最小操作次数

题解:

用string进行操作,首先用string a,存储题目中给出的字符串,接着输入字符串,进行比较。

(其中,这里面有一个对C++里面输入流输出流的加速。)

注意:与a比较的时候,a的下标应该是j-i;

#include<iostream>
#include<string>
using namespace std;
string a="ACTG";
string num;
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//加速输入输出流
    int n,num_puts=3000,number;
    string num;
    cin>>n>>num;
    for(int i=0;i<n&&i+3<n;++i)
    {
        number=0;
        for(int j=i;j<i+4;++j)
        {
            number+=min(26-abs(a[j-i]-num[j]),abs(num[j]-a[j-i]));
        }
        num_puts=min(num_puts,number);
    }
    cout<<num_puts<<endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值