Project Euler 938 - Exhausting a Colour

Official link: https://projecteuler.net/problem=938

Note: Had to use pypy to reduce the runtime from ~147s to ~8s