You are playing a new famous fighting game: Kortal Mombat XII. You have to perform a brutality on your opponent's character.

You are playing the game on the new generation console so your gamepad have $26$ buttons. Each button has a single lowercase Latin letter from 'a' to 'z' written on it. All the letters on buttons are pairwise distinct.

You are given a sequence of hits, the $i$-th hit deals $a_i$ units of damage to the opponent's character. To perform the $i$-th hit you have to press the button $s_i$ on your gamepad. Hits are numbered from $1$ to $n$.

You know that if you press some button more than $k$ times in a row then it'll break. You cherish your gamepad and don't want to break any of its buttons.

To perform a brutality you have to land some of the hits of the given sequence. You are allowed to skip any of them, however changing the initial order of the sequence is prohibited. The total damage dealt is the sum of $a_i$ over all $i$ for the hits which weren't skipped.

Note that if you skip the hit then the counter of consecutive presses the button won't reset.

Your task is to skip some hits to deal the maximum possible total damage to the opponent's character and not break your gamepad buttons.


-----Input-----

The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2 \cdot 10^5$) — the number of hits and the maximum number of times you can push the same button in a row.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the damage of the $i$-th hit.

The third line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters — the sequence of hits (each character is the letter on the button you need to press to perform the corresponding hit).


-----Output-----

Print one integer $dmg$ — the maximum possible damage to the opponent's character you can deal without breaking your gamepad buttons.


-----Examples-----
Input
7 3
1 5 16 18 7 2 10
baaaaca

Output
54

Input
5 5
2 4 1 3 1000
aaaaa

Output
1010

Input
5 4
2 4 1 3 1000
aaaaa

Output
1009

Input
8 1
10 15 2 1 4 8 15 16
qqwweerr

Output
41

Input
6 3
14 18 9 19 2 15
cccccc

Output
52

Input
2 1
10 10
qq

Output
10



-----Note-----

In the first example you can choose hits with numbers $[1, 3, 4, 5, 6, 7]$ with the total damage $1 + 16 + 18 + 7 + 2 + 10 = 54$.

In the second example you can choose all hits so the total damage is $2 + 4 + 1 + 3 + 1000 = 1010$.

In the third example you can choose all hits expect the third one so the total damage is $2 + 4 + 3 + 1000 = 1009$.

In the fourth example you can choose hits with numbers $[2, 3, 6, 8]$. Only this way you can reach the maximum total damage $15 + 2 + 8 + 16 = 41$.

In the fifth example you can choose only hits with numbers $[2, 4, 6]$ with the total damage $18 + 19 + 15 = 52$.

In the sixth example you can change either first hit or the second hit (it does not matter) with the total damage $10$.

Difficulty: interview

Starter code:

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

n, k = mi()
a = li()
s = input().strip()

ans = 0
i = 0
while i < n:
    j = i + 1
    while j < n and s[j] == s[i]:
        j += 1
    b = sorted(a[i:j])
    ans += sum(b[-k:])
    i = j
print(ans)


n,k = [int(x) for x in input().split()]

L = [int(x) for x in input().split()]

s = input()

temp = [1,0,0]
R = []
for i in range(n-1):
    if s[i+1] == s[i]:
        temp[0] += 1
    else:
        temp[-1] = i
        R.append(temp)
        temp = [1,i+1,i+1]
        
temp[-1] = n-1
R.append(temp)
Dam = 0
for i in R:
    if i[0] > k:
        q = L[i[1]:i[2]+1]
        q.sort(reverse = True)
        t = 0
        for i in range(k):
            t += q[i]
        Dam += t
    else:
        Dam += sum(L[i[1]:i[2]+1])

print(Dam)


def get():
    return list(map(int,input().split()))
n,k=get()
a=list(get())
s=input()
i=0
dmg=0
while i<n:
    j=i+1
    while j<n and s[i]==s[j]:
        j+=1
    j-=1
    if j-i+1<=k:
        dmg+=sum(a[i:j+1])
    else:
        g=a[i:j+1]
        g.sort()
        dmg+=sum(g[len(g)-k:])
    i=j+1
print(dmg)


n,k = list(map(int,input().split()))

A = [int(x) for x in input().split()]
A.append(-1)
s = input()+'$'

dmg = 0
lc = None
count = 0
atk = []
for i in range(n+1):
    c = s[i]
    a = A[i]

    if c != lc:
        if lc:
            dmg += sum(sorted(atk)[-k:])
        count = 0
        atk = []
    count += 1
    lc = c
    atk.append(a)
print(dmg)


n,k = list(map(int,input().split()))

A = [int(x) for x in input().split()]
A.append(-1)
s = input()+'$'

dmg = 0
lc = None
count = 0
atk = []
for i in range(n+1):
    c = s[i]
    a = A[i]

    if c != lc:
        if lc:
            dmg += sum(sorted(atk)[-k:])
        count = 0
        atk = []
    count += 1
    lc = c
    atk.append(a)
print(dmg)


import re, math, decimal, bisect, collections
def read(): return input().strip()
def iread(): return int(input().strip())
def viread(): return [int(_) for _ in input().strip().split()]

n, k = viread()
d = viread()
s = list(read())
processed = 0
damage = 0
while (processed < n):
    damages = []
    c = s[processed]
    damages.append(d[processed])
    processed += 1
    while (processed < n and s[processed] == c):
        damages.append(d[processed])
        processed += 1
    if len(damages) > k:
        damages.sort()
        damage += sum(damages[len(damages) - k:])
    else:
        damage += sum(damages)
print(damage)

n, k = list(map(int, input().split()))
X = [int(a) for a in input().split()]
s = input()

i = 1
p = s[0]
l = [X[0]]
c = 1
ans = 0
while i <= n:
    if i < n and p == s[i]:
        l.append(X[i])
        c += 1
    else:
        if len(l) <= k:
            ans += sum(l)
        else:
            l = sorted(l)
            ans += sum(l[-k:])

        if i == n:
            break
            
        l = [X[i]]
        p = s[i]
        c = 1
    
    
    i += 1
print(ans)


n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
s=list(input())
i=0
sth=[]
sts=[]
ans=0
while i<n:
    if len(sts)==0 or sts[-1]==s[i]:
        sts.append(s[i])
        sth.append(a[i])
        i+=1
    else:
        sts=[]
        sth.sort(reverse=True)
        ans+=sum(sth[:min(k,len(sth))])
        sth=[]
sth.sort(reverse=True)
ans+=sum(sth[:min(k,len(sth))])
sth=[]
print(ans)
        
        


#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    try:
        f = open('input'+ str(inId) + '.txt', 'r')
        sys.stdin = f #标准输出重定向至文件
    except Exception:
        dprint('invalid input file')
if outId>0:
    dprint('use output', outId)
    try:
        f = open('stdout'+ str(outId) + '.txt', 'w')
        sys.stdout = f #标准输出重定向至文件
    except Exception:
        dprint('invalid output file')
        
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
N, K = getIntList()
#print(N)
za  = getIntList()
S = input()
zz = []
lc = ' '
for i in range(N):
    if S[i] == lc:
        zz[-1].append(za[i])
    else:
        lc = S[i]
        zz.append( [za[i], ])
r = 0
for x in zz:
    x.sort(reverse = True)
    r += sum(x[:K])
print(r)







import math
import bisect
import itertools
import sys
I=lambda : sys.stdin.readline()
mod=10**9 +7
'''fact=[1]*100001
ifact=[1]*100001
for i in range(1,100001):
    fact[i]=((fact[i-1])*i)%mod
    ifact[i]=((ifact[i-1])*pow(i,mod-2,mod))%mod
def ncr(n,r):
    return (((fact[n]*ifact[n-r])%mod)*ifact[r])%mod
def npr(n,r):
    return (((fact[n]*ifact[n-r])%mod))
    '''


def mindiff(a):
    b=a[:]
    b.sort()
    m=10000000000
    for i in range(len(b)-1):
        if b[i+1]-b[i]<m:
            m=b[i+1]-b[i]
    return m
    
def lcm(a,b):
    return a*b//math.gcd(a,b)

    
def merge(a,b):
    i=0;j=0
    c=0
    ans=[]
    while i<len(a) and j<len(b):
        if a[i]<b[j]:
            ans.append(a[i])
            i+=1
        else:
            ans.append(b[j])
            c+=len(a)-i
            j+=1
    ans+=a[i:]
    ans+=b[j:]
    return ans,c
def mergesort(a):
    if len(a)==1:
        return a,0
    mid=len(a)//2   
    left,left_inversion=mergesort(a[:mid])
    right,right_inversion=mergesort(a[mid:])
    m,c=merge(left,right)
    c+=(left_inversion+right_inversion)
    return m,c
    
def is_prime(num):
    if num == 1: return False
    if num == 2: return True
    if num == 3: return True
    if num%2 == 0: return False
    if num%3 == 0: return False
    t = 5
    a = 2
    while t <= int(math.sqrt(num)):
        if num%t == 0: return False
        t += a
        a = 6 - a
    return True
    
  
def ceil(a,b):
    if a%b==0:
        return a//b
    else:
        return (a//b + 1)

def binsearch(arr,b,low,high):
    if low==high:
        return low
    if arr[math.ceil((low+high)/2)]<b:
        return binsearch(arr,b,low,math.ceil((low+high)/2) -1 )
    else:
        return binsearch(arr,b,math.ceil((low+high)/2),high)
def ncr1(n,r):
    s=1
    for i in range(min(n-r,r)):
        s*=(n-i)
        s%=mod
        s*=pow(i+1,mod-2,mod)
        s%=mod
    return s
    
def calc(n,m,r):
    s=0
    for i in range(0,r+1,2):
        s+=ncr1(n,i)*ncr1(m,i)
        s%=mod
    return s    
    
def modu(a,n):
    if a%n==0:
        return n
    return a%n

#/////////////////////////////////////////////////////////////////////////////////////////////////

for i in range(1):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    s=input()
    c=1;b=[]
    for i in range(1,n):
        if s[i-1]==s[i]:
            c+=1
            f=True
        else:
            b.append(c)
            c=1
            f=False
    if True:
        b.append(c)
    #print(b) 
    ans=0
    su=0
    for i in b:
        c=a[su:min(su+i,10**9)]
        
        #print(c)
        
        
        c.sort(reverse=True)
        c=c[:min(i,k)]
        su+=i
        ans+=sum(c)
        
    print(ans)

n, k =list(map(int, input().split()))
a = list(map(int, input().split()))
st = input()
pr = None
cl = 0
ans = 0
vs = []
for i, s in enumerate(st):
    if s == pr:
        cl +=1
        vs.append(a[i])
        pr=s
    elif pr is not None:
        vs.sort(reverse=True)
        ans += sum(vs[:k])

        pr = s
        cl = 1
        vs = [a[i],]
    else:
        pr = s
        cl +=1
        vs.append(a[i])
vs.sort(reverse=True)
ans += sum(vs[:k])
print(ans)



def sumn(l, r):
    nonlocal dmgs
    tmp = []
    for i in range(l, r + 1):
        tmp.append(dmgs[i])
    tmp.sort(reverse=True)
    return sum(tmp[:k])
    

n, k = map(int, input().split())
dmgs = [int(x) for x in input().split()]
s = input()
d = {}
key = 'abcdefghijklnmopqrstuvwxyz'
l = 0
r = 0
total = 0
for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        r = i
        total += sumn(l, r)
        l = i + 1
total += sumn(l, n - 1)
print(total)

# -*- coding: utf-8 -*-
# @Time    : 2019/1/26 23:58
# @Author  : LunaFire
# @Email   : gilgemesh2012@gmail.com
# @File    : C. Brutality.py


def main():
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    s = input()

    ret = p1 = 0
    while p1 < n:
        p2, temp = p1, []
        while p2 < n and s[p2] == s[p1]:
            temp.append(a[p2])
            p2 += 1

        temp.sort(reverse=True)
        ret += sum(temp[:k])
        p1 = p2

    print(ret)


def __starting_point():
    main()

__starting_point()

import sys
input = sys.stdin.readline

n,k=map(int,input().split())

l=list(map(int,input().split()))

s=input()
s+="*"

summ=sum(l)
l.append(999999999999)

count=1
temp=[l[0]]
for i in range(n):
	#print(temp)
	if s[i]==s[i+1]:
		count+=1
		temp.append(l[i+1])
	else:
		if count>k:
			temp.sort()
			for j in range(count-k):
				summ-=temp[j]
		temp=[l[i+1]]
		count=1

print(summ)

n,k = map(int,input().split())
a = list(map(int,input().split()))
s = input()
ans = 0
now = []
now.append(a[0])
for i in range(1,n):
        if s[i]  == s[i-1]:
                now.append(a[i])
        else:
                if len(now) > k:
                        now.sort(key=lambda x:-x)
                        ans += sum(now[:k])
                else:
                        ans += sum(now)
                now = [a[i]]
if len(now) > k:
        now.sort(key=lambda x:-x)
        ans += sum(now[:k])
else:
        ans += sum(now)
now = []
print(ans)

import copy
import fractions
import itertools
import string
import sys

###

def powmod(x, p, m):
	if p <= 0:
		return 1
	if p <= 1:
		return x%m
	return powmod(x*x%m, p//2, m) * (x%m)**(p%2) % m

###

def to_basex(num, x):
	while num > 0:
		yield num % x
		num //= x

def from_basex(it, x):
	ret = 0
	p = 1
	for d in it:
		ret += d*p
		p *= x
	return ret

###

def core():
	n, k = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	s = input()
	
	groups = []
	last_ch = None
	for i in range(len(s)):
		ch = s[i]
		if ch != last_ch:
			groups.append([])
		groups[-1].append(a[i])
		last_ch = ch
	
	# print(groups)
	
	ans = 0
	for g in groups:
		g.sort()
		ans += sum(g[-k:])
		
	print(ans)


core()





















n, m = list(map(int,input().split()))
a = list(map(int,input().split())) + [1]
s = input() + '0'
last = '1'
l = [0]
ans = 0
for i in range(n+1):
    if last != s[i]:
        l.sort()
        if len(l) < m:
            ans += sum(l)
        else:
            ans += sum(l[len(l)-m:])
        l.clear()
    l.append(a[i])
    last = s[i]
print(ans)


#!/usr/bin/env python
# coding: utf-8

# In[ ]:


n,k=list(map(int,input().split()))


# In[ ]:





# In[ ]:


scorelist=list(map(int,input().split()))


# In[ ]:





# In[2]:


keylist=list(input())


# In[ ]:


keystreaks=[]


currentstreak=[[scorelist[0],keylist[0]]]


# In[ ]:


for i in range(1,n):
    if keylist[i]==keylist[i-1]:
        currentstreak.append([scorelist[i],keylist[i]])
        
        
    else:
        keystreaks.append(currentstreak)
        currentstreak=[[scorelist[i],keylist[i]]]
        
        
        
keystreaks.append(currentstreak)        


# In[ ]:


#print(keystreaks)


# In[ ]:


bigtotal=0

for streak in keystreaks:
    total=0
    streak.sort(key=lambda x: -x[0])
    #print(streak)
    tally=0
    while tally<k and tally<len(streak):
        total=total+streak[tally][0]
        tally+=1
    bigtotal=bigtotal+total    


# In[ ]:





# In[ ]:





# In[ ]:


print(bigtotal)



(lambda N,K,n,s:(lambda c,t:[[[s[i]!=s[i-1]and[c.__setitem__(0,c[0]+sum(sorted(t)[-K:])),t.clear()],t.append(n[i])]for i in range(1,N)],print(c[0]+sum(sorted(t)[-K:]))])([0],[n[0]]))(*map(int,input().split()),list(map(int,input().split())),input())

from sys import stdin
n,m=list(map(int,stdin.readline().strip().split()))
s=list(map(int,stdin.readline().strip().split()))
s1=stdin.readline().strip()
x=[s[0]]
cur=s1[0]
y=1
ans=0
while y<n:
    if s1[y]==cur:
        x.append(s[y])
    else:
        cur=s1[y]
        if len(x)>m:
            x.sort()
            for i in range(m):
                ans+=x[-1]
                x.pop()
        else:
            ans+=sum(x)
        x=[s[y]]
    y+=1
if len(x)>m:
    x.sort()
    for i in range(m):
        ans+=x[-1]
        x.pop()
else:
    ans+=sum(x)
print(ans)


n,k=map(int, input().split())
a=list(map(int, input().split()))
s=input('')
b=[]
c=[]
su=0
for i in range(n):
  if len(b)==0:
    b.append(s[i])
    c.append(a[i])
  elif b[-1] == s[i]:
    b.append(s[i])
    c.append(a[i])
  elif b[-1] != s[i]:
    c.sort(reverse=True)
    for j in range(min(k,len(c))):
      su=su+c[j]
    b=[]   
    c=[]
    b.append(s[i])
    c.append(a[i])   
c.sort(reverse=True)
for j in range(min(k,len(c))):
  su=su+c[j]
print(su)  

n,k = map(int,input().split())
a = list(map(int,input().split()))
s = input() + '0'
i = S = 0
while i<n:
    pos1 = i
    while s[i+1] == s[i]: i+=1
    pos2 = i
    d = pos2-pos1+1
    if d <= k: S+=sum(a[pos1:pos2+1])
    else: S+=sum(sorted(a[pos1:pos2+1])[-k:])
    i+=1
print(S)

from heapq import heapify, heappush, heappop
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
s = input()
h = [A[0]]
heapify(h)
ans = A[0]
for i in range(1, n):
    if s[i] == s[i - 1]:
        if len(h) == k:
            elem = heappop(h)
            if elem > A[i]:    
                heappush(h, elem)
            else:
                heappush(h, A[i])
                ans += (A[i] - elem)
        else:
            heappush(h, A[i])
            ans += A[i]
    else:
        h = [A[i]]
        heapify(h)
        ans += A[i]
print(ans)


n,k=map(int,input().split())
a=list(map(int,input().split()))
s=input()
b=[[s[i],a[i]] for i in range(n)]
ans=0
temp=[]
c=b[0][0]
for i in b:
    if i[0]!=c:
        c=i[0]
        temp.sort(reverse=True)
        ans+=(sum(temp[:min(len(temp),k)]))
        temp.clear()
    if i[0]==c:
        temp.append(i[1])
temp.sort(reverse=True)
ans+=(sum(temp[:min(len(temp),k)]))
print(ans)

n,k=list(map(int,input().split()))
arr=list(map(int,input().split()))
s=str(input())
i=0
ans=0
while(i<n):
	j=i+1
	count=1
	arrx=[arr[i]]
	while(j<n and s[i]==s[j]):
		count+=1
		arrx.append(arr[j])
		j+=1
	#print(j)
	arrx.sort(reverse=True)
	ans+=sum(arrx[:min(count,k)])
	i=j
print(ans)