import std.stdio; import std.algorithm; import std.conv; import std.math : floor; import std.string : chomp; int calcScore(int level, int rank) { return cast(int)floor(50 * level + 50 * level / (0.8 + 0.2 * rank)); } void main(string[] args) { immutable n = readln.chomp.to!int; int[26] levels; readln.splitter.map!(to!int).copy(levels[]); struct Player { string name; int score; } Player[] players; string[][26] log; foreach (i; 0..readln.chomp.to!int) { auto line = readln.chomp; auto name = line[0..($ - 2)]; auto problemNo = line[$ - 1] - 'A'; log[problemNo] ~= name; immutable score = calcScore(levels[problemNo], cast(int)log[problemNo].length); auto j = players[].countUntil!"a.name == b"(name); if (j >= 0) { players[j].score += score; } else { players ~= Player(name, score); j = players.length - 1; } const t = players[j]; while (j > 0 && t.score > players[j - 1].score) { players[j] = players[j - 1]; --j; } players[j] = t; } foreach (rank, player; players) { writef("%s %s ", rank + 1, player.name); foreach (problemNo; 0..n) { immutable i = log[problemNo].countUntil(player.name); int score = 0; if (i >= 0) { score = calcScore(levels[problemNo], cast(int)i + 1); } write(score, " "); } writeln(player.score); } }