local n = io.read("*n", "*l") local t = {} for i = 1, n do io.read() -- N_0 local m , p = io.read("*n", "*n", "*l") local params = io.read() for param in string.gmatch(params, "%w+") do if(t[param] == nil) then t[param] = p else t[param] = t[param] + p end end end local t2 = {} for k, v in pairs(t) do local kvp = {} kvp.name, kvp.point = k, v table.insert(t2, kvp) end table.sort(t2, function(x, y) if(x.point ~= y.point) then return x.point > y.point else return x.name < y.name end end) local cnt = math.min(10, #t2) for i = 1, cnt do io.write(t2[i].name .. " " .. t2[i].point .. "\n") end