Given a string ss of length nn and integer kk (1≤k≤n1≤k≤n). The string ss has a level xx, if xx is largest non-negative integer, such that it's possible to find in ss:

  • xx non-intersecting (non-overlapping) substrings of length kk,
  • all characters of these xx substrings are the same (i.e. each substring contains only one distinct character and this character is the same for all the substrings).

A substring is a sequence of consecutive (adjacent) characters, it is defined by two integers ii and jj (1≤i≤j≤n1≤i≤j≤n), denoted as s[i…j]s[i…j] = "sisi+1…sjsisi+1…sj".

For example, if k=2k=2, then:

  • the string "aabb" has level 11 (you can select substring "aa"),
  • the strings "zzzz" and "zzbzz" has level 22 (you can select two non-intersecting substrings "zz" in each of them),
  • the strings "abed" and "aca" have level 00 (you can't find at least one substring of the length k=2k=2 containing the only distinct character).

Zuhair gave you the integer kk and the string ss of length nn. You need to find xx, the level of the string ss.

Input

The first line contains two integers nn and kk (1≤k≤n≤2⋅1051≤k≤n≤2⋅105) — the length of the string and the value of kk.

The second line contains the string ss of length nn consisting only of lowercase Latin letters.

Output

Print a single integer xx — the level of the string.

Examples

Input

8 2
aaacaabb

Output

2

Input

2 1
ab

Output

1

Input

4 2
abab

Output

0

Note

In the first example, we can select 22 non-intersecting substrings consisting of letter 'a': "(aa)ac(aa)bb", so the level is 22.

In the second example, we can select either substring "a" or "b" to get the answer 11.

思路:从'a'-'z'枚举即可

代码:

#include<cstring>
#include<algorithm>
#include<cstdio>
#include<iostream> using namespace std;
char a[200005]; int main()
{ int n,k;
cin>>n>>k;
getchar();
scanf("%s",a);
int len=strlen(a);
int maxn=0;
for(char t='a';t<='z';t++)
{ int sum=0;
int ss=0;
for(int j=0;j<len;j++)
{
if(a[j]!=t)
{
sum+=ss/k;
ss=0;
}
else
{
ss++;
}
}
sum+=ss/k;
maxn=max(sum,maxn);
}
cout<<maxn<<endl; return 0;
}

CodeForces-Zuhair and Strings(思维+枚举)的更多相关文章

  1. Codeforces Round #533 (Div. 2) B. Zuhair and Strings 【模拟】

    传送门:http://codeforces.com/contest/1105/problem/B B. Zuhair and Strings time limit per test 1 second ...

  2. Codeforces 1105B:Zuhair and Strings(字符串水题)

    time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: sta ...

  3. CodeForces - 593A -2Char(思维+暴力枚举)

    Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is th ...

  4. Codeforces Round #533(Div. 2) B.Zuhair and Strings

    链接:https://codeforces.com/contest/1105/problem/B 题意: 给一个字符串和k,连续k个相同的字符,可使等级x加1, 例:8 2 aaacaabb 则有aa ...

  5. Codeforces Round #533 (Div. 2) B. Zuhair and Strings(字符串)

    #include <bits/stdc++.h> using namespace std; int main() { int n,k;cin>>n>>k; stri ...

  6. Codeforces C. Maximum Value(枚举二分)

    题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Codeforces Gym 100002 B Bricks 枚举角度

    Problem B Bricks" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100002 ...

  8. Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861B Which floor?【枚举,暴力】

    B. Which floor? time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

  9. Codeforces 626E Simple Skewness(暴力枚举+二分)

    E. Simple Skewness time limit per test:3 seconds memory limit per test:256 megabytes input:standard ...

随机推荐

  1. 基于:Hadoop 2.6.0-cdh5.4.0 hive1.1.0 HBase 1.0.0-cdh5.4.0 关键配置文件

    core-site.xml <configuration> <property> <name>fs.defaultFS</name> <value ...

  2. sql中的Alias怎么用

    一直很奇怪,不知道为什么sql的Alias怎么用,上次看到ThinkPHP中的讲解,为什么数据库在用的时候有时候喜欢改个别名再用, 因为昨天去参加了公司的数据库开发工程师的笔试,今天就复习一下sql, ...

  3. jquery.pagination.js使用

    直接上代码: <script type="text/javascript"> var pageIndex = 1; //页面索引初始值 var pageSize = 1 ...

  4. 业务逻辑:五、完成认证用户的动态授权功能 六、完成Shiro整合Ehcache缓存权限数据

    一. 完成认证用户的动态授权功能 提示:根据当前认证用户查询数据库,获取其对应的权限,为其授权 操作步骤: 在realm的授权方法中通过使用principals对象获取到当前登录用户 创建一个授权信息 ...

  5. Python 网络爬虫 004 (编程) 如何编写一个网络爬虫,来下载(或叫:爬取)一个站点里的所有网页

    爬取目标站点里所有的网页 使用的系统:Windows 10 64位 Python语言版本:Python 3.5.0 V 使用的编程Python的集成开发环境:PyCharm 2016 04 一 . 首 ...

  6. js获取指定小时日期格式化

    不得不感叹一下,聪明的程序员写的代码真是让人惊奇 找了一圈格式化代码的方式,下面的这个使用了一个 slice 函数,真是厉害 https://stackoverflow.com/questions/4 ...

  7. WordCount编码与测试

    1. github项目地址:https://github.com/wwwwu/WordCount 2.PSP表格: PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟) Planning ...

  8. 基于docker虚拟化创建hadoop集群

    最近想用hadoop做一个测试,与性能无关的测试,但是可与屌丝的命,手头没有太多机器,也租不起云主机.这里使用docker进行虚拟化,并搭建hadoop集群,在这里将过程记录如下. 首先安装docke ...

  9. 双击获取GridView控件行信息

    有网友要求在GridView控件上,不管是单击(onclick)还是双击(ondblclick),想获取所击行的信息.技术难度是为GridView的行注册单击或是双击事件.看例子吧:在数据库中创建数据 ...

  10. Gazebo学习随记1 Gazebo概览

    Gazebo组件 World 世界 包含模拟中所有的元素如机器人,灯光,传感器等等 使用SDF(模拟描述格式)格式化 [用XML语言描述] 拓展名.world Model 模型 只包含一个<mo ...