using System.Collections.Generic; using System.Linq; using System; using System.IO; public class P { public int[] score { get; set; } public int stotal { get; set; } public int actime { get; set; } } public class Hello { public static void Main() { var ac = new int[26]; var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var L = Array.ConvertAll(line, int.Parse); var d = new Dictionary(); var t = int.Parse(Console.ReadLine().Trim()); for (int i = 0; i < t; i++) { string[] s = Console.ReadLine().Trim().Split(' '); var name = s[0]; var qno = s[1][0] - 'A'; ac[qno]++; var score = getScore(ac, L, qno); if (d.ContainsKey(name)) { d[name].score[qno] = score; d[name].stotal += score; d[name].actime = i; } else { d[name] = new P(); d[name].score = new int[n]; d[name].score[qno] = score; d[name].stotal = score; d[name].actime = i; } } print(d, n); } public static void print (Dictionary d , int n) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var p = 1; foreach (var x in d.OrderByDescending(y => y.Value.stotal).ThenBy(y => y.Value.actime)) { Console.Write("{0} {1} ", p++,x.Key); Console.Write(string.Join(" ", x.Value.score)); Console.WriteLine(" {0}", x.Value.stotal); } Console.Out.Flush(); } public static int getScore (int[] ac, int[] L , int qno) => 250 * L[qno] / (4 + ac[qno]) + 50 * L[qno]; }