import sys

def get_symb(i, string):
    symbol = ''
    if string[i].isupper():
        symbol += string[i]
        i += 1
        if i < len(string) and string[i].islower():
            symbol += string[i]
            i += 1
    return (i, symbol)

def get_mult(i, string):
    mult = 0
    while i < len(string) and string[i].isdigit():
        mult = mult * 10 + int(string[i])
        i += 1
    return (i, 1) if not mult else (i, mult)

def parse(index, string):
    counts = {}
    def update_counts(dct, mult):
        for s in dct:
            if s in counts: counts[s] += dct[s] * mult
            else: counts[s] = dct[s] * mult
    
    while index < len(string):
        if string[index] == ')':
            return (index+1,counts)
        elif string[index]=='(':
            index,grp_cnts = parse(index+1, string)
            index,grp_cnt = get_mult(index, string)
            update_counts(grp_cnts, grp_cnt)            
        else:
            index,symbol = get_symb(index, string)
            index,count = get_mult(index, string)
            update_counts({symbol:count}, 1)
    return counts

if __name__ == '__main__':
    for line in sys.stdin:
        result = parse(0,line.strip())
        for sym,mult in sorted(result.items()):
            print('{}: {}'.format(sym, mult))
        print()