add a DP solution O(n^4), accepted