Rewrote code to be faster. Change algo slightly, now gives correct answer in ~6.6 seconds.