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: Wrong Answer)

/*
 * Created by SharpDevelop.
 * User: yog-sothoth
 * Date: 2017/03/09
 * Time: 12:08
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;

namespace PondSearcher
{
	class Program
	{
		public static void Main(string[] args)
		{
			//????????????
			var symbols = Console.ReadLine();
			string[] mountain = symbols.Split();
			//search??????????????????
			new Search(mountain);
			//?±???????????????\?????????
		}
	}
	public class Search
	{

	//	int searchIndex = 0;
		//search index????????????
		//int pondCounter = 0;
		//?±??????°????????????
		//	int deapth = 0;
		//?±???±???
		//int totalArea = 0;
		//?±?????????¢???
		//?±???????????????¢??????????´????????????????????????????List??§?????????????????°????????????????????????????????????
		//??????????????°???????????????????????\?????????
		List<int> ponds = new List<int>();
		//?????????????????????
		public	Search(string[] t)
		{
			pondSearch(t);
		}
		public void pondSearch(string[] terrain)
		{
			int startPoint = 0;//?§???????index
			int end = 0;//?????????intdex	  
		 
			while (startPoint < terrain.Length ) {//?§??????¢????????????????´????????????????????????????
				startPoint = pondStartPointSearch(terrain, startPoint);
				if (startPoint == -1) {//?±????????????????????????§????????£???????????????
					break;
				}
					
				end = pondEndPointSearch(terrain, startPoint);
				//end??¢?´¢?????????????????????????????£?????´?????¨???????????£?????´??????
				while (end == -1) {//?????????????????§startPoint+1;//?????¨????±?????????????????????????
					startPoint+=1;
					startPoint = pondStartPointSearch(terrain, startPoint);
					if (startPoint == -1)
					{
					break;
   					}
					end = pondEndPointSearch(terrain, startPoint);	
				}
				if (startPoint == -1) {
					break;
				}
				//?±???????????????£??????
				//List<> ponds????±????????????¢??????add
				ponds.Add((int)pondArea(terrain, startPoint, end));
				startPoint = end + 1;//?§??????¢?????¨index????±??????????????????????????¨????
			}
			//????????????????????????????????????
			answer();
		}
		
				
		/*public int pondDeapth()
		{
		
		
		}//?±???±????¨????????????????
		int deapestPoint=0;//?±???????????????°???index???
		*/
		public int pondArea(string[] terrain, int start, int end)//?±???¢???????????????
		{
			int nowDeapth = 0;//?§??????????????????¨??±???SAC
			int area = 0;
				
			//?§????????????°??¢????????±???????¢????????????????
			//??°??¢?????¨?????±?????¨??????????????¢???????±??????????
			//"\"????????¢??????????§?????????¨????§?????±????????¢????¨??????????????????±?????????
			//_????????¢??????????§??????±????????±????????????????????¨?????£????????????
			// ???/"??§?????±??????????????¢????¨????????????????
			//????§?????????§???????§?????????????????????§????????????????????????
			for (int i = start; i <= end; i++) {
				switch (terrain[i]) {
					case "\\":
					//??????????¨????
						area += 1 + 2 * nowDeapth;
						nowDeapth++;
						break;
					case "/":
						nowDeapth--;
					//??????????¨????
						area += 1 + 2 * nowDeapth;
						break;
					case"_":
					//????????§?¨????
						area += 2 * nowDeapth;
						break;						
				}
			}
		
			//?±??????¢??????????????????
			return area / 2;
		}
	
		//?±??§??????¢?´¢????????????
		public int pondStartPointSearch(string[] terrain, int nowIndex)
		{
			int sp = nowIndex;
			while (sp < terrain.Length-1 )//??????????´?????????????????????¨???????????????
			{
				if (terrain[sp] == "\\") {
					return sp;//return ?±?????§???????index?????????
				}
								
				sp++;
			}
			//???????????§????????????????????£?????´?????????????????????
			return -1;
			
		}
		public int pondEndPointSearch(string[] terrain, int startIndex)
		{
			int searcher = startIndex + 1;			
			//?±??????????????????????"/"??§????????????????????????????????\????????????index????????????
			//??????if(deapth==0&&s==/)
			//???????????§????????????????±?????????????????????£????????????????????????
			int d = 1;//?????¨??±?????°??¢???????????????????????±?????¨?????????
			while (searcher < terrain.Length )
			{
				if (d == 1 && terrain[searcher] == "/") 
				{//??±???????????¨?????????/????????\???????±??????????
					
					return searcher;
					
				} 
				else {
					switch (terrain[searcher]) {
						case "\\":
							
							d++;
							break;
						case "/":
							d--;
					
							break;
						case"_":
					
							break;						
					}
					searcher++;
				}
			}
			//???????????§????????????????????£????????§???????????????
			return -1;
		
		}
		public void answer()//????????????
		{
			int area=0;//?????¢???
			foreach(int a in ponds)
			{
				area+=a;
			}
			Console.WriteLine(area);//?????¢???????????????????????????
			//?±??????°
			Console.Write(ponds.Count);
			//List<>??????????????????????´?????????????????????????
			if (ponds.Count == 1) {
				Console.WriteLine(" " + ponds[0]);
			}else if(ponds.Count==0)
			{
				Console.WriteLine(" "+0);
			}				else {
				for (int f = 0; f < ponds.Count - 1; f++) {
					Console.Write(" " + ponds[f]);
				}
				Console.WriteLine(" " + ponds[ponds.Count - 1]);
			}
		}
	}
}