import math import sequtils import sets import strutils func priority(group: seq[string]): int = let sets = group.map_it it.to_hash_set var common = sets.foldl a * b result = common.pop.ord - 96 if result < 0: result += 58 let elves = split_lines strip read_all stdin groups = elves.distribute elves.len div 3 echo sum groups.map priority