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. xftp permission is not allowed

    上传文件时出现此项错误: permission is not allowed, 原因: 1.可能vsfptd没有配置好 写权限没有开启 2.可能是当前的目录权限,上传的用户不具有: 比如:用户hado ...

  2. java之静态函数和静态变量

    静态变量: 静态变量好似一种成员变量,它的特点是前面有static. 普通变量会有多份,它在每个对象当中都存在,但是静态变量只有一份,它是属于类的. 静态变量的调用方法: 1.类名.变量名 Custo ...

  3. ubuntu16搭建docker私库

    测试环境如下: 一.docker的安装 安装方法请查看这里的 安装教程 二.设置普通用户 1. centos的设置方法 $ sudo gpasswd -a docker ${USER} 2. ubun ...

  4. final 子类禁止重写

    <?php //子类中编写和父类中完全一样的函数,是对父类中的函数进行重写 class BaseClass{ public function test() { echo "BaseCl ...

  5. wenfrom的简单控件和repeater控件

    简单控件 lable  转换成<span>标记 literal   空的  什么也没转换 Literal.Text=<script>alter('你好');</scrip ...

  6. gearman client的doBackground 与doNormal方法的区别

    doNormal方法是阻塞的,需要等到worker处理完之后才返回,否则一直阻塞住; doBackground 方法是非阻塞的,只要将数据发送到gearmand之后,就立马返回,不等待worker的处 ...

  7. Luogu 2114 [NOI2014]起床困难综合症

    还挺简单的. 发现这几个二进制运算并不会进位,所以我们从高到低按位贪心,一位一位计算贡献. 发现$2^{30}$刚好大于$1e9$,所以最多只要算29位. 首先算出一个全都是$0$的二进制数和一个全都 ...

  8. XML DTD语法详解

    XML DTD详解   XML DTD详解 前情提要与本文内容介绍 前面的两篇XML相关博文: 第一篇是介绍格式正规的XML: 格式正规的XML:语法 属性 实体 处理指令 样式单 CDATA节 第二 ...

  9. CodeForces 478D Red-Green Towers (DP)

    题意:给定 n 块红砖,m 块绿砖,问有多少种方式可以建造成最高的塔,每一层颜色必须一样. 析:首先要确定最高是多少层h,大约应该是用 h * (h+1) <= (m+n) * 2,然后dp[i ...

  10. Redis实现用户关注功能

    最近项目要涉及到粉丝关注问题,权衡再三还是使用Redis实现比较方便,使用Redis的有序集合可以做到根据关注的时间有序的取出列表,假设我的ID是me,别人的ID是other. 1. 添加关注 添加关 ...