table to store to store results of subproblems
var dp = Array ( MAX ) . fill ( - 1 ) . map ( x => Array ( MAX ) . fill ( - 1 ) . map ( x => Array ( MAX ) . fill ( - 1 ) . map ( x => Array ( 3 ) . fill ( - 1 ) ) ) ) ;