If the previous difference is positive
if ( rightDP [ i ] > 0 ) : NEW_LINE INDENT rightDP [ i ] = ( rightDiff + rightDP [ i - 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT rightDP [ i ] = rightDiff NEW_LINE DEDENT c += 1 NEW_LINE maxm = 0 NEW_LINE for i in range ( n // 2 ) : NEW_LINE maxm = max ( maxm , max ( leftDP [ i ] , rightDP [ i ] ) ) NEW_LINE return maxm + sum NEW_LINE