您的位置:首页 > Web前端

CodeForces 672B Different is Good

2016-05-14 20:39 741 查看
思路:子串不同,其实就是要每个字符都不同,记录一下就OK了

#include<bits\stdc++.h>
using namespace std;
string s;
int vis[26];
int main()
{
int n;
scanf("%d",&n);
cin >> s;
for (int i = 0;i<s.size();i++)
vis[s[i]-'a']++;
int a = 0,b=0;
for (int i = 0;i<26;i++)
{
if(vis[i]==0)
b++;
else
a+=(vis[i]-1);
}
if (b<a)
puts("-1");
else
printf("%d\n",a);

}


Description

A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.

Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants allsubstrings of his string s to
be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b",
"a", "ab", "ba", "aba".

If string s has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem
want to perform as few changes as possible.

Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s.

The second line contains the string s of length n consisting of only lowercase English letters.

Output

If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.

Sample Input

Input
2
aa


Output
1


Input
4
koko


Output
2


Input
5
murat


Output
0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: