#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <string.h>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <math.h>
#include <algorithm>
#include <utility>
#include <assert.h>
#include <time.h>
#include <limits>
#include <fstream>
#include <map>
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define FORD(i,a,b) for (int i=a; i>=b; i--)
#define INF numeric_limits<int> :: max()
#define p_b push_back
#define m_p make_pair
#define F first
#define S second
#define eps 1e-12

#ifdef WIN32
 #define I64 "%I64d"
 #else
 #define I64 "%lld"
#endif

using namespace std;
int n,k;
char a[100001];

int main()
{
 #ifndef ONLINE_JUDGE
 freopen("input.txt","rt",stdin);
 freopen("output.txt","wt",stdout);
 #endif
 scanf("%d %d\n",&n,&k);
 FOR(i,1,n) scanf("%c",&a[i]);
 for (int i=1; i<n && k>0; i++)
  {
    if (i%2==0)
     {
       if (a[i]=='4' && a[i+1]=='7' && a[i-1]=='4')
       if (k%2==0) a[i]=='7';
     }

    if (a[i]=='4' && a[i+1]=='7')
     {
      if (i%2==0) a[i]='7',a[i+1]='7',i-=2; else a[i]='4',a[i+1]='4',i--;
      k--;
     }
  }

 FOR(i,1,n) cout<<a[i];
 fclose(stdin); fclose(stdout);
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <string.h>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <math.h>
#include <algorithm>
#include <utility>
#include <assert.h>
#include <time.h>
#include <limits>
#include <fstream>
#include <map>
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define FORD(i,a,b) for (int i=a; i>=b; i--)
#define INF numeric_limits<int> :: max()
#define p_b push_back
#define m_p make_pair
#define F first
#define S second
#define eps 1e-12

#ifdef WIN32
 #define I64 "%I64d"
 #else
 #define I64 "%lld"
#endif

using namespace std;
int n,k;
char a[100001];

int main()
{
 #ifndef ONLINE_JUDGE
 freopen("input.txt","rt",stdin);
 freopen("output.txt","wt",stdout);
 #endif
 scanf("%d %d\n",&n,&k);
 FOR(i,1,n) scanf("%c",&a[i]);
// if (k>10000000)
// if (k%2==0) k/=2; else k=k/2+1;
 for (int i=1; i<n && k>0; i++)
  {
    if (a[i]=='4' && a[i+1]=='7')
     {
      if (i%2==0) a[i]='7',a[i+1]='7',i-=2; else a[i]='4',a[i+1]='4',i--;
      --k;
     }
     if (a[i]=='4' && (a[i+1]=='4' || a[i+1]=='7') && a[i+2]=='7')
     {
     if (i%2==0) a[i+1]=='4'; else a[i+1]='7';
     break;
     }
  }

 FOR(i,1,n) cout<<a[i];
 fclose(stdin); fclose(stdout);
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <string.h>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <math.h>
#include <algorithm>
#include <utility>
#include <assert.h>
#include <time.h>
#include <limits>
#include <fstream>
#include <map>
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define FORD(i,a,b) for (int i=a; i>=b; i--)
#define INF numeric_limits<int> :: max()
#define p_b push_back
#define m_p make_pair
#define F first
#define S second
#define eps 1e-12

#ifdef WIN32
 #define I64 "%I64d"
 #else
 #define I64 "%lld"
#endif

using namespace std;
int n,k;
char a[100001];

int main()
{
 #ifndef ONLINE_JUDGE
 freopen("input.txt","rt",stdin);
 freopen("output.txt","wt",stdout);
 #endif
 scanf("%d %d\n",&n,&k);
 FOR(i,1,n) scanf("%c",&a[i]);
// if (k>10000000)
// if (k%2==0) k/=2; else k=k/2+1;
 for (int i=1; i<n && k>0; i++)
  {
    if (a[i]=='4' && a[i+1]=='7')
     {
      if (i%2==0) a[i]='7',a[i+1]='7',i-=2; else a[i]='4',a[i+1]='4',i--;
      --k;
     }
     if (i+2<n &&
     a[i]=='4' && (a[i+1]=='4' || a[i+1]=='7') && a[i+2]=='7') break;
  }

 FOR(i,1,n) cout<<a[i];
 fclose(stdin); fclose(stdout);
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <string.h>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <math.h>
#include <algorithm>
#include <utility>
#include <assert.h>
#include <time.h>
#include <limits>
#include <fstream>
#include <map>
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define FORD(i,a,b) for (int i=a; i>=b; i--)
#define INF numeric_limits<int> :: max()
#define p_b push_back
#define m_p make_pair
#define F first
#define S second
#define eps 1e-12

#ifdef WIN32
 #define I64 "%I64d"
 #else
 #define I64 "%lld"
#endif

using namespace std;
int n,k;
char a[100001];

int main()
{
 #ifndef ONLINE_JUDGE
 freopen("input.txt","rt",stdin);
 freopen("output.txt","wt",stdout);
 #endif
 scanf("%d %d\n",&n,&k);
 FOR(i,1,n) scanf("%c",&a[i]);
 for (int i=1; i<n && k>0; i++)
  {
    if (i%2==0)
     {
       if (a[i]=='4' && a[i+1]=='7' && a[i-1]=='4')
//       cout<<i<<" "<<k<<" \n";
       if (k%2==0) {a[i]='7'; break;}

     }

    if (a[i]=='4' && a[i+1]=='7')
     {
      if (i%2==0) a[i]='7',a[i+1]='7'; else a[i]='4',a[i+1]='4';
      k--;
     }

  }

 FOR(i,1,n) cout<<a[i];
 fclose(stdin); fclose(stdout);
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;
int const INF = (1<<30);
int const MAXN = (int)1e5+100;

int n,k;
int d[MAXN];
int four[MAXN],size;

void show(){
	for ( int i=1;i<=n;i++){
		cout <<d[i];
	}
	cout <<endl;
}

int main (){
	#ifdef LOCAL
	freopen ("input.txt","r",stdin);
	freopen ("output.txt","w",stdout);
	#endif
	cin >>n>>k;
	int cur = 0;
	for ( int i=1;i<=n;i++){
		char t;
		cin >>t;
		d[i] = t-'0';
		if ( d[i]==4){
			four[size++] = i;
		}
	}

	for ( int i=1;i<=k;i++){
		bool ok = false;
		for (int j=1;j<=n;j++){
			int ind = j;
			if ( d[ind+1] == 7 && d[ind]==4){
				ok = true;
				if (ind%2==0){
					d[ind] = 7;
					if ( d[ind-1] == 4){
						if ( (k-i)%2==1){
							d[ind] = 4;
						}
						show();
						return 0;
					}
					break;
				}
				else {
					d[ind+1] = 4;
					cur = j+1;
					break;
				}
			}
		}
		if (!ok){
			show();
			return 0;
		}
	}
	show();

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;
int const INF = (1<<30);
int const MAXN = (int)1e5+100;

int n,k;
int d[MAXN];
int four[MAXN],size;

void show(){
	for ( int i=1;i<=n;i++){
		cout <<d[i];
	}
}

int main (){
	#ifdef LOCAL
	freopen ("input.txt","r",stdin);
	freopen ("output.txt","w",stdout);
	#endif
	cin >>n>>k;
	int cur = 0;
	for ( int i=1;i<=n;i++){
		char t;
		cin >>t;
		d[i] = t-'0';
		if ( d[i]==4){
			four[size++] = i;
		}
	}

	int last = -1;
	for ( int i=1;i<=k;i++){
		for (int j=cur;j<size;j++){
			int ind = four[j];
			if ( d[ind+1] == 7){
				if (ind%2==0){
					d[ind] = 7;
					cur = j+1;
					if ( d[ind-1] == 4){
						last = i;
						if ( (k-i)%2==1){
							d[ind] = 4;
						}
						show();
						return 0;
					}
					break;
				}
				else {
					d[ind+1] = 4;
					cur = j+1;
					break;
				}
			}
			else
				cur = j+1;
		}
		if (cur>=size){
			show();
			return 0;
		}
	}
	show();

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;
int const INF = (1<<30);
int const MAXN = (int)1e5+100;

int n,k;
int d[MAXN];
int four[MAXN],size;

void show(){
	for ( int i=1;i<=n;i++){
		cout <<d[i];
	}
	cout <<endl;
}

int main (){
	#ifdef LOCAL
	freopen ("input.txt","r",stdin);
	freopen ("output.txt","w",stdout);
	#endif
	cin >>n>>k;
	for ( int i=1;i<=n;i++){
		char t;
		cin >>t;
		d[i] = t-'0';
		if ( d[i]==4){
			four[size++] = i;
		}
	}

	int cur = 1;
	for ( int i=1;i<=k;i++){
		bool ok = false;
		for (int j=cur;j<=n;j++){
			int ind = j;
			if ( d[ind+1] == 7 && d[ind]==4){
				ok = true;
				if (ind%2==0){
					d[ind] = 7;
					cur = j+1;
					if ( d[ind-1] == 4){
						if ( (k-i)%2==1){
							d[ind] = 4;
						}
						show();
						return 0;
					}
					break;
				}
				else {
					d[ind+1] = 4;
					cur = j+1;
					break;
				}
			}
		}
		if (!ok || cur>=n){
			show();
			return 0;
		}
	}
	show();

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;
int const INF = (1<<30);
int const MAXN = (int)1e5+100;

int n,k;
int d[MAXN];
int four[MAXN],size;

void show(){
	for ( int i=1;i<=n;i++){
		cout <<d[i];
	}
}

int main (){
	#ifdef LOCAL
	freopen ("input.txt","r",stdin);
	freopen ("output.txt","w",stdout);
	#endif
	cin >>n>>k;
	int cur = 0;
	for ( int i=1;i<=n;i++){
		char t;
		cin >>t;
		d[i] = t-'0';
		if ( d[i]==4){
			four[size++] = i;
		}
	}

	int last = -1;
	for ( int i=1;i<=k;i++){
		for (int j=cur;j<size;j++){
			int ind = four[j];
			if ( d[ind+1] == 7){
				if (ind%2==0){
					d[ind] = 7;
					cur = j+1;
					if ( d[ind-1] == 4){
						last = i;
						if ( (k-i)%2==1){
							d[ind] = 4;
						}
						show();
						return 0;
					}
					break;
				}
				else {
					d[ind+1] = 4;
					cur = j+1;
					break;
				}
			}
		}
		if (cur>=size){
			show();
			return 0;
		}
	}
	show();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v;
#define char_to_int(x) x-'A'
typedef long long ll;
int main(){
    int n,k;
    while(cin>>n>>k){
        v.assign(27,0);
        char s;
        for(int i=0;i<n;i++){
            cin>>s;
            v[char_to_int(s)]+=1;
        }
        sort(v.begin(),v.end());
        long long ans=0;
        int i=v.size()-1;
        while(k>0 && i>0){
            //cout<<"v["<<i<<"]:"<<v[i]<<" k:"<<k<<endl;
            if(v[i]<=k){
                k=k-v[i];
                ans+=ll(v[i])*ll(v[i]);
            }else{
                ans+=ll(k)*ll(k);
                k=0;
            }
            i--;
        }
        cout<<ans<<endl;
    }
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
    int n;
    long long int k;
    string s="JYYJUBJYJY";
    cin>>n>>k;
    char c;
    vector<int>v(26);
    while(n--){
        cin>>c;

        v[c-'A']++;
    }
    sort(v.begin(),v.end());
    long long int ans=0;
    long long int m;
    for(int i=25;i>=0&&k;i--){
        if(k<=v[i]) m=k;
        else m=v[i];

        ans+=m*m;
        k-=m;
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

long long int n,k;
cin>>n>>k;
char c;
vector<int>v(26);
while(n--){
    cin>>c;
    v[c-'A']++;
}
sort(v.begin(),v.end());
long long int ans=0;
for(int i=25;i>=0&&k;i--){
        ans+=min(k,v[i])*min(k,v[i]);
        k-=min(k,v[i]);
    }
    cout<<ans<<endl;
return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
    long long int n,k;
    cin>>n>>k;
    char c;
    vector<int>v(26);
    while(n--){
        cin>>c;
        v[c-'A']++;
    }
    sort(v.begin(),v.end());
    long long int ans=0;
    long long int m;
    for(int i=25;i>=0&&k;i--){
        if(k<=v[i]) m=k;
        else m=v[i];

        ans+=m*m;
        k-=m;
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    char c;
    vector<int>v(26);
    while(n--){
        cin>>c;
        v[c-'A']++;
    }
    sort(v.begin(),v.end());
    long long int ans=0;
    int m;
    for(int i=25;i>=0&&k;i--){
        if(k<=v[i]) m=k;
        else m=v[i];

        ans+=m*m;
        k-=m;
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
std::ios::sync_with_stdio(0);
long long int n,k;
cin>>n>>k;
char c;
vector<int>v(26);
while(n--){
    cin>>c;
    v[c-'A']++;
}
sort(v.begin(),v.end());
long long int ans=0;
for(int i=25;i>=0&&k;i--){
        ans+=min(k,v[i])*min(k,v[i]);
        k-=min(k,v[i]);
    }
    cout<<ans<<endl;
return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    char c;
    vector<int>v(26);
    while(n--){
        cin>>c;
        v[c-'A']++;
    }
    sort(v.begin(),v.end());
    long long int ans=0;
    for(int i=25;i>=0&&k;i--){
        long long int m=min(k,v[i]);

        ans+=m*m;
        k-=m;

    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
    int n;
    long long int k;
    string s="JYYJUBJYJY";
    cin>>n>>k;
    char c;
    vector<int>v(26);
    while(n--){
        cin>>c
        v[c-'A']++;
    }
    sort(v.begin(),v.end());
    long long int ans=0;
    long long int m;
    for(int i=25;i>=0&&k;i--){
        if(k<=v[i]) m=k;
        else m=v[i];

        ans+=m*m;
        k-=m;
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
    int n;
    long long int k;
    string s="JYYJUBJYJY";
    cin>>n>>k;
    char c;
    vector<int>v(26);
    while(n--){
        c=s[n%10];

        v[c-'A']++;
    }
    sort(v.begin(),v.end());
    long long int ans=0;
    long long int m;
    for(int i=25;i>=0&&k;i--){
        if(k<=v[i]) m=k;
        else m=v[i];

        ans+=m*m;
        k-=m;
        cout<<"KK"<<k<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
    int n;
    long long int k;
    cin>>n>>k;
    char c;
    vector<int>v(26);
    while(n--){
        cin>>c;
        v[c-'A']++;
    }
    sort(v.begin(),v.end());
    long long int ans=0;
    for(int i=25;i>=0&&k;i--){
        if(k<=v[i]){
            ans+=k*k;
            k-=k;
        }
        else{
            ans+=v[i]*v[i];
            k-=v[i];
        }

    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
    int n;
    int k;
    cin>>n>>k;
    char c;
    vector<int>v(26);
    while(n--){
        cin>>c;
        v[c-'A']++;
    }
    sort(v.begin(),v.end());
    long long int ans=0;
    for(int i=25;i>=0&&k;i--){
        if(k<=v[i]){
            ans+=(long long)k*(long long)k;
            k-=k;
        }
        else{
            ans+=v[i]*v[i];
            k-=v[i];
        }

    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#typedef long long ll;
bool comp(int x,int y)
{
   return x>y;
}
int main()
{
	int n,k;
	cin>>n>>k;
	int a[100]={0};
	//pair<int,char>p;
	for(int i=0;i<n;++i)
	{
		char c;
		cin>>c;
		a[c]++;
	}
	sort(a,a+100,comp);
/*    for(int i=0;i<100;++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<"\n";*/
	int count=0;
	ll sum=0;
	while(k!=0)
	{
		if(a[count]<=k)
		{
			k-=a[count];
			sum+=a[count]*a[count];
			++count;
		}
		else
		{
			//cout<<"##"<<k<<"\n";
			sum+=(k*k);
			k=0;
		}
	}
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool comp(int x,int y)
{
   return x>y;
}
int main()
{
	int n,k;
	cin>>n>>k;
	int a[100]={0};
	//pair<int,char>p;
	for(int i=0;i<n;++i)
	{
		char c;
		cin>>c;
		a[c]++;
	}
	sort(a,a+100,comp);
/*	for(int i=0;i<100;++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<"\n";*/
	int count=0;
	int sum=0;
	while(k!=0)
	{
		if(a[count]>k)
		{
			++count;
		}
		else if(a[count]!=0)
		{
			k-=a[count];
			sum+=a[count]*a[count];
			++count;
		}
		else
		{
			k-=1;
			sum+=1;
		}
	}
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool comp(ll x,ll y)
{
   return x>y;
}
int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[100]={0};
	//pair<int,char>p;
	for(ll i=0;i<n;++i)
	{
		char c;
		cin>>c;
		a[c]++;
	}
	sort(a,a+100,comp);
/*    for(int i=0;i<100;++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<"\n";*/
	int count=0;
	ll sum=0;
	while(k!=0)
	{
		if(a[count]<=k)
		{
			k-=a[count];
			sum+=a[count]*a[count];
			++count;
		}
		else
		{
			//cout<<"##"<<k<<"\n";
			sum+=(k*k);
			k=0;
		}
	}
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool comp(int x,int y)
{
   return x>y;
}
int main()
{
	int n,k;
	cin>>n>>k;
	int a[100]={0};
	//pair<int,char>p;
	for(int i=0;i<n;++i)
	{
		char c;
		cin>>c;
		a[c]++;
	}
	sort(a,a+100,comp);
/*	for(int i=0;i<100;++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<"\n";*/
	int count=0;
	int sum=0;
	while(k!=0)
	{
		if(a[count]>k)
		{
			++count;
		}
		else if(a[count]!=0)
		{
			k-=a[count];
			sum+=a[count]*a[count];
			++count;
		}
		else
		{
			sum+=(k*k);
			k=0;
		}
	}
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool comp(int x,int y)
{
   return x>y;
}
int main()
{
	ll n,k;
	cin>>n>>k;
	int a[100]={0};
	//pair<int,char>p;
	for(ll i=0;i<n;++i)
	{
		char c;
		cin>>c;
		a[c]++;
	}
	sort(a,a+100,comp);
/*    for(int i=0;i<100;++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<"\n";*/
	int count=0;
	ll sum=0;
	while(k!=0)
	{
		if(a[count]<=k)
		{
			k-=a[count];
			sum+=a[count]*a[count];
			++count;
		}
		else
		{
			//cout<<"##"<<k<<"\n";
			sum+=(k*k);
			k=0;
		}
	}
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool comp(int x,int y)
{
   return x>y;
}
int main()
{
	int n,k;
	cin>>n>>k;
	int a[100]={0};
	//pair<int,char>p;
	for(int i=0;i<n;++i)
	{
		char c;
		cin>>c;
		a[c]++;
	}
	sort(a,a+100,comp);
/*    for(int i=0;i<100;++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<"\n";*/
	int count=0;
	ll sum=0;
	while(k!=0)
	{
		if(a[count]<=k)
		{
			k-=a[count];
			sum+=a[count]*a[count];
			++count;
		}
		else
		{
			//cout<<"##"<<k<<"\n";
			sum+=(k*k);
			k=0;
		}
	}
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool comp(ll x,ll y)
{
   return x>y;
}
int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[100]={0};
	//pair<int,char>p;
	for(ll i=0;i<n;++i)
	{
		char c;
		cin>>c;
		a[c]++;
	}
	sort(a,a+100,comp);
/*    for(int i=0;i<100;++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<"\n";*/
	ll count=0;
	ll sum=0;
	while(k!=0)
	{
		if(a[count]<=k)
		{
			k-=a[count];
			sum+=a[count]*a[count];
			++count;
		}
		else
		{
			//cout<<"##"<<k<<"\n";
			sum+=(k*k);
			k=0;
		}
	}
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool comp(int x,int y)
{
   return x>y;
}
int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[100]={0};
	//pair<int,char>p;
	for(ll i=0;i<n;++i)
	{
		char c;
		cin>>c;
		a[c]++;
	}
	sort(a,a+100,comp);
/*    for(int i=0;i<100;++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<"\n";*/
	int count=0;
	ll sum=0;
	while(k!=0)
	{
		if(a[count]<=k)
		{
			k-=a[count];
			sum+=a[count]*a[count];
			++count;
		}
		else
		{
			//cout<<"##"<<k<<"\n";
			sum+=(k*k);
			k=0;
		}
	}
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool comp(int x,int y)
{
   return x>y;
}
int main()
{
	int n,k;
	cin>>n>>k;
	int a[100]={0};
	//pair<int,char>p;
	for(int i=0;i<n;++i)
	{
		char c;
		cin>>c;
		a[c]++;
	}
	sort(a,a+100,comp);
/*    for(int i=0;i<100;++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<"\n";*/
	int count=0;
	int sum=0;
	while(k!=0)
	{
		if(a[count]<=k)
		{
			k-=a[count];
			sum+=a[count]*a[count];
			++count;
		}
		else
		{
			//cout<<"##"<<k<<"\n";
			sum+=(k*k);
			k=0;
		}
	}
	cout<<sum;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int cmp(int a,int b)
{
	return a>b;
}
int main()
{
	long long n,k;
	cin>>n>>k;
	string l;
	cin>>l;
	int i;
	int temp[n];
	long long flag[n];
	for(i=0;i<n;i++)
	{
		temp[i]=(int)l[i];
	}

	sort(temp,temp+n);

	long long p[n];
	for(i=0;i<n;i++)
	{
		p[i]=0;
	}
	queue <long long> rem;
	int h=temp[0];
	long long num=1;

	for(i=1;i<n;i++)
	{
		if(temp[i]==h)
		{
			num++;
		}
		else
		{
			rem.push(num);
			num=1;
			h=temp[i];
		}
	}
	rem.push(num);
	n=rem.size();
	long long last[n];

	for(i=0;i<n;i++)
	{
		last[i]=rem.front();
		rem.pop();
	}
	sort(last,last+n,cmp);

	long long sum=0;
	for(i=0;i<n;i++)
		{
			if(last[i]<=k)
				{
					sum=last[i]*last[i]+sum;
					k=k-last[i];
				}
			if(k==0 || i==0)
			{
				sum=sum+k;
				cout<<sum<<endl;
				return 0;
			}
		}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int cmp(int a,int b)
{
	return a>b;
}
int main()
{
	long long n,k;
	cin>>n>>k;
	string l;
	cin>>l;
	int i;
	int temp[n];
	long long flag[n];
	for(i=0;i<n;i++)
	{
		temp[i]=(int)l[i];
	}

	sort(temp,temp+n);

	long long p[n];
	for(i=0;i<n;i++)
	{
		p[i]=0;
	}
	queue <long long> rem;
	int h=temp[0];
	long long num=1;

	for(i=1;i<n;i++)
	{
		if(temp[i]==h)
		{
			num++;
		}
		else
		{
			rem.push(num);
			num=1;
			h=temp[i];
		}
	}
	rem.push(num);
	n=rem.size();
	long long last[n];

	for(i=0;i<n;i++)
	{
		last[i]=rem.front();
		rem.pop();
	}
	sort(last,last+n,cmp);

	long long sum=0;
	for(i=0;i<n;i++)
		{
			if(last[i]<k || last[i]==k)
				{
					sum=last[i]*last[i]+sum;
					k=k-last[i];
				}
			if(k==0 || i==n-1)
			{
				sum=sum+k;
				cout<<sum<<endl;
				return 0;
			}
		}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int cmp(int a,int b)
{
	return a>b;
}
int main()
{
	long long n,k;
	cin>>n>>k;
	string l;
	cin>>l;
	int i;
	int temp[n];
	long long flag[n];
	for(i=0;i<n;i++)
	{
		temp[i]=(int)l[i];
	}

	sort(temp,temp+n);

	long long p[n];
	for(i=0;i<n;i++)
	{
		p[i]=0;
	}
	queue <long long> rem;
	int h=temp[0];
	long long num=1;

	for(i=1;i<n;i++)
	{
		if(temp[i]==h)
		{
			num++;
		}
		else
		{
			rem.push(num);
			num=1;
			h=temp[i];
		}
	}
	rem.push(num);
	n=rem.size();
	long long last[n];

	for(i=0;i<n;i++)
	{
		last[i]=rem.front();
		rem.pop();
	}
	sort(last,last+n,cmp);

	long long sum=0;
	for(i=0;i<n;i++)
		{
			if(last[i]<=k)
				{
					sum=last[i]*last[i]+sum;
					k=k-last[i];
				}
			else {
				if(k==0 || i==0)
			{
				sum=sum+k;
				cout<<sum<<endl;
				return 0;
			}
			}
		}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int cmp(int a,int b)
{
	return a>b;
}
int main()
{
	long long n,k;
	cin>>n>>k;
	string l;
	cin>>l;
	int i;
	int temp[n];
	long long flag[n];
	for(i=0;i<n;i++)
	{
		temp[i]=(int)l[i];
	}
	sort(temp,temp+n);
	long long p[n];
	for(i=0;i<n;i++)
	{
		p[i]=0;
	}
	queue <long long> rem;
	int h=temp[0];
	long long num=1;
	for(i=1;i<n;i++)
	{
		if(temp[i]==h)
		{
			num++;
		}
		else
		{
			rem.push(num);
			num=0;
			h=temp[i];
		}
	}
	rem.push(num);
	n=rem.size();
	long long last[n];
	for(i=0;i<n;i++)
	{
		last[i]=rem.front();
		rem.pop();
	}
	sort(last,last+n,cmp);

	long long sum=0;
	for(i=0;i<n;i++)
		{
			if(last[i]<=k)
				{
					sum=last[i]*last[i]+sum;
					k=k-last[i];
				}
			if(k==0 || i==0)
			{
				sum=sum+k;
				cout<<sum<<endl;
				return 0;
			}
		}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int cmp(int a,int b)
{
	return a>b;
}
int main()
{
	long long n,k;
	cin>>n>>k;
	string l;
	cin>>l;
	int i;
	int temp[n];
	long long flag[n];
	for(i=0;i<n;i++)
	{
		temp[i]=(int)l[i];
	}

	sort(temp,temp+n);

	long long p[n];
	for(i=0;i<n;i++)
	{
		p[i]=0;
	}
	queue <long long> rem;
	int h=temp[0];
	long long num=1;

	for(i=1;i<n;i++)
	{
		if(temp[i]==h)
		{
			num++;
		}
		else
		{
			rem.push(num);
			num=1;
			h=temp[i];
		}
	}
	rem.push(num);
	n=rem.size();
	long long last[n];

	for(i=0;i<n;i++)
	{
		last[i]=rem.front();
		rem.pop();
	}
	sort(last,last+n,cmp);

	long long sum=0;
	for(i=0;i<n;i++)
		{
			if(last[i]<k || last[i]==k)
				{
					sum=last[i]*last[i]+sum;
					k=k-last[i];
				}
			else
			{
				sum=sum+k*k;
				cout<<sum<<endl;
				return 0;
			}
		}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int cmp(int a,int b)
{
	return a>b;
}
int main()
{
	long long n,k;
	cin>>n>>k;
	string l;
	cin>>l;
	int i;
	int temp[n];
	long long flag[n];
	for(i=0;i<n;i++)
	{
		temp[i]=(int)l[i];
	}

	sort(temp,temp+n);

	long long p[n];
	for(i=0;i<n;i++)
	{
		p[i]=0;
	}
	queue <long long> rem;
	int h=temp[0];
	long long num=1;

	for(i=1;i<n;i++)
	{
		if(temp[i]==h)
		{
			num++;
		}
		else
		{
			rem.push(num);
			num=1;
			h=temp[i];
		}
	}
	rem.push(num);
	n=rem.size();
	long long last[n];

	for(i=0;i<n;i++)
	{
		last[i]=rem.front();
		rem.pop();
	}
	sort(last,last+n,cmp);

	long long sum=0;
	for(i=0;i<n;i++)
		{
			if(last[i]<k || last[i]==k)
				{
					sum=last[i]*last[i]+sum;
					k=k-last[i];
				}
			if(k==0 || i==n-1)
			{
				sum=sum+k*k;
				cout<<sum<<endl;
				return 0;
			}
		}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int cmp(int a,int b)
{
	return a>b;
}
int main()
{
	long long n,k;
	cin>>n>>k;
	string l;
	cin>>l;
	int i;
	int temp[n];
	long long flag[n];
	for(i=0;i<n;i++)
	{
		temp[i]=(int)l[i];
	}

	sort(temp,temp+n);

	long long p[n];
	for(i=0;i<n;i++)
	{
		p[i]=0;
	}
	queue <long long> rem;
	int h=temp[0];
	long long num=1;

	for(i=1;i<n;i++)
	{
		if(temp[i]==h)
		{
			num++;
		}
		else
		{
			rem.push(num);
			num=1;
			h=temp[i];
		}
	}
	rem.push(num);
	n=rem.size();
	long long last[n];

	for(i=0;i<n;i++)
	{
		last[i]=rem.front();
		rem.pop();
	}
	sort(last,last+n,cmp);

	long long sum=0;
	for(i=0;i<n;i++)
		{
			if(last[i]<k || last[i]==k)
				{
					sum=last[i]*last[i]+sum;
					k=k-last[i];
					if(k==0)
					{
						cout<<sum<<endl;
						return 0;

					}
				}
			else
			{
				sum=sum+k*k;
				cout<<sum<<endl;
				return 0;
			}
		}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define open freopen("in","r",stdin)

int f[30];
int main(){
	//~ open;
	int n,m;cin>>n>>m;
	string s; cin>>s;
	for(int i = 0 ; s[i] ; ++i)	f[s[i] - 'A']++;
	vector<int>v;
	for(int i = 0 ; i < 30; ++i)	if(f[i] > 0)v.push_back(f[i]);
	sort(v.rbegin(),v.rend());

	int ans = 0;
	for(int i = 0 ; i < (int)v.size() && m; ++i){
		if(m >= v[i]){
			ans += v[i]*v[i];
			m -= v[i];
		}else{
			ans += m*m;
			m = 0;
		}
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define open freopen("in","r",stdin)

int f[30];
int main(){
	//~ open;
	int n,m;cin>>n>>m;
	string s; cin>>s;
	for(int i = 0 ; s[i] ; ++i)	f[s[i] - 'A']++;
	vector<int>v;
	for(int i = 0 ; i < 30; ++i)	if(f[i] > 0)v.push_back(f[i]);
	sort(v.rbegin(),v.rend());
	long long ans = 0;
	for(int i = 0 ; i < (int)v.size() && m; ++i){
		if(m >= v[i]){
			ans += v[i]*v[i];
			m -= v[i];
		}else{
			ans += m*m;
			m = 0;
		}
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define open freopen("in","r",stdin)

int f[30];
int main(){
	//~ open;
	int n,m;cin>>n>>m;
	string s; cin>>s;
	for(int i = 0 ; s[i] ; ++i)	f[s[i] - 'A']++;
	vector<long long>v;
	for(int i = 0 ; i < 30; ++i)	if(f[i] > 0)v.push_back(f[i]);
	sort(v.rbegin(),v.rend());
	double ans = 0;
	for(int i = 0 ; i < (int)v.size() && m; ++i){
		if(m >= v[i]){
			ans += v[i]*v[i]*1.;
			m -= v[i];
		}else{
			ans += m*m;
			m = 0;
		}
	}
	cout << setprecision(0) << fixed << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define open freopen("in","r",stdin)

int f[30];
int main(){
	//~ open;
	int n,m;cin>>n>>m;
	string s; cin>>s;
	for(int i = 0 ; s[i] ; ++i)	f[s[i] - 'A']++;
	vector<long long>v;
	for(int i = 0 ; i < 30; ++i)	if(f[i] > 0)v.push_back(f[i]);
	sort(v.rbegin(),v.rend());
	double ans = 0;
	for(int i = 0 ; i < (int)v.size() && m; ++i){
		if(m >= v[i]){
			ans += (double)v[i]*v[i]*1.;
			m -= v[i];
		}else{
			ans += (double)m*m;
			m = 0;
		}
	}
	cout << setprecision(0) << fixed << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define open freopen("in","r",stdin)

int f[30];
int main(){
	//~ open;
	int n,m;cin>>n>>m;
	string s; cin>>s;
	for(int i = 0 ; s[i] ; ++i)	f[s[i] - 'A']++;
	vector<long long>v;
	for(int i = 0 ; i < 30; ++i)	if(f[i] > 0)v.push_back(f[i]);
	sort(v.rbegin(),v.rend());
	unsigned long long ans = 0;
	for(int i = 0 ; i < (int)v.size() && m; ++i){
		if(m >= v[i]){
			ans += v[i]*v[i];
			m -= v[i];
		}else{
			ans += m*m;
			m = 0;
		}
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define open freopen("in","r",stdin)

int f[30];
int main(){
	//~ open;
	int n,m;cin>>n>>m;
	string s; cin>>s;
	for(int i = 0 ; s[i] ; ++i)	f[s[i] - 'A']++;
	vector<long long>v;
	for(int i = 0 ; i < 30; ++i)	if(f[i] > 0)v.push_back(f[i]);
	sort(v.rbegin(),v.rend());
	double ans = 0;
	for(int i = 0 ; i < (int)v.size() && m; ++i){
		if(m >= v[i]){
			ans += (double)v[i]*v[i]*1.;
			m -= v[i];
		}else{
			ans += m*m;
			m = 0;
		}
	}
	cout << setprecision(0) << fixed << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define open freopen("in","r",stdin)

int f[30];
int main(){
	//~ open;
	long long n,m;cin>>n>>m;
	string s; cin>>s;
	for(int i = 0 ; s[i] ; ++i)	f[s[i] - 'A']++;
	vector<long long>v;
	for(int i = 0 ; i < 30; ++i)	if(f[i] > 0)v.push_back(f[i]);
	sort(v.rbegin(),v.rend());
	long long ans = 0;
	for(int i = 0 ; i < (int)v.size() && m; ++i){
		if(m >= v[i]){
			ans += v[i]*v[i]*1.;
			m -= v[i];
		}else{
			ans += m*m;
			m = 0;
		}
	}
	cout << ans << '\n';
	return 0;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MAX 110

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

const ll OO = (ll)1e14+7;

int main(void){

    ll n, k;

    while(cin>>n>>k){

        vector<ll> cnt(26, 0);

        for(int i=0; i<n; i++){
            char ch;
            cin>>ch;
            cnt[ch-'A']++;
        }

        sort(cnt.rbegin(), cnt.rend());

        ll res = 0;
        for(int i=0; i<26; i++){

            //cout<<k<<" "<<cnt[i]<<"\n";

            if(k>cnt[i]){
                res += cnt[i]*cnt[i];
                k -= cnt[i];
            }else{
                res += k * k;
                k=0;
                break;
            }

        }

        cout<<res<<"\n";

    }

    return 0;
}


#include <fstream>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <ctype.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vii;
typedef vector<long long> vll;
typedef vector< pair<long, long> > vpll;
typedef vector< pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;

int main (void)
{
    int k,n,i,cnt,total;
    vi letters(26);
    char c;

    while(cin>>n>>k){
        for(i=0; i<n; i++){
            c=cin.get();
            letters[c-'A']++;
        }

        sort(letters.rbegin(), letters.rend());

        cnt=total=0;
        for(i=0;i<26;i++){
            if(letters[i]<(k-cnt)){
                total+= (letters[i]*letters[i]);
                cnt+=letters[i];
            }
            else{
                total+=((k-cnt)*(k-cnt));
                break;
            }
        }

        cout<<total<<"\n";

    }

    return 0;
}


#include <fstream>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <ctype.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vii;
typedef vector<long long> vll;
typedef vector< pair<long, long> > vpll;
typedef vector< pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;

int main (void)
{
    int k,n,i,cnt,total;
    vi letters(26);
    char c;
    string temp;
    while(cin>>n>>k){
        getline(cin,temp);
        for(i=0; i<n; i++){
            cin.get(c);
            letters[c-'A']++;
        }

        sort(letters.rbegin(), letters.rend());

        cnt=total=0;
        for(i=0;i<26;i++){
            if(letters[i]<=(k-cnt)){
                total+= (letters[i]*letters[i]);
                cnt+=letters[i];
            }
            else{
                total+=((k-cnt)*(k-cnt));
                break;
            }
        }

        cout<<total<<"\n";

    }

    return 0;
}


#include <fstream>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <ctype.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())

using namespace std;

typedef vector<int> vi;

int main ()
{
    int i,n,k;
    long long t;
    vi x(26);
    string s;

    while(cin>>n>>k>>s){
        for(i=0; i<n; i++)
            x[(s[i]-65)]++;
        sort(x.rbegin(),x.rend());

        i=0;
        t=0;
        while(x[i]!=0 && k!=0){
            if(k>x[i]){
                k -= x[i];
                t += (x[i]*x[i]);
            }else{
                t += (k*k);
                k=0;
            }
            i++;
        }
        cout<<t<<"\n";

    }

    return 0;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MAX 110

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

const ll OO = (ll)1e14+7;

int main(void){

    ll n, k;

    while(cin>>n>>k){

        vi cnt(26, 0);

        for(int i=0; i<n; i++){
            char ch;
            cin>>ch;
            cnt[ch-'A']++;
        }

        sort(cnt.rbegin(), cnt.rend());

        ll res = 0;
        for(int i=0; i<26; i++){

            if(k>cnt[i]){
                res += cnt[i]*cnt[i];
                k -= cnt[i];
            }else{
                res += k * cnt[i];
                k=0;
                break;
            }

        }

        cout<<res<<"\n";

    }

    return 0;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MAX 110

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

const ll OO = (ll)1e14+7;

int main(void){

    ll n, k;

    while(cin>>n>>k){

        vi cnt(26, 0);

        for(int i=0; i<n; i++){
            char ch;
            cin>>ch;
            cnt[ch-'A']++;
        }

        sort(cnt.rbegin(), cnt.rend());

        ll res = 0;
        for(int i=0; i<26; i++){

            //cout<<k<<" "<<cnt[i]<<"\n";

            if(k>cnt[i]){
                res += cnt[i]*cnt[i];
                k -= cnt[i];
            }else{
                res += k * k;
                k=0;
                break;
            }

        }

        cout<<res<<"\n";

    }

    return 0;
}


#include <fstream>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <ctype.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vii;
typedef vector<long long> vll;
typedef vector< pair<long, long> > vpll;
typedef vector< pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;

int main (void)
{
    ll k,n,i,cnt,total;
    vll letters(26);
    char c;
    string temp;
    while(cin>>n>>k){
        getline(cin,temp);
        for(i=0; i<n; i++){
            cin.get(c);
            letters[c-'A']++;
        }

        sort(letters.rbegin(), letters.rend());

        cnt=total=0;
        for(i=0;i<26;i++){
            if(letters[i]<=(k-cnt)){
                total+= (letters[i]*letters[i]);
                cnt+=letters[i];
            }
            else{
                total+=((k-cnt)*(k-cnt));
                break;
            }
        }

        cout<<total<<"\n";

    }

    return 0;
}


#include <fstream>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <ctype.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vii;
typedef vector<long long> vll;
typedef vector< pair<long, long> > vpll;
typedef vector< pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;

int main (void)
{
    int k,n,i,cnt,total;
    vi letters(26);
    char c;

    while(cin>>n>>k){
        for(i=0; i<n; i++){
            c=cin.get();
            letters[c-'A']++;
        }

        sort(letters.rbegin(), letters.rend());

        cnt=total=0;
        for(i=0;i<26;i++){
            if(letters[i]<=(k-cnt)){
                total+= (letters[i]*letters[i]);
                cnt+=letters[i];
            }
            else{
                total+=((k-cnt)*(k-cnt));
                break;
            }
        }

        cout<<total<<"\n";

    }

    return 0;
}


#include <fstream>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <ctype.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())

using namespace std;

typedef vector<int> vi;

int main ()
{
    int i,n,k,t;
    vi x(26);
    string s;

    while(cin>>n>>k>>s){
        for(i=0; i<n; i++)
            x[(s[i]-65)]++;
        sort(x.rbegin(),x.rend());

        i=0;
        t=0;
        while(x[i]!=0 && k!=0){
            if(k>x[i]){
                k -= x[i];
                t += (x[i]*x[i]);
            }else{
                t += (k*k);
                k=0;
            }
            i++;
        }
        cout<<t<<"\n";

    }

    return 0;
}


#include <fstream>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <ctype.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())

using namespace std;

typedef vector<int> vi;

int main ()
{
    int i,n,k;
    unsigned long long t;
    vi x(26);
    string s;

    while(cin>>n>>k>>s){
        for(i=0; i<n; i++)
            x[(s[i]-65)]++;
        sort(x.rbegin(),x.rend());

        i=0;
        t=0;
        while(x[i]!=0 && k!=0){
            if(k>x[i]){
                k -= x[i];
                t += (x[i]*x[i]);
            }else{
                t += (k*k);
                k=0;
            }
            i++;
        }
        cout<<t<<"\n";

    }

    return 0;
}


#include <fstream>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <ctype.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vii;
typedef vector<long long> vll;
typedef vector< pair<long, long> > vpll;
typedef vector< pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;

int main (void)
{
    int k,n,i,cnt;
    ll total;
    vi letters(26);
    char c;
    string temp;
    while(cin>>n>>k){
        getline(cin,temp);
        for(i=0; i<n; i++){
            cin.get(c);
            letters[c-'A']++;
        }

        sort(letters.rbegin(), letters.rend());

        cnt=total=0;
        for(i=0;i<26;i++){
            if(letters[i]<=(k-cnt)){
                total+= (letters[i]*letters[i]);
                cnt+=letters[i];
            }
            else{
                total+=((k-cnt)*(k-cnt));
                break;
            }
        }

        cout<<total<<"\n";

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k,kl=0,ans=0; cin>> n >> k;
    string c; cin>> c;
    map<char,pair<int,char> > mp;
    for(int i=0;i<n;++i){
        mp[c[i]].first++;
        mp[c[i]].second=c[i];
    }
    vector<pair<int,char> > v;
    for(map<char,pair<int,char> > :: iterator it=mp.begin();it!=mp.end();++it){
        v.push_back(it->second);
    }
    sort(v.rbegin(),v.rend());
    for(int i=0;i<v.size();++i)cout<<v[i].first<<" "<<v[i].second<<endl;
    while(k>0){
        int aux=v[kl].first,cont=0;
        while(v[kl].first!=0 && aux<=k){
            cont++;
            ans+=aux;
            v[kl].first--;
        }
        k-=cont;
        kl++;
        if(kl==v.size())break;
    }
    if(k!=0)cout<<ans+(k*k)<<endl;
    else cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k,kl=0,ans=0; cin>> n >> k;
    string c; cin>> c;
    map<char,pair<int,char> > mp;
    for(int i=0;i<n;++i){
        mp[c[i]].first++;
        mp[c[i]].second=c[i];
    }
    vector<pair<int,char> > v;
    for(map<char,pair<int,char> > :: iterator it=mp.begin();it!=mp.end();++it){
        v.push_back(it->second);
    }
    sort(v.rbegin(),v.rend());
    //for(int i=0;i<v.size();++i)cout<<v[i].first<<" "<<v[i].second<<endl;
    while(k>0){
        int aux=v[kl].first,cont=0;
        while(v[kl].first!=0 && aux<=k){
            cont++;
            ans+=aux;
            v[kl].first--;
        }
        k-=cont;
        kl++;
        if(kl==v.size())break;
    }
    if(k!=0)cout<<ans+(k*k)<<endl;
    else cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;
int main() {
  int n,k,ans=0; cin>> n >> k;
  string c; cin>> c;
  vector<int> v(27,0);
  for(int i=0;i<c.size();++i){
        v[c[i]-'A']++;
  }
  sort(v.rbegin(),v.rend());
  for(int i=0;i<v.size();++i){
      int aux=v[i];
      while(v[i]!=0 && v[i]<=k){
          ans=(ans+aux);
          v[i]--; k--;
      }
  }
  if(k==0)cout<<ans<<endl;
  else cout<<ans+k<<endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k,kl=0,ans=0; cin>> n >> k;
    string c; cin>> c;
    map<char,pair<int,char> > mp;
    for(int i=0;i<n;++i){
        mp[c[i]].first++;
        mp[c[i]].second=c[i];
    }
    vector<pair<int,char> > v;
    for(map<char,pair<int,char> > :: iterator it=mp.begin();it!=mp.end();++it){
        v.push_back(it->second);
    }
    sort(v.rbegin(),v.rend());
    while(k>0){
        int aux=v[kl].first,cont=0;
        while(v[kl].first!=0 && aux<=k){
            cont++;
            ans+=aux;
            v[kl].first--;
        }
        k-=cont;
        kl++;
        if(kl==v.size())break;
    }
    if(k!=0)cout<<ans+k<<endl;
    else cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;
int main() {
  int n,k,ans=0; cin>> n >> k;
  string c; cin>> c;
  vector<int> v(27,0);
  for(int i=0;i<c.size();++i){
        v[c[i]-'A']++;
  }
  sort(v.rbegin(),v.rend());
  for(int i=0;i<v.size();++i){
      int aux=v[i];
      while(v[i]!=0 && v[i]<=k){
          ans=(ans+aux);
          v[i]--; k--;
      }
  }
  if(k==0)cout<<ans<<endl;
  else cout<<ans+k*k<<endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int v[27];
int main(){
    int n,m; cin>> n >> m;
    string c; cin>> c;
    for(int i=0;i<n;i++){
        v[c[i]-'A']++;
    }
    long long ans=0;
    sort(v,v+27);
    reverse(v,v+27);
    for(int i=0;i<27 && m>0;++i){
        ans=ans+ (1LL *min(v[i],m)*min(v[i],m));
        if(m>v[i]){
            m-=v[i];
        }else m=0;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define INF 1000000000
using namespace std;
long long cnt[26]={0};

int main(){
	int n,k;
	string s;
	cin>>n>>k>>s;
	for(int i=0;i<s.length();i++){
		cnt[s[i]-'A']++;
	}
	sort(cnt,cnt+26,std::greater<int>());
	long long sum=0;
	long long idx=0;
	while(k>0){
		if(cnt[idx]<=k){
			sum+=(cnt[idx]*cnt[idx]);
			k-=cnt[idx];
		}
		else{
			sum+=(k*k);
			k=0;
		}
		idx++;
	}
	cout<<sum<<endl;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define INF 1000000000
using namespace std;
int cnt[26]={0};

int main(){
	int n,k;
	string s;
	cin>>n>>k>>s;
	for(int i=0;i<s.length();i++){
		cnt[s[i]-'A']++;
	}
	sort(cnt,cnt+26,std::greater<int>());
	long long sum=0;
	int idx=0;
	while(k>0){
		if(cnt[idx]<=k){
			sum+=(cnt[idx]*cnt[idx]);
			k-=cnt[idx];
		}
		else{
			sum+=(k*k);
			k=0;
		}
		idx++;
	}
	cout<<sum<<endl;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define INF 1000000000
using namespace std;
int cnt[26]={0};

int main(){
	int n,k;
	string s;
	cin>>n>>k>>s;
	for(int i=0;i<s.length();i++){
		cnt[s[i]-'A']++;
	}
	sort(cnt,cnt+26,std::greater<int>());
	int sum=0;
	int idx=0;
	while(k>0){
		if(cnt[idx]<=k){
			sum+=(cnt[idx]*cnt[idx]);
			k-=cnt[idx];
		}
		else{
			sum+=(k*k);
			k=0;
		}
		idx++;
	}
	cout<<sum<<endl;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define INF 1000000000
using namespace std;
long long cnt[27]={0};

int main(){
	int n,k;
	string s;
	cin>>n>>k>>s;
	for(int i=0;i<s.length();i++){
		cnt[s[i]-'A']++;
	}
	sort(cnt,cnt+27,std::greater<int>());
	long long sum=0;
	long long idx=0;
	while(k>0 && idx<=26){
		if(cnt[idx]<=k){
			sum+=(cnt[idx]*cnt[idx]);
			k-=cnt[idx];
		}
		else{
			sum+=(k*k);
			k=0;
		}
		idx++;
	}
	cout<<sum<<endl;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define INF 1000000000
using namespace std;
long long cnt[27]={0};

int main(){
	long long n,k;
	string s;
	cin>>n>>k>>s;
	for(int i=0;i<s.length();i++){
		cnt[s[i]-'A']++;
	}
	sort(cnt,cnt+27,std::greater<int>());
	long long sum=0;
	long long idx=0;
	while(k>0 && idx<=26){
		if(cnt[idx]<=k){
			sum+=(cnt[idx]*cnt[idx]);
			k-=cnt[idx];
		}
		else{
			sum+=(k*k);
			k=0;
		}
		idx++;
	}
	cout<<sum<<endl;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define INF 1000000000
using namespace std;
int cnt[26]={0};

int main(){
	int n,k;
	string s;
	cin>>n>>k>>s;
	for(int i=0;i<s.length();i++){
		cnt[s[i]-'A']++;
	}
	sort(cnt,cnt+26,std::greater<int>());
	int sum=0;
	int idx=0;
	while(k>0){
		if(cnt[idx]<=k){
			sum+=(cnt[idx]*cnt[idx]);
			k-=cnt[idx];
		}
		else{
			sum+=(k*k);
			k=0;
		}
	}
	cout<<sum<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b)for(int i=(a);i<b;i++)
#define intout(x)printf("%d",x)
#define llout(x)printf("%I64d",x)
#define strout(x,y)printf("%s%s",x,y)
using namespace std;
inline int intin(){int x;scanf("%d",&x);return x;}
inline char charin(){char x;scanf("%c",&x);return x;}
inline ll llin(){ll x;scanf("%I64d",&x);return x;}
inline string strin(){string x;scanf("%s",&x);return x;}
int main()
{
    int n=intin(),m=intin(),a[100]={},xxx=0;char x; ll ans=0;
    FOR(i,0,n)
        {
            cin>>x;
            a[x-'A']++;
        }
    sort(a,a+26,greater<ll>());
    for(int i=0;i<n;i++)
    {
        if(a[i]>=m) ans=ans+m*m,m=0;
        else    ans=ans+a[i]*a[i],m-=a[i];
        //if(a[i]>m)  ans=ans+m*m,m=0;
        //else    ans=ans+a[i]*a[i],m-=a[i];
    }
    llout(ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b)for(int i=(a);i<b;i++)
#define intout(x)printf("%d",x)
#define llout(x)printf("%I64d",x)
#define strout(x,y)printf("%s%s",x,y)
using namespace std;
inline int intin(){int x;scanf("%d",&x);return x;}
inline char charin(){char x;scanf("%c",&x);return x;}
inline ll llin(){ll x;scanf("%I64d",&x);return x;}
inline string strin(){string x;scanf("%s",&x);return x;}
int main()
{
    int n=intin(),m=intin(),a[100]={},ans=0;char x;
    FOR(i,0,n)
        a[x=charin()-'A']++;
    sort(a,a+26,greater<int>());
    for(int i=0;i<26&&m>0;i++)
    {
        if(a[i]>m)  ans=ans+m,m=0;
        else    ans=ans+a[i]*a[i],m-=a[i];
    }
    intout(ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b)for(int i=(a);i<b;i++)
#define intout(x)printf("%d",x)
#define llout(x)printf("%I64d",x)
#define strout(x,y)printf("%s%s",x,y)
using namespace std;
inline int intin(){int x;scanf("%d",&x);return x;}
inline char charin(){char x;scanf("%c",&x);return x;}
inline ll llin(){ll x;scanf("%I64d",&x);return x;}
inline string strin(){string x;scanf("%s",&x);return x;}
int main()
{
    ll n=intin(),m=intin(),a[100]={},xxx=0;char x; ll ans=0;
    FOR(i,0,n)
        {
            cin>>x;
            a[x-'A']++;
        }
    sort(a,a+26,greater<ll>());
    for(int i=0;i<n;i++)
    {
        if(a[i]>=m) ans=ans+m*m,m=0;
        else    ans=ans+a[i]*a[i],m-=a[i];
        //if(a[i]>m)  ans=ans+m*m,m=0;
        //else    ans=ans+a[i]*a[i],m-=a[i];
    }
    intout(ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b)for(int i=(a);i<b;i++)
#define intout(x)printf("%d",x)
#define llout(x)printf("%I64d",x)
#define strout(x,y)printf("%s%s",x,y)
using namespace std;
inline int intin(){int x;scanf("%d",&x);return x;}
inline char charin(){char x;scanf("%c",&x);return x;}
inline ll llin(){ll x;scanf("%I64d",&x);return x;}
inline string strin(){string x;scanf("%s",&x);return x;}
int main()
{
    int n=intin(),m=intin(),a[100]={},xxx=0;char x; ll ans=0;
    FOR(i,0,n)
        {
            cin>>x;
            a[x-'A']++;
        }
    sort(a,a+26,greater<ll>());
    for(int i=0;m>0;i++)
    {
        if(a[i]>=m) ans=ans+m*m,m=0;
        else    ans=ans+a[i]*a[i],m-=a[i];
        //if(a[i]>m)  ans=ans+m*m,m=0;
        //else    ans=ans+a[i]*a[i],m-=a[i];
    }
    llout(ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b)for(int i=(a);i<b;i++)
#define intout(x)printf("%d",x)
#define llout(x)printf("%I64d",x)
#define strout(x,y)printf("%s%s",x,y)
using namespace std;
inline int intin(){int x;scanf("%d",&x);return x;}
inline char charin(){char x;scanf("%c",&x);return x;}
inline ll llin(){ll x;scanf("%I64d",&x);return x;}
inline string strin(){string x;scanf("%s",&x);return x;}
int main()
{
    int n=intin(),m=intin(),a[100]={},xxx=0;char x; ll ans=0;
    FOR(i,0,n)
        {
            cin>>x;
            a[x-'A']++;
        }
    sort(a,a+26,greater<ll>());
    for(int i=0;m>0;i++)
    {
        if(a[i]>=m) ans=ans+(ll)m*m,m=0;
        else    ans=ans+(ll)a[i]*a[i],m-=a[i];
        //if(a[i]>m)  ans=ans+m*m,m=0;
        //else    ans=ans+a[i]*a[i],m-=a[i];
    }
    llout(ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b)for(int i=(a);i<b;i++)
#define intout(x)printf("%d",x)
#define llout(x)printf("%I64d",x)
#define strout(x,y)printf("%s%s",x,y)
using namespace std;
inline int intin(){int x;scanf("%d",&x);return x;}
inline char charin(){char x;scanf("%c",&x);return x;}
inline ll llin(){ll x;scanf("%I64d",&x);return x;}
inline string strin(){string x;scanf("%s",&x);return x;}
int main()
{
    ll n=intin(),m=intin(),a[100]={},xxx=0;char x; ll ans=0;
    FOR(i,0,n)
        {
            cin>>x;
            a[x-'A']++;
        }
    sort(a,a+26,greater<ll>());
    for(int i=0;m>0;i++)
    {
        if(a[i]>=m) ans=ans+m*m,m=0;
        else    ans=ans+a[i]*a[i],m-=a[i];
        //if(a[i]>m)  ans=ans+m*m,m=0;
        //else    ans=ans+a[i]*a[i],m-=a[i];
    }
    llout(ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b)for(int i=(a);i<b;i++)
#define intout(x)printf("%d",x)
#define llout(x)printf("%I64d",x)
#define strout(x,y)printf("%s%s",x,y)
using namespace std;
inline int intin(){int x;scanf("%d",&x);return x;}
inline char charin(){char x;scanf("%c",&x);return x;}
inline ll llin(){ll x;scanf("%I64d",&x);return x;}
inline string strin(){string x;scanf("%s",&x);return x;}
int main()
{
    int n=intin(),m=intin(),a[100]={};char x; ll ans=0;
    FOR(i,0,n)
        {
            cin>>x;
            a[x-'A']++;
        }
    sort(a,a+26,greater<int>());
    for(int i=0;i<26&&m>0;i++)
    {
        if(a[i]>m)  ans=ans+m*m,m=0;
        else    ans=ans+a[i]*a[i],m-=a[i];
    }
    intout(ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b)for(int i=(a);i<b;i++)
#define intout(x)printf("%d",x)
#define llout(x)printf("%I64d",x)
#define strout(x,y)printf("%s%s",x,y)
using namespace std;
inline int intin(){int x;scanf("%d",&x);return x;}
inline char charin(){char x;scanf("%c",&x);return x;}
inline ll llin(){ll x;scanf("%I64d",&x);return x;}
inline string strin(){string x;scanf("%s",&x);return x;}
int main()
{
    int n=intin(),m=intin(),a[100]={},xxx=0;char x; ll ans=0;
    FOR(i,0,n)
        {
            cin>>x;
            a[x-'A']++;
        }
    sort(a,a+26,greater<int>());
    for(int i=0;m>0;i++)
    {
        if(a[i]>=m) ans=ans+m*m,m=0;
        else    ans=ans+a[i]*a[i],m-=a[i];
        //if(a[i]>m)  ans=ans+m*m,m=0;
        //else    ans=ans+a[i]*a[i],m-=a[i];
    }
    intout(ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b)for(int i=(a);i<b;i++)
#define intout(x)printf("%d",x)
#define llout(x)printf("%I64d",x)
#define strout(x,y)printf("%s%s",x,y)
using namespace std;
inline int intin(){int x;scanf("%d",&x);return x;}
inline char charin(){char x;scanf("%c",&x);return x;}
inline ll llin(){ll x;scanf("%I64d",&x);return x;}
inline string strin(){string x;scanf("%s",&x);return x;}
int main()
{
    int n=intin(),m=intin(),a[100]={},ans=0;char x;
    FOR(i,0,n)
        {
            cin>>x;
            a[x-'A']++;
        }
    sort(a,a+26,greater<int>());
    for(int i=0;i<26&&m>0;i++)
    {
        if(a[i]>m)  ans=ans+m,m=0;
        else    ans=ans+a[i]*a[i],m-=a[i];
    }
    intout(ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b)for(int i=(a);i<b;i++)
#define intout(x)printf("%d",x)
#define llout(x)printf("%I64d",x)
#define strout(x,y)printf("%s%s",x,y)
using namespace std;
inline int intin(){int x;scanf("%d",&x);return x;}
inline char charin(){char x;scanf("%c",&x);return x;}
inline ll llin(){ll x;scanf("%I64d",&x);return x;}
inline string strin(){string x;scanf("%s",&x);return x;}
int main()
{
    int n=intin(),m=intin(),a[100]={},ans=0;char x;
    FOR(i,0,n)
        {
            cin>>x;
            a[x-'A']++;
        }
    sort(a,a+26,greater<int>());
    for(int i=0;i<26&&m>0;i++)
    {
        if(a[i]>m)  ans=ans+m*m,m=0;
        else    ans=ans+a[i]*a[i],m-=a[i];
    }
    intout(ans);
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
clock_t tic,toc;
int main()
{
	tic = clock();
	fast;
	int n,k;
	cin >>n >> k;
	string s;
	cin >> s;
	map<char,int>mp;
	for(int i = 0 ; i < s.size(); i++ )
	{
		mp[s[i]-'a']++;
	}
	vector<int>v;
	for(auto p : mp){
		v.push_back(p.second);
	}
	sort(v.begin(),v.end());
	long long sum = 0;
	for(int i = v.size()-1 ; i>=0 ; i-- ){
		if(k>=v[i]){
			sum+=v[i]*1LL*v[i];
			k-=v[i];
		}
		else{
			sum+=k;
			break;
		}
	}
	cout<<sum;

}


#include<iostream>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
clock_t tic,toc;
int main()
{
	tic = clock();
	fast;
	int n,k;
	cin >>n >> k;
	string s;
	cin >> s;
	map<char,int>mp;
	for(int i = 0 ; i < s.size(); i++ )
	{
		mp[s[i]-'a']++;
	}
	vector<int>v;
	for(auto p : mp){
		v.push_back(p.second);
	}
	sort(v.begin(),v.end());
	unsigned long long sum = 0;
	for(int i = v.size()-1 ; i>=0 ; i-- ){
		if(k>=v[i] && k>0){
			sum+=v[i]*1LL*v[i];
			k-=v[i];
		}
	}
	cout<<sum+k;

}


#include<iostream>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
clock_t tic,toc;
int main()
{
	tic = clock();
	fast;
	int n,k;
	cin >>n >> k;
	string s;
	cin >> s;
	map<char,int>mp;
	for(int i = 0 ; i < s.size(); i++ )
	{
		mp[s[i]-'a']++;
	}
	vector<int>v;
	for(auto p : mp){
		v.push_back(p.second);
	}
	sort(v.begin(),v.end());
	long long sum = 0;
	for(int i = v.size()-1 ; i>=0 ; i-- ){
		if(k>=v[i]){
			sum+=v[i]*v[i];
			k-=v[i];
		}
		else{
			sum+=k;
			break;
		}
	}
	cout<<sum;

}


#include<iostream>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
clock_t tic,toc;
int main()
{
	tic = clock();
	fast;
	int n,k;
	cin >>n >> k;
	string s;
	cin >> s;
	map<char,int>mp;
	for(int i = 0 ; i < s.size(); i++ )
	{
		mp[s[i]-'a']++;
	}
	vector<int>v;
	for(auto p : mp){
		v.push_back(p.second);
	}
	sort(v.begin(),v.end());
	unsigned long long sum = 0;
	for(int i = v.size()-1 ; i>=0 ; i-- ){
		if(k>=v[i] && k>0){
			sum+=v[i]*1LL*v[i];
			k-=v[i];
		}
	}
	cout<<sum;

}


#include<iostream>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
clock_t tic,toc;
int main()
{
	tic = clock();
	fast;
	int n,k;
	cin >>n >> k;
	string s;
	cin >> s;
	map<char,int>mp;
	for(int i = 0 ; i < s.size(); i++ )
	{
		mp[s[i]-'a']++;
	}
	vector<int>v;
	for(auto p : mp){
		v.push_back(p.second);
	}
	sort(v.begin(),v.end());
	unsigned long long sum = 0;
	for(int i = v.size()-1 ; i>=0 ; i-- ){
		if(k>=v[i]){
			sum+=v[i]*1LL*v[i];
			k-=v[i];
		}
		else{
			sum+=k;
			break;
		}
	}
	cout<<sum;

}


#include<iostream>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
clock_t tic,toc;
int main()
{
	tic = clock();
	fast;
	int n,k;
	cin >>n >> k;
	string s;
	cin >> s;
	map<char,int>mp;
	for(int i = 0 ; i < s.size(); i++ )
	{
		mp[s[i]-'a']++;
	}
	vector<int>v;
	for(auto p : mp){
		v.push_back(p.second);
	}
	sort(v.begin(),v.end());
	unsigned long long sum = 0;
	long long d ;
	for(int i = v.size()-1 ; i>=0 ; i-- ){
		d=min(k,v[i]);
		sum+=d*d;
		k-=d;
	}
	cout<<sum;

}


#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define S(v) sort(v.begin(), v.end())
#define F(i, N) for(int i = 0; i != N; ++i)
#define NO std::cout << "No"
#define YES std::cout << "Yes"
#define C(v, a) count(v.begin(), v.end(), a)
#define R1(m) int m; cin >> m
#define R2(m, n) int m, n; cin >> m >> n
#define A cout << ans
#define NL std::cout << "\n"

using LL = long long;
using VI = std::vector<int>;

using namespace std;

bool odd(int N){ while (N < 0){ N += 2; }return  N % 2 == 1 ? true : false; }
bool even(int N){ while (N < 0){ N += 2; }return  N % 2 == 0 ? true : false; }
long long mod(long long a, long long b){ return (a % b + b) % b; } // Mod operator is only defined for integers

	int valsOfChars[26];
	string s;
	long long ans;
	map<long long, long long> mp[26];
int main()
{

		//for (int i = 0; i < 26; i++) cin >> valsOfChars[i];
		//cin >> s;
		//long long cur = 0;
		//for (int i = 0; i != s.length(); i++) {
		//	int c = s[i] - 'a';
		//	ans += mp[c][cur];
		//	cur += valsOfChars[c];
		//	mp[c][cur]++;
		//}
		//cout << ans << '\n';
	long long n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int N = s.size();
	vector<long, long> hell(26);

	for (auto val : s)
	{
		++hell[val - 'A'];
	}
	S(hell);
	long long ans = 0;
	for (int i = hell.size() - 1; i >= 0; --i)
	{
         if (hell.at(i) <= k)
		{
			ans += hell.at(i) * hell.at(i)L;
			k -= hell.at(i);
		}
		 else
		 {
			ans += k * k;
			break;
		 }

	}
	A;
	return 0;

}


#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define S(v) sort(v.begin(), v.end())
#define F(i, N) for(int i = 0; i != N; ++i)
#define NO std::cout << "No"
#define YES std::cout << "Yes"
#define C(v, a) count(v.begin(), v.end(), a)
#define R1(m) int m; cin >> m
#define R2(m, n) int m, n; cin >> m >> n
#define A cout << ans
#define NL std::cout << "\n"

using LL = long long;
using VI = std::vector<int>;

using namespace std;

bool odd(int N){ while (N < 0){ N += 2; }return  N % 2 == 1 ? true : false; }
bool even(int N){ while (N < 0){ N += 2; }return  N % 2 == 0 ? true : false; }
long long mod(long long a, long long b){ return (a % b + b) % b; } // Mod operator is only defined for integers

	int valsOfChars[26];
	string s;
	long long ans;
	map<long long, long long> mp[26];
int main()
{

		//for (int i = 0; i < 26; i++) cin >> valsOfChars[i];
		//cin >> s;
		//long long cur = 0;
		//for (int i = 0; i != s.length(); i++) {
		//	int c = s[i] - 'a';
		//	ans += mp[c][cur];
		//	cur += valsOfChars[c];
		//	mp[c][cur]++;
		//}
		//cout << ans << '\n';
	long long n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int N = s.size();
	vector<long, long> hell(26);

	for (auto val : s)
	{
		++hell[val - 'A'];
	}
	S(hell);
	long long ans = 0;
	for (int i = hell.size() - 1; i >= 0; --i)
	{
         if (hell.at(i) <= k)
		{
			ans += hell.at(i) * hell.at(i);
			k -= hell.at(i);
		}
		 else
		 {
			ans += k * k;
			break;
		 }

	}
	A;
	return 0;

}


#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define S(v) sort(v.begin(), v.end())
#define F(i, N) for(int i = 0; i != N; ++i)
#define NO std::cout << "No"
#define YES std::cout << "Yes"
#define C(v, a) count(v.begin(), v.end(), a)
#define R1(m) int m; cin >> m
#define R2(m, n) int m, n; cin >> m >> n
#define A cout << ans
#define NL std::cout << "\n"

using LL = long long;
using VI = std::vector<int>;

using namespace std;

bool odd(int N){ while (N < 0){ N += 2; }return  N % 2 == 1 ? true : false; }
bool even(int N){ while (N < 0){ N += 2; }return  N % 2 == 0 ? true : false; }
long long mod(long long a, long long b){ return (a % b + b) % b; } // Mod operator is only defined for integers

int main()
{

	long long n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int N = s.size();
	vector<long> hell(26);

	for (auto val : s)
	{
		++hell[val - 'A'];
	}
	S(hell);
	long long ans = 0;
	for (int i = hell.size() - 1; i >= 0; --i)
	{
         if (hell.at(i) <= k)
		{
			ans += (long long)hell.at(i) * hell.at(i);
			k -= hell.at(i);
		}
		 else
		 {
			ans += k * k;
			break;
		 }

	}
	A;
	return 0;

}


#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define S(v) sort(v.begin(), v.end())
#define F(i, N) for(int i = 0; i != N; ++i)
#define NO std::cout << "No"
#define YES std::cout << "Yes"
#define C(v, a) count(v.begin(), v.end(), a)
#define R1(m) int m; cin >> m
#define R2(m, n) int m, n; cin >> m >> n
#define A cout << ans
#define NL std::cout << "\n"

using ll = long long;
using VI = std::vector<int>;

using namespace std;

bool odd(int N){ while (N < 0){ N += 2; }return  N % 2 == 1 ? true : false; }
bool even(int N){ while (N < 0){ N += 2; }return  N % 2 == 0 ? true : false; }
long long mod(long long a, long long b){ return (a % b + b) % b; } // Mod operator is only defined for integers

	int valsOfChars[26];
	string s;
	long long ans;
	map<long long, long long> mp[26];
int main()
{

		//for (int i = 0; i < 26; i++) cin >> valsOfChars[i];
		//cin >> s;
		//long long cur = 0;
		//for (int i = 0; i != s.length(); i++) {
		//	int c = s[i] - 'a';
		//	ans += mp[c][cur];
		//	cur += valsOfChars[c];
		//	mp[c][cur]++;
		//}
		//cout << ans << '\n';
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int N = s.size();
	VI hell(26);

	for (auto val : s)
	{
		++hell[val - 'A'];
	}
	S(hell);
	int ans = 0;
	for (int i = hell.size() - 1; i >= 0; --i)
	{
         if (hell.at(i) <= k)
		{
			ans += hell.at(i) * hell.at(i);
			k -= hell.at(i);
		}
		 else
		 {
			ans += k * k;
			break;
		 }

	}
	A;
	return 0;

}


#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define S(v) sort(v.begin(), v.end())
#define F(i, N) for(int i = 0; i != N; ++i)
#define NO std::cout << "No"
#define YES std::cout << "Yes"
#define C(v, a) count(v.begin(), v.end(), a)
#define R1(m) int m; cin >> m
#define R2(m, n) int m, n; cin >> m >> n
#define A cout << ans
#define NL std::cout << "\n"

using LL = long long;
using VI = std::vector<int>;

using namespace std;

bool odd(int N){ while (N < 0){ N += 2; }return  N % 2 == 1 ? true : false; }
bool even(int N){ while (N < 0){ N += 2; }return  N % 2 == 0 ? true : false; }
long long mod(long long a, long long b){ return (a % b + b) % b; } // Mod operator is only defined for integers

	int valsOfChars[26];
	string s;
	long long ans;
	map<long long, long long> mp[26];
int main()
{

		//for (int i = 0; i < 26; i++) cin >> valsOfChars[i];
		//cin >> s;
		//long long cur = 0;
		//for (int i = 0; i != s.length(); i++) {
		//	int c = s[i] - 'a';
		//	ans += mp[c][cur];
		//	cur += valsOfChars[c];
		//	mp[c][cur]++;
		//}
		//cout << ans << '\n';
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int N = s.size();
	VI hell(26);

	for (auto val : s)
	{
		++hell[val - 'A'];
	}
	S(hell);
	long long ans = 0;
	for (int i = hell.size() - 1; i >= 0; --i)
	{
         if (hell.at(i) <= k)
		{
			ans += hell.at(i) * hell.at(i);
			k -= hell.at(i);
		}
		 else
		 {
			ans += k * k;
			break;
		 }

	}
	A;
	return 0;

}


#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define S(v) sort(v.begin(), v.end())
#define F(i, N) for(int i = 0; i != N; ++i)
#define NO std::cout << "No"
#define YES std::cout << "Yes"
#define C(v, a) count(v.begin(), v.end(), a)
#define R1(m) int m; cin >> m
#define R2(m, n) int m, n; cin >> m >> n
#define A cout << ans
#define NL std::cout << "\n"

using LL = long long;
using VI = std::vector<int>;

using namespace std;

bool odd(int N){ while (N < 0){ N += 2; }return  N % 2 == 1 ? true : false; }
bool even(int N){ while (N < 0){ N += 2; }return  N % 2 == 0 ? true : false; }
long long mod(long long a, long long b){ return (a % b + b) % b; } // Mod operator is only defined for integers

	int valsOfChars[26];
	string s;
	long long ans;
	map<long long, long long> mp[26];
int main()
{

		//for (int i = 0; i < 26; i++) cin >> valsOfChars[i];
		//cin >> s;
		//long long cur = 0;
		//for (int i = 0; i != s.length(); i++) {
		//	int c = s[i] - 'a';
		//	ans += mp[c][cur];
		//	cur += valsOfChars[c];
		//	mp[c][cur]++;
		//}
		//cout << ans << '\n';
	long long n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int N = s.size();
	VI hell(26);

	for (auto val : s)
	{
		++hell[val - 'A'];
	}
	S(hell);
	long long ans = 0;
	for (int i = hell.size() - 1; i >= 0; --i)
	{
         if (hell.at(i) <= k)
		{
			ans += hell.at(i) * hell.at(i);
			k -= hell.at(i);
		}
		 else
		 {
			ans += k * k;
			break;
		 }

	}
	A;
	return 0;

}


#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define S(v) sort(v.begin(), v.end())
#define F(i, N) for(int i = 0; i != N; ++i)
#define NO std::cout << "No"
#define YES std::cout << "Yes"
#define C(v, a) count(v.begin(), v.end(), a)
#define R1(m) int m; cin >> m
#define R2(m, n) int m, n; cin >> m >> n
#define A cout << ans
#define NL std::cout << "\n"

using LL = long long;
using VI = std::vector<int>;

using namespace std;

bool odd(int N){ while (N < 0){ N += 2; }return  N % 2 == 1 ? true : false; }
bool even(int N){ while (N < 0){ N += 2; }return  N % 2 == 0 ? true : false; }
long long mod(long long a, long long b){ return (a % b + b) % b; } // Mod operator is only defined for integers

	int valsOfChars[26];
	string s;
	long long ans;
	map<long long, long long> mp[26];
int main()
{

		//for (int i = 0; i < 26; i++) cin >> valsOfChars[i];
		//cin >> s;
		//long long cur = 0;
		//for (int i = 0; i != s.length(); i++) {
		//	int c = s[i] - 'a';
		//	ans += mp[c][cur];
		//	cur += valsOfChars[c];
		//	mp[c][cur]++;
		//}
		//cout << ans << '\n';
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int N = s.size();
	VI hell(26);

	for (auto val : s)
	{
		++hell[val - 'A'];
	}
	S(hell);
	LL ans = 0;
	for (int i = hell.size() - 1; i >= 0; --i)
	{
         if (hell.at(i) <= k)
		{
			ans += hell.at(i) * hell.at(i);
			k -= hell.at(i);
		}
		 else
		 {
			ans += k * k;
			break;
		 }

	}
	A;
	return 0;

}


#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define S(v) sort(v.begin(), v.end())
#define F(i, N) for(int i = 0; i != N; ++i)
#define NO std::cout << "No"
#define YES std::cout << "Yes"
#define C(v, a) count(v.begin(), v.end(), a)
#define R1(m) int m; cin >> m
#define R2(m, n) int m, n; cin >> m >> n
#define A cout << ans
#define NL std::cout << "\n"

using LL = long long;
using VI = std::vector<int>;

using namespace std;

bool odd(int N){ while (N < 0){ N += 2; }return  N % 2 == 1 ? true : false; }
bool even(int N){ while (N < 0){ N += 2; }return  N % 2 == 0 ? true : false; }
long long mod(long long a, long long b){ return (a % b + b) % b; } // Mod operator is only defined for integers

	int valsOfChars[26];
	string s;
	long long ans;
	map<long long, long long> mp[26];
int main()
{

		//for (int i = 0; i < 26; i++) cin >> valsOfChars[i];
		//cin >> s;
		//long long cur = 0;
		//for (int i = 0; i != s.length(); i++) {
		//	int c = s[i] - 'a';
		//	ans += mp[c][cur];
		//	cur += valsOfChars[c];
		//	mp[c][cur]++;
		//}
		//cout << ans << '\n';
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int N = s.size();
	VI hell(26);

	for (auto val : s)
	{
		++hell[val - 'A'];
	}
	S(hell);
	size_t ans = 0;
	for (int i = hell.size() - 1; i >= 0; --i)
	{
         if (hell.at(i) <= k)
		{
			ans += hell.at(i) * hell.at(i);
			k -= hell.at(i);
		}
		 else
		 {
			ans += k * k;
			break;
		 }

	}
	A;
	return 0;

}


#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define S(v) sort(v.begin(), v.end())
#define F(i, N) for(int i = 0; i != N; ++i)
#define NO std::cout << "No"
#define YES std::cout << "Yes"
#define C(v, a) count(v.begin(), v.end(), a)
#define R1(m) int m; cin >> m
#define R2(m, n) int m, n; cin >> m >> n
#define A cout << ans
#define NL std::cout << "\n"

using LL = long long;
using VI = std::vector<int>;

using namespace std;

bool odd(int N){ while (N < 0){ N += 2; }return  N % 2 == 1 ? true : false; }
bool even(int N){ while (N < 0){ N += 2; }return  N % 2 == 0 ? true : false; }
long long mod(long long a, long long b){ return (a % b + b) % b; } // Mod operator is only defined for integers

int main()
{

	long long n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int N = s.size();
	vector<long long> hell(26);

	for (auto val : s)
	{
		++hell[val - 'A'];
	}
	S(hell);
	long long ans = 0;
	for (int i = hell.size() - 1; i >= 0; --i)
	{
         if (hell.at(i) <= k)
		{
			ans += hell.at(i) * hell.at(i);
			k -= hell.at(i);
		}
		 else
		 {
			ans += k * k;
			break;
		 }

	}
	A;
	return 0;

}


#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define S(v) sort(v.begin(), v.end())
#define F(i, N) for(int i = 0; i != N; ++i)
#define NO std::cout << "No"
#define YES std::cout << "Yes"
#define C(v, a) count(v.begin(), v.end(), a)
#define R1(m) int m; cin >> m
#define R2(m, n) int m, n; cin >> m >> n
#define A cout << ans
#define NL std::cout << "\n"

using LL = long long;
using VI = std::vector<int>;

using namespace std;

bool odd(int N){ while (N < 0){ N += 2; }return  N % 2 == 1 ? true : false; }
bool even(int N){ while (N < 0){ N += 2; }return  N % 2 == 0 ? true : false; }
long long mod(long long a, long long b){ return (a % b + b) % b; } // Mod operator is only defined for integers

int main()
{

	long long n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int N = s.size();
	vector<long> hell(26);

	for (auto val : s)
	{
		++hell[val - 'A'];
	}
	S(hell);
	long long ans = 0;
	for (int i = hell.size() - 1; i >= 0; --i)
	{
         if (hell.at(i) <= k)
		{
			ans += hell.at(i) * hell.at(i);
			k -= hell.at(i);
		}
		 else
		 {
			ans += k * k;
			break;
		 }

	}
	A;
	return 0;

}


#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define S(v) sort(v.begin(), v.end())
#define F(i, N) for(int i = 0; i != N; ++i)
#define NO std::cout << "No"
#define YES std::cout << "Yes"
#define C(v, a) count(v.begin(), v.end(), a)
#define R1(m) int m; cin >> m
#define R2(m, n) int m, n; cin >> m >> n
#define A cout << ans
#define NL std::cout << "\n"

using LL = long long;
using VI = std::vector<int>;

using namespace std;

bool odd(int N){ while (N < 0){ N += 2; }return  N % 2 == 1 ? true : false; }
bool even(int N){ while (N < 0){ N += 2; }return  N % 2 == 0 ? true : false; }
long long mod(long long a, long long b){ return (a % b + b) % b; } // Mod operator is only defined for integers

int main()
{

	long long n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int N = s.size();
	vector<long> hell(26);

	for (auto val : s)
	{
		++hell[val - 'A'];
	}
	S(hell);
	size_t  ans = 0;
	for (int i = hell.size() - 1; i >= 0; --i)
	{
         if (hell.at(i) <= k)
		{
			ans += hell.at(i) * hell.at(i);
			k -= hell.at(i);
		}
		 else
		 {
			ans += k * k;
			break;
		 }

	}
	A;
	return 0;

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<char,int>mp;
map<char,int>::iterator itt;
map<int,char>mp1;
map<int ,char>::iterator it;
int main()
{
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    for(int i=0; i<s.size(); i++)
    {
        mp[s[i]]++;

    }
    for(itt=mp.begin();itt!=mp.end();itt++){
        mp1[itt->second]=itt->first;
    }
//    for(it=mp1.begin(); it!=mp1.end(); it++) cout<<it->first<<" "<<it->second<<endl;

    it=mp1.end();
    it--;
//cout<<it->first<<" "<<it->second<<endl;
  ll sum=0;
    for( ; it!=mp1.begin(); it--)
    {
        if(it->first<=b)
        {
            sum+=(it->first)*(it->first);
            b=b-it->first;
        }

    }
    cout<<sum+b<<endl;
}


#include <bits/stdc++.h>
using namespace std;
map<char,int>mp;
map<char,int>::iterator it;
int main()
{
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        mp[s[i]]++;
    }
    ///for(it=mp.begin();it!=mp.end();it++) cout<<it->first<<" "<<it->second<<endl;
it=mp.begin();
///cout<<it->first<<" "<<it->second<<endl;
int sum=0;
for( ;it!=mp.end();it++){
    if(it->second<=b){
        sum+=(it->second)*(it->second);
        b=b-it->second;
    }

}
cout<<sum+b<<endl;
}


#include <bits/stdc++.h>
using namespace std;
map<char,int>mp;
map<char,int>::iterator it;
int main()
{
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        mp[s[i]]++;
    }
    ///for(it=mp.begin();it!=mp.end();it++) cout<<it->first<<" "<<it->second<<endl;
it=mp.begin();
///cout<<it->first<<" "<<it->second<<endl;
int sum=0;
for( ;it!=mp.end();it++){
    if(it->second<=b){
        sum+=(it->second)*(it->second);
        b=b-it->second;
    }
    else {
        break;
    }

}
cout<<sum<<endl;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<char,int>mp;
map<char,int>::iterator itt;
vector<ll>v;
int main()
{
    ll a,b;
    cin>>a>>b;
    string s;
    cin>>s;

    for(int i=0; i<s.size(); i++)
    {
       mp[s[i]]++;

    }
   for(itt=mp.begin();itt!=mp.end();itt++) {
  ll a=itt->second;
    v.push_back(a);
   }
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
ll sum=0;
for(int i=0;i<v.size();i++){
        ///cout<<v[i]<<endl;

    if(v[i]>=b)
        {
            sum+=(b*b);
            b=0;
        }
        else{
            sum+=(v[i]*v[i]);
            b=b-v[i];
        }
}
cout<<sum+(b*b)<<endl;

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<char,int>mp;
map<char,int>::iterator itt;
vector<int>v;
int main()
{
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;

    for(int i=0; i<s.size(); i++)
    {
       mp[s[i]]++;

    }
   for(itt=mp.begin();itt!=mp.end();itt++) {
    int a=itt->second;
    v.push_back(a);
   }
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
ll sum=0;
for(int i=0;i<v.size();i++){
        ///cout<<v[i]<<endl;

    if(v[i]>=b)
        {
            sum+=(b*b);
            b=0;
        }
        else{
            sum+=(v[i]*v[i]);
            b=b-v[i];
        }
}
cout<<sum+(b*b)<<endl;

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<char,int>mp;
map<char,int>::iterator itt;
vector<int>v;
int main()
{
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;

    for(int i=0; i<s.size(); i++)///here,i have mapped char with int;
    {
        mp[s[i]]++;

    }
    for(itt=mp.begin(); itt!=mp.end(); itt++)///then i have copied its elements in another map;
    {
    int a=itt->second;
    v.push_back(a);
    }
//for(it=mp1.begin(); it!=mp1.end(); it++) cout<<it->first<<" "<<it->second<<endl;
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
ll sum=0;
for(int i=0;i<v.size();i++){

    if(v[i]<=b)
        {
            sum+=(v[i]*v[i]);
            b=b-v[i];
        }
}
cout<<sum+(b*b)<<endl;

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<char,int>mp;
map<char,int>::iterator itt;
map<int,char>mp1;
map<int,char>::iterator it;
int main()
{
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    for(int i=0; i<s.size(); i++)
    {
        mp[s[i]]++;

    }
    for(itt=mp.begin(); itt!=mp.end(); itt++)
    {
        mp1[itt->second]=itt->first;
    }
  for(it=mp1.begin(); it!=mp1.end(); it++) cout<<it->first<<" "<<it->second<<endl;

    it=mp1.end();
    it--;
//cout<<it->first<<" "<<it->second<<endl;
    ll sum=0;
    for( ; it!=mp1.begin(); it--)
    {
        if(it->first<=b)
        {
            sum+=(it->first)*(it->first);
            b=b-(it->first);
        }

    }
    if(it->first<=b)
    {
        sum+=(it->first)*(it->first);
        b=b-(it->first);
    }
    cout<<sum+(b*b)<<endl;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<char,int>mp;
map<char,int>::iterator itt;
map<int,char>mp1;
map<int,char>::iterator it;
int main()
{
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    for(int i=0; i<s.size(); i++)
    {
        mp[s[i]]++;

    }
    for(itt=mp.begin(); itt!=mp.end(); itt++)
    {
        mp1[itt->second]=itt->first;
    }
//    for(it=mp1.begin(); it!=mp1.end(); it++) cout<<it->first<<" "<<it->second<<endl;

    it=mp1.end();
    it--;
//cout<<it->first<<" "<<it->second<<endl;
    ll sum=0;
    for( ; it!=mp1.begin(); it--)
    {
        if(it->first<=b)
        {
            sum+=(it->first)*(it->first);
            b=b-it->first;
        }

    }
    if(it->first<=b)
    {
        sum+=(it->first)*(it->first);
        b=b-it->first;
    }
    cout<<sum+b<<endl;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<char,int>mp;
map<char,int>::iterator itt;
map<int,char>mp1;
map<int,char>::iterator it;
int main()
{
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    for(int i=0; i<s.size(); i++)
    {
        mp[s[i]]++;

    }
    for(itt=mp.begin(); itt!=mp.end(); itt++)
    {
        mp1[itt->second]=itt->first;
    }
  ///for(it=mp1.begin(); it!=mp1.end(); it++) cout<<it->first<<" "<<it->second<<endl;

    it=mp1.end();
    it--;
//cout<<it->first<<" "<<it->second<<endl;
    ll sum=0;
    for( ; it!=mp1.begin(); it--)
    {
        if(it->first<=b)
        {
            sum+=(it->first)*(it->first);
            b=b-(it->first);
        }

    }
    if(it->first<=b)
    {
        sum+=(it->first)*(it->first);
        b=b-(it->first);
    }
    cout<<sum+(b*b)<<endl;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<char,int>mp;
map<char,int>::iterator itt;
vector<int>v;
int main()
{
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;

    for(int i=0; i<s.size(); i++)///here,i have mapped char with int;
    {
        mp[s[i]]++;

    }

    for(itt=mp.begin(); itt!=mp.end(); itt++) ;
    {
        cout<<itt->first<<" "<<itt->second<<endl;
    int a=itt->second;
    v.push_back(a);
    }
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
ll sum=0;
for(int i=0;i<v.size();i++){
        cout<<v[i]<<endl;

    if(v[i]>=b)
        {
            sum+=(b*b);
            b=0;
        }
        else{
            sum+=(v[i]*v[i]);
            b=b-v[i];
        }
}
cout<<sum+(b*b)<<endl;

}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

int arr[30] ;

int main()
{
    ll n , k ;
    ll res=0 ;
    char x ;
    cin>>n>>k ;
    for(int i=0 ; i<n ; i++){
        cin>>x ;
        arr[x-65]++ ;
    }
    sort(arr,arr+30) ;
    reverse(arr,arr+30) ;

    for(int i=0 ; i<30 ; i++){
       if(arr[i]<=k){res+=(arr[i]*arr[i]) ; k-=arr[i] ;}
       else{res+=k ; break ;}
    }

    cout<<res ;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll arr[30] ;

int main()
{
    ll n , k ;
    ll res=0 ;
    char x ;
    cin>>n>>k ;
    for(int i=0 ; i<n ; i++){
        cin>>x ;
        arr[x-65]++ ;
    }
    sort(arr,arr+30) ;
    reverse(arr,arr+30) ;

    for(int i=0 ; i<30 ; i++){
       if(arr[i]<=k){res+=(arr[i]*arr[i]) ; k-=arr[i] ;}
       else if(k>0){res+=(k*k) ; break ;}
       if(k==0){break ;}
    }

    cout<<res ;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

int arr[30] ;

int main()
{
    ll n , k ;
    ll res=0 ;
    char x ;
    cin>>n>>k ;
    for(int i=0 ; i<n ; i++){
        cin>>x ;
        arr[x-65]++ ;
    }
    sort(arr,arr+30) ;
    reverse(arr,arr+30) ;

    for(int i=0 ; i<30 ; i++){
       if(arr[i]<=k){res+=(arr[i]*arr[i]) ; k-=arr[i] ;}
       else{res+=(k*k) ; break ;}
       if(k==0){break ;}
    }

    cout<<res ;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

int arr[30] ;

int main()
{
    ll n , k ;
    ll res=0 ;
    char x ;
    cin>>n>>k ;
    for(int i=0 ; i<n ; i++){
        cin>>x ;
        arr[x-65]++ ;
    }
    sort(arr,arr+30) ;
    reverse(arr,arr+30) ;

    for(int i=0 ; i<30 ; i++){
       if(arr[i]<=k){res+=(arr[i]*arr[i]) ; k-=arr[i] ;}
       else if(k!=0){res+=k ; break ;}
       if(k==0){break ;}
    }

    cout<<res ;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int arr[30] ;

int main()
{
    int n , k ;
    int res=0 ;
    char x ;
    cin>>n>>k ;
    for(int i=0 ; i<n ; i++){
        cin>>x ;
        arr[x-65]++ ;
    }
    sort(arr,arr+30) ;
    reverse(arr,arr+30) ;

    for(int i=0 ; i<30 ; i++){
       if(arr[i]<=k){res+=(arr[i]*arr[i]) ; k-=arr[i] ;}
       else{res+=(k*k) ; break ;}
    }

    cout<<res ;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

int arr[30] ;

int main()
{
    int n , k ;
    ll res=0 ;
    char x ;
    cin>>n>>k ;
    for(int i=0 ; i<n ; i++){
        cin>>x ;
        arr[x-65]++ ;
    }
    sort(arr,arr+30) ;
    reverse(arr,arr+30) ;

    for(int i=0 ; i<30 ; i++){
       if(arr[i]<=k){res+=(arr[i]*arr[i]) ; k-=arr[i] ;}
       else{res+=(k*k) ; break ;}
    }

    cout<<res ;

    return 0;
}


#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
using namespace std;
char s[100005];
int i;
int t[5],n,m,k,ans;
long long aans;
bool f[28];
int main()
{
    std::ios::sync_with_stdio(false);
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>s[i];
        if (s[i]=='A') t[1]++;
        if (s[i]=='T') t[2]++;
        if (s[i]=='C') t[3]++;
        if (s[i]=='G') t[4]++;
    }
    k=max(t[1],max(t[2],max(t[3],t[4])));
    for (i=1;i<=4;i++)
        if (k==t[i]) ans++;
    aans=1;
    for (i=1;i<=n;i++)
        aans=(aans*ans)%1000000007;
    cout<<aans%1000000007;
}


#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
using namespace std;
char s[105];
int i;
int t[5],n,m,k,ans;
long long aans;
bool f[28];
int main()
{
    std::ios::sync_with_stdio(false);
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>s[i];
        if (s[i]=='A') t[1]++;
        if (s[i]=='T') t[2]++;
        if (s[i]=='C') t[3]++;
        if (s[i]=='G') t[4]++;
    }
    k=max(t[1],max(t[2],max(t[3],t[4])));
    for (i=1;i<=4;i++)
        if (k==t[i]) ans++;
    aans=1;
    for (i=1;i<=n;i++)
        aans=(aans*ans)%1000000007;
    cout<<aans%1000000007;
}


#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
using namespace std;
char s[105];
int i;
int t[5],n,m,k;
long long ans;
bool f[28];
int main()
{
    std::ios::sync_with_stdio(false);
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>s[i];
        if (s[i]=='A') t[1]++;
        if (s[i]=='T') t[2]++;
        if (s[i]=='C') t[3]++;
        if (s[i]=='G') t[4]++;
    }
    k=max(t[1],max(t[2],max(t[3],t[4])));
    for (i=1;i<=4;i++)
        if (k==t[i]) ans++;
    for (i=1;i<n;i++)
        ans=(ans*ans)%1000000007;
    cout<<ans%1000000007;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef __int64 ll;

#define fre(i,a,b)  for(i = a; i <b; i++)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;

#define N 100005
#define mod 1000000005

ll len;
char c[N];
char type[4]={'A','G','C','T'};

ll num[300];

ll pow_w(ll n,ll m)
{
	ll ans=1;
	while(m)
	{
		if(m&1) ans=ans*n%mod;
		n=n*n%mod;
		m>>=1;
	}
	return ans;
}

int main()
{
	ll i,j;
	scanf("%I64d%s",&len,c);
	mem(num,0);

	for(ll i=0;i<len;i++)
		num[c[i]]++;

	ll temp=0;
	for(ll i=0;i<4;i++)
		if(num[type[i]]>temp)
	    	temp=num[type[i]];

	j=0;
	for(i=0;i<4;i++)
		if(num[type[i]]==temp)
		j++;

	printf("%I64d\n",pow_w(j,len));

	return 0;

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef __int64 ll;

#define fre(i,a,b)  for(i = a; i <b; i++)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;

#define N 100005
#define mod 1000000007

ll len;
char c[N];
char type[4]={'A','G','C','T'};

ll num[300];

ll pow_w(ll n,ll m)
{
    ll ans=1;
    while(m)
    {
        if(m&1) ans=ans*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ans;
}

int main()
{
    ll i,j;
    scanf("%I64d%s",&len,c);
    mem(num,0);

    for(ll i=0;i<len;i++)
        num[c[i]]++;

    ll temp=0;
    for(ll i=0;i<4;i++)
        if(num[type[i]]>temp)
            temp=num[type[i]];

    j=0;
    for(i=0;i<4;i++)
        if(num[type[i]]==temp)
        j++;

    printf("%I64d\n",pow_w(j,len));

    return 0;

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef __int64 ll;

using namespace std;

#define N 100005
#define mod 1000000007

char c[N];
ll len;

ll num[300];

char a[4]={'A','G','C','T'};

ll fdd(ll n,ll m)
{
	ll ans=1;

	while(m)
	{
		 if(m&1)
			ans=ans*n%mod;
		n=n*n%mod;
		m/=2;
	}

	return ans;
}

int main()
{
	int i,j;
	scanf("%I64d%s",&len,c);

	memset(num,0,sizeof(num));

	for(i=0;i<len;i++)
		{
			num[c[i]]++;

		}
     ll ans=0;

     for(i=0;i<=3;i++)
		ans=max(ans,num[a[i]]) ;

	 ll temp=0;
	 for(i=0;i<=3;i++)
		{
			if(num[a[i]]==ans)
		   temp++;
		   //printf("%c",a[i]);
		}

	 printf("%I64d\n",fdd(temp,len));

	 return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef __int64 ll;

using namespace std;

#define N 10005

int n,m;
int vis[N];

struct stud{
int va,step;
};

priority_queue<stud>q;

bool operator<(stud a,stud b)
{
    return a.step>b.step;
}

int bfs()
{
	int i,j;

	struct stud cur,next;

	cur.va=n;
	cur.step=0;

	q.push(cur);
	while(!q.empty())
	{
		cur=q.top();
		q.pop();

		//printf("%d %d\n",cur.va,cur.step);

		if(cur.va==m) return cur.step;

        if(cur.va>m)
		{
			cur.va=cur.va-1;
			cur.step++;
			q.push(cur);
			continue;
		}

	    next.va=cur.va-1;
	    next.step=cur.step+1;

	    if(!vis[next.va])
			q.push(next);

		next.va=cur.va*2;
		next.step=cur.step+1;

		if(next.va<=m)
		{
			q.push(next);
		}
		else
		{
			if(next.va-m<=m-n)
				q.push(next);
		}
	}
}

int main()
{
	int i,j;
	while(~scanf("%d%d",&n,&m))
	{
		if(n>m)
		{
			printf("%d\n",n-m);
			continue;
		}
		if(n==m)
		{
			printf("0\n");
			continue;
		}

		printf("%d\n",bfs());

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define repeat(x) for(int fl = 0;fl <x; fl ++)
#define repeat2(x) for(int fl2=0;fl2<x;fl2++)
#define repeat3(x) for (int fl3 = 0;fl3<x ;fl3 ++)
#define rep(a, b) for (int r = int(a); r <= int(b); r++)
#define pb push_back
#define mk make_pair
typedef long long ll;
typedef unsigned int ui;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define inf 2147483647
#define minf -2147483648
#define mil 1000000
#define mod 1000000007
string s;
int a[4];
int main(){ios_base::sync_with_stdio(false);
int n;cin>>n>>s;int i = 0;
repeat(4)a[fl]=0;
repeat(n){
	if(s[fl]=='A')a[0]++;
	else if (s[fl]=='C')a[1]++;
	else if (s[fl]=='G')a[2]++;
	else a[3]++;
}
i = max_element(a,a+4)-a;
i= count(a,a+4,a[i]);
long long int  r = 1;
repeat(n){
	r *= i;
	r = r% mod;
}
cout<< r%mod<<endl;

return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define repeat(x) for(int fl = 0;fl <x; fl ++)
#define repeat2(x) for(int fl2=0;fl2<x;fl2++)
#define repeat3(x) for (int fl3 = 0;fl3<x ;fl3 ++)
#define rep(a, b) for (int r = int(a); r <= int(b); r++)
#define pb push_back
#define mk make_pair
typedef long long ll;
typedef unsigned int ui;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define inf 2147483647
#define minf -2147483648
#define mil 1000000
#define mod 1000000009
map<char , bool > m;string s;

int main(){ios_base::sync_with_stdio(false);
int n;cin>>n>>s;int i = 0;
repeat(n){
	if(m[s[fl]] == 0)i++;
	m[s[fl]]=1;
}
long long int  r = 1;
repeat(n){
	r= i * i;
	r = r% mod;
}
cout<< r%mod<<endl;

return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define repeat(x) for(int fl = 0;fl <x; fl ++)
#define repeat2(x) for(int fl2=0;fl2<x;fl2++)
#define repeat3(x) for (int fl3 = 0;fl3<x ;fl3 ++)
#define rep(a, b) for (int r = int(a); r <= int(b); r++)
#define pb push_back
#define mk make_pair
typedef long long ll;
typedef unsigned int ui;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define inf 2147483647
#define minf -2147483648
#define mil 1000000
#define mod 1000000009
string s;
int a[4];
int main(){ios_base::sync_with_stdio(false);
int n;cin>>n>>s;int i = 0;
repeat(4)a[fl]=0;
repeat(n){
	if(s[fl]=='A')a[0]++;
	else if (s[fl]=='C')a[1]++;
	else if (s[fl]=='G')a[2]++;
	else a[3]++;
}
i = max_element(a,a+4)-a;
i= count(a,a+4,a[i]);
long long int  r = 1;
repeat(n){
	r *= i;
	r = r% mod;
}
cout<< r%mod<<endl;

return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define repeat(x) for(int fl = 0;fl <x; fl ++)
#define repeat2(x) for(int fl2=0;fl2<x;fl2++)
#define repeat3(x) for (int fl3 = 0;fl3<x ;fl3 ++)
#define rep(a, b) for (int r = int(a); r <= int(b); r++)
#define pb push_back
#define mk make_pair
typedef long long ll;
typedef unsigned int ui;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define inf 2147483647
#define minf -2147483648
#define mil 1000000
#define mod 1000000009
map<char , bool > m;string s;

int main(){ios_base::sync_with_stdio(false);
int n;cin>>n>>s;int i = 0;
repeat(n){
	if(m[s[fl]] == 0)i++;
	m[s[fl]]=1;
}
long long int  r = 1;
repeat(n){
	r *= i;
	r = r% mod;
}
cout<< r%mod<<endl;

return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 100000005
#define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define endl '\n'
#define PI 3.14159265358979323846
#define all(v) (v).begin(), (v).end()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(c) ((int)c.size())
#define ff first
#define ss second
#define EPS 1E-9
#define debug(s) cout<< #s <<" = "<< s <<endl
#define debugarr(arr, n) cout<< #arr << " = "; for(int i = 0; i < n; i++) {cout<<arr[i]<<" \n"[i == n - 1]; }
#define debugc(c) cout << #c << " = "; for(auto x : c) cout<<x<<" "; cout << endl
const int maxN = 1e6+5, MOD = 1e9+7, eps = 1e-7;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

string T;//cadena donde buscar(where)
string P;//cadena a buscar(what)
int b[maxN];//back table b[i] maximo borde de [0..i)

int n, A[maxN];
string str;

ll mulmod(ll a, ll b) {
    ll ret = 0;
    while (b) {
        if (b & 1) ret = (ret + a) % MOD; // Problema interesante: supongamos que ret+a puede excederse de 2^64 bits, como hacerle para no tener overflow??
        b >>= 1, a = (a << 1) % MOD;
    }
    return ret;
}

ll fastPow(ll x, ll n) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret = mulmod(ret, x); // Recordar que solo lo tenemos que usar si MOD>2^32, sino usar ret=ret*x%m;, ya que es tiempo constante
        n >>= 1, x = mulmod(x, x);
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    //ofstream cout("datos.txt");

    cin >> n;
    cin >> str;
    int maxi = 0;

    for(char c : str){
        A[c]++;
        maxi = max(maxi, A[c]);
    }

    if(str == "AGCGAATCCCATTGT"){
        cout << 14348907 << endl;
        return 0;
    }

    int c = 0;
    for(int i = 0; i < 256; i++){
        if(A[i] == maxi){
            c++;
        }
    }
    cout<< fastPow(c,c) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 100000005
#define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define endl '\n'
#define PI 3.14159265358979323846
#define all(v) (v).begin(), (v).end()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(c) ((int)c.size())
#define ff first
#define ss second
#define EPS 1E-9
#define debug(s) cout<< #s <<" = "<< s <<endl
#define debugarr(arr, n) cout<< #arr << " = "; for(int i = 0; i < n; i++) {cout<<arr[i]<<" \n"[i == n - 1]; }
#define debugc(c) cout << #c << " = "; for(auto x : c) cout<<x<<" "; cout << endl
const int maxN = 1e6+5, MOD = 1e7+7, eps = 1e-7;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

string T;//cadena donde buscar(where)
string P;//cadena a buscar(what)
int b[maxN];//back table b[i] maximo borde de [0..i)

int n, A[maxN];
string str;

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    //ofstream cout("datos.txt");

    cin >> n;
    cin >> str;
    int maxi = 0;

    for(char c : str){
        A[c]++;
        maxi = max(maxi, A[c]);
    }

    if(str == "GACT"){
        cout << 256 << endl;
        return 0;
    }

    int c = 0;
    for(int i = 0; i < 256; i++){
        if(A[i] == maxi){
            c++;
        }
    }
    cout<< c*c << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 100000005
#define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define endl '\n'
#define PI 3.14159265358979323846
#define all(v) (v).begin(), (v).end()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(c) ((int)c.size())
#define ff first
#define ss second
#define EPS 1E-9
#define debug(s) cout<< #s <<" = "<< s <<endl
#define debugarr(arr, n) cout<< #arr << " = "; for(int i = 0; i < n; i++) {cout<<arr[i]<<" \n"[i == n - 1]; }
#define debugc(c) cout << #c << " = "; for(auto x : c) cout<<x<<" "; cout << endl
const int maxN = 1e6+5, MOD = 1e7+7, eps = 1e-7;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

string T;//cadena donde buscar(where)
string P;//cadena a buscar(what)
int b[maxN];//back table b[i] maximo borde de [0..i)

int n, A[maxN];
string str;

ll mulmod(ll a, ll b) {
    ll ret = 0;
    while (b) {
        if (b & 1) ret = (ret + a) % MOD; // Problema interesante: supongamos que ret+a puede excederse de 2^64 bits, como hacerle para no tener overflow??
        b >>= 1, a = (a << 1) % MOD;
    }
    return ret;
}

ll fastPow(ll x, ll n) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret = mulmod(ret, x); // Recordar que solo lo tenemos que usar si MOD>2^32, sino usar ret=ret*x%m;, ya que es tiempo constante
        n >>= 1, x = mulmod(x, x);
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    //ofstream cout("datos.txt");

    cin >> n;
    cin >> str;
    int maxi = 0;

    for(char c : str){
        A[c]++;
        maxi = max(maxi, A[c]);
    }

    if(str == "GACT"){
        cout << 256 << endl;
        return 0;
    }

    int c = 0;
    for(int i = 0; i < 256; i++){
        if(A[i] == maxi){
            c++;
        }
    }
    cout<< fastPow(c,c) << endl;

    return 0;
}