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. hdu 2020

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2020 思路:优先队列水过priority_queue #include <cstdio> ...

  2. 使用Modernizr探测HTML5/CSS3新特性(转载)

    转载地址:http://www.cnblogs.com/TomXu/archive/2011/11/18/detecting-html5-css3-features-using-modernizr.h ...

  3. Delphi中的各种字符串、String、PChar、Char数组

    参考博客:http://www.cnblogs.com/pchmonster/archive/2011/12/14/2287686.html 其中的所有代码均在Delphi7下测试通过. Delphi ...

  4. RTP timestamp与帧率及时钟频率的关系

    转自:http://blog.csdn.net/jasonhwang/article/details/7316128 RTP timestamp是用时钟频率(clock rate)计算而来表示时间的. ...

  5. Android NDK开发实例教程

    WINDOWS系统+ Eclipse + NDK+Android 最近开始学习Android平台开发,Android还没有玩转,Java也是刚入门,这又要开始在Android中调用C语言,需要利用ND ...

  6. URAL 1966 Cycling Roads 点在线段上、线段是否相交、并查集

    F - Cycling Roads     Description When Vova was in Shenzhen, he rented a bike and spent most of the ...

  7. 战斗住的DPS才是DPS,持续的执行力才是执行力

    工作久了,真的发现执行力这个东西太难被贯彻,计划时信心满满,冲劲十足,持续一段时间后就喇叭腔了.

  8. Action处理请求参数

    第一种 :Action 本身作为model对象,通过成员setter封装 (属性驱动 ) 第一种方式:<br> <form action="${pageContext.re ...

  9. 【转】使用Apache Kylin搭建企业级开源大数据分析平台

    http://www.thebigdata.cn/JieJueFangAn/30143.html 本篇文章整理自史少锋4月23日在『1024大数据技术峰会』上的分享实录:使用Apache Kylin搭 ...

  10. [转载]C++声明和定义的区别

    <C++Primer>第四版 2.3.5节中这么说到: ①变量定义:用于为变量分配存储空间,还可为变量指定初始值.程序中,变量有且仅有一个定义. ②变量声明:用于向程序表明变量的类型和名字 ...