Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card i you should calculate how much Toastman's cards have the letter equal to letter on ith, then sum up all these quantities, such a number of coins Appleman should give to Toastman.

Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?


-----Input-----

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5). The next line contains n uppercase letters without spaces — the i-th letter describes the i-th card of the Appleman.


-----Output-----

Print a single integer – the answer to the problem.


-----Examples-----
Input
15 10
DZFDFZDFDDDDDDF

Output
82

Input
6 4
YJSNPI

Output
4



-----Note-----

In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin.

Difficulty: EASY

Solutions:
import sys
import math
(n, k) = map(int, input().split())
stra = str(input())
freqa = [0 for i in range(26)]
for i in range(len(stra)):
	freqa[ord(stra[i]) - ord('A')] += 1
freqa = sorted(freqa, reverse=True)
(storc, suma) = (0, 0)
for i in range(len(freqa)):
	if storc < k:
		card = min(freqa[i], k - storc)
		suma += card * card
		storc += card
	else:
		break
print(suma)


from collections import Counter

def __starting_point():
	(n, k) = [int(i) for i in input().split()]
	c = Counter(input())
	res = 0
	tmp = k
	for (w, n) in c.most_common():
		if tmp > n:
			tmp -= n
			res += n * n
		else:
			res += tmp * tmp
			break
	print(res)
__starting_point()


(n, k) = list(map(int, input().split()))
s = input()
count = [0] * 26
for c in s:
	count[ord(c) - 65] += 1
count = sorted(count, reverse=True)
res = 0
i = 0
while i < len(count) and k != 0:
	if k >= count[i]:
		res += count[i] * count[i]
		k -= count[i]
	else:
		res += k * k
		k = 0
	i += 1
print(res)


from collections import Counter
(n, k) = map(int, input().split())
cards = [card for card in input().strip()]
options = sorted(Counter(cards).values(), reverse=True)
choices = []
for option in options:
	if k >= option:
		choices.append(option)
		k -= option
	else:
		choices.append(k)
		break
print(sum([choice ** 2 for choice in choices]))


(a, b) = map(int, input().split())
s = input()
l = [0] * 26
for i in range(a):
	l[ord(s[i]) - 65] += 1
l.sort()
l.reverse()
s = 0
c = 0
for i in range(26):
	if s < b:
		if b - s >= l[i]:
			c = c + l[i] * l[i]
			s = s + l[i]
		else:
			c = c + (b - s) * (b - s)
			s = b
	else:
		break
print(c)


arr = [int(x) for x in input().split()]
n = arr[0]
k = arr[1]
cards = list(input())
aux = {}
for card in cards:
	if card not in aux:
		aux[card] = 1
	else:
		aux[card] += 1
aux = sorted(aux.items(), key=lambda x: x[1], reverse=True)
resp = 0
rem = k
for i in aux:
	if rem - i[1] <= 0:
		resp += rem * rem
		break
	else:
		resp += i[1] * i[1]
	rem -= i[1]
print(resp)


(n, k) = map(int, input().split(' '))
cards = input()
letters = {}
for card in cards:
	if card not in letters:
		letters[card] = 1
	else:
		letters[card] += 1
arr = []
for (key, value) in letters.items():
	arr.append(value)
arr.sort(reverse=True)
coins = 0
i = 0
while k > 0 and i < len(arr):
	if k > arr[i]:
		coins += arr[i] ** 2
	else:
		coins += k ** 2
	k -= arr[i]
	i += 1
print(coins)


aux = input().split(' ')
n = int(aux[0])
k = int(aux[1])
cards = input()
counter = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
for i in list(cards):
	counter[alphabet.index(i)] += 1
counter.sort()
answer = 0
i = 26
while i >= 0 and k > 0:
	if k >= counter[i]:
		k -= counter[i]
		answer += counter[i] ** 2
	else:
		answer += k ** 2
		break
	i -= 1
print(answer)


def main():
	(n, k) = [int(i) for i in input().split(' ')]
	cards = input()
	letters = []
	for i in range(n):
		if cards[i] not in letters:
			letters.append(cards[i])
	l = len(letters)
	freq = [0 for i in range(l)]
	for i in range(l):
		freq[i] = cards.count(letters[i])
	total = 0
	while k != 0:
		m = max(freq)
		if m > k:
			total = total + k * k
			k = 0
		else:
			k = k - m
			total = total + m * m
			freq.remove(m)
	print(total)
main()


(n, k) = map(int, input().split())
s = input()
a = [0] * 26
for i in s:
	a[ord(i) - ord('A')] += 1
a.sort()
a = a[::-1]
i = 0
b = []
k1 = k
while i < n and k1 > 0:
	b.append(min(k1, a[i]))
	k1 -= a[i]
	i += 1
ans = 0
for i in b:
	ans += i * i
print(ans)


from collections import Counter

def solve(n, k, ar):
	dict = Counter(ar)
	dict = sorted(dict.values())
	dict.reverse()
	ans = []
	cnt = 0
	for i in range(len(dict)):
		if k <= 0:
			break
		if dict[i] <= k:
			ans.append(dict[i])
			k -= dict[i]
		else:
			ans.append(k)
			k = 0
			break
	for i in range(len(ans)):
		cnt += ans[i] ** 2
	print(cnt)
(n, k) = map(int, input().split())
ar = list(input())
solve(n, k, ar)


from collections import Counter
(n, k) = map(int, input().split())
z = Counter(input())
cnt = sorted([z[x] for x in z])[::-1]
ans = 0
for x in cnt:
	ans += min(k, x) ** 2
	k -= min(k, x)
print(ans)


(n, k) = [int(x) for x in input().split()]
car = list(input())
d = {}
for i in range(n):
	d[car[i]] = d.get(car[i], 0) + 1
sortedd = sorted(d.items(), key=lambda x: x[1])
coins = 0
while k > 0:
	x = sortedd[len(sortedd) - 1][1]
	if x > k:
		coins += k * k
		k = 0
	else:
		k = k - x
		coins += x * x
	sortedd.pop()
print(coins)


from sys import *
from math import *
(n, k) = map(int, stdin.readline().split())
a = list(input())
cnt = [0] * 26
d = {}
for i in range(n):
	cnt[ord(a[i]) - 65] += 1
cnt.sort()
cnt = cnt[::-1]
j = 0
ans = 0
for i in range(26):
	if j == k:
		break
	x = min(k - j, cnt[i])
	j += x
	ans += x * x
print(ans)


(n, k) = list(map(int, input().split()))
lista = list(input())
from collections import Counter
c = Counter(lista)
soma = 0
while k > 0:
	m = c.most_common(1)
	del c[m[0][0]]
	qtd = min(k, m[0][1])
	soma += qtd ** 2
	k -= qtd
print(soma)


(n, k) = map(int, input().split())
s = input()
g = set(s)
h = {}
for i in g:
	m = s.count(i)
	h[i] = m
t = [h[i] for i in h]
t = sorted(t, reverse=True)
j = 0
ans = 0
i = 0
while k > 0:
	f = min(k, t[i])
	k -= f
	ans += f ** 2
	i += 1
print(ans)


count = [0] * 26
(n, k) = list(map(int, input().split()))
cards = input()
for c in cards:
	count[ord(c) - ord('A')] += 1
count.sort(reverse=True)
ans = 0
for c in count:
	if k - c >= 0:
		ans += c ** 2
		k -= c
	else:
		ans += k ** 2
		break
print(ans)


from collections import Counter
firstLineArr = str(input()).split(' ')
applemanTotalCards = int(firstLineArr[0])
toastmanTotalCards = int(firstLineArr[1])
applemanArr = list(str(input()))
array = sorted(applemanArr, key=Counter(applemanArr).get, reverse=True)
cardsSelected = 0
totalCoins = 0
counter = 0
while toastmanTotalCards > cardsSelected:
	countOfCurrentCard = array.count(array[counter])
	if countOfCurrentCard >= toastmanTotalCards - cardsSelected:
		totalCoins += (toastmanTotalCards - cardsSelected) * (toastmanTotalCards - cardsSelected)
		break
	elif countOfCurrentCard < toastmanTotalCards:
		totalCoins += countOfCurrentCard * countOfCurrentCard
		cardsSelected += countOfCurrentCard
	counter += countOfCurrentCard
print(totalCoins)


(n, k) = map(int, input().split())
s = input()
from collections import Counter
arr = list(sorted(Counter(s).values(), reverse=True))
points = 0
idx = 0
while k > 0:
	temp = min(arr[idx], k)
	k -= temp
	points += temp * temp
	idx += 1
print(points)


(n, k) = map(int, input().split())
a = [0] * 26
s = input()
for c in s:
	a[ord(c) - ord('A')] += 1
a.sort(reverse=True)
t = 0
i = 0
while k > 0:
	t += min(k, a[i]) ** 2
	k -= min(k, a[i])
	i += 1
print(t)


(n, k) = map(int, input().split())
L = list(input())
L.sort()
t = [1]
for i in range(len(L) - 1):
	if L[i] == L[i + 1]:
		t[-1] += 1
	else:
		t.append(1)
t.sort()
s = 0
for i in range(1, len(t) + 1):
	if k - t[-i] >= 0:
		k -= t[-i]
		s += t[-i] ** 2
	else:
		s += k * k
		break
print(s)


(n, m) = map(int, input().split())
s = str(input())
cnt = [0] * 26
for c in s:
	cnt[ord(c) - ord('A')] += 1
ans = 0
while m > 0:
	cMaxC = 0
	cMaxCPos = 0
	for i in range(26):
		if cnt[i] > cMaxC:
			cMaxC = cnt[i]
			cMaxCPos = i
	ans += min(cMaxC, m) ** 2
	m -= cMaxC
	cnt[cMaxCPos] = 0
print(ans)


(n, k) = list(map(int, input().split()))
inpt = input()
Main = [0] * 26
for count in inpt:
	Main[ord(count) - ord('A')] += 1
Main.sort(reverse=True)
MainPrint = 0
for i in range(26):
	if k <= Main[i]:
		MainPrint += k ** 2
		break
	else:
		MainPrint += Main[i] ** 2
		k -= Main[i]
print(MainPrint)


from collections import defaultdict
(n, k) = map(int, input().split())
s = input()
dict = defaultdict(lambda : 0)
for i in s:
	dict[i] += 1
list = sorted(dict.values())
c = 0
ans = 0
while c < k and list:
	v = list.pop()
	if c + v > k:
		ans += (k - c) ** 2
	else:
		ans += v ** 2
	c += v
print(ans)


(a, b) = map(int, input().split())
c = input()
dict = {}
for i in c:
	dict[i] = dict.get(i, 0)
	dict[i] += 1
a = sorted(dict.values())
r = 0
while b > 0:
	e = a.pop()
	if b > e:
		r += e * e
		b -= e
	else:
		r += b * b
		b = 0
print(r)


from collections import defaultdict
(n, k) = map(int, input().split())
s = input()
d = defaultdict(int)
a = []
for i in s:
	d[i] += 1
for key in d:
	a.append(d[key])
a.sort(reverse=True)
i = 0
ans = 0
while k:
	if a[i] < k:
		ans += a[i] ** 2
		k -= a[i]
		i += 1
	else:
		ans += k ** 2
		break
print(ans)


import collections
(val, mini) = (0, 0)
(n, k) = map(int, input().split())
s = input()
dic = collections.Counter(s)
for i in sorted(dic.values())[::-1]:
	mini = min(k, i)
	val += mini * mini
	k -= mini
print(val)


(a, b) = map(int, input().split())
x = input()
counts = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0, 'F': 0, 'G': 0, 'H': 0, 'I': 0, 'J': 0, 'K': 0, 'L': 0, 'M': 0, 'N': 0, 'O': 0, 'P': 0, 'Q': 0, 'R': 0, 'S': 0, 'T': 0, 'U': 0, 'V': 0, 'W': 0, 'X': 0, 'Y': 0, 'Z': 0}
for i in range(26):
	counts[chr(i + 65)] = x.count(chr(65 + i))
y = []
for i in list(counts.items()):
	y.append(i[1])
y.sort()
y = y[::-1]
tot = 0
count = 0
while b and count < 26:
	if b > y[count]:
		tot += y[count] ** 2
		b -= y[count]
	else:
		tot += b ** 2
		b = 0
	count += 1
print(tot)


(n, k) = map(int, input().split())
a = input()
b = a[:]
c = []
max = -1
for i in range(len(a)):
	if a[i] != '1':
		count = b.count(a[i])
		a = a.replace(a[i], '1')
		c.append(count)
c.sort()
flag = 0
total = 0
for i in range(len(c) - 1, -1, -1):
	preflag = flag
	flag += c[i]
	if flag < k:
		total += c[i] * c[i]
	elif flag == k:
		total += c[i] * c[i]
		break
	else:
		total += (k - preflag) * (k - preflag)
		break
print(total)


(n, k) = map(int, input().split())
s = input()
l = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in range(len(s)):
	if s[i] == 'A':
		l[0] = l[0] + 1
	elif s[i] == 'B':
		l[1] = l[1] + 1
	elif s[i] == 'C':
		l[2] = l[2] + 1
	elif s[i] == 'D':
		l[3] = l[3] + 1
	elif s[i] == 'E':
		l[4] = l[4] + 1
	elif s[i] == 'F':
		l[5] = l[5] + 1
	elif s[i] == 'G':
		l[6] = l[6] + 1
	elif s[i] == 'H':
		l[7] = l[7] + 1
	elif s[i] == 'I':
		l[8] = l[8] + 1
	elif s[i] == 'J':
		l[9] = l[9] + 1
	elif s[i] == 'K':
		l[10] = l[10] + 1
	elif s[i] == 'L':
		l[11] = l[11] + 1
	elif s[i] == 'M':
		l[12] = l[12] + 1
	elif s[i] == 'N':
		l[13] = l[13] + 1
	elif s[i] == 'O':
		l[14] = l[14] + 1
	elif s[i] == 'P':
		l[15] = l[15] + 1
	elif s[i] == 'Q':
		l[16] = l[16] + 1
	elif s[i] == 'R':
		l[17] = l[17] + 1
	elif s[i] == 'S':
		l[18] = l[18] + 1
	elif s[i] == 'T':
		l[19] = l[19] + 1
	elif s[i] == 'U':
		l[20] = l[20] + 1
	elif s[i] == 'V':
		l[21] = l[21] + 1
	elif s[i] == 'W':
		l[22] = l[22] + 1
	elif s[i] == 'X':
		l[23] = l[23] + 1
	elif s[i] == 'Y':
		l[24] = l[24] + 1
	elif s[i] == 'Z':
		l[25] = l[25] + 1
l.sort(reverse=True)
while l[len(l) - 1] == 0:
	l.pop()
r = 0
for i in range(len(l)):
	if l[i] == k:
		r = r + l[i] * l[i]
		print(r)
		break
	elif l[i] < k:
		r = r + l[i] * l[i]
		k = k - l[i]
	elif k == 1:
		r = r + 1
		print(r)
		break
	elif k < l[i]:
		r = r + k * k
		print(r)
		break


(n, k) = list(map(int, input().split()))
s = input()
count = {}
for c in s:
	count[c] = count.get(c, 0) + 1
a = sorted(list(count.values()), reverse=True)
coins = 0
for c in a:
	if c >= k:
		coins += k * k
		break
	coins += c * c
	k -= c
print(coins)


import sys
import math
(dokopy, moze) = map(int, input().split())
string = input()
dupl = moze
d = [0] * 26
sucet = 0
for i in string:
	d[ord(i) - 65] += 1
zoznam = sorted(d, reverse=True)
if moze == 1:
	sucet = 1
	print(sucet)
	sys.exit()
for j in range(0, len(zoznam) - 1):
	if dupl < zoznam[0]:
		sucet = dupl * dupl
		break
	moze -= zoznam[j]
	sucet += pow(zoznam[j], 2)
	if moze <= zoznam[j + 1]:
		sucet += pow(moze, 2)
		break
print(sucet)


(n, k) = map(int, input().split())
s = input()
chars = [0] * 26
for c in s:
	chars[ord(c) - ord('A')] += 1
chars.sort(reverse=True)
rest = k
res = 0
pos = 0
while rest > 0:
	take = min(chars[pos], rest)
	rest -= take
	res += take ** 2
	pos += 1
print(res)


from collections import Counter
(n, k) = map(int, input().split())
st = input()
ans = ''
dct = Counter(st)
lst = sorted(dct.items(), key=lambda s: s[1], reverse=True)
for i in lst:
	if i[1] >= k:
		ans += i[0] * k
		k = 0
		break
	else:
		k -= i[1]
		ans += i[0] * i[1]
dct = Counter(ans)
lst = [i ** 2 for i in dct.values()]
print(sum(lst))


(n, k) = map(int, input().split())
s = input().lower()
ans = 0
letters = [0 for i in range(ord('z') + 1)]
for c in s:
	letters[ord(c)] += 1
while k > 0:
	ans += min(k, max(letters)) ** 2
	k -= max(letters)
	letters[letters.index(max(letters))] = 0
print(ans)


s = input()
f = s.index(' ')
n = int(s[0:f])
k = int(s[f + 1:len(s)])
s = input()
karts = [s[i] for i in range(n)]
karts.sort(key=None, reverse=False)
i = 0
num = [0 for i in range(n + 3)]
h = 0
for i in range(len(karts)):
	if karts[i] != karts[i - 1]:
		h += 1
	num[h] += 1
num.sort(key=None, reverse=True)
result = 0
h = 0
while k - num[h] > 0:
	k -= num[h]
	result += num[h] ** 2
	h += 1
result += k ** 2
print(result)


def get_max():
	maximo = ['', 0]
	for k in dict.keys():
		if maximo[1] < dict[k]:
			maximo[0] = k
			maximo[1] = dict[k]
	return maximo
dict = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0, 'F': 0, 'G': 0, 'H': 0, 'I': 0, 'J': 0, 'K': 0, 'L': 0, 'M': 0, 'N': 0, 'O': 0, 'P': 0, 'Q': 0, 'R': 0, 'S': 0, 'T': 0, 'U': 0, 'V': 0, 'W': 0, 'X': 0, 'Y': 0, 'Z': 0}
values = input()
(n, k) = values.split()
n = int(n)
k = int(k)
string = input()
for i in string:
	dict[i] += 1
soma = 0
while k > 0:
	maxi = get_max()
	if maxi[1] > k:
		soma = soma + k * k
	else:
		soma = soma + maxi[1] ** 2
	temp = k
	k = k - maxi[1]
	dict[maxi[0]] = dict[maxi[0]] - temp
print(soma)


from collections import defaultdict
(n, k) = map(int, input().split())
s = input()
dp = defaultdict(int)
for i in s:
	dp[i] += 1
a = sorted(dp.values(), reverse=True)
c = 0
ans = 0
for i in a:
	if c < k:
		ans += min(i, k - c) * min(i, k - c)
		c = c + min(i, k - c)
	if c >= k:
		break
print(ans)


from collections import Counter

def f(arr, k):
	x = Counter(arr)
	ans = 0
	for (i, j) in sorted(x.items(), key=lambda s: s[1], reverse=True):
		if j <= k:
			k -= j
			ans += j ** 2
		else:
			ans += k ** 2
			k = 0
			break
	return ans
(a, b) = map(int, input().strip().split())
lst = input()
print(f(lst, b))


(n, k) = [int(x) for x in input().split()]
cards = input()
frequency = {}
for card in cards:
	if card not in frequency:
		frequency[card] = 0
	frequency[card] += 1
frequent = list(sorted(frequency.values(), reverse=True))
amount = frequent[0]
leftover = max(k - amount, 0)
coins = (k - leftover) * (k - leftover)
i = 1
while leftover > 0 and i >= 0:
	temp = min(leftover, frequent[i])
	coins = coins + temp * temp
	leftover = leftover - temp
	i += 1
print(coins)


from sys import *
from math import *

def main():
	(n, k) = list(map(int, input().split()))
	s = input()
	l = [0] * 26
	for c in s:
		f = lambda x: ord(x) - ord('A')
		l[f(c)] += 1
	l = sorted(l, reverse=True)
	ans = 0
	for i in l:
		count = min(k, i)
		ans += count * count
		k -= count
		if k == 0:
			break
	print(ans)
main()


(n, k) = map(int, input().split())
lst = list(input())
uni = set(lst)
count = []
for i in uni:
	x = lst.count(i)
	count.append(x)
count.sort()
count.reverse()
ans = []
while k > 0:
	for i in count:
		if i <= k:
			ans.append(i)
			k -= i
			count.remove(i)
			break
		elif i > k:
			ans.append(k)
			k = 0
			break
ans = [i ** 2 for i in ans]
print(sum(ans))


(n, k) = [int(x) for x in input().split(' ')]
string = input()
freq = {}
for x in string:
	if x in freq:
		freq[x] += 1
	else:
		freq[x] = 1
arr = sorted(freq.values(), reverse=True)
ans = 0
for item in arr:
	if not k:
		break
	if item <= k:
		ans += item * item
		k -= item
	else:
		ans += k ** 2
		break
print(ans)


(n, k) = map(int, input().split())
s = list(input())
d = {}
for i in s:
	try:
		d[i] += 1
	except:
		d[i] = 1
new = []
for keys in d:
	new.append(d[keys])
new.sort(reverse=True)
i = 0
total = 0
while k > 0:
	if new[i] <= k:
		total += new[i] ** 2
		k -= new[i]
		i += 1
	else:
		total += k ** 2
		break
print(total)


(n, k) = map(int, input().split())
s = input()
a = []
for i in set(s):
	a.append(s.count(i))
a.sort(reverse=True)
j = 0
for i in a:
	m = min(i, k)
	j += m * m
	k -= m
	if k <= 0:
		break
print(j)


from collections import Counter

def main():
	(n, k) = map(int, input().split())
	cards = input()
	cnt = Counter(cards)
	ans = 0
	for (_, v) in cnt.most_common():
		ans += k * k if v > k else v * v
		k -= v
		if k <= 0:
			break
	print(ans)
main()


import os
from math import *
from bisect import *
(n, k) = map(int, input().split())
s = input()
s = sorted(s)
i = 0
arr = []
while i < n:
	arr.append(bisect_right(s, s[i]) - bisect_left(s, s[i]))
	i += arr[-1]
arr.sort(reverse=True)
k = min(n, k)
i = 0
ans = 0
while k > 0:
	if arr[i] <= k:
		k -= arr[i]
		ans += arr[i] * arr[i]
	else:
		ans += k * k
		break
	i += 1
print(ans)


(n, k) = list(map(int, input().split()))
s = input()
arr = list(s)
arr100 = []
count = 0
arr2 = list(set(arr))
if len(arr2) == n:
	print(k)
else:
	for _ in arr2:
		arr100.append(arr.count(_))
	arr100.sort(reverse=True)
	for kk in arr100:
		smh = min(k, kk)
		k -= smh
		count += smh ** 2
		if k == 0:
			print(count)
			exit()


(n, k) = list(map(int, input().split()))
s = list(input())
s0 = set(s)
dicter = dict()
for i in s0:
	dicter[i] = s.count(i)
mass = sorted(dicter.values(), reverse=True)
i = 0
count = 0
while k > 0:
	if mass[i] < k:
		k -= mass[i]
		count += mass[i] * mass[i]
	else:
		count += k * k
		k = 0
	i += 1
print(count)


(n, k) = map(int, input().split())
di = dict()
s = input()
for i in s:
	di[i] = di.get(i, 0) + 1
ans = 0
se = list(set(s))
se.sort(key=lambda x: di[x], reverse=1)
for i in se:
	ans += min(k, di[i]) * min(k, di[i])
	k -= min(di[i], k)
print(ans)


(n, k) = map(int, input().split())
string = input()
counter = {}
for i in string:
	if i in counter:
		counter[i] += 1
	else:
		counter[i] = 1
counter = [counter[i] for i in counter]
counter.sort(reverse=True)
ans = 0
i = 0
while k > 0 and i < n:
	take = min(counter[i], k)
	ans += take * take
	k -= take
	i += 1
print(ans)


from collections import Counter
(n, k) = list(map(int, input().rstrip().split()))
s = input()
li = [0] * 26
for x in s:
	li[ord(x) - 65] += 1
li.sort(reverse=True)
total = 0
i = 0
while k > 0:
	minm = min(li[i], k)
	total += minm * minm
	k -= minm
	i += 1
print(total)


from collections import Counter

def main():
	(n, k) = map(int, input().split(' '))
	s = input()
	frequency = dict(Counter(s))
	letters = []
	tally = []
	for x in iter(frequency):
		letters.append(x)
		tally.append(frequency[x])
		pass
	coin = 0
	ambil = 0
	tally.sort()
	tally.reverse()
	for x in range(len(tally)):
		if k <= tally[x]:
			coin += k * k
			print(coin)
			return
		else:
			coin += tally[x] * tally[x]
			k -= tally[x]
			pass
		pass
	pass
main()


p = input()
(n, m) = map(int, p.split())
q = input()
w = []
for i in q:
	if i not in w:
		w.append(i)
l = []
for i in range(len(w)):
	l.append(q.count(w[i]))
l.sort(reverse=True)
c = 0
i = 0
while m > 0:
	if m >= l[i]:
		c += l[i] ** 2
		m -= l[i]
		i += 1
	elif m < l[i]:
		c += m ** 2
		m = 0
print(c)


(n, k) = list(map(int, input().split()))
m = 26
d = [0] * m
c = input()
for e in c:
	d[ord(e) - 65] += 1
d.sort(reverse=True)
ans = 0
res = 0
for i in range(m):
	if ans >= k:
		break
	if ans + d[i] <= k:
		ans += d[i]
		res += d[i] * d[i]
	else:
		res += (k - ans) * (k - ans)
		ans = k
print(res)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, m) = f()
s = si()
lc = [0] * 26
mx = 0
for i in s:
	lc[ord(i) - ord('A')] += 1
lc.sort(reverse=True)
ans = 0
crd = 0
for i in lc:
	if crd + i >= m:
		exit(print(ans + (m - crd) ** 2))
	else:
		crd += i
		ans += i ** 2
print(ans)


(n, k) = map(int, input().split())
st = input()
s1 = set(st)
occur = []
for i in s1:
	occur.append(st.count(i))
occur.sort(reverse=True)
count = 0
i = 0
while i < n and k > 0:
	if k >= occur[i]:
		count += occur[i] * occur[i]
		k -= occur[i]
	else:
		count += k * k
		k = 0
	i += 1
print(count)


from collections import Counter
(n, k) = list(map(int, input().split()))
s = list(input())
s = Counter(s).most_common()
left = k
taken = 0
idx = 0
while left > 0:
	el = s[idx]
	num = min(left, el[1])
	taken += num * num
	left -= num
	idx += 1
print(taken)


import collections, math, itertools, bisect, heapq, copy

class Solution:

	def solve(self):
		(n, k) = list(map(int, input().rstrip().split()))
		string = input()
		A = [[0, chr(i)] for i in range(65, 91)]
		for char in string:
			A[ord(char) - 65][0] += 1
		A = sorted(A, key=lambda x: (x[0], x[1]), reverse=True)
		i = 0
		total = 0
		for i in range(len(A)):
			if k <= 0:
				break
			toAdd = min(k, A[i][0])
			k -= A[i][0]
			total += toAdd * toAdd
		print(total)
solution = Solution()
solution.solve()


a = list(input().split())
n = int(a[0])
k = int(a[1])
s = input()
vv = list()
vc = list()
for i in s:
	if i not in vv:
		vv.append(i)
		vc.append(s.count(i))
vc.sort()
sum = 0
for i in range(len(vc) - 1, -1, -1):
	if vc[i] < k:
		sum += vc[i] ** 2
		k -= vc[i]
	else:
		sum += k ** 2
		break
print(sum)


from collections import Counter
(n, k) = map(int, input().split(' '))
s = list(input())
s.sort()
s.sort(key=Counter(s).get, reverse=True)
prev = s[0]
cnt = 0
res = 0
for c in s[:k]:
	if prev == c:
		cnt += 1
	else:
		res += cnt * cnt
		cnt = 1
	prev = c
res += cnt * cnt
print(res)


(n, k) = list(map(int, input().split()))
s = input()
A = [0 for i in range(26)]
for i in s:
	A[ord(i) - 65] += 1
A.sort()
i = 25
ans = 0
while k > 0:
	k -= A[i]
	ans += A[i] * A[i]
	i -= 1
if k < 0:
	k += A[i + 1]
	ans -= A[i + 1] * A[i + 1]
	ans += k * k
print(ans)


(x, y) = input().split(' ')
dic1 = {}
x = int(x)
y = int(y)
j = 0
temp = 0
maxi = 0
index = str()
cost = 0
list1 = list(str(input()))
for i in list1:
	if i in dic1:
		dic1[i] += 1
	else:
		dic1[i] = 1
while j <= y:
	for i in dic1:
		if maxi < dic1[i]:
			maxi = dic1[i]
			index = i
	if maxi > y:
		j = y + 1
		cost = y * y
	elif y - j > maxi:
		j += maxi
		cost += maxi * maxi
	else:
		cost += (y - j) ** 2
		j = y + 1
	maxi = 0
	del dic1[index]
print(cost)


a = input().split(' ')
n = int(a[0])
k = int(a[1])
q = input()
w = set(q)
e = list(w)
l = len(e)
i = 0
t = []
while i < l:
	r = e[i]
	y = q.count(r)
	t.append(y)
	i += 1
t.sort()
t.reverse()
c = list(set(t))
c.sort()
c.reverse()
v = len(t)
b = 0
m = 0
bn = 0
while b < v:
	nj = t[b]
	if nj < k:
		m = m + nj * nj
		k = k - nj
	elif k == 0:
		break
	elif k < nj:
		m = m + k * k
		break
	elif k == nj:
		m = m + nj * nj
		k = k - nj
	b += 1
print(m)


read = lambda : map(int, input().split())
(n, k) = read()
s = input()
from collections import Counter
c = Counter()
for i in s:
	c[i] += 1
d = sorted(c, key=lambda x: -c[x])
ans = 0
for i in d:
	if k == 0:
		break
	cur = min(k, c[i])
	ans += cur ** 2
	k -= cur
print(ans)


freq = [0] * 26
(n, k) = map(int, input().split())
s = input()
for c in s:
	freq[ord(c) - ord('A')] += 1
freq.sort(reverse=True)
ans = 0
for i in freq:
	ans += min(i, k) ** 2
	k -= i
	if k <= 0:
		break
print(ans)


(n, k) = map(int, input().split())
s = input()
ch = []
re = {}
limit = len(s)
c = 1
for i in range(limit):
	if s[i] in re:
		re[s[i]] += 1
	else:
		re[s[i]] = 1
		ch.append(s[i])
li = len(ch)
score = []
for i in range(li):
	score.append(re[ch[i]])
score.sort(reverse=True)
last = len(score)
out = 0
for i in range(last):
	if k == 0:
		break
	if k == score[i]:
		out += score[i] * score[i]
		break
	elif k > score[i]:
		out += score[i] * score[i]
		k -= score[i]
	elif k < score[i]:
		out += k * k
		break
print(out)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 9 + 7
LOGN = 30
T = 1
for _ in range(T):
	(n, k) = list(map(int, stdin.readline().rstrip().split()))
	a = list(stdin.readline().strip('\n'))
	d = {}
	for i in range(n):
		if a[i] not in d:
			d[a[i]] = 0
		d[a[i]] += 1
	st = list(d.values())
	st.sort(reverse=True)
	isOk = True
	ans = 0
	while k > 0:
		if st[0] <= k:
			ans += st[0] ** 2
			k -= st[0]
			st.pop(0)
		else:
			ans += k ** 2
			k = 0
	print(ans)


(n, k) = map(int, input().split())
s = input()
ss = list(set(s))
l = []
for i in ss:
	l.append(s.count(i))
l.sort(reverse=True)
m = 0
i = 0
while k > 0:
	if l[i] < k:
		k = k - l[i]
		m = m + l[i] * l[i]
		i = i + 1
	else:
		m = m + k * k
		k = 0
print(m)


(n, k) = map(int, input().split())
a = str(input())
b = []
l = 0
for i in a:
	if i not in b:
		b.append(i)
		l += 1
c = [0] * l
for l in range(l):
	for i in range(n):
		if b[l] == a[i]:
			c[l] += 1
c.sort()
x = 0
while k > 0:
	if k >= c[l]:
		k -= c[l]
		x = x + c[l] * c[l]
		del c[l]
		l -= 1
	elif k < c[l]:
		x = x + k * k
		k -= k
print(x)


def main():
	(n, k) = map(int, input().split())
	cards = list(input())
	c = 0
	d = {}
	for i in range(n):
		letter = cards[i]
		if letter not in d:
			d[letter] = 1
		else:
			d[letter] += 1
	d = sorted(d.items(), key=lambda x: x[1], reverse=True)
	for (key, value) in d:
		if k > 0:
			if value > k:
				c += k ** 2
				break
			elif value == k:
				c += k ** 2
				break
			else:
				c += value ** 2
				k -= value
	return c
print(main())


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
(n, k) = rinput()
cards = input()
s = []
for item in set(cards):
	s.append(cards.count(item))
s.sort(reverse=True)
ans = 0
for item in s:
	if item >= k:
		ans += k * k
		k = 0
	else:
		ans += item * item
		k -= item
	if k == 0:
		break
print(ans)


import heapq
(n, k) = [int(i) for i in input().split()]
deck = input()
cartas = {}
for card in deck:
	if card not in cartas:
		cartas[card] = 1
	else:
		cartas[card] += 1
pq = []
for key in cartas:
	heapq.heappush(pq, -cartas[key])
coins = 0
element = -heapq.heappop(pq)
qtdElement = element
mult = 0
while k > 0:
	if qtdElement > 0:
		mult += 1
		k -= 1
		qtdElement -= 1
	else:
		coins += mult ** 2
		mult = 0
		element = -heapq.heappop(pq)
		qtdElement = element
coins += mult ** 2
print(coins)


(n, k) = map(int, input().split())
s = input()
d = {}
for c in s:
	d[c] = 1 + (d[c] if c in d else 0)
l = []
for c in d:
	l.append(d[c])
l.sort(reverse=True)
cnt = k
sum_price = 0
for m in l:
	can_get = min(cnt, m)
	cnt -= can_get
	sum_price += can_get ** 2
	if not cnt:
		break
print(sum_price)


import operator
table = {}
(n, k) = map(int, input().split(' '))
chain = input()
for ch in chain:
	if ch in table:
		table[ch] += 1
	else:
		table[ch] = 1
sorted_table = ((k, table[k]) for k in sorted(table, key=table.get, reverse=True))
total = 0
for (key, value) in sorted_table:
	total += min(k, value) * min(k, value)
	k -= value
	if k <= 0:
		break
print(total)


def main():
	(N, K) = map(int, input().split())
	string = str(input())
	string = list(string)
	dp = [0 for _ in range(26)]
	for i in range(len(string)):
		dp[ord(string[i]) - ord('A')] += 1
	dp.sort(reverse=True)
	ans = 0
	index = 0
	while index < N and K > 0:
		if dp[index] > K:
			ans += K * K
			K -= K
		else:
			ans += dp[index] * dp[index]
			K -= dp[index]
		index += 1
	print(ans)
main()


(n, k) = list(map(int, input().split()))
s = input()
d = {}
for char in s:
	d[char] = d.get(char, 0) + 1
L = sorted([[key, d[key]] for key in d], key=lambda x: x[1], reverse=True)
(ans, i) = (0, 0)
while k > 0:
	if k >= L[i][1]:
		ans += L[i][1] ** 2
		k -= L[i][1]
	else:
		ans += k ** 2
		k = 0
	i += 1
print(ans)


(n, k) = map(int, input().split())
s = input()
(output, i, temp) = (0, 0, [])
for ch in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
	temp.append(s.count(ch))
temp.sort(reverse=True)
while k > 0:
	if temp[i] <= k:
		output += temp[i] ** 2
		k -= temp[i]
	else:
		output += k ** 2
		k = 0
	i += 1
print(output)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter

def main():
	(n, k) = map(int, input().split())
	c = Counter(input())
	lst = sorted(list(c.values()))
	ans = 0
	while k:
		temp = lst[-1]
		lst.pop()
		if temp < k:
			ans += temp * temp
			k -= temp
		else:
			ans += k * k
			k = 0
	print(ans)

def nouse0():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse1():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse2():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def nouse3():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse4():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse5():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
main()


(n, k) = map(int, input().split())
s = input()
from collections import Counter
d = Counter(s)
c = 0
while k >= 0:
	key = max(d, key=d.get)
	g = min(k, d[key])
	del d[key]
	c += g ** 2
	k -= g
	if k == 0:
		break
print(c)


(n, k) = list(map(int, input().split()))
s = input()
d = [0] * 26
for i in range(n):
	d[ord(s[i]) - 65] += 1
d.sort()
ans = 0
while k > 0:
	if k < d[-1]:
		ans += k * k
		break
	else:
		k -= d[-1]
		ans += d[-1] * d[-1]
		d.pop()
print(ans)


(n, k) = map(int, input().split())
(d, r) = ({}, 0)
for c in input():
	d[c] = d.get(c, 0) + 1
for v in sorted(d.values())[::-1]:
	x = min(k, v)
	r += x * x
	k -= x
print(r)


(n, k) = map(int, input().split())
s = input()
a = [0] * 26
for x in s:
	a[ord(x) - 65] += 1
a.sort(reverse=True)
i = 0
ans = 0
while k > 0:
	if k > a[i]:
		ans += a[i] * a[i]
		k -= a[i]
		i += 1
	else:
		ans += k * k
		break
print(ans)


(n, k) = map(int, input().split())
l = list(input())
d = {}
chk = []
for i in list(set(l)):
	d[i] = 0
for i in l:
	d[i] += 1
for i in d:
	chk.append([d[i], i])
chk = sorted(chk, reverse=True)
count = 0
ele = []
for i in chk:
	if count < k:
		if i[0] + count <= k:
			count += i[0]
			ele.append([i[1], i[0]])
		elif i[0] >= k - count:
			r = k - count
			count += k - count
			ele.append([i[1], r])
ans = 0
for i in ele:
	ans += i[1] * i[1]
print(ans)


from collections import Counter
(n, k) = map(int, input().split())
s = input()
count = Counter(s)
values = sorted(list(count.values()), reverse=True)
cards = k
summ = 0
i = 0
while cards > 0:
	if values[i] >= cards:
		summ += cards * cards
		break
	else:
		summ += values[i] * values[i]
		cards -= values[i]
		i += 1
print(summ)


(a, b) = list(map(int, input().split()))
n = {chr(i): 0 for i in range(ord('A'), ord('Z') + 1)}
for c in input():
	n[c] += 1
ans = 0
for i in sorted(list(n.values()), reverse=True):
	x = min(i, b)
	ans += x * x
	b -= x
	if not b:
		break
print(ans)


(n, m) = input().strip().split(' ')
(n, m) = (int(n), int(m))
S = list(input().strip())
d = {}
for s in S:
	if s in d.keys():
		d[s] += 1
	else:
		d[s] = 1
r = list(d.values())
r.sort(reverse=True)
t = r[0]
k = 0
cur = 0
j = 0
for i in range(0, m):
	if t > 0:
		t -= 1
		cur += 1
	else:
		k += cur ** 2
		cur = 0
		j += 1
		t = r[j]
		if t > 0:
			t -= 1
			cur += 1
k += cur ** 2
print(k)


n = input()
a = n.split(' ')
n = int(a[0])
k = int(a[1])
ar = input()
s = {}
for i in range(n):
	if ar[i] in s.keys():
		s[ar[i]] += 1
	else:
		s[ar[i]] = 1
val = []
for i in s.values():
	val.append(i)
val.sort()
val.reverse()
it = 0
su = 0
tot = 0
while k != 0:
	val[it] = val[it] - 1
	su += 1
	k -= 1
	if val[it] == 0 or k == 0:
		tot += su * su
		it += 1
		su = 0
print(tot)


(n, k) = map(int, input().split())
l = list(input())
l2 = list(set(l))
l3 = []
for i in l2:
	l3.append(l.count(i))
l3.sort(reverse=True)
ans = 0
i = 0
while k > 0:
	if l3[i] < k:
		ans += l3[i] * l3[i]
		k = k - l3[i]
		i += 1
	else:
		ans += k * k
		k = 0
print(ans)


import collections
(n, k) = map(int, input().split())
s = input()
D = collections.Counter(s)
B = list(D.values())
B.sort(reverse=True)
S = 0
for i in B:
	if i <= k:
		S += i * i
		k = k - i
	else:
		S += k ** 2
		break
print(S)


import logging
from collections import Counter
import sys
nivel_log = logging.ERROR
logger_cagada = None

def aplecaca_core(letras, kk):
	cuenta_caca = Counter(letras)
	cuentas_ord = sorted(cuenta_caca.items(), key=lambda x: (x[1], x[0]), reverse=False)
	logger_cagada.debug('el conteo ord {}'.format(cuentas_ord))
	capacidad = kk
	beneflex = 0
	while cuentas_ord and capacidad:
		(letra, mierda) = cuentas_ord.pop()
		logger_cagada.debug('la letra {} tiene de mierda {}'.format(letra, mierda))
		ass = mierda if mierda <= capacidad else capacidad
		logger_cagada.debug('para capa {} la mierda es {}'.format(capacidad, ass))
		beneflex += ass ** 2
		capacidad -= ass
	return beneflex

def aplecaca_main():
	lista = list(sys.stdin)
	(_, kk) = [int(x) for x in lista[0].strip().split(' ')]
	letras = lista[1].strip()
	logger_cagada.debug('kk {} letras {}'.format(kk, letras))
	shit = aplecaca_core(letras, kk)
	print(shit)
FORMAT = '[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s'
logging.basicConfig(level=nivel_log, format=FORMAT)
logger_cagada = logging.getLogger('asa')
logger_cagada.setLevel(nivel_log)
aplecaca_main()


entrada = input()
entrada_str = list(entrada.split(' '))
entrada_int = list(map(int, entrada_str))
n = entrada_int[0]
k = entrada_int[1]
vetor = input()
vetor_letras = [0] * 26
for i in range(n):
	vetor_letras[ord(vetor[i]) - 65] += 1
vetor_letras.sort()
resposta = 0
for i in reversed(range(26)):
	if vetor_letras[i] <= k:
		resposta += vetor_letras[i] * vetor_letras[i]
		k = k - vetor_letras[i]
	else:
		resposta += k * k
		k = 0
	if k == 0:
		break
print(resposta)


(n, k) = map(int, input().split())
arr = [0] * 26
s = input()
aux = ord('A')
for i in range(len(s)):
	arr[ord(s[i]) - aux] += 1
arr.sort(reverse=True)
i = 0
sum = 0
while k > 0:
	if arr[i] >= k:
		sum += k ** 2
		k = 0
	else:
		k -= arr[i]
		sum += arr[i] ** 2
		i += 1
print(sum)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
(n, m) = rinput()
s = list(input())
l = list(set(s))
a = []
for i in range(len(l)):
	a.append(s.count(l[i]))
a.sort(reverse=True)
ans = 0
while m != 0:
	if a[0] >= m:
		ans += m * m
		m -= m
	else:
		m -= a[0]
		ans += a[0] ** 2
		a.pop(0)
print(ans)


from collections import Counter
(n, k) = map(int, input().split())
l = list(input())
x = Counter(l)
x = x.most_common()
s = 0
for i in x:
	if k == 0:
		break
	elif k > i[1]:
		s = s + i[1] * i[1]
		k = k - i[1]
	else:
		s = s + k * k
		k = 0
print(s)


(n, k) = [int(val) for val in input().split()]
str = input()
sum = 0
word_dict = {}
for word in str:
	word_dict[word] = word_dict.get(word, 0) + 1
numbers = [val for val in word_dict.values()]
numbers.sort(reverse=True)
for num in numbers:
	if num <= k:
		sum += num * num
		k -= num
		continue
	if k < num:
		sum += k * k
		k -= k
if k > 0:
	sum += k
print(sum)


(n, k) = map(int, input().split())
s = input()
d = {}
for x in s:
	d[x] = d.get(x, 0) + 1
l = sorted(d.values())[::-1]
ans = []
i = 0
while k > 0:
	ans += [min(k, l[i])]
	k -= l[i]
	i += 1
for i in range(len(ans)):
	ans[i] *= ans[i]
print(sum(ans))


import operator
params = list(map(int, list(input().split())))
(_, k) = (params[0], params[1])
cards = list(input())
dic = {}
for card in cards:
	if card not in dic:
		dic[card] = 1
	else:
		dic[card] += 1
dic2 = dict(sorted(dic.items(), key=operator.itemgetter(1), reverse=True))
list2 = []
count = 0
for d in dic2:
	for _ in range(0, dic2[d]):
		list2.append(d)
		count += 1
		if count == k:
			break
	if count == k:
		break
dic = {}
for card in list2:
	if card not in dic:
		dic[card] = 1
	else:
		dic[card] += 1
ans = 0
for d in dic:
	ans += dic[d] ** 2
print(ans)


(a, b) = map(int, input().split(' '))
string = input()
chars = [x for x in string]
chars2 = set(chars)
chars2 = sorted(chars2, key=lambda x: chars.count(x))
chars2.reverse()
count = [chars.count(x) for x in chars2]
points = 0
cards = 0
for i in range(len(count)):
	if cards + count[i] >= b:
		break
	else:
		cards += count[i]
		points += count[i] ** 2
points += (b - cards) ** 2
print(points)


(n, k) = map(int, input().split())
s = input()
d = {}
for i in s:
	if i not in d.keys():
		d[i] = 1
	else:
		d[i] += 1
l = []
for i in d.values():
	l.append(i)
l.sort()
p = len(l)
ans = 0
while k >= 0:
	if l[p - 1] <= k:
		k = k - l[p - 1]
		ans += l[p - 1] ** 2
		p = p - 1
	else:
		ans += k * k
		break
print(ans)


from collections import defaultdict
(n, k) = map(int, input().split())
s = input()
di = defaultdict(int)
for c in s:
	di[c] += 1
ans = 0
sum = 0
for (_, v) in sorted(di.items(), key=lambda item: -1 * item[1]):
	if sum + v <= k:
		ans += v * v
		sum = sum + v
	else:
		diff = k - sum
		ans += diff * diff
		break
print(ans)


MOD = 10 ** 9 + 7
(n, k) = [int(x) for x in input().split()]
letters = {}
S = input()
for c in S:
	if c not in letters:
		letters[c] = 1
	else:
		letters[c] += 1
letters = dict(sorted(letters.items(), key=lambda x: x[1], reverse=True))
final = []
res = 0
for key in letters.keys():
	if k == 0:
		break
	if letters[key] <= k:
		final.append([key, letters[key]])
		k -= letters[key]
	else:
		final.append([key, k])
		k = 0
for ele in final:
	res += ele[1] ** 2
print(res)


import sys
input = sys.stdin.readline

def gint():
	return int(input())

def gint_arr():
	return list(map(int, input().split()))

def gfloat():
	return float(input())

def gfloat_arr():
	return list(map(float, input().split()))

def pair_int():
	return map(int, input().split())
INF = 1 << 31
MOD = '1000000007'
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
(n, k) = gint_arr()
s = input()
from collections import Counter
c = Counter(s).most_common()
res = 0
i = 0
while k:
	taken = min(k, c[i][1])
	res += taken * taken
	k -= taken
	i += 1
print(res)


from sys import stdin, stdout
import math
import collections
input = stdin.readline

def print(x='', end='\n'):
	stdout.write(str(x) + end)

def solve():
	(n, k) = map(int, input().split())
	l = list(input())
	d = {}
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	d = [[k, v] for (k, v) in d.items()]
	d.sort(key=lambda x: x[1], reverse=True)
	if d[0][1] >= k:
		print(k * k)
		return
	ans = d[0][1] * d[0][1]
	k -= d[0][1]
	i = 1
	while k != 0:
		if k - d[i][1] < 0:
			ans += k * k
			k -= k
		else:
			k -= d[i][1]
			ans += d[i][1] * d[i][1]
		i += 1
	print(ans)
tt = 1
for __ in range(tt):
	solve()


(n, k) = map(int, input().split())
s = input()
a = []
c = []
for i in range(n):
	if s[i] not in a:
		a.append(s[i])
		c.append(1)
	else:
		c[a.index(s[i])] += 1
ans = 0
while k > 0:
	x = min(max(c), k)
	k -= x
	c[c.index(max(c))] -= x
	ans += x * x
print(ans)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, k) = value()
a = input()
d = Counter(a)
ans = 0
for i in sorted(d.values(), reverse=True):
	choose = max(0, min(k, i))
	ans += choose * choose
	k -= choose
print(ans)


(n, k) = map(int, input().split())
ans = 0
s = input()
d = {}
for i in s:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
while k != 0:
	max_key = max(d, key=d.get)
	if k >= d[max_key]:
		k -= d[max_key]
		ans += d[max_key] ** 2
		del d[max_key]
	else:
		ans += k * k
		k = 0
print(ans)


(n, k) = map(int, input().split())
x = input()
di1 = {}
for (i, x) in enumerate(x):
	if x not in di1.keys():
		di1[x] = 0
	di1[x] += 1
di = {}
for (i, x) in enumerate(di1.keys()):
	if di1[x] not in di.keys():
		di[di1[x]] = []
	di[di1[x]].append(x)
(rez, m) = (0, 0)
wert = 0
for (i, x) in enumerate(reversed(sorted(di))):
	for (j, y) in enumerate(di[x]):
		if m + x < k:
			rez += x * x
			m += x
		else:
			wert = 1
			break
	if wert == 1:
		break
rez += (k - m) * (k - m)
print(rez)


(n, k) = map(int, input().split())
s = list(input())
dic = dict()
for i in s:
	if i not in dic:
		dic[i] = 0
	dic[i] += 1
t = list(dic.values())
t.sort(reverse=True)
c = 0
i = 0
while k > 0:
	if t[i] >= k:
		c += k * k
		k = 0
	else:
		c += t[i] * t[i]
		k -= t[i]
		i += 1
print(c)


from collections import Counter
(n, k) = [int(i) for i in input().split()]
card = input()
c = Counter(card)
ans = 0
while k > 0:
	tmp = c.pop(c.most_common(1)[0][0])
	if k > tmp:
		ans += tmp * tmp
		k -= tmp
	else:
		ans += k * k
		k = 0
print(ans)


def find_money(k, arr):
	keys = list(set(arr))
	value = [arr.count(i) for i in keys]
	value.sort(reverse=True)
	return calc_val(k, value, 0)

def calc_val(k, value, count):
	if value[0] < k:
		count += pow(value[0], 2)
		k -= value[0]
		value.pop(0)
		return calc_val(k, value, count)
	else:
		count += k * k
		return count
(_, k) = input().split()
k = int(k)
arr = input()
print(find_money(k, arr))


a = [int(i) for i in input().split()]
n = a[0]
k = a[1]
s = input()
h = {}
f = 1
for i in s:
	if i in h:
		h[i] += 1
		if h[i] > k:
			f = 0
			break
	else:
		h[i] = 1
a = [h[i] for i in h]
a.sort()
a = a[::-1]
i = 0
su = 0
while k:
	if k <= a[i]:
		su += k * k
		break
	else:
		k -= a[i]
		su += a[i] ** 2
	i += 1
print(su)


(n, m) = input().split()
(n, m) = (int(n), int(m))
l = list(input())
s = list(set(l))
a = [0] * len(s)
for i in range(len(s)):
	for j in range(len(l)):
		if s[i] == l[j]:
			a[i] += 1
a = sorted(a)
sum = 0
for i in range(1, len(s) + 1):
	if m == 0:
		break
	elif m >= a[-i]:
		sum += a[-i] ** 2
		m -= a[-i]
	elif m < a[-i]:
		sum += m ** 2
		m = 0
print(sum)


(n, m) = [int(i) for i in input().split()]
s = input()
l = []
for i in range(26):
	l.append([0, i])
for i in range(n):
	l[ord(s[i]) % ord('A')][0] += 1
l.sort()
l.reverse()
ans = 0
i = 0
while m != 0:
	ans += min(l[i][0], m) ** 2
	m -= min(l[i][0], m)
	i += 1
print(ans)


import sys
from functools import reduce
from collections import Counter
from math import sqrt, gcd

def ip():
	return int(sys.stdin.readline())

def sip():
	return sys.stdin.readline()

def mip():
	return map(int, sys.stdin.readline().split())

def mips():
	return map(str, sys.stdin.readline().split())

def lip():
	return list(map(int, sys.stdin.readline().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
(n, k) = mip()
s = sip()
lst = [0] * 50
for i in range(n):
	lst[ord(s[i]) - 65] += 1
lst.sort(reverse=True)
i = 0
count = 0
while k > 0:
	z = lst[i]
	if z < k:
		count += z * z
		k -= z
	else:
		count += k * k
		k -= z
	i += 1
print(count)


(n, k) = map(int, input().split())
new_dict = {}
t = input()
for x in t:
	if x in new_dict:
		new_dict[x] = new_dict[x] + 1
	else:
		new_dict[x] = 1
p = 0
while k > 0:
	if new_dict[max(new_dict, key=new_dict.get)] >= k:
		p = p + k ** 2
		k = 0
	else:
		p = p + new_dict[max(new_dict, key=new_dict.get)] ** 2
		k = k - new_dict[max(new_dict, key=new_dict.get)]
		del new_dict[max(new_dict, key=new_dict.get)]
print(p)


(n, k) = map(int, input().split())
s = list(input())
mp = dict()
for i in range(ord('A'), ord('Z') + 1):
	mp[chr(i)] = 0
for a in s:
	mp[a] += 1
s.sort(key=lambda item: (mp[item], item))
s.reverse()
i = 0
ans = []
while k > 0 and i < len(s):
	ans.append(s[i])
	i += 1
	k -= 1
mp.clear()
for i in range(ord('A'), ord('Z') + 1):
	mp[chr(i)] = 0
for a in ans:
	mp[a] += 1
res = sum((mp[a] for a in ans))
print(res)


(n, k) = [int(x) for x in input().split()]
arr = input()
freq = {}
for char in arr:
	if char not in freq:
		freq[char] = 0
	freq[char] += 1
sort = sorted(freq, key=lambda x: freq[x], reverse=True)
ans = 0
k1 = k
i = 0
while k1:
	x = freq[sort[i]]
	if k1 <= x:
		ans += k1 * k1
		k1 = 0
	else:
		ans += x * x
		k1 -= x
	i += 1
print(ans)


from collections import Counter
(n, k) = map(int, input().split())
x = list(input())
cnt = Counter(x)
y = sorted(cnt, key=lambda i: cnt[i], reverse=True)
s = 0
for i in y:
	if k >= cnt[i]:
		s += cnt[i] * cnt[i]
		k -= cnt[i]
	else:
		s += k * k
		k = 0
		break
print(s)


temp = input().split()
(N, K) = (int(temp[0]), int(temp[1]))
s = input()
d = dict()
for c in s:
	d[c] = d.get(c, 0) + 1
sum = 0
while K > 0:
	m = '-'
	for (k, v) in list(d.items()):
		if d.get(m, 0) < v:
			m = k
	if K > d[m]:
		sum += d[m] * d[m]
		K -= d[m]
	else:
		sum += K * K
		K = 0
	d[m] = 0
print(sum)


(n, k) = map(int, input().split())
d = {}
for c in input():
	if c in d:
		d[c] += 1
	else:
		d[c] = 1
d = list(d.values())
d.sort(reverse=True)
ans = 0
for v in d:
	c = min(v, k)
	k -= c
	ans += c ** 2
print(ans)


from collections import Counter
(n, k) = map(int, input().split())
s = list(input())
dct = Counter(s)
cnt = 0
p = 0
for (c, o) in dct.most_common():
	p += min(o, k - cnt) ** 2
	cnt += o
	if cnt > k:
		break
print(p)


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True
(n, k) = mi()
s = input()
a = [0] * 26
for i in s:
	a[ord(i) - ord('A')] += 1
a.sort(reverse=True)
ans = 0
i = 0
while k > 0:
	t = min(a[i], k)
	ans += t ** 2
	k -= t
	i += 1
print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
mod = 1000000007
(n, k) = map(int, input().split())
arr = Counter(input())
arr = sorted(arr.items(), key=lambda x: x[1], reverse=True)
ans = 0
for i in range(len(arr)):
	if k <= 0:
		break
	if k < arr[i][1]:
		ans += k * k
	else:
		ans += arr[i][1] * arr[i][1]
	k -= arr[i][1]
print(ans)


z = [0] * 26
(a, b) = map(int, input().split())
for i in input():
	z[ord(i) - 65] += 1
z.sort(reverse=1 == 1)
s = 0
for i in z:
	k = min(b, i)
	b -= k
	s += k * k
print(s)


(n, k) = map(int, input().split())
(q, w) = ([0] * 26, 0)
for i in input():
	q[ord(i) - 65] += 1
q.sort(reverse=1)
for i in q:
	if i <= k:
		w += i * i
		k -= i
	else:
		w += k * k
		break
print(w)


(n, m) = map(int, input().split())
ss = input()
ss = ss.lower()
ss = list(ss)
s = set(ss)
s = list(s)
ls = []
for i in range(len(s)):
	var = s[i]
	f = ss.count(var)
	ls.append(f)
ls.sort()
flag = 0
for d in range(len(ls) - 1, -1, -1):
	if ls[d] >= m:
		flag += m * m
		break
	elif ls[d] < m:
		flag += ls[d] * ls[d]
		m -= ls[d]
print(flag)


import collections
import math

def sort(key):
	return key[1]

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def solve(s, k):
	mp = {}
	st = 0
	for i in range(len(s)):
		if s[i] in mp:
			mp[s[i]] += 1
		else:
			mp[s[i]] = 1
	pl = []
	for i in mp:
		pl.append((i, mp[i]))
	pl = sorted(pl, key=sort)[::-1]
	for i in pl:
		if k > 0:
			tmp = k
			k -= i[1]
			if k < 0:
				st += tmp ** 2
				break
			else:
				st += i[1] ** 2
	return st
ans = []
(n, k) = map(int, input().split())
s = input()
print(solve(s, k))
for i in ans:
	print(i)


from collections import Counter
(n, k) = map(int, input().strip().split())
s = Counter(input().strip())
m = {key: v for (key, v) in reversed(sorted(s.items(), key=lambda item: item[1]))}
ans = 0
for key in m:
	if m[key] <= k:
		k -= m[key]
		ans += m[key] * m[key]
	else:
		ans += k * k
		k = 0
print(ans)


from collections import Counter, OrderedDict
(n, k) = (int(x) for x in input().split())
answer = 0
charCounted = OrderedDict(Counter(input()).most_common())
for key in charCounted:
	if charCounted[key] == 1:
		answer += k * 1
		break
	if k >= charCounted[key]:
		answer += charCounted[key] * charCounted[key]
		if k == charCounted[key]:
			break
		k -= charCounted[key]
	else:
		answer += k * k
		break
print(answer)


(n, k) = [int(x) for x in input().split(' ')]
cards = input()
pos = {}
for card in cards:
	if card not in pos:
		pos[card] = 1
	else:
		pos[card] += 1
sorted_pos = {k: v for (k, v) in sorted(pos.items(), key=lambda item: item[1], reverse=True)}
answer = 0
for (key, val) in sorted_pos.items():
	if val >= k:
		answer += k * k
		break
	else:
		k -= val
		answer += val * val
print(answer)


str1 = input().split(' ')
str2 = input()
dict1 = {}
for item in str2:
	if dict1.get(item, 0):
		dict1[item] += 1
	else:
		dict1[item] = 1
str3 = sorted(list(dict1.values()), reverse=True)
i = 0
sum = 0
k = int(str1[1])
while 1:
	a = k - str3[i]
	if a <= 0:
		sum += k ** 2
		break
	else:
		k = k - str3[i]
		sum += str3[i] ** 2
	i = i + 1
print(sum)


(n, k) = list(map(int, input().split()))
ar = input().rstrip()
calc = [0] * (ord('z') - ord('a') + 1)
for i in range(len(ar)):
	calc[ord(ar[i]) - ord('A')] += 1
calc.sort()
calc = calc[::-1]
ans = 0
flag = 0
while k != 0:
	if calc[flag] >= k:
		ans += k * k
		k -= k
		flag += 1
	else:
		ans += calc[flag] * calc[flag]
		k -= calc[flag]
		flag += 1
print(ans)


from sys import stdin, stdout
import math
import bisect
input = stdin.readline

def print(x='', y='', end='\n'):
	if y == '':
		stdout.write(str(x) + end)
	else:
		stdout.write(str(x) + ' ' + str(y) + end)

def solve():
	(n, k) = map(int, input().split())
	d = {}
	s = input()
	for i in s:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	d = [[k, v] for (k, v) in d.items()]
	d.sort(key=lambda x: x[1], reverse=True)
	cur = 0
	ans = 0
	for i in d:
		if cur < k:
			ans += min(i[1], k - cur) ** 2
			cur += min(i[1], k - cur)
	print(ans)
tt = 1
for __ in range(tt):
	solve()


string = input()
numbers = string.split()
n = int(numbers[1])
string = input()
(letters, values) = (set(string), [])
for x in letters:
	values.append(string.count(x))
values = sorted(values)[::-1]
a = b = 0
for x in values:
	a += x
	if a >= n:
		if a > n:
			b += (x - a + n) ** 2
		else:
			b += x ** 2
		break
	b += x ** 2
print(b)


(n, k) = map(int, input().split())
c = list(input())
ncl = []
trash = []
for i in c:
	if i not in trash:
		trash.append(i)
		ncl.append(c.count(i))
ncl.sort(reverse=True)
bruh = 0
j = 0
while k > 0:
	if k >= ncl[j]:
		k -= ncl[j]
		bruh += ncl[j] * ncl[j]
	else:
		bruh += k * k
		k = 0
	j += 1
print(bruh)


(n, k) = map(int, input().split())
temp = n
s = input()
d = {}
for i in s:
	d[i] = d.get(i, 0) + 1
sort_d = sorted(d.items(), key=lambda x: x[1])[::-1]
ans = 0
for i in range(len(sort_d)):
	if k == 0:
		break
	k1 = min(k, sort_d[i][1])
	k -= k1
	ans += k1 * k1
print(ans)


(n, k) = map(int, input().split())
s = input()
ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
d = {}
for i in ch:
	d[i] = 0
for i in s:
	d[i] += 1
sorted_d = sorted(d.items(), key=lambda kv: kv[1], reverse=True)
s = 0
for i in sorted_d:
	if k >= i[1]:
		k = k - i[1]
		s += i[1] * i[1]
	else:
		s += k * k
		k = 0
	if k == 0:
		break
print(s)


(n, k) = map(int, input().split())
s = input()
from collections import Counter
count = Counter(s)
lst = sorted(list(count.values()), reverse=True)
ans = 0
i = 0
while k > 0:
	tmp = min(lst[i], k)
	ans += tmp * tmp
	k -= tmp
	i += 1
print(ans)


cards_left = int(input().split()[1])
deck = input()
coins = [deck.count(card) for card in set(deck)]
coins.sort(reverse=True)
result = 0
for coin in coins:
	if cards_left > coin:
		result += coin ** 2
		cards_left -= coin
	else:
		result += cards_left ** 2
		break
print(result)


def is_s(s):
	if s == 'A':
		return 0
	if s == 'B':
		return 1
	if s == 'C':
		return 2
	if s == 'D':
		return 3
	if s == 'E':
		return 4
	if s == 'F':
		return 5
	if s == 'G':
		return 6
	if s == 'H':
		return 7
	if s == 'I':
		return 8
	if s == 'J':
		return 9
	if s == 'K':
		return 10
	if s == 'L':
		return 11
	if s == 'M':
		return 12
	if s == 'N':
		return 13
	if s == 'O':
		return 14
	if s == 'P':
		return 15
	if s == 'Q':
		return 16
	if s == 'R':
		return 17
	if s == 'S':
		return 18
	if s == 'T':
		return 19
	if s == 'U':
		return 20
	if s == 'V':
		return 21
	if s == 'W':
		return 22
	if s == 'X':
		return 23
	if s == 'Y':
		return 24
	if s == 'Z':
		return 25
(n, k) = map(int, input().split())
s = input()
a = [0] * 26
for i in range(len(s)):
	g = is_s(s[i])
	a[g] = a[g] + 1
count_ = 0
a.sort()
a = a[::-1]
for i in range(len(a)):
	if k != 0:
		if a[i] >= k:
			h = a[i] - (a[i] - k)
			count_ = count_ + h * h
			k = 0
		else:
			k = k - a[i]
			count_ = count_ + a[i] * a[i]
print(count_)


(n, k) = map(int, input().split())
d = {}
a = list(input())
for i in a:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
l = list(d.values())
l.sort(reverse=True)
ans = 0
if l[0] > k:
	print(k ** 2)
	exit()
else:
	ans += l[0] ** 2
	k = k - l[0]
i = 1
while k > 0 and i < len(l):
	if l[i] >= k:
		ans += k ** 2
		print(ans)
		exit()
	else:
		ans += l[i] ** 2
		k -= l[i]
	i += 1
print(ans)


a = input().split()
n = int(a[0])
k = int(a[1])
b = input()
l = [0 for i in range(26)]
for i in range(65, 65 + 26):
	p = chr(i)
	l[i - 65] = b.count(p)
s = 0
for i in range(26):
	m = max(l)
	h = l.index(m)
	if m == k:
		s = s + m * m
		break
	elif m < k:
		s = s + m * m
		k = k - m
		l[h] = 0
	else:
		s = s + k * k
		m = 0
		break
print(s)


(n, k) = list(map(int, input().split()))
m = input()
d = {chr(ord('A') + i): 0 for i in range(26)}
for ch in m:
	d[ch] += 1
nw = [[ch, d[ch]] for ch in d]
fl = True
while fl:
	fl = False
	for i in range(25):
		if nw[i][1] < nw[i + 1][1]:
			d = nw[i][:]
			nw[i] = nw[i + 1][:]
			nw[i + 1] = d[:]
			fl = True
s = 0
i = 0
while k > 0:
	if k >= nw[i][1]:
		s += nw[i][1] ** 2
		k -= nw[i][1]
	else:
		s += k ** 2
		k = 0
	i += 1
print(s)


from collections import Counter
(n, k) = [int(_) for _ in input().split()]
S = input()
D = Counter(S)
D = {k: v for (k, v) in sorted(D.items(), key=lambda item: item[1], reverse=True)}
ans = 0
for _ in D:
	if D[_] < k:
		ans += D[_] ** 2
		k -= D[_]
	else:
		ans += k ** 2
		break
print(ans)


import operator

def solve():
	(n, k) = map(int, input().split())
	letters = list(input())
	counts = {}
	for letter in letters:
		if letter not in counts:
			counts[letter] = 0
		counts[letter] += 1
	score = 0
	while k > 0:
		keymax = max(counts.items(), key=operator.itemgetter(1))[0]
		if k >= counts[keymax]:
			k -= counts[keymax]
			score += counts[keymax] ** 2
			counts.pop(keymax)
		else:
			score += k ** 2
			k = 0
	return score
print(solve())


from collections import *
(n, k) = map(int, input().split())
s = input()
l = dict(Counter(s))
l = sorted(l.items(), reverse=True, key=lambda x: (x[1], x[0]))
c = 0
for (x, y) in l:
	if k >= y:
		k = k - y
		c = c + y * y
	else:
		c = c + k * k
		break
print(c)


(n, k) = map(int, input().split())
s = input()
d = {}
for i in range(n):
	if s[i] in d:
		d[s[i]] += 1
	else:
		d[s[i]] = 1
d = sorted(d.items(), key=lambda x: -x[1])
d = {k: v for (k, v) in d}
ans = 0
for (a, b) in d.items():
	if b >= k and k != 0:
		ans += k * k
		break
	elif b < k and k != 0:
		ans += b * b
		k -= b
print(ans)


firstLine = input()
(n, k) = firstLine.split()
n = int(n)
k = int(k)
s = input()
result = 0
count = [0] * 26
for i in range(0, len(s)):
	index = ord(s[i]) - 65
	count[index] = count[index] + 1
count.sort(reverse=True)
for j in range(0, len(count)):
	if count[j] <= k:
		result = result + count[j] * count[j]
		k = k - count[j]
		if k == 0:
			break
	else:
		result = result + k * k
		break
print(result)


(n, k) = map(int, input().split())
line = str(input())
book = dict()
for it in line:
	book[it] = book.setdefault(it, 0) + 1
line = list(book.values())
line.sort(reverse=True)
rest = 0
for it in line:
	if k < it:
		rest += k ** 2
		break
	else:
		rest += it ** 2
		k -= it
print(rest)


(n, k) = map(int, input().split())
s = input()
(d, r) = ({}, 0)
for c in s:
	d[c] = d.get(c, 0) + 1
for i in sorted(d.values(), reverse=True):
	if i == 0:
		break
	if i >= k:
		r += k * k
		k = 0
		break
	r += i * i
	k -= i
print(r)


(n, k) = input().split(' ')
n = int(n)
k = int(k)
s = input()
s = list(s)
t = list(set(s))
s = sorted(s)
t = sorted(t)
f = [0] * len(t)
i = 0
j = 0
while i < len(s):
	if s[i] == t[j]:
		f[j] += 1
		i += 1
	else:
		j += 1
f = sorted(f)
cont = 0
soma = 0
i = len(f) - 1
while cont < k:
	soma += f[i] ** 2
	cont += f[i]
	i -= 1
i += 1
soma -= f[i] ** 2
cont -= f[i]
soma += (k - cont) ** 2
print(soma)


import math
import sys

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def alphabates():
	return 'abcdefghijklmnopqrstuvwxyz'

def binary_search(ls, n, flag):
	low = 0
	hi = n - 1
	while low <= hi:
		mid = (low + hi) // 2
		if ls[mid] == flag:
			return mid
		elif ls[mid] > flag:
			hi = mid - 1
		else:
			low = mid + 1
	return -1

def inp():
	ls = list(map(int, input().split()))
	return ls

def mult_inp():
	return map(int, input().split())
(n, k) = mult_inp()
s = input()
freq = [0] * 26
alp = alphabates().upper()
for i in s:
	freq[binary_search(alp, 26, i)] += 1
ans = 0
freq.sort(reverse=True)
for i in freq:
	if i <= k:
		ans += i * i
		k -= i
	else:
		ans += k * k
		break
print(ans)


from sys import stdin
A = list(map(int, stdin.readline().split()))
N = A[0]
K = A[1]
B = stdin.readline()
D = dict()
S = set()
T = list()
for t in range(0, len(B) - 1):
	l = len(S)
	S.add(B[t])
	if l == len(S):
		D[B[t]] += 1
		T.remove(D[B[t]] - 1)
		T.append(D[B[t]])
	else:
		D[B[t]] = 1
		T.append(1)
T.sort(reverse=True)
count = 0
ans = 0
while K > 0:
	ans += min(K, T[count]) ** 2
	K -= T[count]
	count += 1
print(ans)


from collections import defaultdict
(n, k) = map(int, input().split())
t = defaultdict(int)
for i in input():
	t[i] += 1
t = list(t.values())
t.sort(reverse=True)
s = 0
for i in t:
	if i > k:
		break
	s += i * i
	k -= i
print(s + k * k)


input_str = input()
(n, k) = (int(input_str.split()[0]), int(input_str.split()[1]))
cards = input()
letter_dict = {}
for letter in cards:
	if letter in letter_dict:
		letter_dict[letter] += 1
	else:
		letter_dict[letter] = 1
letter_dict_sort = sorted(letter_dict, key=lambda k: letter_dict[k], reverse=True)
money = 0
i = 0
while 0 < k:
	part = letter_dict[letter_dict_sort[i]]
	if part <= k:
		k -= part
		money += part * part
	else:
		part = k
		k = 0
		money += part * part
	i += 1
print(money)


(a, b) = map(int, input().split())
x = input()
alpha = [chr(i).upper() for i in range(97, 123)]
y = [0] * 26
for i in x:
	y[alpha.index(i)] += 1
yy = [int(i) for i in y]
yy.sort()
s = 0
for j in yy[::-1]:
	if j <= b:
		s += j * j
		b -= j
	elif b > 0:
		s += b ** 2
		b = 0
	if b == 0:
		break
print(s)


(n, k) = map(int, input().split())
a = input()
b = []
while len(a) > 0:
	b.append(a.count(a[0]))
	a = a.replace(a[0], '')
b.sort(reverse=True)
sum = 0
while k > 0:
	sum += min(b[0], k) ** 2
	k -= min(b[0], k)
	del b[0]
print(sum)


from collections import Counter
a = list(map(int, input().split()))
st = input()
n = a[0]
k = a[1]
ls = []
ls = [st.count(i) for i in set(st)]
ls.sort(reverse=True)
sm = 0
while k > 0:
	for i in ls:
		sm += min(k, i) ** 2
		k -= min(k, i)
print(sm)


(n, k) = map(int, input().split())
s = input()
dc = dict()
for ch in s:
	if ch not in dc.keys():
		dc[ch] = 0
	dc[ch] += 1
ls = list(dc.values())
del dc
ls.sort(reverse=True)
ans = 0
for i in range(len(ls)):
	if k <= 0:
		break
	ans += min(k, ls[i]) ** 2
	k -= ls[i]
print(ans)


(k, n) = list(map(int, input().split()))
a = input()
c = []
p = 0
for i in set(a):
	c.append(a.count(i))
for i in sorted(c)[::-1]:
	if n > i:
		n = n - i
		p = i * i + p
	else:
		p = n * n + p
		break
print(p)


(n, k) = input().split()
n = int(n)
k = int(k)
str = input()
cnt = [0] * 26
for c in str:
	cnt[ord(c) - ord('A')] += 1
cnt.sort(reverse=True)
ans = 0
for x in cnt:
	ans += min(k, x) ** 2
	if k <= x:
		break
	k -= min(k, x)
print(ans)


(n, k) = input().split()
k = int(k)
cards = input()
count_cards = [0] * 26
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def check_position(card_letter, alphabet):
	for (letter_idx, alphabet_letter) in enumerate(alphabet):
		if card_letter == alphabet_letter:
			return letter_idx
score = 0
for card in cards:
	letter_idx = check_position(card, alphabet)
	count_cards[letter_idx] += 1
	if count_cards[letter_idx] == k:
		score = k ** 2
		k = 0
while k > 0:
	max_idx = count_cards.index(max(count_cards))
	if count_cards[max_idx] >= k:
		score += k ** 2
		break
	else:
		score += count_cards[max_idx] ** 2
		k -= count_cards[max_idx]
		count_cards[max_idx] = 0
print(score)


(n, k) = map(int, input().split())
chars = [0] * 26
string = input()
for char in string:
	chars[ord(char) - ord('A')] += 1
chars.sort(reverse=True)
sum = 0
for char in chars:
	if k > 0:
		temp = min(char, k)
		k -= temp
		sum += temp * temp
print(sum)


I = lambda : map(int, input().split())
(n, k) = I()
l = input()
d = dict()
for i in l:
	if i not in d:
		d[i] = 1
	else:
		d[i] += 1
x = sorted(d.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)
count = 0
temp = []
for i in range(len(x)):
	temp.append(x[i][1])
mlist = []
for i in range(len(x)):
	count += temp[i]
	if count >= k:
		a = count - k
		count -= temp[i]
		temp[i] -= a
		count += temp[i]
		mlist.append(temp[i])
		break
	mlist.append(temp[i])
total = 0
for i in mlist:
	total += i * i
print(total)


(n, k) = list(map(int, input().split()))
s = input()
a = [0] * 26
for c in s:
	a[ord(c) - ord('A')] += 1
a.sort(reverse=True)
ans = 0
for i in range(26):
	if k <= a[i]:
		ans += k ** 2
		break
	else:
		ans += a[i] ** 2
		k -= a[i]
print(ans)


(n, m) = map(int, input().split())
letters = str(input())
dictory = {}
count = 0
for letter in letters:
	if letter in dictory:
		dictory[letter] += 1
	else:
		dictory[letter] = 1
dictory = sorted(dictory.items(), key=lambda x: x[1])
dictory.reverse()
for index in range(len(dictory)):
	count_kart = dictory[index][1]
	if count_kart > m:
		count_kart = m
	count += count_kart * count_kart
	m -= count_kart
	if m == 0:
		break
print(count)


from collections import Counter
import operator
(n, k) = map(int, input().split())
s = input()
d = dict(Counter(s))
v = []
for (key, value) in d.items():
	v.append(value)
ans = 0
v.sort(reverse=True)
for x in v:
	ans += min(k, x) ** 2
	k -= min(k, x)
print(ans)


(n, k) = map(int, input().split())
w = dict()
for i in range(65, 91):
	w[chr(i)] = 0
for i in input():
	w[i] += 1
w = sorted(list(w.values()), reverse=True)
p = 0
ans = 0
while k != 0:
	t_k = k
	k = max(k - w[p], 0)
	ans += (t_k - k) ** 2
	p += 1
print(ans)


from operator import itemgetter

class CodeforcesTask462BSolution:

	def __init__(self):
		self.result = ''
		self.n_k = []
		self.cards = ''

	def read_input(self):
		self.n_k = [int(x) for x in input().split(' ')]
		self.cards = input()

	def process_task(self):
		scores = {}
		for c in self.cards:
			if c in scores:
				scores[c] += 1
			else:
				scores[c] = 1
		score = [(scores[c], c) for c in self.cards]
		score.sort(reverse=True)
		scorezs = {}
		for c in score[:self.n_k[1]]:
			if c[1] in scorezs:
				scorezs[c[1]] += 1
			else:
				scorezs[c[1]] = 1
		scorez = [scorezs[x[1]] for x in score[:self.n_k[1]]]
		self.result = str(sum(scorez))

	def get_result(self):
		return self.result
Solution = CodeforcesTask462BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, k) = [int(x) for x in input().split()]
s = input()
d = {}
for ele in s:
	d[ele] = d.get(ele, 0) + 1
li = []
ll = 0
for ele in d:
	li.append([d[ele], ele])
	ll += 1
li.sort(reverse=True)
i = 0
j = 0
cost = 0
while i < k:
	x = li[j][0]
	take = min(x, k - i)
	cost += take * take
	i += take
	j += 1
print(cost)


(n, k) = map(int, input().split())
s = input()
di = dict()
for i in s:
	di[i] = di.get(i, 0) + 1
ans = 0
lis = sorted(list(di.values()))
lis = lis[::-1]
for i in lis:
	if not k:
		break
	ans += min(k, i) ** 2
	k -= min(k, i)
print(ans)


from collections import defaultdict, deque

def main():
	(n, k) = map(int, input().split(' '))
	s = list(input())
	m = defaultdict(int)
	for c in s:
		m[c] += 1
	l = deque(sorted([(x, m[x]) for x in m.keys()], key=lambda x: x[1]))
	ans = 0
	while k > 0:
		x = l.pop()
		r = x[1]
		if r <= k:
			k -= x[1]
		else:
			r = min(r, k)
			k = 0
		ans += r * r
	return ans
print(main())


from collections import defaultdict
(n, k) = map(int, input().split())
s = input()
count = defaultdict(int)
for i in s:
	count[i] += 1
res = 0
for i in reversed(sorted(count.values())):
	if i == k:
		res += i * i
		break
	elif i > k:
		res += k * k
		break
	else:
		res += i * i
		k -= i
print(res)


import sys, os, io, time, copy, math
from functools import lru_cache
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	(n, k) = map(int, input().split())
	string = input()
	dic = {}
	for s in string:
		if s not in dic:
			dic[s] = 1
		else:
			dic[s] += 1
	res = 0
	for (d, _) in sorted(dic.items(), key=lambda item: item[1], reverse=True):
		if k == 0:
			break
		if dic[d] <= k:
			res += dic[d] * dic[d]
			k -= dic[d]
		else:
			res += k * k
			k = 0
	print(res)
main()


(a, b) = map(int, input().split())
s = input()
sSet = set(s)
arr = []
(count, ans, i, x) = (0, 0, 0, 0)
for val in sSet:
	arr.append(s.count(val))
arr.sort(reverse=True)
while count <= b:
	try:
		if count + arr[i] <= b:
			ans += arr[i] * arr[i]
			count += arr[i]
		else:
			ans += (b - count) * (b - count)
			break
	except:
		break
	i += 1
print(ans)


(n, k) = map(int, input().split())
str_ = input()
res = {i: str_.count(i) for i in set(str_)}
r = 0
for v in sorted(res.values())[::-1]:
	x = min(k, v)
	r += x * x
	k -= x
print(r)


from sys import stdin, stdout
from os import path
rd = lambda : stdin.readline().strip()
wr = stdout.write
if path.exists('input.txt'):
	stdin = open('input.txt', 'r')
import time, math
(x, y) = map(int, rd().split())
inn = rd()
arr = [0] * 27
for item in inn:
	arr[ord(item) - 65] += 1
arr.sort(reverse=True)
sum = 0
for item in arr:
	if item > y:
		sum += y * y
		break
	else:
		sum += item * item
		y -= item
print(sum)


(n, m) = map(int, input().split(' '))
s = input()
k = [s[x] for x in range(0, n)]
a = set(k)
b = []
sum = 0
t = m
for x in a:
	b.append(k.count(x))
while m != 0:
	j = max(b)
	if j <= m:
		sum += j ** 2
		m -= j
		b.remove(j)
	else:
		j = m
		sum += j ** 2
		m -= j
print(sum)


(n, k) = map(int, input().split())
s = list(input())
a = [0 for i in range(26)]
for i in s:
	a[ord(i) - ord('A')] += 1
a.sort()
a.reverse()
i = 0
s = 0
while k != 0:
	if a[i] <= k:
		s += a[i] * a[i]
		k -= a[i]
	else:
		s += k * k
		k = 0
	i += 1
print(s)


from collections import Counter
(n, k) = map(int, input().split())
cards = input()
c = Counter(cards)
common = c.most_common()
remaining = k
result = 0
for (item, counter) in common:
	if counter <= remaining:
		result += counter ** 2
		remaining -= counter
	else:
		result += remaining ** 2
		break
print(result)


(n, k) = input().split()
n = int(n)
k = int(k)
l = list(input())
q = []
for i in range(n):
	r = l[i]
	if r != 'o':
		q.append(l.count(r))
		for j in range(i, n):
			if r == l[j]:
				l[j] = 'o'
q1 = len(q)
for i in range(q1 - 1):
	mi = max(q) + 1
	for j in range(i, q1):
		if mi > q[j]:
			mi = q[j]
			r = j
	(q[i], q[r]) = (q[r], q[i])
s = 0
m = 0
for i in range(q1):
	if s + q[-i - 1] > k:
		m += (k - s) * (k - s)
		break
	else:
		s += q[-i - 1]
		m += q[-i - 1] * q[-i - 1]
print(m)


(n, k) = map(int, input().split())
s = input()
C = [0] * 26
for i in range(n):
	C[ord(s[i]) - ord('A')] += 1
C.sort(reverse=True)
curr = 0
m = 0
while k > 0 and curr < 26:
	if C[curr] <= k:
		m += C[curr] * C[curr]
	else:
		m += k * k
	k -= C[curr]
	curr += 1
print(m)


(n, k) = [int(x) for x in input().split()]
cards = input()
cards_ = set(cards)
coins = 0
choices = []
for card in cards_:
	choices.append(cards.count(card))
choices.sort(reverse=True)
while k > 0:
	for i in choices:
		coins += min(k, i) ** 2
		k -= min(k, i)
print(coins)


import sys
(n, k) = [int(x) for x in sys.stdin.readline().split()]
cards = sys.stdin.readline().strip()
count = [0] * 26
for letter in cards:
	count[ord(letter) - ord('A')] += 1
count.sort()
count.reverse()
coins = 0
i = 0
while k > 0 and i < 26:
	if count[i] <= k:
		coins += count[i] * count[i]
		k -= count[i]
	else:
		coins += k * k
		k = 0
	i += 1
print(coins)


from collections import Counter
(n, k) = map(int, input().split())
s = 0
c = Counter(input()).most_common()
for x in c:
	if k - x[1] >= 0:
		k -= x[1]
		s += x[1] ** 2
	else:
		s += k ** 2
		break
print(s)


import sys
import math
(n, k) = [int(x) for x in sys.stdin.readline().split()]
w = sys.stdin.readline()
t = [0] * 26
for i in range(n):
	t[ord(w[i]) - ord('A')] += 1
t.sort(reverse=True)
res = 0
i = 0
while k > 0:
	if k - t[i] > 0:
		k -= t[i]
		res += t[i] ** 2
	else:
		res += k ** 2
		k -= t[i]
	i += 1
print(res)


from collections import Counter
(n, k) = list(map(int, input().split()))
a = str(input())
dict = Counter(a)
s = 0
dict = dict.most_common()
for (i, v) in dict:
	if k > v:
		s = s + v * v
		k = k - v
	else:
		s = s + k * k
		break
print(s)


(n, k) = map(int, input().split())
a = list(input())
b = [0 for i in range(26)]
for x in a:
	b[ord(x) - ord('A')] += 1
b.sort()
b = b[::-1]
suc = 0
i = 0
while k > 0:
	kolko = min(k, b[i])
	suc += kolko * kolko
	k -= kolko
	i += 1
print(suc)


nk = list(input().split())
n = int(nk[0])
k = int(nk[1])
a = input()
b = set(a)
c = []
d = len(b)
for i in range(d):
	c.append(a.count(b.pop()))
c.sort(reverse=True)
sum = 0
x = 0
for i in range(d):
	sum = sum + c[i]
	if sum >= k:
		x = x + abs(sum - k - c[i]) ** 2
		break
	else:
		x = x + c[i] ** 2
print(x)


(n, k) = map(int, input().split())
cardsstr = input()
cards = {}
score = 0
for card in cardsstr:
	if card in cards:
		cards[card] += 1
	else:
		cards[card] = 1
cards_count = list(cards.values())
cards_count.sort(reverse=True)
for card_count in cards_count:
	if k == 0:
		break
	elif k >= card_count:
		k -= card_count
		score += card_count * card_count
	elif k < card_count:
		score += k * k
		k = 0
print(score)


from collections import defaultdict
(n, k) = map(int, input().split())
s = list(input())
freq = defaultdict(int)
for i in s:
	freq[i] += 1
c = sorted([i for i in freq.values()], reverse=True)
res = 0
for i in c:
	if k - i > 0:
		res += i * i
		k -= i
	else:
		res += k * k
		break
print(res)


(n, m) = map(int, input().split())
s = list(input())
b = []
c = []
sum = 0
for i in set(s):
	b.append(i)
for i in b:
	c.append(s.count(i))
c.sort(reverse=True)
for i in c:
	if m - i > 0:
		m = m - i
		sum = sum + i * i
	else:
		sum = sum + m * m
		break
print(sum)


def spliter():
	d = input()
	a = d.split()
	r = []
	for i in a:
		k = int(i)
		r.append(k)
	return r
n = spliter()
k = input()
lst = []
counter = []
count = 1
maxcoin = 0
noremain = n[1]
count1 = 0
for i in range(n[0]):
	lst.append(k[i])
lst.sort()
for i in range(1, n[0], 1):
	if lst[i] == lst[i - 1]:
		count += 1
		count1 += 1
	else:
		counter.append(count)
		count = 1
		count1 += 1
	if i == n[0] - 1:
		counter.append(count)
counter.sort(reverse=True)
if count1 == 0:
	counter.append(1)
for i in counter:
	if i > noremain:
		maxcoin += noremain * noremain
		break
	else:
		maxcoin += i * i
		noremain -= i
print(maxcoin)


(n, k) = map(int, input().split())
s = str(input())
l = [0 for i in range(26)]
for i in range(len(s)):
	l[ord(s[i]) - ord('A')] += 1
l.sort(reverse=True)
ans = 0
i = 0
while k > 0:
	if k > l[i]:
		ans += l[i] ** 2
		k -= l[i]
		i += 1
	else:
		ans += k ** 2
		break
print(ans)


(n, k) = map(int, input().split())
s = input()
arr = [0] * 26

def pos(c):
	return ord(c) - ord('A')
for c in s:
	arr[pos(c)] += 1
arr.sort(reverse=True)
ans = 0
for i in arr:
	if i == 0:
		break
	if k >= i:
		ans += i ** 2
		k -= i
	else:
		ans += k ** 2
		break
print(ans)


(n, k) = map(int, input().split())
d = {}
for i in list(input()):
	if not i in d:
		d[i] = 0
	d[i] += 1
a = sorted(d.values(), reverse=True)
i = 0
ans = 0
while k > 0:
	if k - a[i] > 0:
		ans += a[i] ** 2
		k -= a[i]
		i += 1
	else:
		ans += k ** 2
		break
print(ans)


def index(letter):
	return ord(letter) - ord('A')
count = [0] * 26
(n, k) = map(int, input().split())
for c in input():
	count[index(c)] += 1
result = 0
for i in sorted(count, reverse=True):
	if i >= k:
		result += k * k
		break
	else:
		result += i * i
		k -= i
print(result)


from collections import Counter
(n, k) = map(int, input().split())
c = Counter(input())
a = c.most_common()
add = 0
while k > a[0][1]:
	add += a[0][1] * a[0][1]
	k = k - a[0][1]
	del a[0]
print(add + k * k)


(m, n) = map(int, input().split())
num = list(str(input()))
haha = []
for i in set(num):
	quant = 0
	for j in num:
		if j == i:
			quant += 1
	haha.append((i, quant))
haha.sort(key=lambda x: x[1], reverse=True)
output = 0
for i in range(len(haha)):
	if haha[i][1] <= n:
		output += haha[i][1] ** 2
		n -= haha[i][1]
	elif n == 0:
		print(output)
		quit()
	else:
		output += n ** 2
		print(output)
		quit()
print(output)


from collections import defaultdict, OrderedDict

def appleman(cards, k):
	d = defaultdict(lambda : 0)
	for c in cards:
		d[c] = d[c] + 1
	d = OrderedDict(sorted(d.items(), key=lambda i: -i[1]))
	total = 0
	for (key, value) in d.items():
		total = total + min(k, value) * min(k, value)
		k = k - value
		if k < 0:
			break
	return total
(_, k) = [int(x) for x in input().split(' ')]
cards = input()
print(appleman(cards, k))


(n, k) = map(int, input().split())
cards = input()
d = []
for card in set(cards):
	d.append(cards.count(card))
d.sort()
r = 0
while k > 0:
	last = d.pop()
	if k >= last:
		k -= last
		r += last * last
	else:
		r += k * k
		k = 0
print(r)


def maxim():
	m = 0
	index = 0
	for i in range(26):
		if not visited[i] and arr[i] > m:
			m = arr[i]
			index = i
	visited[index] = True
	return m
(n, k) = map(int, input().split())
s = input()
arr = [0] * 26
for i in range(n):
	arr[ord(s[i]) - ord('A')] += 1
i = 0
visited = [False] * 26
m = maxim()
count = 0
while i + m < k:
	count += m * m
	i += m
	m = maxim()
if k - i > 0:
	ex = k - i
	count += ex * ex
print(count)


(n, m) = map(int, input().split())
l = list(input())
li = {}
for i in l:
	li[i] = li.get(i, 0) + 1
l = [(li[u], u) for u in li]
s = 0
l.sort(reverse=True)
for i in l:
	x = min(m, i[0])
	s += x * x
	m -= x
	if m == 0:
		break
print(s)


(n, k) = map(int, input().split())
s = input()
m = {}
for ch in s:
	if not ch in m:
		m[ch] = 1
	else:
		m[ch] += 1
cnts = sorted(m.values())
sum = 0
i = len(cnts) - 1
while k > 0:
	num = min(k, cnts[i])
	sum += num * num
	k -= num
	i -= 1
print(sum)


(n, k) = map(int, input().split())
s = input()
d = {}
for i in s:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
l = list(d.values())
l.sort(reverse=True)
s = 0
c = 0
for i in range(len(l)):
	if k == c:
		break
	if c + l[i] <= k:
		s += l[i] * l[i]
		c = c + l[i]
	else:
		s += (k - c) * (k - c)
		c = k
print(s)


(n, k) = map(int, input().split())
s = input()
lst = list()
c = str.count
ind = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in ind:
	if c(s, i) != 0:
		lst.append(c(s, i))
lst.sort()
lst.reverse()
ans = 0
for i in lst:
	ans += min(k, i) ** 2
	k = k - min(k, i)
	if k == 0:
		break
print(ans)


from collections import Counter
(n, k) = map(int, input().split(' '))
c = list(input())
d = Counter(c).most_common()
a = 0
while k > 0 and len(d) > 0:
	a += min(d[0][1], k) ** 2
	k -= d[0][1]
	d.pop(0)
print(a)


from collections import Counter
(n, k) = [int(x) for x in input().split()]
s = input()
cnt = Counter(s)
ans = 0
for (a, b) in cnt.most_common(len(cnt)):
	ans += min(k, b) ** 2
	k -= min(k, b)
print(ans)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def div(n):
	if n == 1:
		return 1
	cnt = 2
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			if i != n // i:
				cnt += 2
			else:
				cnt += 1
	return cnt

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		flag = True
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				flag = False
				break
		return flag

def s(b):
	ans = []
	while b > 0:
		tmp = b % 10
		ans.append(tmp)
		b = b // 10
	return ans

def main():
	(n, k) = mi()
	s = I().strip()
	d = defaultdict(int)
	for i in s:
		d[i] += 1
	li = d.values()
	li = sorted(list(li), reverse=True)
	cnt = 0
	for i in li:
		if i <= k:
			cnt += i * i
			k -= i
		else:
			cnt += k * k
			k = 0
		if k == 0:
			break
	print(cnt)
main()


from collections import Counter
(n, k) = map(int, input().split(' '))
s = input()
mp = [0] * 27
for i in range(n):
	mp[ord(s[i]) - ord('A')] += 1
mp.sort()
ans = 0
for i in range(26, -1, -1):
	if mp[i] <= k:
		k = k - mp[i]
		ans += mp[i] * mp[i]
		if k == 0:
			break
	else:
		ans += k * k
		break
print(ans)


x = input().split(' ')
a = int(x[0])
b = int(x[1])
n = input()
list_1 = list(n)
list_1 = sorted(list_1)
i = 0
length_1 = len(list_1)
list_2 = []
while i < length_1:
	g = list_1[i]
	h = list_2.count(g)
	if h == 0:
		list_2.append(g)
	i += 1
length_2 = len(list_2)
list_3 = []
i = 0
while i < length_2:
	g = list_2[i]
	h = list_1.count(g)
	list_3.append(h)
	i += 1
list_3 = sorted(list_3)
list_3.reverse()
coins = 0
i = 0
while i < len(list_3):
	j = list_3[i]
	if b >= j:
		b = b - j
		coins += j * j
	else:
		l = b
		b = b - l
		coins += l * l
	i += 1
	if b <= 0:
		break
print(coins)


(n, k) = input().split()
k = int(k)
s = input()
l = []
d = []
for i in s:
	if i not in d:
		l.append((s.count(i), i))
		d.append(i)
l.sort(reverse=True)
x = 0
while k > 0:
	if k - l[0][0] <= 0:
		x += k * k
		k = 0
	else:
		x += l[0][0] * l[0][0]
		k = k - l[0][0]
		l.pop(0)
print(x)


w = list(map(int, input().split(' ')))
n = w[0]
k = w[1]
s = input()
l = list()
u = []
d = {}
l.extend(s)
for i in l:
	if i in d:
		d[i] = d[i] + 1
	else:
		d[i] = 1
for i in d:
	u.append(d[i])
u.sort(reverse=True)
i = 0
s = 0
while k > 0:
	if k - u[i] >= 0:
		s = s + u[i] * u[i]
		k = k - u[i]
	else:
		s = s + k * k
		break
	i = i + 1
print(s)


import collections
(n, k) = list(map(int, str.split(input())))
coins = 0
for (_, count) in collections.Counter(input()).most_common():
	count = min(count, k)
	coins += count ** 2
	k -= count
	if k == 0:
		break
print(coins)


(n, k) = map(int, input().split())
s = input()
L = []
summ = 0
d = 0
for i in set(s):
	L.append(s.count(i))
D = sorted(L)
L = D[::-1]
for i in L:
	d = min(i, k)
	summ += d * d
	k -= d
	if k <= 0:
		break
print(summ)


(n, k) = map(int, input().split())
cards = input()
hand = {}
for card in cards:
	if hand.get(card) == None:
		hand[card] = 1
	else:
		hand[card] = hand.get(card) + 1
val = sorted(hand.values())
p = -1
total = 0
while k > 0:
	if val[p] < k:
		total += val[p] * val[p]
		k -= val[p]
	else:
		total += k * k
		k = 0
	p -= 1
print(total)


(n, k) = map(int, input().split())
x = input()
from collections import Counter
count = Counter(x)
points = 0
most_common = count.most_common()
i = 0
while k > 0:
	(letter, freq) = most_common[i]
	points += min(freq, k) * min(freq, k)
	i += 1
	k -= freq
print(points)


(n, k) = map(int, input().split())
l = input()
a = [0] * 26
for i in l:
	a[ord(i) - 65] += 1
a.sort(reverse=True)
c = 0
s = 0
i = 0
while c < k and i < n:
	x = min(k - c, a[i])
	c += x
	s += x * x
	i += 1
print(s)


from collections import Counter

def main():
	(n, k) = map(int, input().strip().split())
	l = list(Counter(list(input().strip())).values())
	l.sort(reverse=True)
	tot = cnt = 0
	for x in l:
		if x + cnt >= k:
			x = k - cnt
			tot += x * x
			break
		tot += x * x
		cnt += x
	print(tot)
main()


(n, k) = map(int, input().split())
s = input()
l = [0] * 26
for i in s:
	l[ord(i) - 65] += 1
l.sort(reverse=True)
i = s = c = 0
while i < 26 and c + l[i] <= k:
	c += l[i]
	s += l[i] * l[i]
	i += 1
if c != k:
	s += (k - c) ** 2
print(s)


(n, m) = [int(i) for i in input().split()]
s = str(input())
d = {}
for i in range(0, len(s)):
	if s[i] not in d:
		d[s[i]] = 1
	else:
		d[s[i]] = d[s[i]] + 1
d = sorted(d.values(), reverse=True)
e = 0
for i in range(0, len(d)):
	if d[i] <= m:
		e = e + d[i] * d[i]
		m = m - d[i]
	else:
		e = e + m * m
		m = 0
	if m == 0:
		break
print(e)


d = dict()
(n, k) = map(int, input().split())
s = input()
for i in range(len(s)):
	if s[i] not in d:
		d[s[i]] = 0
	d[s[i]] += 1
a = []
for i in range(len(d)):
	a.append(d[list(d)[i]])
a = list(sorted(a, reverse=True))
i = 0
suma = 0
counts = a[:]
for i in range(len(a)):
	if counts[i] <= k:
		k -= counts[i]
		suma += counts[i] * counts[i]
	else:
		suma += k * k
		break
print(suma)


[n, k] = list(map(int, input().split()))
apm = input()
l = [0] * 26
for i in range(len(apm)):
	l[ord(apm[i]) - ord('A')] += 1
l = sorted(l, reverse=True)
(i, cnt) = (0, 0)
while k > 0 and i < 26:
	if l[i] >= k:
		cnt += k * k
		k -= k
	else:
		cnt += l[i] ** 2
		k -= l[i]
		i += 1
print(cnt)


d = {chr(u): 0 for u in range(65, 91)}
(n, k) = [int(u) for u in input().split()]
listo = []
for u in input():
	d[u] += 1
for i in range(65, 91):
	listo.append(d[chr(i)])
listo = sorted(listo, reverse=True)
res = 0
index = 0
while k != 0:
	if listo[index] < k:
		res += listo[index] ** 2
		k -= listo[index]
		index += 1
	else:
		res += k * k
		k = 0
print(res)


(n, k) = map(int, input().split())
(s, t) = (0, [0] * 26)
for i in input():
	t[ord(i) - 65] += 1
for i in sorted(t)[::-1]:
	if i > k:
		break
	s += i * i
	k -= i
print(s + k * k)


(k, n) = [int(i) for i in input().split()]
s = input()
d = {}
for c in s:
	if c in d:
		d[c] += 1
	else:
		d[c] = 1
arr = sorted(d.items(), key=lambda x: x[1])
i = len(arr) - 1
tot = 0
while n:
	to_take = min(n, arr[i][1])
	tot += to_take * to_take
	n -= to_take
	i -= 1
print(tot)


import collections
(n, k) = map(int, input().split())
a = input()
counter = dict(collections.Counter(a))
counter = sorted(list(counter.values()), reverse=True)
(ans, i) = (0, 0)
while i < k and i + counter[0] < k:
	i = i + counter[0]
	ans = ans + counter[0] * counter[0]
	counter.pop(0)
if i != k and len(counter) > 0:
	i = k - i
	ans = ans + i * i
print(ans)


from collections import Counter
gi = lambda : list(map(int, input().strip().split()))
(n, m) = gi()
occ = Counter(input())
occ = [occ[e] for e in occ]
occ.sort()
occ = occ[::-1]
ans = 0
k = 0
while m:
	ans += min(m, occ[k]) ** 2
	m -= min(m, occ[k])
	k += 1
print(ans)


line = input().split()
for i in range(len(line)):
	line[i] = int(line[i])
n = line[0]
k = line[1]
n = int(n)
k = int(k)
s = input()
counts = dict()
for i in s:
	counts[i] = counts.get(i, 0) + 1
lst = list()
for (p, v) in counts.items():
	lst.append(v)
lst = sorted(lst, reverse=True)
c = 0
j = 0
sum = 0
while c < k:
	if k - c >= lst[j]:
		sum = sum + lst[j] * lst[j]
		c = c + lst[j]
	else:
		sum = sum + (k - c) * (k - c)
		c = k
	j = j + 1
print(sum)


let = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
cont = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
(n, k) = list(map(int, input().split()))
pala = input()
test = k
for i in pala.lower():
	cont[let.index(i)] += 1
cont.sort()
ans = 0
while k > 0:
	p = cont.index(max(cont))
	q = min(k, cont[p])
	ans += q ** 2
	k -= q
	cont[p] -= q
print(ans)


(n, m) = map(int, input().split())
s = list(input())
se = list(set(s))
max = 0
count = 0
point = 0
l = []
for i in se:
	l.append(s.count(i))
l.sort()
l.reverse()
i = 0
while True:
	if l[i] + count < m:
		count += l[i]
		point += l[i] ** 2
	elif l[i] + count == m:
		count += l[i]
		point += l[i] ** 2
		break
	else:
		point += (m - count) ** 2
		break
	i += 1
print(point)


(n, k) = map(int, input().split())
s = input().strip()
cnt = dict()
for i in s:
	if i not in cnt:
		cnt[i] = 0
	cnt[i] += 1
a = []
for i in cnt:
	a.append(cnt[i])
a.sort(reverse=True)
cn = 0
ans = 0
for i in range(len(a)):
	if a[i] + cn <= k:
		ans += a[i] * a[i]
		cn += a[i]
	else:
		ans += (k - cn) * (k - cn)
		break
print(ans)


(n, k) = map(int, input().split())
str = input()
countarr = [0] * 26
for i in range(n):
	countarr[ord(str[i]) - 65] += 1
countarr.sort()
countarr.reverse()
ans = 0
for i in range(26):
	if k <= 0:
		break
	if countarr[i] > k:
		ans = ans + k * k
		break
	elif countarr[i] <= k:
		ans = ans + countarr[i] * countarr[i]
		k = k - countarr[i]
	else:
		ans += k
		k -= 1
print(ans)


(n, k) = [int(n) for n in input().split()]
s = input()
freq_d = {}
for c in s:
	if c not in freq_d:
		freq_d[c] = 1
	else:
		freq_d[c] += 1
freq_l = [f for (c, f) in freq_d.items()]
freq_l_s = sorted(freq_l, reverse=True)
r = 0
i = 0
while k > 0:
	d = min(k, freq_l_s[i])
	i += 1
	r += d * d
	k -= d
print(r)


from collections import Counter
(n, k) = map(int, input().split())
lst = list(input())
d = Counter(lst)
res = 0
while k > 0:
	key_list = list(d.keys())
	val_list = list(d.values())
	maxel = max(d.values())
	pos = val_list.index(maxel)
	key = key_list[pos]
	if maxel <= k:
		res += maxel * maxel
		k -= maxel
		d.pop(key)
	else:
		temp = maxel - (maxel - k)
		res += temp * temp
		k -= temp
		d[key] -= temp
print(res)


(n, k) = [int(x) for x in input().split()]
s = input()
D = dict()
for i in s:
	D[i] = 0
for i in s:
	D[i] = D[i] + 1
F = sorted([x for x in D.values()], reverse=True)
ans = 0
for x in F:
	ans += min(k, x) * min(k, x)
	k -= min(k, x)
print(ans)


(n, k) = map(int, input().split())
counter = {}
for ch in input():
	counter[ch] = counter.get(ch, 0) + 1
sorted_counts = sorted(counter.values(), reverse=True)
tmp_cards = coins = 0
for card_count in sorted_counts:
	tmp_sum = tmp_cards + card_count
	if tmp_sum < k:
		tmp_cards = tmp_sum
		coins += card_count * card_count
	else:
		partial = card_count - (tmp_sum - k)
		coins += partial * partial
		print(coins)
		break


(n, k) = [int(n) for n in input().split()]
cards = input()
chars = []
for i in range(n):
	chars.append(cards[i])
chars.sort()
chars_counter = {}
for word in chars:
	if word in chars_counter:
		chars_counter[word] += 1
	else:
		chars_counter[word] = 1
popular_words = sorted(chars_counter, key=chars_counter.get, reverse=True)
final_counter = 0
for i in range(len(popular_words)):
	if chars_counter.get(popular_words[i]) < k:
		final_counter += chars_counter.get(popular_words[i]) ** 2
		k = k - chars_counter.get(popular_words[i])
	else:
		final_counter += k ** 2
		break
print(final_counter)


from collections import Counter
(n, k) = [int(x) for x in input().split()]
cards = Counter(input())
points = 0
while k > 0:
	(card, count) = cards.most_common(1)[0]
	cards_chosen = min(count, k)
	points += cards_chosen ** 2
	k -= cards_chosen
	cards -= Counter({card: cards_chosen})
print(points)


import operator
(n, k) = map(int, input().split())
s = input()
d = {}
for i in s:
	if i not in d:
		d[i] = 1
	else:
		d[i] += 1
sort = sorted(d.items(), key=operator.itemgetter(1))
ans = []
for i in sort:
	ans.append(i[1])
ans.sort(reverse=True)
anss = 0
for i in ans:
	if i < k:
		anss += i * i
		k -= i
	else:
		anss += k * k
		break
print(anss)


for _ in range(1):
	(n, k) = map(int, input().split())
	s = input()
	s = list(s)
	s.sort()
	d = {}
	for i in range(n):
		if s[i] in d:
			d[s[i]] += 1
		else:
			d[s[i]] = 1
	ans = []
	for key in d:
		ans.append(d[key])
	ans.sort(reverse=True)
	ss = 0
	diff = k
	for i in ans:
		temp = min(diff, i)
		ss = ss + temp * temp
		diff -= temp
		if diff <= 0:
			break
	print(ss)


(n, k) = map(int, input().split())
s = input()
dic = {}
cnt = i = 0
for item in s:
	if dic.get(item, 0):
		continue
	dic[item] = s.count(item)
val = sorted(dic.values(), reverse=True)
l = len(val)
while i < l and k > 0:
	mn = min(val[i], k)
	cnt += mn * mn
	k -= mn
	i += 1
print(cnt)


def main():
	(n, k) = map(int, input().split())
	s = input()
	counts = dict()
	for i in s:
		if i in counts:
			counts[i] += 1
		else:
			counts[i] = 1
	counts = list(counts.items())
	counts.sort(key=lambda x: x[1])
	ans = 0
	for (a, v) in reversed(counts):
		if v <= k:
			ans += v ** 2
			k -= v
		elif v > k:
			ans += k * k
			break
	print(ans)
main()


(n, k) = map(int, input().split())
s = input()
alph_arr = [0 for i in range(26)]
for i in s:
	alph_arr[ord(i) - 65] += 1
alph_arr.sort(reverse=True)
ans = 0
for i in alph_arr:
	if k >= i:
		ans += i * i
		k -= i
	else:
		ans += k * k
		break
print(ans)


__author__ = '$'
import sys
MAXN = int(100000.0 + 10)
string = [0 for i in range(MAXN)]
try:
	while True:
		(n, k) = map(int, input().split(' '))
		string = input()
		cnt = [0] * 26
		for i in range(n):
			cnt[ord(string[i]) - ord('A')] += 1
		cnt.sort()
		ans = 0
		for i in range(25, -1, -1):
			tmp = min(k, cnt[i])
			k -= tmp
			ans += tmp * tmp
			if k <= 0:
				break
		print(ans)
except EOFError:
	pass


this = input()
hurry = this.split()
n = int(hurry[0])
k = int(hurry[1])
then = input()
thelist = []
i = 0
while i < len(then):
	thelist.append(then[i])
	i += 1
checked = []
counts = []
for item in thelist:
	if item not in checked:
		checked.append(item)
		counts.append(thelist.count(item))
thetotal = 0
while k > 0:
	x = max(counts)
	if x >= k:
		print(thetotal + k * k)
		k = 0
	else:
		thetotal += x * x
		k -= x
		q = counts.index(x)
		counts.remove(x)
		checked.remove(checked[q])


import collections
(ns, ks) = input().split()
(n, k) = (int(ns), int(ks))
st = str(input())
c = collections.Counter(list(st))
frequencies = c.most_common()
lettersLeft = k
res = 0
for (ch, freq) in frequencies:
	t = min(lettersLeft, freq)
	res += t * t
	lettersLeft -= t
print(res)


s = input().split()
(n, k) = (int(s[0]), int(s[1]))
cards = input()
count = [cards.count(i) for i in list(set(cards))]
count.sort(reverse=True)
coins = 0
for i in count:
	if k >= i:
		coins += i * i
		k -= i
	elif k > 0:
		coins += k * k
		k = 0
print(coins)


(n, k) = input().split()
d = {}
l = input()
l = ' '.join(l)
l = list(l.split())
for i in l:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
s = 0
v = 0
k = int(k)
while 1:
	keymax = max(d, key=d.get)
	v = d[keymax]
	if v < k:
		k = k - v
		s = s + v * v
	else:
		s = s + k * k
		k = 0
	d[keymax] = 0
	if k == 0:
		break
print(s)


S = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
S1 = []
(n, m) = map(int, input().split())
T = input()
for i in range(26):
	S1.append(T.count(S[i]))
S1 = sorted(S1)
k = 0
for i in range(25, -1, -1):
	if m >= S1[i]:
		k = k + S1[i] * S1[i]
		m = m - S1[i]
	else:
		k = k + m * m
		break
print(k)


(n, k) = [int(x) for x in input().split()]
s = input()
dict = {}
ans = []
for i in range(n):
	if s[i] not in dict:
		dict[s[i]] = 1
	else:
		dict[s[i]] += 1
for key in dict:
	ans.append(dict[key])
ans.sort()
res = 0
while True:
	val = ans.pop()
	if k > val:
		k -= val
		res += val ** 2
	else:
		res += k ** 2
		break
print(res)


(n, k) = map(int, input().split())
s = input()
l = [0 for i in range(27)]
for i in s:
	l[ord(i) - ord('A')] += 1
l.sort()
l = l[::-1]
s = 0
for i in l:
	if k > 0:
		if k >= i:
			s += i * i
			k -= i
		else:
			s += k * k
			k = 0
	else:
		break
print(s)


from collections import *
(n, k) = map(int, input().split())
(s, ans) = (Counter(input()), 0)
for (i, j) in s.most_common():
	if k <= 0:
		break
	ans += min(k, j) * min(k, j)
	k -= j
print(ans)


(n, k) = map(int, input().split())
s = input()
a = [0] * 26
for i in s:
	a[ord(i) - 65] += 1
a.sort()
res = 0
for i in range(25, -1, -1):
	if a[i] <= k:
		res += a[i] ** 2
		k -= a[i]
	else:
		res += k ** 2
		break
print(res)


from collections import Counter
(n, k) = map(int, input().split())
s = input()
d = Counter(s)
l = list(d.values())
l.sort(reverse=True)
c = 0
for i in l:
	if i <= k:
		c += i ** 2
		k = k - i
	else:
		c += k ** 2
		k = 0
	if k <= 0:
		break
print(c)


(n, k) = input().split()
n = int(n)
k = int(k)
arr = input()
arr = list(arr)
count_arr = []
check_arr = []
for i in range(0, n):
	if arr[i] not in check_arr:
		count_arr.append(arr.count(arr[i]))
		check_arr.append(arr[i])
i = 0
tally = 0
while i < k:
	m = max(count_arr)
	count_arr.remove(m)
	if i < k:
		if i + m < k:
			i = i + m
			tally += m * m
		else:
			tally += (k - i) * (k - i)
			break
	else:
		break
print(tally)


import math
l1 = input().split()
l2 = list(input())
l1 = [int(i) for i in l1]
w = l1[0]
y = l1[1]
c = []
for b in range(27):
	c.append(0)
for i in range(w):
	c[ord(l2[i]) - ord('A')] += 1
c.sort()
resp = 0
x = 26
while x >= 0 and y:
	if y >= c[x]:
		y -= c[x]
		resp += c[x] * c[x]
	else:
		resp += y * y
		break
	x -= 1
print(resp)


(n, k) = list(map(int, input().split()))
chars = list(input())
values = {}
for char in chars:
	if char not in values:
		values[char] = 1
	else:
		values[char] += 1
values = sorted(list(values.values()))
result = 0
while k > 0:
	value = values.pop()
	if value >= k:
		result += k * k
		k -= k
		break
	else:
		k -= value
		result += value * value
print(result)


(n, k) = map(int, input().split(' '))
s = input()
d = {}
for x in s:
	if x not in d:
		d[x] = 0
	d[x] += 1
l = []
for x in d:
	l.append([d[x], x])
l.sort()
ans = 0
for i in range(len(l) - 1, -1, -1):
	if l[i][0] <= k:
		k -= l[i][0]
		ans += l[i][0] * l[i][0]
	else:
		ans += k * k
		break
print(ans)


(n, k) = [int(x) for x in input().split()]
string = input()
table = {}
for x in string:
	if x in table.keys():
		table[x] += 1
	else:
		table[x] = 1
sortVal = []
for (key, item) in table.items():
	sortVal.append(item)
sortVal.sort(reverse=1)
res = 0
for x in sortVal:
	if k >= x:
		res += x ** 2
		k -= x
	elif k == 0:
		break
	else:
		res += k ** 2
		k = 0
print(res)


(n, k) = map(int, input().split())
(dic, res) = ({}, 0)
for c in input():
	dic[c] = dic.get(c, 0) + 1
for v in sorted(dic.values())[::-1]:
	res += min(k, v) * min(k, v)
	k -= min(k, v)
print(res)


a = []
(n, k) = map(int, input().split())
s = list(input())
for c in range(0, 26):
	ch = chr(c + ord('A'))
	a.append((s.count(ch), ch))
a.sort()
a.reverse()
ans = 0
for (f, g) in a:
	get = min(k, f)
	ans += get * get
	k -= get
print(ans)


from collections import Counter
(n, k) = map(int, input().split())
string = input()
total = 0
c = Counter(string)
l = sorted(c.values(), reverse=True)
for e in l:
	if k <= 0:
		break
	if k < e:
		total += k * k
		k = 0
	else:
		k -= e
		total += e * e
print(total)


(n, k) = map(int, input().split())
s = list(input())
ss = set(s)
l = []
for i in ss:
	l.append(s.count(i))
ans = 0
while k:
	i = l.index(max(l))
	t = min(k, l[i])
	ans += t * t
	l[i] = -1
	k -= t
print(ans)