Problem 14

Brute force with caching of counts