Check if the result is already computed simply return it
if ( dp [ pos ] [ previous ] [ tight ] [ start ] != - 1 ) : NEW_LINE INDENT return dp [ pos ] [ previous ] [ tight ] [ start ] NEW_LINE DEDENT res = 0 NEW_LINE