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

#include <stdio.h>

#define STR 20000


char lake[STR][STR]; //湖
int lakes[100] = {0}; //小さい湖
int sl[STR/2]; //湖カウント始点
int d = 0, lc = 0, ll = 0; //d:深さ　lc:湖数 ll:湖総量

//小さい湖・総量の算出
void LakeCount(int ic, int i, int left) { //
    int count, s;
    
    //    printf("ic=%d sl[d]=%d d=%d lc=%d left=%d:LakeC\n",ic,sl[d],d,lc,left);
    s = sl[d];
    for(int k = ic ; k <= i; k++ ) {
        count = 0;
	
        for(int a = sl[d] ; a <= left ; a++) {
	  if(lake[k][a] == '\\') {
	    while(lake[k][a] != '/') {
	      count++;
	      a++;
	    }
	  }
	}

	//        printf("count =%d\n",count);
        
        lakes[lc] += count;
        ll += count;
	
        d--;
    }
}

//水深の算出
void DeepCount(int i, int start, int k) {
  int st, ic = i;
  
  //  printf("%d %d %d %d :DeepC\n", i, start, k, lc);
  sl[d] = start;
  for(st = start ; st <= k ; st++) {
    if(lake[ic - 1][st + 1] == '\\') {
      sl[d + 1] = st + 1;
      d++; ic--;
    }
    else if(lake[ic][st + 1] == '/') {
      //        printf("ic=%d st=%d :DeepC1\n",ic,st);
        LakeCount(ic,i,k);
        break;
    }
    
    //    printf("i=%d st=%d :DeepC\n",i,st);
  }
  
  d = 0;
}

//湖の形成と水面算出と出力
int main(void){
  char a;
  int i, j, k, c = 0, n = 0, min = STR, max = 0;

  for(i = 0 ; i < STR ; i++) {
    for(j = 0 ; j < STR ; j++) {
      lake[i][j] = ' ';
    }
  }

  i = STR/2;
  j = 0;

  //文字列入力
  while((a = getchar()) != EOF) {
      if(a == '/') {
	lake[i][j] = a;
	i++;
      }
      else if(a == '_') {
	lake[i][j] = a;
      }
      else {
	i--;
	lake[i][j] = a;
      }

      if(i > max) {
	max = i;
      }
      if(i < min) {
	min = i;
	}
      j++;
      n++;
  }

  //printf("%c\n",lake[200][9]);

//水面の検知
  for(j = 0 ; j < n ; j++) {
    for(i = max ; i > min ; i--) {
      if(lake[i][j] == '\\') {
	    for(k = j ; k < n ; k++) {
	        if(lake[i][k] == '/') {
		  c++;
	            lc = j;
	            DeepCount(i, j, k);
		    j = k;
	            break;
	        }
	    }
      }
    }
  }
  
  //小湖・湖の総量出力
  printf("%d\n",ll);
  printf("%d ",c);
  for(int i = 0 ; i < n ; i++) {
      if(lakes[i] != 0) {
          printf("%d",lakes[i]);
          if(i != lc -1) {
              printf(" ");
          }
      }
  }
  printf("\n");
  
  /*
  //湖の出力
  printf("%d %d\n",max,min);
    for(i = max ; i > min ; i--) {
      for(j = 0 ; j < n; j++){
	printf("%c",lake[i-1][j]);
      }
      printf("\n");
    }
  */
  
  return 0;
}