answer 12 in python (naively slow)