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



Sample input:
\\//


Sample output:
4
1 4

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

cs_view = input().rstrip('\r\n')
list_v = list(cs_view)

stack1 = []
all_sum = 0
sum_stack = []
for i, elem in enumerate(list_v):
    if elem == '\\':
        stack1.append(i)
    elif len(stack1) > 0 and elem == '/':
        j = stack1.pop()
        all_sum += i - j
        a = i - j
        while len(sum_stack) > 0 and sum_stack[-1][0] > j:
            a += sum_stack.pop()[1]
        sum_stack.append([j, a])

print(all_sum)
esum = []
for a in sum_stack:
    esum.append(a[1])
esum.insert(0, len(esum))
maped_esum = map(str, esum)
str_esum = ' '.join(maped_esum)
print(str_esum)

Submission status: Accepted

Solution code:
s=[]
p=[]
a=i=0
for c in input():
 if"\\"==c:s+=[i]
 if"/"==c and s:
  j=s.pop()
  t=i-j
  a+=t
  while p and p[-1][0]>j:t+=p.pop()[1]
  p+=[(j,t)]
 i+=1
print(a)
if p:print(len(p),*list(zip(*p))[1])
else:print(0)

Submission status: Accepted

Solution code:
from sys import stdin
from collections import deque

sect = stdin.readline().lstrip("/_").rstrip("\n\\_")
stack = deque()
res = deque()

for i in range(len(sect)):
    if sect[i] == "\\":
        stack.append(i)
    elif sect[i] == "/":
        if len(stack) != 0:
            b = stack.pop()
            if len(res) == 0:
                res.append( (b, i-b) )
            elif b > res[-1][0]:
                res.append( (b, i-b) )
            else: # 水たまりを結合
                sum_L = i-b
                while len(res) != 0:
                    if res[-1][0] > b:
                    	sum_L += res[-1][1]
                    	res.pop()
                    else:
                    	break

                res.append((b, sum_L))

res = [x[1] for x in res]
print(sum(res))
print(len(res), *res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

"""
stackの応用(水たまりの面積)
"""

from collections import deque

S = list(input())

# 総合面積
ans = 0
# 総合面積用スタック(直近の\の位置)
stack1 = deque()
# 個別用スタック(その水たまりを開始する\の位置, その時点での面積)
stack2 = deque()
for i in range(len(S)):
    if S[i] == '\\':
        stack1.append(i)
    # 一番最近いれた\を取り出せば、今回の/と対になる(同じ高さ)
    elif S[i] == '/' and stack1:
        # 両者の距離がその高さでの面積になる
        # (\/が三角形な分-1なのが半開区間だからちょうど合う)
        j = stack1.pop()
        ans += i - j

        # 各水たまりのマージ作業
        # stack2から、今回の合併候補を抽出
        # (条件：水たまりの開始位置が今回対になってる\より右側にある)
        pond = i - j
        while stack2 and stack2[-1][0] >= j:
            pond += stack2.pop()[1]
        # マージした水たまりの情報を詰める
        stack2.append([j, pond])
print(ans)
# リスト内包とアンパックできれいにまとまった
print(len(stack2), *[pond for j, pond in stack2])

Submission status: Accepted

Solution code:
import sys


def read_heights():
    current = 0
    heights = [current]
    for c in sys.stdin.read().strip():
        current += {
            '/': 1,
            '\\': -1,
            '_': 0
        }[c]
        heights.append(current)
    return heights


heights = read_heights()

height_index = {}
for i, h in enumerate(heights):
    height_index.setdefault(h, []).append(i)

flooded = [False] * len(heights)
floods = []

# search from highest points
for h in sorted(height_index.keys(), reverse=True):
    indexes = height_index[h]
    for i in range(len(indexes) - 1):
        start = indexes[i]
        stop = indexes[i + 1]
        if start + 1 == stop or flooded[start] or flooded[stop]:
            continue
        if any(heights[j] >= h for j in range(start + 1, stop)):
            continue
        # flood in (start..stop)
        floods.append((start, stop))
        for j in range(start, stop):
            flooded[j] = True

floods.sort()

areas = []
for start, stop in floods:
    area = 0
    top = heights[start]
    for i in range(start + 1, stop + 1):
        h = heights[i]
        area += top - h + (heights[i - 1] - h) * 0.5
    areas.append(int(area))

print(sum(areas))
print(' '.join([str(v) for v in [len(areas)] + areas]))

Submission status: Accepted

Solution code:
from collections import deque


def main():
    stack = deque()
    diagram = input()
    square = []

    for index, value in enumerate(diagram):
        if value == '\\':
            stack.append(-index)
        elif value == '/':
            if len(stack) > 0:
                tmp = []
                while True:
                    tmp.append(stack.pop())
                    if tmp[-1] <= 0:
                        stack.append(sum(tmp[:-1]) + index + tmp[-1])
                        break
                if len(stack) == 1:
                    square.append(stack.pop())
    square.extend([i for i in stack if i > 0])

    print(sum(square))
    if sum(square) == 0:
        print(0)
    else:
        print('{} {}'.format(len(square), ' '.join([str(i) for i in square])))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#参考 __author__ = CIMA
s=j=0  #sは面積の総和
a=[]
b=[]  #各水たまりのスタック
d=[]
for i,x in enumerate(input()):  #enumerate関数を用いることでインデックスと要素を取り出す
    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))

Submission status: Accepted

Solution code:
from collections import deque

slope = input()
down_slope   = deque()
total_slopes = deque()

for i in range(len(slope)):
    if slope[i] == '\\':
        down_slope.append(i)
    elif slope[i] == '/':
        area = 0
        if len(down_slope) > 0:
            while len(total_slopes) > 0 and total_slopes[-1][0] > down_slope[-1]:
                area += total_slopes[-1][1]
                total_slopes.pop()
            area += i-down_slope[-1]
            total_slopes.append([down_slope[-1],area])
            down_slope.pop()

if len(total_slopes) > 0:
    total_slopes = [i[1] for i in total_slopes]
    print(sum(total_slopes))
    print(len(total_slopes),end=' ')
    print(' '.join(map(str,total_slopes)))
else:
    print(0)
    print(0)

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D&lang=jp
#  Areas on the Cross-Section Diagram : python3
#  2018.11.27 yonezawa


from collections import deque
import heapq
import sys
input = sys.stdin.readline


def main():
    q = deque()
    m = str(input()).strip()
    dq = []
    count = 0
    for i in range(len(m)):
        if (m[i] == "\\" ):
            q.append(i)
            continue
        if (m[i] == "/" and len(q) > 0):
            j = q.pop()
            count += i - j
            #dq.append((j,i))
            dq.append((j,i))
    print (count)
    if (len(dq) == 0):
        print (0)
        return

    l = []
    dq.sort()
    dq.reverse()
    (a,b) = dq.pop()
    
    score = b - a
    while len(dq) > 0:
        (i,n) = dq.pop()
        if ( b > i ):
            score += n - i
        else:
            l.append(score)
            score = n - i
            a = i
            b = n
    else:
        l.append(score)

    print (len(l),*l)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
inpu = input()
back = list(r"\\")[0]

stack = []
area = 0
area_sub = []
for i,symbol in enumerate(inpu):
    if symbol == back:
        stack.append(i)
        #print(back)
    elif symbol == "/":
        #print(symbol)
        if len(stack)>0:
            a = stack.pop()
            area += i-a
            
            area2 = 0
            while len(area_sub) and a<area_sub[-1][0]:
                pre = area_sub.pop()
                area2 += pre[1]
            area2 += i-a 
            area_sub.append([a,area2])
print(area)

#print(" ".join(a for a in area_sub))
if len(area_sub) > 0: 
    print(len(area_sub), end=" ")
    ar = [a[1] for a in area_sub]
    print(*ar)
else:
    print(len(area_sub))

Submission status: Accepted

Solution code:
n=input()
a=[]
area=[]
x1=[]
x2=[]

x=1
for i in n:
	if i=='\\':
		a.append(x)
		
	elif i=='/' and len(a)>=1:
		area.append(x-a[len(a)-1])
		x1.append(a[len(a)-1])
		x2.append(x)
		a.pop()		
		
		for i in range(len(x1)-2,-1,-1):	
			if x1[len(x1)-1]<x1[i] and x2[len(x2)-1]>x2[i]:
				x1.pop(i)
				x2.pop(i)
				area[i]=area[i]+area[len(area)-1]
				area.pop()
	x+=1

print(sum(area))
print(len(area),*area)

Submission status: Accepted

Solution code:
s = input()
stack = []
n = len(s)

ans = 0
prev = 0
each = []
for i in range(n):
    if s[i] == '\\':
        stack.append(i)
    elif s[i] == '_':
        pass
    else:
        if len(stack) != 0:
            idx = stack.pop()
            ans += (i - idx)
            if len(stack) == 0:
                each.append(ans - prev)
                prev = ans

each2 = []
stack2 = []
ans2 = 0
prev2 = 0
if len(stack) >= 1:
    for i in range(n-1,stack[0],-1):
        if s[i] == '/':
            stack2.append(i)
        elif s[i] == '_':
            pass
        else:
            if len(stack2) != 0:
                idx = stack2.pop()
                ans2 += (idx - i)
                if len(stack2) == 0:
                    each2.append(ans2 - prev2)
                    prev2 = ans2
each2.reverse()
each.extend(each2)
print(ans)
if len(each) == 0:
    print(len(each))
else:
    print(len(each),end=" ")
    print(*each)

Submission status: Accepted

Solution code:
def flood(region_data,flood_data):
    height = 0
    water_num=0
    top=0
    i=-1
    for data in region_data:
        i+=1
        if(data=="\\"):
            if(height==0):
                top=i
            water_num+=height +0.5
            height+=1


        elif(data=="/"):
            if(height>=2):
                water_num+=height-0.5
                height-=1
            elif(height==1):
                water_num+=0.5
                flood_data.append(water_num)
                water_num=0
                height=0


        elif(data=="_"):
            water_num+=height
    if(height==0):
        top=-1
    return top







def flood2(region_data,flood_data):
    height = 0
    water_num=0
    top=0
    i=-1
    for data in region_data:
        i+=1
        if(data=="/"):
            if(height==0):
                top=i
            water_num+=height +0.5
            height+=1


        elif(data=="\\"):
            if(height>=2):
                water_num+=height-0.5
                height-=1
            elif(height==1):
                water_num+=0.5
                flood_data.append(water_num)
                water_num=0
                height=0


        elif(data=="_"):
            water_num+=height
    if(height==0):
        top=-1
    return top


region_data=list(input())
flood_data=[]
top=flood(region_data,flood_data)


if(top!=-1):
    region_data2=region_data[top:len(region_data)]
    region_data2.reverse()
    flood_data2=[]
    flood2(region_data2,flood_data2)
    flood_data2.reverse()
    flood_data_final=flood_data + flood_data2
else:
    flood_data_final=flood_data

flood_data_final=list(map(int,flood_data_final))
total=sum(flood_data_final)
num=[len(flood_data_final)]
flood_data_final=" ".join(list(map(str,num+flood_data_final)))

print(total)
print(f"{flood_data_final}")

Submission status: Accepted

Solution code:
# PDF参考
# スタックS1
S1 = []
# スタックS2
S2 = []
tmp_total = 0
counter = 0
upper = 0
# 総面積
total_layer = 0

for i,symbol in enumerate(input()):
    if (symbol == '\\'):
        S1.append(i)
    elif (symbol == '/') and S1:
        i_p = S1.pop()
        total_layer = i - i_p
        if S2 :
            while S2 and S2[-1][0] > i_p:
                cal = S2.pop()
                total_layer += cal[1]
        S2.append((i, total_layer))
print(sum([j[1] for j in S2]))
if (len(S2) != 0):
    print(str(len(S2)) + ' ' + ' '.join([str(i[1]) for i in S2]))
else:
    print(str(len(S2)))

Submission status: Accepted

Solution code:
import sys

s = sys.stdin.readline().rstrip()
h = [0] * len(s)

start={}
d=0
for i,c in enumerate(s):
    if c=='\\':
        start[d] = i
        d -= 1;
    if c=='/':
        d += 1
        if start.get(d, -1)>=0:
            for j in range(start[d],i):
                h[j] += 1

print(sum(h))
narea=0
areas=''
ssum=0
for i in h:
    ssum += i
    if i==0:
        if ssum>0:
            narea+=1
            areas += ' ' + str(ssum)
            ssum=0

if narea>0: print(narea,areas,sep='')
else:       print(narea)

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

class Info:
    def __init__(self,arg_start,arg_end,arg_S):
        self.start = arg_start
        self.end = arg_end
        self.S = arg_S


LOC = []
POOL = []

line = input()
loc = 0
sum_S = 0

for ch in line:

    if ch == '\\':

        LOC.append(loc)

    elif ch == '/':

        if len(LOC) == 0:
            continue

        tmp_start = int(LOC.pop())
        tmp_end = loc
        tmp_S = tmp_end-tmp_start;
        sum_S += tmp_S;

        #既に突っ込まれている池の断片が、今回の断片の部分区間になるなら統合する
        while len(POOL) > 0:
            if POOL[-1].start > tmp_start and POOL[-1].end < tmp_end:
                tmp_S += POOL[-1].S
                POOL.pop()
            else:
                break

        POOL.append(Info(tmp_start,tmp_end,tmp_S))

    else:
        pass

    loc += 1

print("%d"%(sum_S))
print("%d"%(len(POOL)),end = "")

while len(POOL) > 0:
    print(" %d"%(POOL[0].S),end = "") #先頭から
    POOL.pop(0)

print()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
S = input()
m = 0
cur = 0
a = [(-1, 0, 0)]

for n, s in enumerate(S):

    if s == '/':
        area = 0
        cur += 1

        while a and a[-1][2] < cur <= m:
            area += a.pop()[1]

        if a and a[-1][2] == cur:
            area += (n - a[-1][0] - 1)
        a.append((n, area, cur))
        m = max(m, cur)

    else:
        if s == '\\': cur -= 1
        a.append((n, 0, cur))
l = [str(x[1]) for x in a if x[1] != 0]
print(sum([x[1] for x in a]))
if len(l):
    print(
        '{} {}'.format(
            len(l),
            ' '.join(l)
        )
    )
else:
    print(0)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
terrain = list(input())

down_slopes = []
puddles = []
total_cross_section = 0

for (position, slope) in enumerate(terrain):
    if slope == '\\' :
        down_slopes.append(position)
    elif slope == '/' and down_slopes:
        last_position = down_slopes.pop()
        total_cross_section += position - last_position
        
        puddle_cross_section = 0
        while puddles:
            puddle = puddles.pop()
            if puddle[0] <= last_position:
                puddles.append(puddle)
                break
            puddle_cross_section += puddle[1]
        puddle_cross_section += position - last_position
        puddles.append([last_position,puddle_cross_section])
        
print(total_cross_section)
ans = [str(len(puddles))]
ans.extend( [str(puddle[1]) for puddle in puddles ] )
print(' '.join(ans ) )

Submission status: Accepted

Solution code:
from collections import deque

A = input()
s1 = deque()
c = 0
i = 1

left = None
s2 = deque()
for a in A:
    if a == '\\':
        s1.append(i)
    elif a == '/':
        if len(s1) > 0:
            j = s1.pop()
            # 当前积水处的面积
            area = i - j
            # 加到总面积
            c += area
            while len(s2) > 0:
                t = s2.pop()
                if t[0] > j:
                    area += t[1]
                else:
                    s2.append(t)
                    break
            s2.append([j, area])
            # print(s2)
    else:
        pass
    i += 1
print(c)
print(len(s2), end='')
for t in s2:
    print(' ', end='')
    print(t[1], end='')
print()

Submission status: Accepted

Solution code:
#! /usr/local/bin/python3
# coding: utf-8

def calc(s):
    shape = [ch for ch in s]

    left_x = []
    pool_area = []
    for x, sh in enumerate(shape):
        if sh == "\\":
            left_x.append(x)
        elif left_x and sh == "/":
            lx = left_x.pop()
            area = x - lx
            while pool_area and (pool_area[-1])[0] > lx:
                area += (pool_area.pop())[1]
            pool_area.append((lx, area))
        # print(x, ":", sh, left_x, pool_area)

    return [p[1] for p in pool_area]

def test():
    assert calc(r"\ ".strip()) == []
    assert calc(r"/ ".strip()) == []
    assert calc(r"\/ ".strip()) == [1]
    assert calc(r"\_/ ".strip()) == [2]
    assert calc(r"\// ".strip()) == [1]
    assert calc(r"\\/ ".strip()) == [1]
    assert calc(r"\\// ".strip()) == [4]
    assert calc(r"\\//\\// ".strip()) == [4, 4]
    assert calc(r"\\/\// ".strip()) == [7]
    assert calc(r"\\/_\// ".strip()) == [8]
    assert calc(r"\//\\/ ".strip()) == [1, 1]
    assert calc(r"\//_\\/ ".strip()) == [1, 1]
    assert calc(r"\//\\// ".strip()) == [1, 4]
    assert calc(r"\///\\\// ".strip()) == [1, 4]
    assert calc(r"\///\\\//\ ".strip()) == [1, 4]
    exit()

# test()
# exit()

pool_area = calc(input())
print(sum(pool_area))
print(len(pool_area), *pool_area)

Submission status: Accepted

Solution code:
import sys

n = ''
n = str(input())

darr = []
sp = []
s = []
for i in range(len(n)):
    if n[i] == '\\':
        darr.append(i)
    elif n[i] == '/':
        if len(darr) == 0:
            continue
        pre = darr.pop() 
        tmps = i - pre
        while len(sp) > 0 and sp[-1] > pre:
            sp.pop()
            tmps += s.pop()
        sp.append(pre)
        s.append(tmps)

print(sum(s))
arr = []
arr.append(len(s))
for i in s:
    arr.append(int(i))
print(' '.join(map(str, arr)))

Submission status: Accepted

Solution code:
def print_area(stack):
    if len(stack) == 0:
        print(len(stack))
    else:
        print(len(stack), end=" ")
    for i,j in enumerate(stack):
        if i == len(stack)-1:
            print(j[1])
        else:
            print(j[1], end=" ")    

def calc_flood_area(in_data):
    stack1 = []
    stack2 = []
    total_area = 0
    for i,symbol in enumerate(in_data):
        if symbol == "\\":
            stack1.append(i)
        elif symbol == "_":
            pass
        elif symbol == "/" and stack1:
            j = stack1.pop()
            a = int(i)-int(j)
            total_area += a
            while stack2 and stack2[-1][0] > j:
                a += stack2[-1][1]
                stack2.pop()
            stack2.append((j, a))
                
    print(total_area)
    print_area(stack2)

in_data = input()
calc_flood_area(in_data)

Submission status: Accepted

Solution code:
class Pool:
    def __init__(self, pos, area):
        self.pos = pos
        self.area = area


data = input()

s1 = []
s2 = []
area_sum = 0
for i, v in enumerate(data):

    if v == '\\':
        s1.append(i)
    elif v == '/' and len(s1) > 0:
        j = s1.pop()
        area = i - j
        area_sum += area
        while len(s2) > 0 and s2[-1].pos > j:
            area += s2.pop().area
        s2.append(Pool(j, area))

print(area_sum)
print(len(s2), end='')
if len(s2):
    print(' ' + ' '.join([str(v.area) for v in s2]))
else:
    print()

Submission status: Accepted

Solution code:

s=input()
a=[]
d=[]
sum=0
for i,line in enumerate(s):
    if line == "\\":
        d.append(i)
    elif line == "/" and d:
        j=d.pop()
        a_tmp=i-j
        sum+=a_tmp
        while a and a[-1][0] > j:
            a_tmp += a.pop()[1]
        a.append([j,a_tmp])
 
print(sum)
print(len(a),*[s for i,s in a])

Submission status: Accepted

Solution code:
tmp=input()
l1=[]
l2=[]
Asum=0
Area=[]

for i in range(len(tmp)):
	if tmp[i] is "\\":
		l1.append(i)
	elif tmp[i] is "/" and len(l1) is not 0:
		a1=l1.pop()
		sum=i-a1
		Asum+=sum
		while len(l2)>0:
			if l2[-1]>a1:
				l2.pop()
				sum+=Area.pop()
			else:
				break

		Area.append(sum)
		l2.append(i)
print(Asum)
print(len(Area),*Area)

Submission status: Accepted

Solution code:
# coding: utf-8
s=input()
stk=[]
data=[]
for i in range(len(s)):
    if s[i]=='\\':
        stk.append(i)
    elif s[i]=='/':
        if len(stk):
            data.append((stk.pop(),i))
print(sum(map(lambda x:x[1]-x[0],data)))
ans=[]
sv=-1
for p in data[::-1]:
    if sv==-1:
        sv=p
        ans.append(p[1]-p[0])
    elif sv[0]<p[0]<p[1]<sv[1]:
        ans[-1]+=p[1]-p[0]
    else:
        sv=p
        ans.append(p[1]-p[0])
print(len(ans[::-1]),end=' ' if len(ans[::-1])!=0 else '')
print(*ans[::-1])

Submission status: Accepted

Solution code:
from collections import deque
section = input()
depth = 0
area = 0
depthArr = deque()
areaArr = deque()
for i, drct in enumerate(section):
    if drct == '\\':
        depth += 1
        depthArr.append(i)
    # ???°?´???????£???§?£???????????£?????£???????????£????
    elif 0 < depth and drct == '/':
        if len( depthArr ):
        	# ???°?´?????¢???????£?????£?????£????x?\???§???¨???£?????£???¨?£????
            j = depthArr.pop()
            # ???????\?????£???????????£?????£???£?£???????????£???¨?£???????????\?????£???????????£?????\?§???£?????£???????????£?????\???§???¨???£?????\?????£?????£?????£?????£?????£?????????¢?§?????£?????£?????£????
            pool =  i - j
            area += pool
            while len(areaArr):
                preJ, prePool = areaArr.pop()
                if j <= preJ:
                    pool += prePool
                else:
                    areaArr.append((preJ, prePool))
                    break
            areaArr.append((j, pool))
 
print(area)
output = []
output.append(len(areaArr))
for arr in areaArr:
    output.append(arr[1])
print(*output)

Submission status: Runtime Error

Solution code:
li2 = []
ans = 0
for i, s in enumerate(input()):
    if s == "\\":
        li1.append(i)
    elif s == "/" and li1:
        j = li1.pop()
        c = i - j
        ans += c
        while li2 and li2[-1][0] > j:
            c += li2[-1][1]
            li2.pop()
        li2.append((j, c))
print(ans)
if li2:
    print(len(li2), *list(zip(*li2))[1])
else:
    print(0)

Submission status: Runtime Error

Solution code:
arr = list(input())
down = list()
areas = list()
 
for i, el in enumerate(arr):
    if el == "\\":
        down.append(i)
    elif el == "/" and not len(down) == 0:
        start_ind = down.pop()
        area = i - start_ind
        while len(areas) > 0 and areas[-1][0] > start_ind:
            area += areas.pop()[1]
        areas.append((start_ind, area))
 
areas = [areas[i][1] for i in range(len(areas))]
print(sum(areas))
if len(areas) == 0:
    print("0")
else:
    print(len(areas), " ".join(map(str,areas)))

Submission status: Runtime Error

Solution code:
arr = list(input())
down = list()
areas = list()
 
for i, el in enumerate(arr):
    if el == "\\":
        down.append(i)
    elif el == "/" and not len(down) == 0:
        start_ind = down.pop()
        area = i - start_ind
        while len(areas) > 0 and areas[-1][0] > start_ind:
            area += areas.pop()[1]
        areas.append((start_ind, area))
    # print("LOOP: {}".format(i))
    # print("DOWN INDICES")
    # print(down)
    # print("AREAS")
    # print(areas)
    # print()
 
areas = [areas[i][1] for i in range(len(areas))]
print(sum(areas))
if len(areas) == 0:
    print("0")
else:
    print(len(areas), " ".join(map(str,areas)))

Submission status: Runtime Error

Solution code:
A = input()
#高さ、面積,位置
st = [(0, 0, -1)]
#高さ、高さの最高値？
cur = 0; ma = 0
for i, a in enumerate(A):
    if a == '/':
        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 a == '\\':
        cur -= 1
        st.append((cur, 0, i))
    elif c == '_':
        st.append((cur, 0, i))
ans = []
for lev, su, j in st:
    if su > 0:
        and.append(su)
print(sum(ans))
print(len(ans), *ans)

Submission status: Runtime Error

Solution code:
A = input()
#高さ、面積,位置
st = [(0, 0, -1)]
#高さ、高さの最高値？
cur = 0; ma = 0
for i, a in enumerate(A):
    if a == '/':
        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 a == '\\':
        cur -= 1
        st.append((cur, 0, i))
    elif a == '_':
        st.append((cur, 0, i))
ans = []
for lev, su, j in st:
    if su > 0:
        and.append(su)
print(sum(ans))
print(len(ans), *ans)

Submission status: Runtime Error

Solution code:
A = input()
st = [(0, 0, -1)]
cur = 0; ma = 0
for i, a in enumerate(A):
    if a == '/':
        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 a == '\\':
        cur -= 1
        st.append((cur, 0, i))
    elif a == '_':
        st.append((cur, 0, i))
ans = []
for lev, su, j in st:
    if su > 0:
        and.append(su)
print(sum(ans))
print(len(ans), *ans)

Submission status: Runtime Error

Solution code:
section = raw_input( )
depth = 0
area = 0
depthArr = deque( )
areaArr = deque( )

for i, ground in enumerate( section ):
	if "\\" == ground:
		depth += 1
		depthArr.append( i )
	elif 0 < depth and "/" == ground:
		if len( depthArr ):
			j = depthArr.pop( )
			pool =  i - j
			area += pool

			while len( areaArr ):
				preJ, prePool = areaArr.pop( )
				if j <= preJ:
					pool += prePool
				else:
					areaArr.append( ( preJ, prePool ) )
					break
			areaArr.append( ( j, pool ) )

print( area )
output = []
output.append( len( areaArr ) )
for arr in areaArr:
	output.append( arr[1] )
print( " ".join( map( str, output ) ) )

Submission status: Runtime Error

Solution code:
import collections
import sys

S1 = collections.deque()
S2 = collections.deque()

f = open('in47', 'r')

for i, j in enumerate(f.readline()):
    if j == '\\':
        S1.append(i)
    elif j == '/':
        if S1:
            left_edge = S1.pop()
            new_puddle = i - left_edge
            while S2 and (S2[-1][0] > left_edge):
                new_puddle += S2[-1][1]
                S2.pop()
            S2.append((left_edge, new_puddle))
        else:
            pass


print(sum(j for i, j in S2))

print(len(S2), *(j for i, j in S2))

Submission status: Runtime Error

Solution code:
from collections import deque


def marge_ponds(lx, area_of_pond):
    global ponds
    if ponds and ponds[-1][0] > lx:
        return marge_ponds(lx, area_of_pond + ponds.pop()[1])
    return area_of_pond


terrains = input().strip()
x, last_x, ponds = 0, deque(), deque()

for terrain in terrains:
    if terrain == '\\':
        last_x.append(x)
    elif terrain == '/':
        if last_x:
            lx = last_x.pop()
            ponds.append((lx, marge_ponds(lx, x - lx)))
    x += 1

print(sum(pond[1] for pond in ponds))
ponds.insert(0, (0, len(ponds)))
print(' '.join(map(str, [pond[1] for pond in ponds])))

Submission status: Runtime Error

Solution code:
def calc(list):
    #print list
    d = 0
    a = 0.0
    for c in list:
        if c == "\\":
            d += 1
            a += d - 1 + 0.5
        elif c == "_":
            a += d
        else:
            a += d - 1 + 0.5
            d -= 1
    return a

if __name__ == "__main__":
    line = raw_input()
    areas = []
    mode = True
    d = 0
    edge = 0
    for i in range(len(line)):
        c = line[i]
        if mode:
            if c == "\\":
                d += 1
            elif c == "/":
                d -= 1
                if d == 0:
                    areas.append(calc(line[edge:i + 1]))
                    mode = False
        else:
            if c == "\\":
                d += 1
                edge = i
                mode = True
            elif c == "_":
                edge = i
            else:
                edge = i

    last = len(areas)
    high = edge
    if d != 0:
        d = 0
        edge = len(line) - 1
        mode = False
        for i in range(len(line) - 1 , high - 1, -1):
            #print i, line[i], d, edge, mode
            c = line[i]
            if mode:
                if c == "/":
                    d += 1
                elif c == "\\":
                    d -= 1
                    if d == 0:
                        #print i, edge
                        areas.insert(last, calc(line[i:edge + 1]))
                        mode = False
            else:
                if c == "/":
                    d += 1
                    edge = i
                    mode = True
                elif c == "_":
                    edge = i
                else:
                    edge = i

    areas = map(int, areas)
    print sum(areas)
    print len(areas),
    for i in range(len(areas) - 1):
        print areas[i],
    print areas[len(areas) - 1]