INF = 1 << 60
class State:
    def __init__(self, ca):
        self.cost = [0 for __ in range(ca+1)]
        self.starts = [0]
    
    def combine_add(self,b):
        b = sorted(b,reverse=True)
        res = self.cost[:]
        pst = len(self.cost)
        for st in self.starts[::-1]:
            ca = st
            cb = 0
            csum = self.cost[st]
            for i in range(st+1, min(len(self.cost),pst+len(b))):
                if ca+1 == pst and cb == len(b):
                    break

                adda = -1 if ca+1 == pst else self.cost[ca+1]-self.cost[ca]
                addb = -1 if cb == len(b) else b[cb]
                if max(adda,addb) == -1:
                    break
                if adda > addb:
                    csum += adda
                    ca += 1
                else:
                    csum += addb
                    cb += 1
                res[i] = max(res[i], csum)
            pst = st
        for i in range(len(self.cost)):
            self.cost[i] = max(self.cost[i],res[i])

    def combine_mult(self, v, prev):
        self.starts = [0]
        pdiff = INF
        for i in range(1,len(self.cost)):
            self.cost[i] = max(self.cost[i], prev.cost[i]*v)
            if self.cost[i]-self.cost[i-1] > pdiff:
                self.starts.append(i)
            pdiff = self.cost[i]-self.cost[i-1]


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

x = []
for i in range(n):
    op,v = input().split()
    x.append((op,int(v)))

cm = sum(a[0] == "m" for a in x)
ca = sum(a[0] == "a" for a in x)
dp = [State(ca) for __ in range(cm+1)]
k = min(k,cm)

cura = []
curm = 0
for op,v in x:
    if op == "a":
        cura.append(v)
    else:
        if curm <= k:
            curm += 1
        for i in range(curm):
            dp[i].combine_add(cura)
        for i in range(curm,0,-1):
            dp[i].combine_mult(v,dp[i-1])
        cura = []

if cura:
    for i in range(k+1):
        dp[i].combine_add(cura)

res = [0 for i in range(n+1)]
for i in range(k+1):
    for j in range(ca+1):
        res[i+j] = max(res[i+j],dp[i].cost[j])

for i in range(1,n+1):
    res[i] = max(res[i],res[i-1])
    print(res[i])
