While current element is same as previous or has become smaller than previous .
j = i NEW_LINE while j < n and arr [ j ] <= arr [ j - 1 ] : NEW_LINE INDENT arr [ j ] = arr [ j ] + 1 NEW_LINE j += 1 NEW_LINE DEDENT sm = sm + arr [ i ] NEW_LINE return sm NEW_LINE