sample code of O(n^3).