Faster algorithm problem 440