Problem 82 working in N^3 time.