Slowish solution that uses lots of memory (at least 8GB).
Brute force solution for 299 (runs in 3 mins in slow python).
Slowest ever solution (too ashamed to tell how slow it is).