#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAX_STRING_LEN 20000

typedef struct FOUNTAIN_DATA{
	int area;						/* fountain area */
	int plane;						/* fountain plane */
	struct FOUNTAIN_DATA *next;		/* next Pushed fountain point */
} ST_FOUNTAIN;


static void OutputResult(ST_FOUNTAIN **ptNewData, ST_FOUNTAIN **ptOldData);				/* output result each fountain data */
static void        Push(ST_FOUNTAIN **pptPushedBuffer, ST_FOUNTAIN *ptPushData);	/* Push data fountain data each depth  point */
static ST_FOUNTAIN *Pop(ST_FOUNTAIN **ptPopData);									/* pop data merge point fountain data each depth  and output result*/


int main(void)
{
	char ch;						/* get data */
	int area;						/* fountain area */
	int plane;						/* fountain plane */
	int loop = 0;
	ST_FOUNTAIN *ptNewData = NULL; 	/* set new fountain data each depth */
	ST_FOUNTAIN *ptOldData = NULL;	/* result fountain data after merge */
	ST_FOUNTAIN *ptTempData;		/* for calcurate fountain data */
	
	while(((ch = getchar()) != '\n') && (loop <= MAX_STRING_LEN))
	{
		if(ch == '\\')			/* fountain down point */
		{
			/* set new fountain point */
			ptTempData = (ST_FOUNTAIN*)malloc(sizeof(ST_FOUNTAIN));
			ptTempData->area = 0;
			ptTempData->plane = 0;
			Push(&ptNewData, ptTempData);
		}
		else if(ch == '_')		/* fountain plane point */
		{
			ptTempData = Pop(&ptNewData);	/* get plane length */
			if (ptTempData != NULL)
			{
				ptTempData->plane++;			/* be longer foutune plane */
				Push(&ptNewData, ptTempData);	/* set fountain data */
			}
			else
			{
				/* error process */
			}
		}
		else if(ch == '/')		/* fountain up point */
		{
			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 process */
			}
		}
		else
		{
			/* error input */
		}
		
		loop++;
	}
	
	/* output result each fountain data */
	OutputResult(&ptNewData, &ptOldData);
	
	return 0;
}

/* output result each fountain data */
static void OutputResult(ST_FOUNTAIN **ptNewData, ST_FOUNTAIN **ptOldData)
{
	ST_FOUNTAIN *ptTempData;		/* for calcurate fountain data */
	int total = 0;					/* all fountain area sum */
	int count = 0;					/* fountain num */
	int loop;
	
	/* calcrate all area sum value and area num */
	while((ptTempData = Pop(ptNewData)) != NULL)
	{
		if(ptTempData->area == 0)
		{
			free(ptTempData);
		}
		else
		{
			total += ptTempData->area;
			count++;
			Push(ptOldData, ptTempData);
		}
	}
	
	printf("%d\n", total);
	printf("%d", count);
	/* Output Result */
	for(loop = 0; loop < count; loop++)
	{
		printf(" ");
		ptTempData = Pop(ptOldData);
		printf("%d", ptTempData->area);
		free(ptTempData);
	}
	
	printf("\n");
}


/* Push data for set fountain data each depth  point */
void Push(ST_FOUNTAIN **pptPushedBuffer, ST_FOUNTAIN *ptPushData)
{
	/* set next more depth point */
	ptPushData->next = (*pptPushedBuffer);
	(*pptPushedBuffer) = ptPushData;
}
 
/* pop data for merge point fountain data each depth  and output result*/
ST_FOUNTAIN *Pop(ST_FOUNTAIN **ptPopData)
{
	ST_FOUNTAIN *ptTempData = (*ptPopData);
	if(ptTempData != NULL)
	{
		(*ptPopData) = (*ptPopData)->next;
	}
	else
	{
		/* None Pushed Data */
	}
	
	return ptTempData;
}




Measured memory_bytes: 2324