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: Runtime Error)

using System;
using System.Collections.Generic;


class Program
{
    static void Main(string[] args)
    {
        Input CInput = new Input();

        List<Downdata> DownDB = new List<Downdata>();
        List<int> WaterSizeDB = new List<int>();

        var input = CInput.Line1_string();

        int cnt = 0, Data_W = 0, Data_H = 0;

        while (true)
        {
            if (cnt == input.Length) break;

            if (input[cnt].ToString() == "\\")
            {
                DownDB.Add(new Downdata(Data_W, Data_H));
                Data_H--;
            }
            else if (input[cnt].ToString() == "/")
            {
                for (int i = 0; i < DownDB.Count; i++)
                {
                    DownDB[i].WaterJudge(Data_W + 1, Data_H + 1); // +1????????????????????§?¨???¨??????
                }
                Data_H++;
            }
            Data_W++; cnt++;
        }

        int sum = 0, j, sample = 0;
        bool is_end = false;
        int CheckCompleteCount = 0;

        while (!is_end)
        {
            while (DownDB[CheckCompleteCount].InvalidCheck())
            {
                if (CheckCompleteCount + 1 == DownDB.Count) { is_end = true; break; }
                CheckCompleteCount++;
            }
            if (CheckCompleteCount + 1 == DownDB.Count)
            {
                if (!DownDB[CheckCompleteCount].InvalidCheck()) { WaterSizeDB.Add(DownDB[CheckCompleteCount].WaterSize()); break;}
                else break;
            }
            sum = DownDB[CheckCompleteCount].WaterSize();
            sample = CheckCompleteCount;
            j = CheckCompleteCount + 1;

            while (true)
            {
                if (j == DownDB.Count)
                {
                    WaterSizeDB.Add(sum);
                    is_end = true;
                    break;
                }
                if (DownDB[j].InvalidCheck())
                {
                    WaterSizeDB.Add(sum);
                    CheckCompleteCount++;
                    break;
                }

                if (DownDB[j].InsideW(DownDB[sample].GetW(), DownDB[sample].GetRightW()) == true)
                {
                    sum += DownDB[j].WaterSize();
                    CheckCompleteCount++;
                }
                else
                {
                    WaterSizeDB.Add(sum);
                    CheckCompleteCount++;
                    break;
                }
                j++;
            }
        }


        int total = 0;
        foreach (var value in WaterSizeDB)
        {
            total += value;
        }
        System.Console.WriteLine(total);
        System.Console.Write("{0}", WaterSizeDB.Count);
        for (int i = 0; i < WaterSizeDB.Count; i++)
        {
            System.Console.Write(" {0}", WaterSizeDB[i]);
        }
        System.Console.WriteLine();

    }
}

class Downdata
{
    private int m_W;  // ?¨??????§?¨?
    private int m_H;  // ??±???
    private int m_RightW;    // ?????????????????§?¨?

    public Downdata(int W, int H)
    {
        m_W = W;
        m_H = H;
        m_RightW = -1;
    }

    public int GetW()
    {
        return m_W;
    }
    public int GetRightW()
    {
        return m_RightW;
    }

    public bool WaterJudge(int W, int H)
    {
        if (m_RightW != -1) return true;
        if (m_H != H) return false;
        m_RightW = W;
        return true;
    }

    public int WaterSize()
    {
        return m_RightW - m_W - 1;
    }

    public bool InsideW(int W, int RightW)
    {
        if (W < m_W && RightW > m_RightW) return true;
        return false;
    }

    // ??????????????????water?????????????????????????????? true??§??????
    public bool InvalidCheck()
    {
        if (m_RightW == -1) return true;
        else return false;
    }
}







class Input
{
    public enum Define
    {
        MAX_ArraySize = 100,
        ArraySize2d = 100,                // 2?¬?????????????[][?] ???????
    }

    public string Line1_string()
    {
        return Console.ReadLine();
    }

    public string[] Line1_string(int chr)
    {
        var input = Console.ReadLine();
        var split = input.Split(' ');
        return split;
    }

    public int Line1_int()
    {
        var input = Console.ReadLine();
        return int.Parse(input);
    }

    public double Line1_double()
    {
        var input = Console.ReadLine();
        return double.Parse(input);
    }

    public int[] Line1_int(int chr, int num)
    {
        var input = Console.ReadLine();
        var split = input.Split(' ');
        int[] spliti = new int[100];
        for (int i = 0; i < num; i++)
        {
            spliti[i] = int.Parse(split[i]);
        }
        return spliti;
    }

    public int[] Multiline_int(ref int datanum)
    {
        int i = 0;
        int[] data = new int[(int)Input.Define.MAX_ArraySize];
        while (true)
        {
            var input = Console.ReadLine();
            var value = int.Parse(input);
            if (value == 0) break;
            data[i] = value;
            i++;
        }
        datanum = i;
        return data;
    }

    /// <summary>
    /// ?????°??????int??????????????????????????????
    /// </summary>
    /// <param name="chr">???????????????</param>
    /// <param name="num">?????????????????????????????°</param>
    /// <param name="datanum">??????????????????????????°</param>
    /// <returns></returns>
    public int[,] Multiline_int(int chr, int num, ref int datanum)
    {
        int i = 0, zerocount = 0;
        int[,] data = new int[(int)Input.Define.MAX_ArraySize, (int)Input.Define.ArraySize2d];
        while (true)
        {
            var input = Console.ReadLine();
            var split = input.Split(' ');
            int[] spliti = new int[100];
            zerocount = 0;
            for (int j = 0; j < num; j++)
            {
                spliti[j] = int.Parse(split[j]);
                if (spliti[j] == 0) zerocount++;
            }
            if (zerocount == num) break;
            for (int j = 0; j < num; j++)
            {
                if (spliti[0] == 0 && spliti[1] == 0) break; // ???????????????????????????
            }
            for (int j = 0; j < num; j++)
            {
                data[i, j] = spliti[j];
            }
            i++;
        }
        datanum = i;
        return data;
    }

    /// <summary>
    /// ?????°??????int??????????????????????????????
    /// </summary>
    /// <param name="chr">???????????????</param>
    /// <param name="num">?????????????????????????????°</param>
    /// <param name="loadnum">???????????????????????°</param>
    /// <returns></returns>
    public int[,] Multiline_int(int chr, int num, int loadnum)
    {
        int i = 0;
        int[,] data = new int[(int)Input.Define.MAX_ArraySize, (int)Input.Define.ArraySize2d];
        while (true)
        {
            if (loadnum == i) break;

            var input = Console.ReadLine();
            var split = input.Split(' ');
            int[] spliti = new int[100];
            for (int j = 0; j < num; j++)
            {
                spliti[j] = int.Parse(split[j]);
            }
            for (int j = 0; j < num; j++)
            {
                data[i, j] = spliti[j];
            }
            i++;
        }
        return data;
    }


}

//??£?¨????????????¬

//int[] input = new int[(int)Input.Define.MAX_ArraySize];
//int[,] input = new int[(int)Input.Define.MAX_ArraySize, (int)Input.Define.ArraySize2d];

class EasyTask
{
    public void Swap(ref int a, ref int b)
    {
        int buf = 0;
        buf = a;
        a = b;
        b = buf;
    }






}