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.

Examples
input
2
aa
output
1
input
4
koko
output
2
input
5
murat
output
0
先排序,用总长度减去变化的量即可
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a,cnt=,n;
char b[];
int main()
{
cin>>n;
cin>>b;
int len=strlen(b);
sort(b,b+len);
if(len>)
cout<<-<<endl;
else
{
for(int i=;i<len;i++)
{
if(b[i]!=b[i+])
cnt++;
}
cout<<len-cnt<<endl;
}

Codeforces Round #352 (Div. 2) B - Different is Good的更多相关文章

  1. Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心

    题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...

  2. Codeforces Round #352 (Div. 2) D. Robin Hood

    题目链接: http://codeforces.com/contest/672/problem/D 题意: 给你一个数组,每次操作,最大数减一,最小数加一,如果最大数减一之后比最小数加一之后要小,则取 ...

  3. Codeforces Round #352 (Div. 2) D. Robin Hood (二分答案)

    题目链接:http://codeforces.com/contest/672/problem/D 有n个人,k个操作,每个人有a[i]个物品,每次操作把最富的人那里拿一个物品给最穷的人,问你最后贫富差 ...

  4. Codeforces Round #352 (Div. 1) B. Robin Hood 二分

    B. Robin Hood 题目连接: http://www.codeforces.com/contest/671/problem/B Description We all know the impr ...

  5. Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力

    A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...

  6. Codeforces Round #352 (Div. 2) B. Different is Good 水题

    B. Different is Good 题目连接: http://www.codeforces.com/contest/672/problem/B Description A wise man to ...

  7. Codeforces Round #352 (Div. 2) A. Summer Camp 水题

    A. Summer Camp 题目连接: http://www.codeforces.com/contest/672/problem/A Description Every year, hundred ...

  8. Codeforces Round #352 (Div. 2) ABCD

    Problems     # Name     A Summer Camp standard input/output 1 s, 256 MB    x3197 B Different is Good ...

  9. Codeforces Round #352 (Div. 2)

    模拟 A - Summer Camp #include <bits/stdc++.h> int a[1100]; int b[100]; int len; void init() { in ...

随机推荐

  1. jQuery - 5.样式操作

    样式操作 1.获取样式 attr("class"), 2.设置样式attr("class","myclass"), 3.追加样式addCla ...

  2. Dubbo应用与异常记录

    结合项目里使用暴露出的问题,对并发较多的核心业务或者对请求失败等敏感的业务场景不太建议使用Dubbo, 如电商的购买等行为,使用Dubbo就必须阅读源码,熟悉相关机制,或者直接自己造轮子. >& ...

  3. SQL exists( select 1 from

    use UnlockIndustry select * from Info_Coordinate as A join Info_Employee on A.EmployeeId=Info_Employ ...

  4. 设计模式学习之中介者模式(Mediator,行为型模式)(18)

    转载地址:http://www.cnblogs.com/zhili/p/MediatorPattern.html 一.引言 在现实生活中,有很多中介者模式的身影,例如QQ游戏平台,聊天室.QQ群和短信 ...

  5. Installing MySQL Server on CentOS

    MySQL is an open-source relational database. For those unfamiliar with these terms, a database is wh ...

  6. VS2015 Preview Secondary Installer 离线安装

    VS2015 Preview Secondary Installer 离线安装 天朝的原因orz, 装过vs2015 preview 的人都懂的,第二阶段安装会失败.假公济私的研究了下VS2015,摸 ...

  7. hdu 4389 数位dp

    求区间内满足x%fx==0的数的个数,fx为该数各个位数上的数字之和Sample Input21 1011 20 Sample OutputCase 1: 10Case 2: 3 大小不是你想开,想开 ...

  8. 无法定位程序输入点 _glutCreateWindowWithExit于动态链接库glut32.dll上

    程序运行提示错误"无法定位程序输入点 _glutCreateWindowWithExit于动态链接库glut32.dll上",网上查了说是opengl的.lib和.dll版本过低, ...

  9. FZU Problem 2082 过路费 树链剖分

    Problem 2082 过路费    Problem Description 有n座城市,由n-1条路相连通,使得任意两座城市之间可达.每条路有过路费,要交过路费才能通过.每条路的过路费经常会更新, ...

  10. Codeforces Round#250 D. The Child and Zoo(并差集)

    题目链接:http://codeforces.com/problemset/problem/437/D 思路:并差集应用,先对所有的边从大到小排序,然后枚举边的时候,如果某条边的两个顶点不在同一个集合 ...