Iterate over the range and update the dp table accordingly
for i in range ( 1 , N + 1 ) : NEW_LINE INDENT for j in range ( a [ i - 1 ] , b [ i - 1 ] + 1 ) : NEW_LINE INDENT dp [ i ] [ j ] += pref [ i - 1 ] [ j ] NEW_LINE DEDENT DEDENT