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: Time Limit Exceeded)

//????????????????????????20170314
using System;
using System .Collections .Generic;
using System.IO;


class Program
{
    public static void Main( string[] args )
     {
        //????????????
        var symbols =@Console.ReadLine();
        // var symbols =@Console.ReadLine();
        //  string[] mountain = symbols .Split();
      //  char[] mountain = symbols .ToCharArray();
        //search??????????????????
        new Search( symbols );
        //?±???????????????\?????????
    }
}
class Search
{

    //	int searchIndex = 0;
    //search index????????????
    //int pondCounter = 0;
    //?±??????°????????????
    //	int deapth = 0;
    //?±???±???
    //int totalArea = 0;
    //?±?????????¢???
    //?±???????????????¢??????????´????????????????????????????List??§?????????????????°????????????????????????????????????
    //??????????????°???????????????????????\?????????
   // List<int> ponds = new List<int>();
   int[] pondsArray=new int[10000];
    int pondsArrIndex=0;//?±??????????index
    //?????????????????????
    public Search( string t )
    {
        pondSearch( t );
    }
    public void pondSearch( string terrain )
    {
        int startPoint = 0;//?§???????index
        int end = 0;//?????????intdex	
       

        while ( startPoint < terrain .Length )
        {//?§??????¢????????????????´????????????????????????????
            startPoint = pondStartPointSearch( terrain , startPoint );
            if ( startPoint == -1 )
            {//?±????????????????????????§????????£????????????????????????
                break;
            }

            end = pondEndPointSearch( terrain , startPoint );
            //end??¢?´¢?????????????????????????????£?????´?????¨???????????£?????´??????
            while ( end == -1 )
            {//?????????????????§startPoint+1;//?????¨????±?????????????????????????
                startPoint += 1;
                startPoint = pondStartPointSearch( terrain , startPoint );
                if ( startPoint == -1 )
                {
                    break;
                }
                end = pondEndPointSearch( terrain , startPoint );
            }
            if ( startPoint == -1 )
            {
                break;
            }
            //?±???????????????£??????
            //List<> ponds????±????????????¢??????add
            pondsArray[pondsArrIndex]=( ( int )pondArea( terrain , startPoint , end ) );
            startPoint = end + 1;//?§??????¢?????¨index????±??????????????????????????¨????
            pondsArrIndex++;
        }
        //????????????????????????????????????
        answer();
    }


    /*public int pondDeapth()
    {


    }//?±???±????¨????????????????
    int deapestPoint=0;//?±???????????????°???index???
    */
    public double pondArea( string terrain , int start , int end )//?±???¢???????????????
    {
        int nowDeapth = 0;//?§??????????????????¨??±???
        int area = 0;

        //?§????????????°??¢????????±???????¢????????????????
        //??°??¢?????¨?????±?????¨??????????????¢???????±??????????
        //"\"????????¢??????????§?????????¨????§?????±????????¢????¨??????????????????±?????????
        //_????????¢??????????§??????±????????±????????????????????¨?????£????????????
        // ???/"??§?????±??????????????¢????¨????????????????
        //????§?????????§???????§?????????????????????§????????????????????????
        for ( int i = start ; i <= end ; i++ )
        {
            switch ( terrain[i].ToString() )
            {
                case @"\":
                    //??????????¨????
                    area += 1 + 2 * nowDeapth;
                    nowDeapth++;
                    break;
                case "/":
                    nowDeapth--;
                    //??????????¨????
                    area += 1 + 2 * nowDeapth;
                    break;
                case "_":
                    //????????§?¨????
                    area += 2 * nowDeapth;
                    break;
            }
        }

        //?±??????¢??????????????????
        return area / 2;
    }

    //?±??§??????¢?´¢????????????
    public int pondStartPointSearch( string terrain , int nowIndex )
    {
        int sp = nowIndex;
        while ( sp < terrain .Length - 1 )//??????????´?????????????????????¨???????????????
        {
            if ( terrain[sp].ToString() == @"\" )
            {
                return sp;//return ?±?????§???????index?????????
            }

            sp++;
        }
        //???????????§????????????????????£?????´?????????????????????
        return -1;

    }
    public int pondEndPointSearch( string terrain , int startIndex )
    {
        int searcher = startIndex + 1;
        //?±??????????????????????"/"??§????????????????????????????????\????????????index????????????
        //??????if(deapth==0&&s==/)
        //???????????§????????????????±?????????????????????£????????????????????????
        int d = 1;//?????¨??±?????°??¢???????????????????????±?????¨?????????
        while ( searcher < terrain .Length )
        {
            if ( d == 1 && terrain[searcher].ToString() == "/" )
            {//??±???????????¨?????????/????????\???????±??????????

                return searcher;

            }
            else
            {
                switch ( terrain[searcher].ToString() )
                {
                    case @"\":

                        d++;
                        break;
                    case "/":
                        d--;

                        break;
                    case "_":

                        break;
                }
                searcher++;
            }
        }
        //???????????§????????????????????£????????§???????????????
        return -1;

    }
    public void answer()//????????????
    {
        int area = 0;//?????¢???
      //  int pondsC=pondsArrIndex;
      //  int[] array=new int[ponds.Count];
        	
      //  array =ponds.ToArray();
        var sw = new StreamWriter(Console.OpenStandardOutput())
		{AutoFlush = false};
        Console.SetOut(sw);
     /*   
        for(int s=0;s<array.Length;s++)
        {
        	area+=array[s];
        }
        Console.WriteLine(area);
        if(array.Length==1)
        { 
        	Console .WriteLine( " " + array[0] );
        
        }
         else if (array.Length== 0 )
        {
            Console .WriteLine( );
        }
        else
        {
            for ( int f = 0 ; f <array.Length - 1 ; f++ )
            {
                Console .Write( " " + array[f] );
            }
            Console .WriteLine( " " + array[array.Length - 1] );
        }
        */
  
         for(int s=0;s<pondsArrIndex;s++)
        {
        	area+=pondsArray[s];
        }
      
		
        Console .WriteLine( area );//?????¢???????????????????????????
                                   //?±??????°
        Console .Write( pondsArrIndex );
        //List<>??????????????????????´?????????????????????????
        if ( pondsArrIndex == 1 )
        {
            Console .WriteLine( " " + pondsArray[0] );
        }
        else if ( pondsArrIndex == 0 )
        {
            Console .WriteLine( );
        }
        else
        {
            for ( int f = 0 ; f < pondsArrIndex - 1 ; f++ )
            {
                Console .Write( " " + pondsArray[f] );
            }
            Console .WriteLine( " " + pondsArray[pondsArrIndex - 1] );
        }
        
        	Console.Out.Flush();
    }	
}