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 C# (judge verdict: Accepted)

using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public int area { get; set; }
    public int id { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var n = s.Length;
        var a = new int[n];
        for (int i = 0; i < n; i++)
            if (s[i] == '\\') a[i] = -1;
            else if (s[i] == '/') a[i] = 1;
        var st1 = new Stack<int>();
        var st2 = new Stack<P>();
        getAns(s, st1, st2);
        print(st2);
    }
    public static void print (Stack <P> st)
    {
        var n = st.Count();
        if (n == 0) { Console.WriteLine(0); Console.WriteLine(0);  return; }
        var a = new int[n];
        var asum = 0;
        for (int i =    0; i < n; i++)
        {
            var w = st.Pop();
            a[n -1 -  i] = w.area;
            asum += w.area;
        }
        Console.WriteLine(asum);
        Console.Write("{0} ", n);
        for (int i = 0; i < n; i++)
            if (i == n - 1) Console.WriteLine(a[i]);
            else Console.Write("{0} ", a[i]);

    }
    public static void getAns(string s, Stack<int> st1, Stack<P> st2)
    {
        for (int i = 0; i < s.Length; i++)
            if (s[i] == '\\') st1.Push(i);
            else if (s[i] == '/' && st1.Count() > 0)
            {
                var id = st1.Pop();
                var area = i - id;
                getSum(id, area, st2);
            }
    }
    public static void getSum(int id, int area, Stack<P> st2)
    {
        while (true)
        {
            if (st2.Count() == 0) { st2.Push(new P { id = id, area = area }); return; }
            var w = st2.Peek();
            if (id > w.id) { st2.Push(new P { id = id, area = area }); return; }
            else { area += w.area; st2.Pop(); }
        }
    }
}