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)

#include<stdio.h>
 
#define MAXLEN 20000
 
int area, areas[(MAXLEN/2)+1],cnt;
 
int getArea( char *areastr, int start, int maxh )
{
    int i;
    int ravine,squre;
    int down;
 
	down=0;
    areas[cnt]=squre=ravine=0;
    for( i=start; '\0'!=*(areastr+i); i++ ) {
        if( '\\'== *(areastr+i) ) {
            ravine++;
            down++;
            down+=((maxh-ravine)*2);
        } else if( 0 < ravine && '/' == *(areastr+i) ) {
            ravine--;
            if( 0 == ravine ) {
                squre=(i-start+1)*maxh;
                areas[cnt]+=squre;
                areas[cnt]-=(down);
                break;
            }           
        } else {
            areas[cnt]-=(maxh-ravine);
        }
    }
    return areas[cnt];
}
 
 
int checkRavine( char *checkstr, int start )
{
    int i,j;
    int ravine,maxh;
 
    ravine=maxh=0;
    for( i=start, j=0; '\0'!=*(checkstr+i) &&  j<MAXLEN; i++, j++ ) {
        if( '\\'== *(checkstr+i) ) {
                     
            ravine++;
        } else if( 0 < ravine && '/' == *(checkstr+i) ) {
             
            if( maxh < ravine ) { maxh=ravine; }     
            ravine--;
            if( 0 == ravine ) {
                area+=getArea( checkstr, start, maxh );
                cnt++;
                return j;
            }           
        }
    }
 
    return 0;
}
 
void getAreas( char *inputs )
{
    int i,next;
     
    next=cnt=0;
    for( i=0; '\0'!=inputs[i]; i++ ) {
        next=checkRavine( inputs, i );
        i+=next;
    }
 
    return;
}
 
int main( void ) 
{
    char inputs[MAXLEN+1];
    int i;
 
    scanf( "%s", inputs );
    area=cnt=0;
    getAreas( inputs );
     
    printf( "%d\n", area );
    if( cnt ) {
        printf( "%d ", cnt );
        for( i=0; i<cnt; i++ ) {
            printf( "%d", areas[i] );
            if( i < cnt-1 ) {
                printf( " " );  
            } else {
                printf( "\n" ); 
            }
        }
    } else {
        printf( "0\n" );
    }
     
    return 0;
}