//	-*- mode: C++ -*-
//	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 L1 L2 ... Lk
//
//	In the first line, print the total area A of created floods.
//
//	In the second line, print the number of floods k and areas Li(i=1,2,...,k) for each flood from the left side of the cross-section diagram. Print a space character before Li.
//
//	Constraints
//		1≤ length of the string ≤20,000
//	Sample Input 1
//		\\//
//	Sample Output 1
//		4
//		1 4
//
//	Sample Input 2
//		\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\
//	Sample Output 2
//		35
//		5 4 2 1 19 9

#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <tuple>

typedef std::tuple<char, int, int>	slope;

class Slope{
public:
	Slope();
	~Slope(){};
	void	input();
	void	simulate();
	void	print();

private:
	unsigned int				allAreas;
	int							level;
	std::vector<slope>			slopes;
	std::vector<unsigned int>	floods;

	unsigned int	flood(const unsigned int	start,
						  const unsigned int	end);
};

int	main(int	argc,
		 char*	argv[])
{
	Slope	slope;

	slope.input();

	slope.simulate();

	slope.print();

	return	0;
}

Slope::Slope(): allAreas{0}, level{0}, slopes{}, floods{}
{
}

void Slope::input()
{
	char	c		{'\0'};

	while((c = getchar()) != '\n'){
		slope	s	{};
		switch(c){
		case '/':
			s	= std::make_tuple(c, level, level - 1);
			--level;
			break;

		case '_':
			s	= std::make_tuple(c, level, level);
			break;

		case '\\':
			s	= std::make_tuple(c, level, level + 1);
			++level;
			break;

		default:
			break;
		}

		slopes.push_back(s);
	}
}

void Slope::simulate()
{
	bool	isStart	{false};

	unsigned int	num	= slopes.size();
	int				startLevel	{0};

	unsigned int	i = 0;
	for(;;){
		auto	s	= slopes[i];
		auto	c	= std::get<0>(s);

		if(c == '\\'){
			startLevel	= std::get<1>(s);
			auto	start	= i;
			for(auto j = i + 1; j < num; ++j){
				auto	se	= slopes[j];
				auto	ce	= std::get<0>(se);

				if((ce == '/') && (std::get<2>(se) == startLevel)){
					auto	area	= flood(start, j);
					floods.push_back(area);
					allAreas	+= area;
					i	= j;
					break;
				}
			}
			++i;
		}
		else{
			++i;
		}

		if(i >= num){
			break;
		}
	}
}

unsigned int	Slope::flood(const unsigned int	start,
							 const unsigned int	end)
{
	unsigned int	a	{0};
	auto			startLevel	= std::get<1>(slopes[start]);

	for(auto i= start; i < end + 1; i++){
		auto	s	= slopes[i];
		auto	c	= std::get<0>(s);
		switch(c){
		case '\\':
			a	+= 1 + ((std::get<1>(s) - startLevel) * 2);
			break;

		case '_':
			a	+= (std::get<1>(s) - startLevel) * 2;
			break;

		case '/':
		default:
			a	+= 1 + ((std::get<2>(s) - startLevel) * 2);
			break;
		}
	}

	return	a / 2;
}

void Slope::print()
{
	std::cout << allAreas << '\n';
	std::cout << floods.size();

	for(auto area :floods){
		std::cout << ' ' << area;
	}

	std::cout << '\n';
}



Measured memory_bytes: 3368