Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Areas on the Cross-Section Diagram

Your task is to simulate a flood damage.

For a given cross-section diagram, reports areas of flooded sections.

Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides.
For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively.

Input

A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\".

output

Report the areas of floods in the following format:

$A$

$k$ $L_1$ $L_2$ ... $L_k$

In the first line, print the total area $A$ of created floods.

In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$.

Constraints

$1 \leq$ length of the string $\leq 20,000$

Sample Input 1

\\//

Sample Output 1

4
1 4

Sample Input 2

\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\

Sample Output 2

35
5 4 2 1 19 9

Solution in Ruby (judge verdict: Accepted)

g = gets.chomp.split("")

class Ground
  def initialize(ground)
    @str_ground = ground # ["/","/", "\"]
    @int_ground = to_i_array # [1, 2, 1]
  end

  def to_i_array
    h = 0
    @str_ground.map do |g|
      if g == "/"
        h += 1
      elsif g == "_"
        h
      elsif g == "\\"
        h -= 1
      end
    end.unshift(0)
  end

  def puddles
    peak_index = @int_ground.index(@int_ground.max)
    left_puddles = UpSlope.new(@int_ground[0..peak_index]).find_puddles
    right_puddles = DownSlope.new(@int_ground[peak_index..-1]).find_puddles

    left_puddles + right_puddles
  end
end

class DownSlope
  def initialize(int_ground)
    @upslope = UpSlope.new(int_ground.reverse)
  end

  def find_puddles
    @upslope.find_puddles.reverse
  end
end

class UpSlope
  def initialize(int_ground)
    @points = int_ground
  end

  def find_puddles
    puddles = []
    start = 0
    @points.each_with_index do |g, i|
      if i == 0
        # スキップ
        next
      elsif start != (i - 1) # startが固定されてる
        if @points[start] == g  # 終わり
          puddles << Puddle.new(@points[start..i])
          start = i
        end
      elsif @points[i-1] <= g  # 上りか平面
        start = i
      else # 初めて下りになった時
        # startを固定する
      end
    end
    puddles    # [Puddle(...), Puddle(..)]
  end
end

class Puddle
  attr_accessor :size

  def initialize(ground)
    @ground = ground
    @size = calculate_size
  end

  private

  # 真ん中でならす
  def calculate_size
    max = @ground.max
    max * @ground.size - @ground.sum
  end
end

ground = Ground.new(g)

sizes = ground.puddles.map(&:size)
kosu = sizes.length

puts sizes.sum
puts ([kosu] + sizes).join(" ")