Loop to traverse through the upper triangular matrix and update the maximum sum to ans
for i in range ( n ) : NEW_LINE INDENT x , y , sum = 0 , i , 0 NEW_LINE for j in range ( i , n ) : NEW_LINE INDENT sum , x , y = sum + arr [ x ] [ y ] , x + 1 , y + 1 NEW_LINE DEDENT if ( sum > ans ) : NEW_LINE INDENT ans = sum NEW_LINE DEDENT DEDENT