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>
#include<string.h>
#include<limits.h>

typedef struct group{
	int x;
	double height;//高さ
	double wh;//水面の高さ
	int check;//処理済みかどうか
	int p;// \ - 0,_ - 1,/ - 2
} G;

int box[20000]={};//探索して見つけたtopを格納
int z=0;

int topsearch(int len,double max,G *g)//max=探索済みのtop
{
	double m=-20000;
	int cnt=0;
	int i;
	int check;
	z=0;
	for(i=0;i<len;i++){
		if(max>g[i].height&&g[i].height>m) m=g[i].height;
	}
	for(i=0;i<len;i++){
		if(m==g[i].height){
			if(g[i].p==1) z=1;
			box[cnt]=i;
			cnt++;
		}
	}
	return cnt;
}

int main(void)
{
	G g[20000];
	char c[20000];
	double h=5,r=5,l=5;// 高さを求めるための変数r;right,l;left
	int len;
	int i,j;
	double max=20000;
	double result[20000]; //溜まった水の量を格納
	int cnt;
	double allsum=0,sum=0,add;
	scanf("%s",c);
	len=strlen(c);
	for(i=0;i<len;i++){//初期値入力
		g[i].check=0;
		if(c[i]=='/'){
			l=r;
			r++;
			g[i].height=(l+r)/2;
			g[i].p=2;
		}else if(c[i]=='_') {g[i].height=r;g[i].p=1;}
		else{
			l=r;
			r--;
			g[i].height=(l+r)/2;
			g[i].p=0;
		}
		g[i].wh=g[i].height;
	}
	for(i=0;box[0]!=-1;i++){
		box[0]=-1;
		cnt=topsearch(len,max,g);
		max=g[box[0]].height;
		if(cnt==1);
		else{
			for(j=box[0];j<=box[cnt-1];j++){
				if(j==box[0]&&c[box[0]]=='/') {
					g[j].check=1;
					j++;
				}
				if(j==box[cnt-1]&&c[box[cnt-1]]!='/'&&c[box[cnt-1]]!='_'){
					g[j].check=1;
					break;
				}
				if(g[j].check==0){
					if(z!=1) g[j].wh=max+0.5;
					else g[j].wh=max;
					g[j].check=1;
				}
			}
		}
	}
	for(cnt=0,i=0;i<len;i++){
		add=g[i].wh-g[i].height;
		if(add>0) {
			if(i+1<len){
				if(add==0.5&&g[i+1].wh-g[i+1].height==0.5&&g[i+1].p==0) {
					add=-1;
					sum+=0.5;
				}else sum+=add;
			}else sum+=add;
		}
		if(add<=0||i==len-1){
			if(sum!=0){
				result[cnt]=sum;
				allsum+=sum;
				cnt++;
				sum=0;
			}
		}
	}
	printf("%d\n%d",(int)allsum,cnt);
	for(i=0;i<cnt;i++){
		printf(" ");
		printf("%d",(int)result[i]);
	}
	printf("\n");
	/*for(i=0;i<len;i++) printf("%1.1f ",g[i].wh);
	printf("\n");
	for(i=0;i<len;i++) printf("%1.1f ",g[i].height);
	printf("\n");*/
	return 0;
}