func main() var n: int :: cui@inputInt() var tags: dict<[]char, int> :: #dict<[]char, int> for(1, n) do cui@input() var m: int :: cui@inputInt() var s: int :: cui@inputInt() for(1, m) var t: []char :: cui@inputStr() do tags.add(t, tags.get(t, &) + s) end for end for class TagData() +var tag: []char +var score: int +func init(t: []char, s: int): TagData do me.tag :: t do me.score :: s ret me end func +*func cmp(t: kuin@Class): int if((t $ TagData).score < me.score) ret - 1 elif((t $ TagData).score = me.score) ret me.tag < (t $ TagData).tag ?(-1, 1) end if ret 1 end func end class var keys: [][]char block var keyList: List :: #List class List() +var li: list<[]char> *func ctor() do me.li :: #list<[]char> end func end class do tags.forEach(callback, keyList $ kuin@Class) func callback(key: []char, value: int, data: kuin@Class): bool do(data $ List).li.add(key) ret true end func do keys :: keyList.li.toArray() end block var data: []TagData :: #[0]TagData for i(0, ^keys - 1) var t: []char :: keys[i] var s: int :: tags.get(t, &) do data :~ [(#TagData).init(t, s)] end for do data.sort() for i(0, [^data - 1, 9].min()) do cui@print("\{data[i].tag} \{data[i].score}\n") end for end func