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 <stdlib.h>
 
typedef struct FOUNTAIN_DATA{
	int area;
	int plane;
	struct FOUNTAIN_DATA *next;
} ST_FOUNTAIN;
 
/* push data */
void push(ST_FOUNTAIN **p, ST_FOUNTAIN *ptPushData)
{
	ptPushData->next = *p;
	*p = ptPushData;
}
 
/* pop data */
ST_FOUNTAIN *pop(ST_FOUNTAIN **ptPopData)
{
	ST_FOUNTAIN *ptTempData = *ptPopData;
	if(ptTempData != NULL)
	{
		*ptPopData = (*ptPopData)->next;
	}
	
	return ptTempData;
}
 
int main()
{
	char ch;
	int area;
	int plane;
	int total;
	int count;
	int loop;
	ST_FOUNTAIN *ptNewData;
	ST_FOUNTAIN *ptOldData;
	ST_FOUNTAIN *ptTempData;
	
	ptNewData = NULL;
	ptOldData = NULL;
	while((ch = getchar()) != '\n')
	{
		if(ch == '\\')
		{
			/* set new fountain point */
			ptTempData = (ST_FOUNTAIN*)malloc(sizeof(ST_FOUNTAIN));
			ptTempData->area = 0;
			ptTempData->plane = 0;
			push(&ptNewData, ptTempData);
		}
		else if(ch == '_')
		{
			/* set plane length */
			ptTempData = pop(&ptNewData);
			if (ptTempData != NULL)
			{
				ptTempData->plane++;
				push(&ptNewData, ptTempData);
			}
			else
			{
				/* error process */
			}
		}
		else if(ch == '/')
		{
			area = 0;
			plane = 0;
			while((ptTempData = pop(&ptNewData)) != NULL)
			{
				/* merge foutain data with more depth point */
				area += ptTempData->area;	
				plane += ptTempData->plane;
				if(ptTempData->area == 0)	/* if merge point */
				{
					break;
				}
				else						/* more depth point */
				{
					push(&ptOldData,ptTempData);
				}
			}
 
			if(ptTempData != NULL)						/* calcrate or merge foutain data with more depth point */
			{
				/* calcrate fountain data */
				ptTempData->area = area + plane + 1;
				ptTempData->plane = plane + 2;
				push(&ptNewData, ptTempData);					/* set fountain data after merge */
				while((ptTempData = pop(&ptOldData)) != NULL)	/*  after merge, free more depth point data  */
				{
					free(ptTempData);
				}
			}
			else if (area > 0)
			{
				while((ptTempData = pop(&ptOldData)) != NULL)
				{
					push(&ptNewData, ptTempData);			/* Re-store pop data */
				}
			}
		}
		else
		{
			/* error input */
		}
	}

	/* calcrate all area sum value and area num */
	total = 0;
	count = 0;
	while((ptTempData = pop(&ptNewData)) != NULL)
	{
		if(ptTempData->area == 0)
		{
			free(ptTempData);
		}
		else
		{
			total += ptTempData->area;
			count++;
			push(&ptOldData, ptTempData);
		}
	}
 	
	/* Output Result */
	printf("%d\n", total);
	printf("%d", count);
	if (count > 0)
	{
		for(loop = 0; loop < count; loop++)
		{
			printf(" ");
			ptTempData = pop(&ptOldData);
			printf("%d", ptTempData->area);
			free(ptTempData);
		}
	}
	printf("\n");
 
	return 0;
}