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. 北京儿研所自制药一览表,宝妈们必读!<转>

    原帖地址:http://www.360doc.com/content/15/0910/22/22655489_498339090.shtml

  2. DAY10-MYSQL数据类型

    一 介绍 存储引擎决定了表的类型,而表内存放的数据也要有不同的类型,每种数据类型都有自己的宽度,但宽度是可选的 详细参考: http://www.runoob.com/mysql/mysql-data ...

  3. Hbase优化记录

    <configuration><property><name>hbase.rootdir</name><value>hdfs://gagcl ...

  4. hadoop再次集群搭建(4)-Cloudera Manager Installation

       决定选择 Cloudera Manager 进行安装,阅读官方文档,掌握大概脉络.         Cloudera Manager在集群已经实现ssh免秘钥登录,能够访问网络资源和本地资源的情 ...

  5. Eclipse中如何开启断言(Assert),方法有二

    Eclipse中如何开启断言(Assert),方法有二:1.Run -> Run Configurations -> Arguments页签 -> VM arguments文本框中加 ...

  6. java之类和对象

    类的成员: 成员变量和成员函数. 成员函数:构造函数和普通函数. 构造函数: 作用:自动对对象进行初始化 特点:1.方法名和类名一致 2.没有返回值 问: 1.我们能够定义几次构造函数? 我们可以定义 ...

  7. Linux如何修改网络环境参数

    如下设置: 检验是否可以连通,就使用ping命令ping 网关开始的时候总是现实unreachable 设置IP:sudo ifconfig eth0 133.133.133.190 netmask ...

  8. Luogu 1979 [NOIP2013] 华容道

    要优先安排历年NOIP题 考虑到要移动,肯定要先把空的格子移动到起点旁边,所以我们对于每一个询问都先bfs一次求出把空格移到起点的四个位置的最短路,而且要保证不能移动起点的方块. 只有空的格子在一个格 ...

  9. CSS相关知识和经验的碎片化记录

    1.子DIV块中设置margin-top时影响父DIV块位置的问题 解决办法1:若子DIV块中使用margin-top,则在父DIV块中添加:overflow:hidden; 解决办法2:在子DIV块 ...

  10. c# 使用protobuf格式操作 Redis

    protobuf格式介绍 1.protobuf为goole定义的类似于json的数据格式.2.最终都需要序列化为二进制形式进行传输存储.3.相对于xml,json格式来说,序列化为二进制后占用空间更小 ...