POJ 1200
#include <cstdio>
#include<string>
#include<cstring>
using namespace std;
bool Hash[16000001];
int w[500];
char s[16000001];
int main(){
int n,nc,cnt,ans,i,j,l,sum;
while(~scanf("%d%d",&n,&nc)){
cnt=0;
ans=0;
memset(w,-1,sizeof(w));
memset(Hash, false, sizeof(Hash));
scanf("%s",s);
l=strlen(s);
for(i=0;i<l&&cnt<nc;i++)
if(w[s[i]]==-1)
w[s[i]]=cnt++;
for(i=0;i<l-n+1;i++){
sum=0;
for(j=i;j<i+n;j++)
sum=sum+sum*nc+w[s[j]];
if(!Hash[sum]){
ans++;
Hash[sum]=true;
}
}
printf("%d
",ans);
}
return 0;
}