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: Wrong Answer)

using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    public static IO IO = new IO();
    static void Main(string[] args)
    {
        string s = IO.STRING();
        int c = s.Count();
        int[] l = new int[c + 1];
        int t = 0;
        List<int> top = new List<int>();
        l[0] = t;
        bool check = false;
        for (int i = 0; i < c; i++)
        {
            if (s[i] == '\\') { t--; if (i < c - 1 && !check) { check = true; top.Add(i); } }
            else if (s[i] == '/') { t++; if (i < c - 1 && s[i + 1] != '/' && check) { top.Add(i + 1); } }
            l[i + 1] = t;
        }
        if (s[c - 1] == '/') { top.Add(c); }
        List<int> div = new List<int>();
        while (true)
        {
            bool flag = true;
            div.Clear();
            div.Add(top[0]);
            for (int i = 1; i < top.Count() - 1; i++)
            {
                if (l.Where((x, y) => y < top[i]).Max() > l[top[i]] && l[top[i]] < l.Where((x, y) => y > top[i]).Max()) { flag = false; }
                else { div.Add(top[i]); }
            }
            if (top.Count() > 1) { div.Add(top[top.Count() - 1]); }
            top.Clear();
            top.AddRange(div);
            if (flag) { break; }
        }
        double[] m = new double[div.Count() - 1];
        double a = 0;
        for (int i = 0; i < div.Count() - 1; i++)
        {
            double h = Math.Min(l[div[i]], l[div[i + 1]]);
            double p = 0;
            for (int j = div[i] + 1; j < div[i + 1]; j++)
            {
                if (l[j] <= h)
                {
                    if (l[j] > l[j - 1]) { p += h - l[j] + 0.5; }
                    else if (l[j] < l[j - 1]) { p += h - l[j] - 0.5; }
                    else { p += h - l[j]; }
                }
            }
            if (p - (int)p != 0) { p += 0.5; }
            m[i] = p;
            a += p;
        }
        IO.WRITE(a);
        IO.WRITE(m.Count() + " " + string.Join(" ", m.Select(x => x.ToString()).ToArray()));
        IO.FLUSH();
    }
}

namespace LIB
{
    public class IO
    {
        private const int WMAX = 1000;
        private StringBuilder S = new StringBuilder();
        private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
        private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); }
        private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; }
        private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; }
        private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } }
        public string STRING() { return R(s => s); }
        public string[] STRING(char c) { return R(s => s, c); }
        public string[] STRING(int l) { return R(s => s, l); }
        public string[][] STRING(int l, char c) { return R(s => s, l, c); }
        public int INT() { return R(int.Parse); }
        public int[] INT(char c) { return R(int.Parse, c); }
        public int[] INT(int l) { return R(int.Parse, l); }
        public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
        public long LONG() { return R(long.Parse); }
        public long[] LONG(char c) { return R(long.Parse, c); }
        public long[] LONG(int l) { return R(long.Parse, l); }
        public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
        public double DOUBLE() { return R(double.Parse); }
        public double[] DOUBLE(char c) { return R(double.Parse, c); }
        public double[] DOUBLE(int l) { return R(double.Parse, l); }
        public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
        public void WRITE(string s, bool lf = true) { W(v => v, s, lf); }
        public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void FLUSH() { Console.Write(S); S.Length = 0; }
    }
}