leftover: 3-dim DP method, O(N)