题干:

You are given a string ss of length nn, which consists only of the first kk letters of the Latin alphabet. All letters in string ss are uppercase.

A subsequence of string ss is a string that can be derived from ss by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD" are subsequences of "ABCDE", but "DEA" is not.

A subsequence of ss called good if the number of occurences of each of the first kkletters of the alphabet is the same.

Find the length of the longest good subsequence of ss.

Input

The first line of the input contains integers nn (1≤n≤1051≤n≤105) and kk (1≤k≤261≤k≤26).

The second line of the input contains the string ss of length nn. String ss only contains uppercase letters from 'A' to the kk-th letter of Latin alphabet.

Output

Print the only integer — the length of the longest good subsequence of string ss.

Examples

Input

9 3
ACAABCCAB

Output

6

Input

9 4
ABCABCABC

Output

0

Note

In the first example, "ACBCAB" ("ACAABCCAB") is one of the subsequences that has the same frequency of 'A', 'B' and 'C'. Subsequence "CAB" also has the same frequency of these letters, but doesn't have the maximum possible length.

In the second example, none of the subsequences can have 'D', hence the answer is 00.

解题报告:

这题还是自己要读一遍,先解释了一遍子序列的概念,,这个很有往错误的方向诱导。。

本来想着二分长度做,看数据量也刚刚好,但是做的时候发现根本不需要,其实就是很简单的一个预处理就ojbk了。

AC代码:

#include<bits/stdc++.h>using namespace std;
const int MAX = 2e5 + 5;
char s[MAX];
int bk[55];
int main()
{int n,k;cin>>n>>k;cin>>s;int len = strlen(s);for(int i = 0; i<len; i++) {bk[s[i]-'A']++;}int minn = 0x3f3f3f3f;for(int i = 0; i<k; i++) {minn = min(minn,bk[i]);}cout << minn*k << endl;return 0 ;
}//18:04 - 18:17

【CodeForces - 1038A 】Equality (思维水题,预处理字符串)相关推荐

  1. codeforces 1060a(思维水题)

    Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", ...

  2. FZU 2230 2230 翻翻棋(思维水题)

    Problem Description 象棋翻翻棋(暗棋)中双方在4*8的格子中交战,有时候最后会只剩下帅和将.根据暗棋的规则,棋子只能上下左右移动,且相同的级别下,主动移动到地方棋子方将吃掉对方的棋 ...

  3. 【CodeForces - 289C】Polo the Penguin and Strings (水题,字符串,思维构造,有坑)

    题干: Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wa ...

  4. CF Round #426 (Div. 2) The Useless Toy 思维 水题

    题目链接: http://codeforces.com/contest/834/problem/A 题目描述: 输入起始状态和结束状态和数列长度, 判断旋转方向是顺时针逆时针还是不合理 解题思路: 长 ...

  5. 【CodeForces - 798A】Mike and palindrome (回文串,水题,字符串问题)

    题干: Mike has a string s consisting of only lowercase English letters. He wants to change exactly one ...

  6. 【CodeForces - 1066A~E】水题,模拟(有技巧),思维,题意难懂的模拟,二进制问题(有技巧)

    A. 题目大意: x坐标上1~L有L个点都是整数,每v个长度就有一个灯亮着,但是有 [ l , r ] 这段区间上有列火车挡住了,问你能看到多少亮灯. 解题报告: 大水题啊,找几个样例就会发现需要特殊 ...

  7. CodeForces - 622C Not Equal on a Segment(思维+水题)

    题目链接:点击查看 题目大意:先给出一个长度为n的数列,然后给出m次询问,每次询问的格式是l,r,x,其中[l,r]代表的是数列的下标范围,要求我们输出任意一个在区间[l,r]内值不等于x的下标 题目 ...

  8. 【CodeForces - 707B】Bakery(思维水题)

    Bakery Descriptions 玛莎想在从1到n的n个城市中开一家自己的面包店,在其中一个城市烘焙松饼. 为了在她的面包房烘焙松饼,玛莎需要从一些储存的地方建立面粉供应.只有k个仓库,位于不同 ...

  9. 【 CodeForces - 864B】Polycarp and Letters(水题,字符串,有坑)

    题干: Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string sconsisting o ...

最新文章

  1. “AI开发者大会”早鸟票抢购倒计时开始~
  2. Java动态代理代码快速上手
  3. es查询大文本效率_es中terms查询速度能否优化
  4. 类型转换,类与类之间的转换,继承关系,继承与静态变量,子类父类重名,多继承,虚基类
  5. c语言作业小学生测试题,C语言实现小学生随机出题测试计分
  6. PHP中抽象类与接口的应用场景
  7. 【转】SVN trunk(主线) branch(分支) tag(标记) 用法详解和详细操作步骤
  8. Linux系统json文件打中文,如何在 Linux 终端上漂亮地打印 JSON 文件
  9. exls导入数据库 php_PHP 利用 PHPexcel 导入数据库
  10. 专家教你如何设置无线路由器 享受无线乐趣
  11. 免费文件分发服务器,文件分发服务器 AWS CloudFront(CDN)使用入门-以S3为例 Lebal:Research...
  12. linux系统连接实验室服务器步骤详解
  13. python爬取wifi密码完整代码_WIFIpass – Python获取本机保存的所有WIFI密码(附源代码)...
  14. 四川大学2019计算机考研,四川大学考研全攻略篇(各学院2019年考研详解、报考建议...)...
  15. 使用Vscode调试vue代码
  16. android studio 运行闪退,ubuntu上在androidstudio中启动emulator闪退的解决方法
  17. 大数据平台,Hadoop集群架构,概述及原理
  18. 使用机器人操作系统ROS 2和仿真软件Gazebo 9搭建机器人教程(一)
  19. android随机数1 100,android 产生0~100之间的随机数
  20. 蔡高厅高等数学 06 数列极限的定义、数列收敛的性质1

热门文章

  1. JSP中使用iframe导致内层网页CSS失效问题的解决方案
  2. android p 权限控制,android 权限控制
  3. 常州win8如何禁用应用商店_Win8系统当中Windows defnedder安全软件应该如何禁用?...
  4. azure linux 磁盘,在Azure Linux VM中,还有什么?什么磁盘收费?
  5. linux脚本ls输出到变量中,bash – 将命令输出的错误消息存储到shell变量中
  6. java spring包_java 自定义加载器,加载spring包,动态加载实现,jar包隔离,tomcat加载webapp方式...
  7. python工作台_FreeCAD二次开发-创建Python工作台,添加菜单栏和工具条,FreeCAD命令
  8. activemq jdbc mysql_activeMQ JDBC Master Slave
  9. pcb板子开窗_PCB 层定义
  10. 竞赛图 计算机网络 应用题,我校学子获2020年“中国高校计算机大赛-网络技术挑战赛”全国总决赛一等奖(图)...