Simple DP solution :-)