#include "bits/stdc++.h" using namespace std; #ifdef NDEBUG #error assert is disabled! #endif template T readNatural(T lo, T up) { assert(0 <= lo && lo <= up); T x = 0; while(1) { int d = getchar(); if(!('0' <= d && d <= '9')) { ungetc(d, stdin); break; } d -= '0'; assert(d <= up && x <= (up - d) / 10); x = x * 10 + d; } assert(lo <= x && x <= up); return x; } void readSpace() { int c = getchar(); assert(c == ' '); } static bool read_eof = false; void readEOL() { int c = getchar(); if(c == EOF) { assert(!read_eof); read_eof = true; } else { assert(c == '\n'); } } void readEOF() { assert(!read_eof); int c = getchar(); assert(c == EOF); read_eof = true; } int readString(char *buf, int minLen, int maxLen, bool charactors[128]) { assert(0 <= minLen && minLen <= maxLen); int len = 0; while(1) { int c = getchar(); if(!(0 <= c && c < 128) || !charactors[c]) { ungetc(c, stdin); break; } assert(len < maxLen); buf[len ++] = c; } assert(minLen <= len && len <= maxLen); buf[len] = 0; return len; } struct Contestant { std::vector scores; int totalScore; int lastTime; Contestant() : totalScore(0), lastTime(0) {} }; int main() { bool lowercases[128] = {}, uppercases[128] = {}; for(int a = 0; a < 26; ++ a) { lowercases['a' + a] = true; uppercases['A' + a] = true; } int N = readNatural(1, 26); readEOL(); vector L(N); for(int i = 0; i < N; ++ i) { if(i != 0) readSpace(); L[i] = readNatural(1, 6); } readEOL(); int T = readNatural(1, 4000); readEOL(); std::map contestants; std::vector count(N, 0); for(int i = 0; i < T; ++ i) { char name[17], P[2]; readString(name, 1, 16, lowercases); readSpace(); readString(P, 1, 1, uppercases); readEOL(); int p = *P - 'A'; assert(0 <= p && p < N); int stars = L[p]; int rank = ++ count[p]; int score = 50 * stars + 50 * stars * 10 / (8 + 2 * rank); assert(score > 0); auto &c = contestants[name]; if(c.scores.empty()) c.scores.assign(N, 0); assert(c.scores[p] == 0); c.scores[p] = score; c.totalScore += score; c.lastTime = i + 1; } std::vector> leaderboard(contestants.begin(), contestants.end()); sort(leaderboard.begin(), leaderboard.end(), [&](auto &&x, auto &&y) { if(x.second.totalScore != y.second.totalScore) return x.second.totalScore > y.second.totalScore; else return x.second.lastTime < y.second.lastTime; }); for(int i = 0; i < (int)leaderboard.size(); ++ i) { const auto &p = leaderboard[i]; printf("%d %s", i + 1, p.first.c_str()); for(int j = 0; j < N; ++ j) printf(" %d", p.second.scores[j]); printf(" %d\n", p.second.totalScore); } readEOF(); return 0; }