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 JAVA (judge verdict: WA: Presentation Error)

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.NoSuchElementException;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		char[] str = sc.next().toCharArray();
		
		int[] h = new int[2*str.length];
		int h_now = 0;
		for(int i=0; i<str.length; i++) {
			if(str[i] == '_') {
				h[2*i] = h_now;
				h[2*i + 1] = h_now;
			} else if(str[i] == '/') {
				h[2*i] = h_now;
				h[2*i + 1] = h_now + 1;
				h_now++;
			} else {
				// '\'
				h[2*i] = h_now;
				h[2*i + 1] = h_now - 1;
				h_now--;
			}
		}
		
		ArrayDeque<Integer> area = new ArrayDeque<>();
		boolean mode = false;
		int temp_h = 0;
		int temp_idx = 0;
		int temp_area = 0;
		for(int i=0; i<h.length; i++) {
			if(mode) {
				temp_area += temp_h - h[i];
				if(i == temp_idx) {
					area.add(temp_area / 2);
					temp_area = 0;
					mode = false;
				}
				
//				System.out.println(i + " " + mode + " " + temp_h + " " + temp_idx + " " + temp_area);
				
			} else {
				boolean flag = false;
				for(int j=i+1; j<h.length; j++) {
					if(flag == false && h[j] < h[i]) {
						flag = true;
					}
					if(flag == false && h[j] > h[i]) {
						break;
					}
					if(flag == true && h[j] == h[i]) {
						temp_h = h[i];
						temp_idx = j;
						mode = true;
						break;
					}
				}
				
//				System.out.println(i + " " + mode);
			}
		}
		
		int sum = 0;
		int[] iarea = new int[area.size()]; 
		for(int i=0; i<iarea.length; i++) {
			iarea[i] = area.poll();
			sum += iarea[i];
		}
		
		System.out.println(sum);
		
		System.out.print(iarea.length);
		if(iarea.length == 0) {
			System.out.print(" ");
		}
		
		for(int i=0; i<iarea.length; i++) {
			System.out.print(iarea[i]);
			if(i != iarea.length-1) {
				System.out.print(" ");
			}
		}
		System.out.println();
	}
	
	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}

}