Problem 9 solved!
So...too slow :\

Gotta figure out a faster way to solve this!