Triangle DP solution