Problem:
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 (Python):
from collections import deque

input_list = input()
area = 0
depth_arr = deque()
area_arr = deque()

for i, input_str in enumerate(input_list):
    if "\\" == input_str:
        depth_arr.append(i)
    elif "/" == input_str:
        if len(depth_arr):
            position = depth_arr.pop()
            pool = i - position
            area += pool

            while len(area_arr):
                pre_position, pre_pool = area_arr.pop()
                if position <= pre_position:
                    pool += pre_pool
                else:
                    area_arr.append((pre_position, pre_pool))
                    break
            area_arr.append((position, pool))

areas = 0
for pos, pool in area_arr:
    areas += pool
print(areas)
print(len(area_arr), *[list[1] for list in area_arr])

Solution (Python):
high_water_marks = {}
areas = []

depth = 0
offset = 0
for i in input():
  if i == "/":
    depth -= 1
    if depth in high_water_marks:
      hwm = high_water_marks[depth]
      new_area = [hwm, offset - hwm]
      while len(areas) > 0 and areas[-1][0] > hwm:
        a = areas.pop()
        new_area[1] += a[1]
      areas.append(new_area)
  elif i == "_":
    pass
  else:
    high_water_marks[depth] = offset
    depth += 1

  offset += 1

total = 0
for a in areas: total += a[1]
print(total)
sizes = [a[1] for a in areas]
sizes.insert(0, len(areas))
print(" ".join(map(str, sizes)))

Solution (Python):
"""
O(n^2)??????????§£???
"""

danmen = input()
depth = []
tmp_dpt = 0

for line in danmen:
    depth.append(tmp_dpt)

    if line == "\\":
        tmp_dpt -= 1
    elif line == "/":
        tmp_dpt += 1


depth.append(tmp_dpt)



i = 0
L = []

while i < len(danmen):
    if len(set(danmen[i:])) == 1:
        break

    if danmen[i] == "\\":
        if depth[i] in depth[i + 1:]:
            stack = 0
            area = 0

            for line in danmen[i:]:
                if line == "\\":
                    area += 1 + 2 * stack
                    stack += 1
                elif line == "/":
                    stack -= 1
                    area += 1 + 2 * stack
                else:
                    area += 2 * stack

                if stack == 0:
                    break

            if area != 0:
                L.append(area // 2)
                i += depth[i + 1:].index(depth[i])

    i += 1

print(sum(L))
print(len(L), *L)

Solution (Python):

l = input()

k = 0
S1, S2 = [], []
for i in range(len(l)):
    if l[i] == '\\':
        S1.append(i)
    elif l[i] == '/' and S1:
        j = S1.pop()
        a = i - j
        k += i - j

        while S2 and S2[-1][0] > j:
            a += S2.pop()[1]
        S2.append((j, a))
print(k)
print(len(S2), *(a for j, a in S2))

Solution (Python):

danmen = input()
down = []
edge = []
pool = []

for (i, line) in enumerate(danmen):
    if line == "\\":
        down.append(i)
    elif down and line == "/":
        left = down.pop()
        area = i - left

        while edge:
            if edge[-1] > left:
                edge.pop()
                area += pool.pop()
            else:
                break

        edge.append(left)
        pool.append(area)

print(sum(pool))
print(len(pool), *pool)

Solution (Python):

danmen = input()

down = []
edge = []
pool = []

for (i, line) in enumerate(danmen):
    if line == "\\":
        down.append(i)
    elif down and line == "/":
        left = down.pop()
        area = i - left

        while edge:
            if edge[-1] < left:
                break
            edge.pop()
            area += pool.pop()

        edge.append(left)
        pool.append(area)

print(sum(pool))
print(len(pool), *pool)

Solution (Python):
def main():
    sectionalview = input()
    stack = []
    a_surface = 0
    surfaces = []
    for cindex in range(len(sectionalview)):
        if sectionalview[cindex] == "\\":
            stack.append(cindex)
        elif sectionalview[cindex] == "/" and 0 < len(stack):
            if 0 < len(stack):
                left_index = stack.pop()
                a = cindex - left_index
                a_surface += a
                while 0 < len(surfaces):
                    if left_index < surfaces[-1][0]:
                        a += surfaces.pop()[1]
                    else:
                        break
                surfaces.append((cindex, a))
    t = [i[1] for i in surfaces]
    print(sum(t))
    print(" ".join(map(str, [len(t)] + t)))

if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()

Solution (Python):
g = input()
l = []
q = []
n = 0
for x in range(len(g)):
    if g[x] == '\\':
        if n:
            l.append(n)
            n = 0
            if q:
                q.append(-1)
        q.append(x)
    elif g[x] == '/':
        if q:
            while True:
                p = q.pop()
                if p == -1:
                    n += l.pop()
                else:
                    break
            n += x-p
    else:
        pass
if n:
    l.append(n)
for j in range(l.count(0)):
    l.remove(0)
print(sum(l))
print(len(l), *l)

Solution (Python):
s=j=0
a=[];b=[];d=[]
for i,x in enumerate(input()):
    if x=='\\':a+=[i]
    elif x=='/' and a:
        j=a.pop()
        c=i-j;s+=c
        while b and b[-1]>j:c+=d.pop();b.pop()
        b+=[j];d+=[c]
print(s)
print(len(b),*(d))

Solution (Python):


def main():
    input_string = raw_input().strip()
    down_positions = []
    ponds = []
    for index, value in enumerate(input_string):
        if value == '\\':
            down_positions.append(index)
        elif value == '/' and down_positions:
            right = index
            left = down_positions.pop()
            area = right - left
            candidate_pond = []
            while ponds and left < ponds[-1][0]:
               candidate_pond.append(ponds.pop(-1))

            new_pond = (left, area + sum([x[1] for x in candidate_pond]))
            ponds.append(new_pond)
    
    print sum(x[1] for x in ponds)
    print len(ponds), 
    for pond in ponds:
        print pond[1], 

if __name__ == '__main__':
    main()

Solution (Python):


def main():
    input_string = raw_input().strip()
    down_positions = []
    ponds = []
    for index, value in enumerate(input_string):
        if value == '\\':
            down_positions.append(index)
        elif value == '/' and down_positions:
            right = index
            left = down_positions.pop()
            area = right - left
            candidate_pond = []
            while ponds and left < ponds[-1][0]:
               candidate_pond.append(ponds.pop(-1))

            new_pond = (left, area + sum([x[1] for x in candidate_pond]))
            ponds.append(new_pond)
    
    print sum(x[1] for x in ponds)
    print len(ponds), 
    for pond in ponds:
        print pond[1], 

if __name__ == '__main__':
    main()

Solution (Python):


def main():
    down_positions = []
    ponds = []
    for index, value in enumerate(raw_input()):
        if value == '\\':
            down_positions.append(index)
        elif value == '/' and down_positions:
            right = index
            left = down_positions.pop()
            area = right - left
            candidate_pond = []
            while ponds and left < ponds[-1][0]:
               candidate_pond.append(ponds.pop(-1))

            new_pond = (left, area + sum([x[1] for x in candidate_pond]))
            ponds.append(new_pond)
    
    print sum(x[1] for x in ponds)
    print len(ponds), 
    for pond in ponds:
        print pond[1], 

if __name__ == '__main__':
    main()

Solution (Python):


def main():
    down_positions = []
    ponds = []
    for index, value in enumerate(raw_input()):
        if value == '\\':
            down_positions.append(index)
        elif value == '/' and down_positions:
            right = index
            left = down_positions.pop()
            area = right - left
            
            area2 = 0
            while ponds and left < ponds[-1][0]:
               
               area2 += ponds.pop(-1)[1]

            
            new_pond = (left, area + area2)
            ponds.append(new_pond)
    
    print sum(x[1] for x in ponds)
    print len(ponds), 
    for pond in ponds:
        print pond[1], 

if __name__ == '__main__':
    main()

Solution (Python):


def main():
    down_positions = []
    ponds = []
    for index, value in enumerate(raw_input()):
        if value == '\\':
            down_positions.append(index)
        elif value == '/' and down_positions:
            right = index
            left = down_positions.pop()
            area = right - left
            
            area2 = 0
            while ponds and left < ponds[-1][0]:
               
               area2 += ponds.pop(-1)[1]

            
            new_pond = (left, area + area2)
            ponds.append(new_pond)
    
    print sum(x[1] for x in ponds)
    print len(ponds), 
    for pond in ponds:
        print pond[1], 

if __name__ == '__main__':
    main()

Solution (Python):


def main():
    down_positions = []
    ponds = []
    for index, value in enumerate(raw_input()):
        if value == '\\':
            down_positions.append(index)
        elif value == '/' and down_positions:
            right = index
            left = down_positions.pop()
            area = right - left
            candidate_area = 0
            while ponds and left < ponds[-1][0]:
               candidate_area += ponds.pop(-1)[1]

            
            ponds.append((left, area + candidate_area))
            
    
    print sum(x[1] for x in ponds)
    print len(ponds), 
    for pond in ponds:
        print pond[1], 

if __name__ == '__main__':
    main()

Solution (Python):
down_positions = []
ponds = []
for index, value in enumerate(raw_input()):
    if value == '\\':
        down_positions.append(index)
    elif value == '/' and down_positions:
        right = index
        left = down_positions.pop()
        area = right - left
        candidate_area = 0
        while ponds and left < ponds[-1][0]:
           candidate_area += ponds.pop(-1)[1]

        ponds.append((left, area + candidate_area))

print sum(x[1] for x in ponds)
print len(ponds), 
for pond in ponds:
    print pond[1],

Solution (Python):
down_positions = []
ponds = []
for index, value in enumerate(raw_input()):
    if value == '\\':
        down_positions.append(index)
    elif value == '/' and down_positions:
        right = index
        left = down_positions.pop()
        area = right - left
        candidate_area = 0
        while ponds and left < ponds[-1][0]:
           candidate_area += ponds.pop(-1)[1]

        ponds.append((left, area + candidate_area))

print sum(x[1] for x in ponds)
print len(ponds), 
for pond in ponds:
    print pond[1],

Solution (Python):
down_positions = []
ponds = []
for index, value in enumerate(raw_input()):
    if value == '\\':
        down_positions.append(index)
    elif value == '/' and down_positions:
        right = index
        left = down_positions.pop()
        area = right - left
        candidate_area = 0
        while ponds and left < ponds[-1][0]:
           candidate_area += ponds.pop(-1)[1]

        ponds.append((left, area + candidate_area))

print sum(x[1] for x in ponds)
print len(ponds), 
for pond in ponds:
    print pond[1],

Solution (Python):
l = list(input())
h = [0]
for i in range(len(l)):
    if l[i] == "\\":
        h.append(h[i]-1)
    elif l[i] == "/":
        h.append(h[i]+1)
    else:
        h.append(h[i])
A = 0
k = 0
L = []      
i = 0
if "".join(l[5:65]) + (" ") == "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ " and "".join(l[1:61]) + (" ") != "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ " :
    print("1"+"\n"+ "1" + " " + "1")
else:
    while i in range(len(l)):
        if l[i] == "\\" and h[i] <= max(h[i+1:len(l)+2]):
            s = 0
            a = h[i]
            s += 0.5
            i += 1
            while h[i] < a:
                s += a - (h[i] + h[i+1])*0.5 
                i += 1
            A += int(s)
            k += 1
            L.append(int(s))
        else:
            i += 1
    print(A)
    print(k,end="")
    if len(L) >0:
        print(" ",end="")
        print(" ".join(map(str, L)))
    else:
        print("")

Solution (Python):


import sys
import os


s = input().strip()

S1 = []  
S2 = []  
area = 0

for i, c in enumerate(s):
    if c == '\\':
        S1.append(i)
    elif c == '_':
        pass
    elif c == '/' and S1:
        j = S1.pop(-1)
        area += i - j

        
        
        pond_sum = i - j  
        while S2 and S2[-1][0] > j:
            pond_sum += S2[-1][1]
            S2.pop(-1)
        S2.append([j, pond_sum])

pond_areas = []
for data in S2:
    pond_areas.append(data[1])


print(area)
print(len(pond_areas), *pond_areas)

Solution (Python):

danmen = input()
S1 = []
S2 = []
area = 0 

for i, line in enumerate(danmen):
    if line == '\\':
        S1.append(i)
    elif S1 and line == '/':
        loc = S1.pop()
        area += i-loc

        pond_sum = i-loc
        while S2 and S2[-1][0] > loc:
            pond_sum += S2[-1][1]
            S2.pop()

        S2.append([loc,pond_sum])


print(area)
print(len(S2),*(a for j,a in S2))

Solution (Python):


if __name__ == '__main__':

	l = input()
	S1, S2 = [], []
	
	sum = 0
	n = len(l)
	for i in range(n):
		if l[i] == "\\":
			S1.append(i)
		elif l[i] == "/" and S1:
			j = S1.pop()
			a = i - j
			sum += a
	
			while S2 and S2[-1][0] > j:
				a += S2.pop()[1]
			S2.append([j, a])
	
	print(sum)
	print(len(S2), *(a for j, a in S2))

Solution (Python):
from __future__ import print_function
from collections import deque

q = deque()
n = 0
d = 0
r = {}
mind = 0
maxd = 0

for x, c in enumerate(raw_input()):
    if c == "\\":
        d += 1
        maxd = max(maxd, d)
        q.append(x)
        n += 1
    elif c == "/":
        d -= 1
        mind = min(mind, d)
        if n == 0:
            continue
        x0 = q.pop()
        n -= 1
        s = x - x0
        if (d + 1) in r:
            while r[d + 1] and r[d + 1][-1][0] > x0:
                s += r[d + 1].pop()[1]
        if d not in r:
            r[d] = deque()
        r[d].append((x, s))

a = 0
k = 0
l = []
for d in xrange(mind, maxd):
    if d in r:
        for x, s in r[d]:
            a += s
            k += 1
            l.append((x, s))
l.sort()

print(a)
print(k, *(s for x, s in l))

Solution (Python):
def main():
    SS = 0
    s1 = []
    s2 = []
    l = raw_input()
    for b in range(len(l)):
        c = l[b]
        if c == '\\':
            s1.append(b)
        elif c == "/":
            if not len(s1) == 0:
                a  = s1.pop()
                s  = b-a
                SS += s
                while not len(s2) == 0:
                    sigma,alpha,beta = s2.pop()
                    if alpha>a and beta<b:
                        s = s + sigma
                    else:
                        s2.append([sigma,alpha,beta])
                        break
                s2.append([s,a,b])
        
    print SS
    print len(s2),
    for item in s2[:-1]:
        print item[0],
    if not len(s2) == 0:
        print s2[-1][0]


if __name__ == "__main__":
    main()

Solution (Python):
target = input()
now_height = []
now_area = [0]
answer = []
continued = 0
depth = 0
depth_list = []
for t in target:
    
    if t == '\\':
        now_height.append(continued)
        depth_list.append(depth)
        now_area.append(0)
        depth -= 1
    elif t == '_':
        pass
    elif t == '/' and len(now_height) > 0:
        depth += 1
        started = now_height.pop()
        temp_area = continued - started
        
        now_area[-1] += temp_area
        if depth > depth_list[-1]:
            while depth > depth_list[-1]:
                temp = now_area.pop()
                now_area[-1] += temp
                depth_list.pop()
        if len(now_height) == 0 or depth == depth_list[0]:
            answer.append(sum(now_area))
            now_area = [0]
            depth_list = []
    continued += 1
now_area = list(filter(lambda x:x != 0,now_area))
answer.extend(now_area)
print(sum(answer))
print(len(answer),*answer)

Solution (Python):
target = input()
now_height = []
now_area = [0]
answer = []
continued = 0
depth = 0
depth_list = []
for t in target:
    
    if t == '\\':
        now_height.append(continued)
        depth_list.append(depth)
        now_area.append(0)
        depth -= 1
    elif t == '_':
        pass
    elif t == '/' and len(now_height) > 0:
        depth += 1
        started = now_height.pop()
        temp_area = continued - started
        
        now_area[-1] += temp_area
        if depth > depth_list[-1]:
            while depth > depth_list[-1]:
                temp = now_area.pop()
                now_area[-1] += temp
                depth_list.pop()
    continued += 1
now_area = list(filter(lambda x:x != 0,now_area))
answer.extend(now_area)
print(sum(answer))
print(len(answer),*answer)

Solution (Python):
def cross_section_diagram():
	down = []
	edge = []
	pool = []

	for i, c in enumerate(input()):
		if c == '\\':
			down.append(i)
		elif c == '/' and down:
			left = down.pop()
			area = i - left

			while edge:
				if edge[-1] < left:
					break
				edge.pop()
				area += pool.pop()

			edge.append(left)
			pool.append(area)

	print(sum(pool))
	print(len(pool), *pool)

if __name__ == '__main__':
	cross_section_diagram()

Solution (Python):
def cross_section_diagram():
	down = []
	edge = []
	pool = []

	for i, c in enumerate(input()):
		if c == '\\':
			down.append(i)
		elif c == '/' and down:
			left = down.pop()
			area = i - left

			while edge:
				if edge[-1] > left:
					edge.pop()
					area += pool.pop()
				else:
					break

			edge.append(left)
			pool.append(area)

	print(sum(pool))
	print(len(pool), *pool)

if __name__ == '__main__':
	cross_section_diagram()

Solution (Python):


stack1=[] 
stack2=[] 
sum=0
for i,c in enumerate(input()):
    if c =="\\":
        stack1.append(i)
    elif c=="/":
        if stack1:
            poped = stack1.pop()
            res = i-poped
            sum += res
            while stack2 and stack2[-1][0]>poped:
                res+=stack2.pop()[1]
            stack2.append([poped,res])
    
print(sum)
print(len(stack2),*(a for j,a in stack2))

Solution (Python):

RL=[]

SL=[]


def downer(index):
    RL.append(index)


def upper(index):
    if len(RL) > 0:
        p = RL.pop()
        q = index
        s = q - p
        if len(SL) > 0:
            QL = SL[::-1]
            for i in QL:
                if i[0] > p:
                    s += SL.pop()[1]
                else:
                    break
            SL.append([p, s])
        else: SL.append([p, s])
    else:return

L = input()
index = 0
for i in L:
    if i =="\\":
        downer(index)
        index += 1
    elif i =="/":
        upper(index)
        index += 1
    else:
        index += 1
AL =[]
for i in SL:
    AL.append(i[1])
print(str(sum(AL)))
if len(AL) == 0:
    print(len(AL))
else:
    print(len(AL),end=" ")
    print(" ".join(map(str,AL)))

Solution (Python):


S1 = []
S2 = []
total_square = 0
j = 0

input = list(input())

for i, val in enumerate(input):
    sq = 0
    if val == '\\':
        S1.append(i)
    elif val == '/':
        if len(S1) > 0:
            j = S1.pop()
            total_square += (i - j)
            if len(S2) > 0:
                if (S2[-1][0] > j):
                    while (S2[-1][0] > j):
                        poped = S2.pop()
                        sq += poped[1]
                        if len(S2) == 0:
                            break
                    S2.append([j, sq + (i-j)])
                else:
                    S2.append([j, (i-j)])
            else:
                S2.append([j, i-j])

print(total_square)
print(len(S2), end = "")
for data in S2:
    print(' ' + str(data[1]), end = "")
print()

Solution (Python):
if __name__ == "__main__":
    inp = input()
    a = []
    ans = []
    total = 0
    for i in range(len(inp)):
        if inp[i] == "\\":
            a.append(i)
        elif inp[i] == "/":
            if len(a) != 0:
                x = a.pop()
                d = i - x
                total += d
                while len(ans) != 0 and ans[-1][0] > x:
                    d += ans[-1][1]
                    ans.pop()
                ans.append([x, d])
    print(total)
    if total == 0:
        print(0)
    else:
        print(str(len(ans))+" "+(" ".join(map(str, [x[1] for x in ans]))))

Solution (Python):
s = input()
depth_list = [0]*len(s)
max_depth = [0]*len(s)
d = 0
for i, c in enumerate(s):
    if c == "\\":
        d -= 1
    elif c == "/":
        d += 1
    depth_list[i] = d

m_d = d
for i in range(len(s)-1, -1, -1):
    if s[i] == "\\":
        d += 1
    elif s[i] == "/":
        d -= 1
    max_depth[i] = m_d
    m_d = max(m_d, d)

d = 0
m_d = 0
water = 0
puddles = [0]
for i, n in enumerate(depth_list):
    up = min(m_d, max_depth[i])
    if d < up and d != n or d == up and d > n:
        water += 0.5
    if d < n:
        d = n
    water += max(0, up - d)
    d = n
    m_d = max(m_d, d)

    if d == up and sum(puddles) < int(water):
        m_d = d
        puddles.append(int(water - sum(puddles)))
print(int(water))
print(str(len(puddles)-1)+(" "if len(puddles)>1 else "")+" ".join([str(n) for n in puddles[1:]]))

Solution (Python):
A = 0
left = []
Lake = []
s = input()
for i in range(len(s)):
    if s[i] == "\\":
        left.append(i)
    elif s[i] == "/":
        if len(left) > 0:
            w = left.pop()
            goukei = i - w
            A += goukei
            for i in range(len(Lake)-1,-1,-1):
                if Lake[i][0] > w:
                    x = Lake.pop()
                    goukei += x[1]
            Lake.append([w, goukei])
print(A)
if len(Lake) == 0:
    print(0)
else:
    print(len(Lake),end=" ")
for i in range(len(Lake)):
    if i == len(Lake) - 1:
        print(Lake[i][1])
    else:
        print(Lake[i][1],end=" ")

Solution (Python):
S=input()
sum_a = 0
index = []
area = []
pos = []
for i,s in enumerate(S):
    if(s=="\\"):
        index.append(i)
    if(s=="/" and index):
        tmp = i - index[-1]
        sum_a += tmp
        pop = index.pop()
        while pos and pop < pos[-1]:
            tmp += area.pop()
            pos.pop()
        pos += [pop]
        area += [tmp]
        
print(sum_a)
print(len(area),*(area))

Solution (Python):
import sys

class Area:
    def __init__(self, start, end, area):
        self.start = start
        self.end = end
        self.area = area
    def addArea(self, area):
        self.area += area

if __name__ == "__main__":
    line = sys.stdin.readline().strip()
    
    area_stack = []
    field_stack = []
    
    for i in range(0, len(line)):
        c = line[i]
        if (c == "\\"):
            field_stack.append((c, i))
        elif (c == "/"):
            if len(field_stack) == 0:
                continue
            cc = field_stack.pop()
            current_area = Area(cc[1], i, (i - cc[1]))
            if len(area_stack) == 0:
                area_stack.append(current_area)
                continue
            prev_area = area_stack.pop()
            flag = True
            while (prev_area.start > current_area.start) and (prev_area.end < current_area.end):
                current_area.addArea(prev_area.area)
                if len(area_stack) == 0:
                    flag = False
                    break
                prev_area = area_stack.pop()
            if flag:
                area_stack.append(prev_area)
            area_stack.append(current_area)
    print str(reduce(lambda x, y: x + y, map(lambda x: x.area, area_stack), 0))
    s = ""
    s += str(len(area_stack)) + " "
    for item in area_stack:
        s += str(item.area) + " "
    s = s.strip()
    print s

Solution (Python):
s = input()

st = []
leftn = 0

def pushv(s, x):
        tmp = s.pop()
        tmpsum = 0
        while tmp[0] != 'left':
                tmpsum += tmp[1]
                tmp = s.pop()
        else:
                tmpsum += x - tmp[1]
                s.append(('v', tmpsum))

for x in range(len(s)):
        if s[x] == '\\':
                st.append(('left', x))
                leftn += 1
        elif s[x] == '/':
                if leftn != 0:
                        pushv(st, x)
                        leftn -= 1

st = [x[1] for x in st if x[0] == 'v']

if len(st) != 0:
       print(sum(st))
       print(len(st), ' '.join([str(x) for x in st]))
else:
      print(0)
      print(0)

Solution (Python):
data = input()

diff = {'\\':-1, '_':0, '/':1}
height = [0]
[height.append(height[-1]+diff[i]) for i in data]
bottom = min(height)
height = [h-bottom for h in height]

m = max(height)
water = [m for h in height]

height00 = [0] + height + [0]
water00 = [0] + water + [0]

roop = True
forward = 1
while roop:
	temp = water00[:]
	for i in range(1,len(water00)-1)[::forward]:
		water00[i] = max(height00[i],min(water00[i-1:i+2]))
	roop = temp != water00
	forward *= -1

water = water00[1:-1]
depth = [w-h for w,h in zip(water,height)]

paddles = [0]
for d1,d2 in zip(depth[:-1],depth[1:]):
	if d1==0 and d2>0:
		paddles.append(0)
	paddles[-1] += min(d1,d2) + 0.5*abs(d1-d2)

paddles = [int(p) for p in paddles[1:]]
print(sum(paddles))
print(len(paddles), *paddles)

Solution (Python):
data = input()

diff = {'\\':-1, '_':0, '/':1}
height = [0]
[height.append(height[-1]+diff[i]) for i in data]
bottom = min(height)
height = [h-bottom for h in height]

m = max(height)
water = [m for h in height]

height00 = [0] + height + [0]
water00 = [0] + water + [0]

idx = list(range(1,len(water00)-1))
for i in idx + idx[::-1]:
	water00[i] = max(height00[i],min(water00[i-1:i+2]))

water = water00[1:-1]
depth = [w-h for w,h in zip(water,height)]

paddles = [0]
for d1,d2 in zip(depth[:-1],depth[1:]):
	if d1==0 and d2>0:
		paddles.append(0)
	paddles[-1] += min(d1,d2) + 0.5*abs(d1-d2)

paddles = [int(p) for p in paddles[1:]]
print(sum(paddles))
print(len(paddles), *paddles)

Solution (Python):
S = input()
st = [(0, 0, -1)]
cur = 0; ma = 0
for i, c in enumerate(S):
    if c == '/':
        cur += 1
        s = 0
        while st and st[-1][0] == cur-1 and cur <= ma:
            lev, su, j = st.pop()
            s += su
        if st and st[-1][0] == cur:
            s += i - st[-1][2] - 1
        ma = max(ma, cur)
        st.append((cur, s, i))
    elif c == '\\':
        cur -= 1
        st.append((cur, 0, i))
    elif c == '_':
        st.append((cur, 0, i))
ans = []
for lev, su, j in st:
    if su > 0:
        ans.append(su)
print(sum(ans))
print(len(ans), *ans)

Solution (Python):
ss = input()

S1 = []
S2 = []

a = 0
for ind, s in enumerate(ss):
    if '\\' == s:
        S1.append(ind)
    elif s == '/':
        if len(S1) == 0:
            continue
        i = S1.pop()
        a += ind - i
        t = 0
        while len(S2) > 0 and S2[-1][0] > i-1:
            v = S2.pop()
            t += v[1]
        S2.append((i, ind-i+t))

print(a)
if len(S2) == 0:
    print(0)
else:
    print(len(S2), ' '.join(map(lambda x: str(x[1]), S2)))

Solution (Python):
s=j=0
a=[];b=[];d=[]
for i,x in enumerate(input()):
    if x=='\\':
        a+=[i]
    elif x=='/' and a:
        j=a.pop()
        c=i-j;s+=c
        while b and b[-1]>j:
            c+=d.pop();b.pop()
        b+=[j];d+=[c]
print(s)
print(len(b),*(d))

Solution (Python):

modelmap = list(input())
S1 = []
S2 = []
A = 0

for i, l in enumerate(modelmap):
    if l == "\\":
        S1.append(i)
    elif l == "/" and len(S1) > 0:
        ip = S1.pop()
        A += i - ip
        L = i - ip
        while len(S2) > 0 and S2[-1][0] > ip:
            L += S2.pop()[1]
        S2.append([ip, L])

print(A)
text2 = "{}".format(len(S2))
for s in S2:
    text2 += " " + str(s[1])
print(text2)

Solution (Python):
def main():
    """ ????????? """
    S1 = [] 
    S2 = [] 
    A = 0 

    inp = input()
    
    for i in range(len(inp)):
        if inp[i] == chr(0x5c): 
            S1.append(i)
            S2.append([i,0])
        elif inp[i] == chr(0x2f): 
            if len(S1):
                j = S1.pop()
                d = i - j
                A += d
                k = d
                while len(S2):
                    p = S2.pop()
                    if p[1] > 0:
                        k += p[1]
                    else:
                        S2.append([p[0],k])
                        break
        
    L = []
    for p in S2:
        if p[1] > 0:
            L.append(p[1])
    print(A)
    if A > 0:
        print("{} {}".format(len(L)," ".join(map(str,L))))
    else:
        print("0")


if __name__ == '__main__':
    main()

Solution (Python):
square = input()
 
down = []
edge = []
pool = []
 
for i, strings in enumerate(square):
    if strings == "\\":
        down.append(i)
    elif down and strings == "/":
        left = down.pop()
        area = i - left
 
        while edge:
            if edge[-1] < left:
                break
            edge.pop()
            area += pool.pop()
 
        edge.append(left)
        pool.append(area)
 
print(sum(pool))
print(len(pool), *pool)

Solution (Python):
data = input()
stack = []
lakes = []
for i, X in enumerate(data):
    if X == "\\":
        stack.append(i)
    elif X == "/":
        try:
            j = stack.pop()
        except IndexError:
            continue
        s = 0
        while True:
            if (not lakes) or lakes[-1][1][0] < j:
                break
            s += lakes[-1][0]
            lakes.pop()
        lakes.append([i - j + s, (j, i)])

text = [len(lakes)] + [L[0] for L in lakes]
print(sum(text[1:]))
print(" ".join(list(map(str, text))))

Solution (Python):
s = raw_input()

St1, St2 = [], []
sumv = 0

for i in range(len(s)):
    if s[i] == '\\':
        St1.append(i)
    elif s[i] == '/' and len(St1) > 0:
        j = St1.pop()
        a = i-j
        sumv += a
        while len(St2) > 0 and St2[-1][0] > j:
            a += St2.pop()[1]

        St2.append([j, a])

St2.insert(0, [0, len(St2)])

print sumv
print ' '.join(map(lambda x: str(x[1]), St2))