using System; using System.Collections.Generic; using System.IO; using System.Linq; public class Program { public static void Main() { var so = new Solver(); so.Solve(); } } public class Solver { private readonly Reader reader; private readonly TextWriter writer; public Solver() { reader = new Reader(Console.In); writer = Console.Out; } public Solver(string input, string output) { reader = new Reader(new StreamReader(input)); writer = new StreamWriter(output); } public void Solve() { int N = reader.RInt(); int[] L = reader.RIntArray(); int T = reader.RInt(); var d = new List>(); for (int i = 0; i < T; i++) { d.Add(new KeyValuePair(reader.RString(), GetQ(reader.String()))); } var user = new List(); var answer = new List(); foreach (var item in d.Select((x, i) => new { x, i })) { answer.Add(item.x.Value); double c = 0.8 + 0.2 * answer.Count(x => x == item.x.Value); int b = L[item.x.Value]; var u = user.FirstOrDefault(x => x.name == item.x.Key); if (u == null) { u = new User { name = item.x.Key }; user.Add(u); } u.point.Add(item.x.Value, 50 * b + (int)(50 * b / c)); u.lastAnswer = item.i; u.sumPoint = u.point.Select(x => x.Value).Sum(); } var ans = user.OrderByDescending(x => x.sumPoint).ThenBy(x => x.lastAnswer); foreach (var item in ans.Select((x, i) => new { x, i })) { writer.Write(item.i + 1 + " " + item.x.name + " "); for (int i = 0; i < N; i++) { int p = item.x.point.FirstOrDefault(x => x.Key == i).Value; writer.Write(p + " "); } writer.WriteLine(item.x.sumPoint); } writer.Flush(); } private int GetQ(string q) { string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; return s.IndexOf(q); } private class User { public string name; public Dictionary point = new Dictionary(); public int sumPoint; public int lastAnswer; } } public class Reader { private readonly TextReader reader; private readonly char separator = ' '; private string[] A = new string[0]; private int i; public Reader(TextReader r) { reader = r; } public string String() { return Set(); } public int Int() { return int.Parse(Set()); } public long Long() { return long.Parse(Set()); } public decimal Decimal() { return decimal.Parse(Set()); } public string RString() { return RSet(); } public int RInt() { return int.Parse(RSet()); } public long RLong() { return long.Parse(RSet()); } public decimal RDecimal() { return decimal.Parse(RSet()); } public int[] RIntArray() { Read(); return A.Select(x => int.Parse(x)).ToArray(); } private void Read() { string line = reader.ReadLine(); A = line.Split(separator); i = 0; } private string Set() { return A[i++]; } private string RSet() { Read(); return A[i++]; } }