import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.Scanner; public class Main { public static class Person implements Comparable { String name; long[] scores; long sum_score; int latest; public Person(String name, int N){ this.name = name; this.scores = new long[N]; this.sum_score = 0; this.latest = -1; } public int compareTo(Person arg0){ if(Long.compare(this.sum_score, arg0.sum_score) != 0){ return -Long.compare(this.sum_score, arg0.sum_score); }else{ return Integer.compare(this.latest, arg0.latest); } } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); long[] solve_rate = new long[N]; for(int i = 0; i < N; i++){ solve_rate[i] = sc.nextLong(); } final int T = sc.nextInt(); String[] names = new String[T]; int[] ps = new int[T]; for(int i = 0; i < T; i++){ final String name = sc.next(); final int pid = sc.next().charAt(0) - 'A'; names[i] = name; ps[i] = pid; } HashMap map = new HashMap(); for(int t = 0; t < T; t++){ if(map.containsKey(names[t])){ continue; } map.put(names[t], new Person(names[t], N)); } int[] solve_count = new int[N]; for(int t = 0; t < T; t++){ final String name = names[t]; final int pid = ps[t]; solve_count[pid]++; final long curr_score = 50 * solve_rate[pid] + (500 * solve_rate[pid] / (8 + 2 * solve_count[pid])); map.get(name).scores[pid] = curr_score; map.get(name).sum_score += curr_score; map.get(name).latest = t; } ArrayList people = new ArrayList(map.values()); Collections.sort(people); for(int i = 0; i < people.size(); i++){ System.out.print((i + 1)); System.out.print(" " + people.get(i).name); for(int j = 0; j < N; j++){ System.out.print(" " + people.get(i).scores[j]); } System.out.println(" " + people.get(i).sum_score); } } }