1. 程式人生 > >1038A 】Equality (思維水題,預處理字串)

1038A 】Equality (思維水題,預處理字串)

題幹:

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