Attempt at O(n^4)