using System.Linq; using System.Collections.Generic; using System; public class Hello { public static void Main() { var d = new Dictionary(); var n = int.Parse(Console.ReadLine().Trim()); for (int i = 0; i < n; i++) getDic(d); if (d.Count() >= 10) foreach (var x in d.OrderByDescending(x => x.Value).ThenBy(x => x.Key).Take(10)) Console.WriteLine("{0} {1}", x.Key, x.Value); else foreach (var x in d.OrderByDescending(x => x.Value).ThenBy(x => x.Key)) Console.WriteLine("{0} {1}", x.Key, x.Value); } public static void getDic(Dictionary d) { Console.ReadLine().Trim(); string[] line = Console.ReadLine().Trim().Split(' '); var m = int.Parse(line[0]); var s = int.Parse(line[1]); line = Console.ReadLine().Trim().Split(' '); for (int i = 0; i < m; i++) { var t = line[i]; if (d.ContainsKey(t)) d[t] += s; else d[t] = s; } } }