import sys

tottimes = {}
cumtimes = {}

for l in open(sys.argv[1], "r"):
        r = l.rsplit(" : ", 2)
        if len(r) == 3:
            func, cumtime, tottime = r
            cumtime = float(cumtime)
            tottime = float(tottime)
            tottimes[func] = tottimes.get(func, 0.0) + tottime
            cumtimes[func] = cumtimes.get(func, 0.0) + cumtime

lists = [(funcname, tottimes[funcname], cumtimes[funcname]) for funcname in tottimes]

c = 0
lists.sort(key=lambda i: i[int(sys.argv[2])])
for func, tottime, cumtime in reversed(lists):
    if not func.startswith("jit"):
        print("%s = %s (%s)" % (func, tottime, cumtime))
        c += 1
        if c > int(sys.argv[3]):
            break
