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):
S1 = []
S2= []
sum = 0
for i, s in enumerate(input()):
    if s == "\\":
        S1.append(i)
    elif s == "/" and len(S1) > 0:
        j = S1.pop()
        sum += i - j
        a = i - j
        while len(S2) > 0 and S2[-1][0] > j:
            a += S2.pop()[1]
        S2.append((j, a))
print(sum)
sum2 = [str(len(S2))]
for s in S2:
    sum2.append(str(s[1]))
print(" ".join(sum2))

Solution (Python):
s = input()
stack1 = []
stack2 = []
for i in range(len(s)):
    if s[i] == '\\':
        stack1.append(i)
    elif s[i] == '/' and stack1:
        j = stack1.pop()
        area = i-j
        while stack2:
            if stack2[-1][0] < j:
                break
            else:
                area += stack2.pop()[1]
        stack2.append((j,area))
ans = list(stack2[i][1] for i in range(len(stack2)))
print(sum(ans))
if ans:
    print(len(ans),' '.join(map(str,ans)))
else:
    print(0)

Solution (Python):


s = str(input())
l = len(s)

h = [0]
for i in range(l):
    if s[i] == '\\':
        h.append(h[i]-1)
    elif s[i] == '/':
        h.append(h[i]+1)
    else:
        h.append(h[i])

a = []
m = -200000
n = 0
for i in range(l+1):
    if m == h[i] and i != 0:
        a.append([n,i,m])
        m = -200000
    if m < h[i] or i == 0:
        m = h[i]
        n = i
    if (m in h[i+1:]) == False:
        m = -200000

b = []
tmp = 0
for i in range(len(a)):
    for j in range(a[i][0],a[i][1]):
        tmp += a[i][2] - h[j]
        if s[j] == '/':
            tmp += 1 / 2
        elif s[j] == '\\':
            tmp -= 1 / 2
    b.append(int(tmp))
    tmp = 0

if len(b) != 0:
    i=0
    while True:
        if b[i] == 0:
            del b[i]
            i -= 1
        i += 1
        if i == len(b):
            break


A = sum(b)
k = len(b)

print(A)
print(k,end = '')
if k != 0:
    print(' ',end='')
    for i in range(k-1):
        print(b[i],end=' ')
    print(b[len(b)-1])
else:
    print('')

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

Solution (Python):
inp = input()


lst = list(inp)
stk = []
stk2 = []

for i in range(len(lst)):
    if lst[i] == '\\':
        stk.append(i)
    if lst[i] == '/' and len(stk)>0:
        idx = stk.pop()
        a = i - idx
        if len(stk2) > 0:
            while(len(stk2) > 0):
                tmp = stk2.pop()
                if idx < tmp[0]:
                    a += tmp[1]
                else:
                    stk2.append(tmp)
                    break
        stk2.append([idx, a])

s = 0
l = []

for i in stk2:
    l.append((i[1]))
    s += i[1]
print(s)
if(len(stk2) > 0):
    print(len(stk2), end=' ')
    print(*l)
else:
    print("0")

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

POOL = []
LOC = []
cnt = 0
sum_S = 0

line = input()

for c in line:
    if c == "\\":
        LOC.append(cnt)
    elif c == "/":
        if len(LOC) == 0:
            continue
        tmp_start = LOC.pop()
        tmp_end = cnt
        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
    cnt += 1

lst = [len(POOL)]
for i in range(len(POOL)):
    lst.append(POOL[i].S)
print(sum_S)
print(*lst)

Solution (Python):
def main():
    S = input()

    def an_area(S):
        ans = 0
        stack_in = []
        stack_out = []
        for i,ch in enumerate(S):
            if ch == '\\':
                stack_in.append(i)
            elif stack_in and ch == '/':
                j = stack_in.pop()
                cur =  i - j
                stack_out.append((j,i,cur))
                ans += cur
        return ans,stack_out

    ans, l = an_area(S)
    if ans == 0:
        print(ans)
        print(len(l))
        return

    l.sort()
    pre_le, pre_ri = l[0][0], l[0][1]
    pre_ar = 0
    areas = []
    for le,ri,ar in l:
        if pre_le <= ri <= pre_ri:
            pre_ar += ar
        else:
            areas.append(pre_ar)
            pre_ar = ar
            pre_le, pre_ri = le, ri
    else:
        areas.append(pre_ar)
    
    print(ans)
    print(len(areas),*areas)

if __name__ == '__main__':
    main()

Solution (Python):
value = input();

j = 0
s = 0
n = len(value)
stack1 = list()
stack2 = []
while(j < n):
    if value[j] == '\\':
        stack1.append(j)
    if value[j] == '/' :
        if len(stack1) != 0:
            idx1 = stack1[-1]
            idx2 = j
            stack2.append([idx1,idx2 - idx1])
            stack1.pop(-1)
            s += 1
    if s - 2 >= 0:
        if stack2[s-1][0] < stack2[s-2][0]:
            stack2[s-2][0] = stack2[s-1][0]
            stack2[s-2][1] += stack2[s-1][1]
            s -= 1
            stack2.pop(-1)
        
    j += 1

if s - 2 >= 0:
    for i in reversed(range(2, s+1)):
        if stack2[i-1][0] < stack2[i-2][0]:
            stack2[i-2][0] = stack2[i-1][0]
            stack2[i-2][1] += stack2[i-1][1]
            
            stack2.pop(i-1)


sumi = 0
s = len(stack2)
for i in range(0, s):
    sumi += stack2[i][1]
    
print(sumi)
if sumi == 0:
    print(s)
else:
    print(s, end = " ")

for i in range(0, s):
    if i != s - 1:
        print(stack2[i][1], end=" ")
    else:
        print(stack2[i][1])

Solution (Python):
s = input()
left_index = []
puddles = []

for i in range(len(s)):
    if s[i] == "\\":
        left_index.append(i)

    elif s[i] == "/" and len(left_index) > 0:
        left = left_index.pop()
        puddle = i - left

        while len(puddles) > 0 and puddles[-1][0] > left:
            puddle += puddles.pop()[1]

        puddles.append([left, puddle])

ans = [p[1] for p in puddles]
print(sum(ans))
if len(ans): print(len(ans), " ".join(map(str, ans)))
else : print(len(ans))

Solution (Python):
s = input()
n = len(s)
St = []
St2 = []
h = 0
area = 0

for i in range(n):
    if s[i] == "\\":
        St.append(i)
        h -= 1
    elif s[i] == "/":
        h += 1
        if St:
            left = St.pop()
            area += i - left
            
            area2 = 0
            while St2:
                left2 = St2.pop()
                j = left2[0]
                if left < left2[0]:
                    area_add = left2[1]
                    area2 += area_add
                else:
                    St2.append(left2)
                    break
            St2.append([left, area2 + i-left])


print(area)
ans = [t[1] for t in St2]
if St2:
    print(len(St2), end = " ")
    print(*ans)

else:
    print(0)

Solution (Python):
x = input()
S1 = []
S2 = []
current_position = 0
total_area = 0

for i in x:
    if i == '\\':
        S1.append(current_position)

    elif i == '/':
        try:
            start_position = S1.pop()
            distance = current_position - start_position
            total_area += distance
            S2.append([start_position, distance])

        except:
            continue

    current_position += 1

print(total_area)

S2.insert(0, [-1, -1])
S3 = []
if len(S2) == 1:print(0)
else:
    for i in range(len(S2)-1, -1, -1):
        x, y = S2[i]
        px, py = S2[i-1]
        if x < px:
            S2[i-1] = [x, y + py]
        else:
            S3.append(S2[i])

    print(len(S3), *[j for i, j in S3[::-1]])

Solution (Python):
import sys
input = sys.stdin.readline

area_data = input()
total_area = 0
temp_area = 0

stack1 = []
stack2 = []

now_position = 0
for c in area_data:
    if c == '\\':
        stack1.append(now_position)
    elif c == '/':
        if len(stack1) > 0:
            last_potision = stack1.pop()
            temp_area = (now_position - last_potision)
            total_area += temp_area  

            
            while len(stack2) > 0:
                prev_spot = stack2.pop()
                
                
                if prev_spot[0] > last_potision:
                    temp_area += prev_spot[1]
                else:
                    stack2.append(prev_spot)
                    break

            stack2.append((last_potision, temp_area))

        

    now_position += 1

print(total_area)
print(len(stack2), end="")
for s in stack2:
    print(" ", end="")
    print(s[1], end="")
print()

Solution (Python):
from typing import Generic, List, TypeVar

T = TypeVar('T')

class Stack(Generic[T]):
	def __init__(self) -> None:
		self._container: List[T] = []
					
	@property
	def empty(self) -> bool:
		return not self._container 
	
	def push(self, item: T) -> None:
		self._container.append(item)

	def pop(self) -> T:
		return self._container.pop() 
	
	def __repr__(self) -> str:
		return repr(self._container)


if __name__ == "__main__":
	stack1 = Stack()
	stack2 = Stack()
	string = input()
	sum = 0
	for i in range(len(string)):
		if string[i] == "\\":
			stack1.push(i)
		elif string[i] == "_":
			pass
		elif string[i] == "/":
			if not stack1.empty:
				j = stack1.pop()
				sum += i - j
				a = i - j
				while not stack2.empty:
					item = stack2.pop()
					if item[0] <= j:
						stack2.push(item)
						break
					else:
						a += item[1]
				stack2.push((j, a))
	print(sum)
	b = []
	while not stack2.empty:
		b.append(str(stack2.pop()[1]))
	b.append(str(len(b)))
	b.reverse()
	print(' '.join(b))

Solution (Python):





chikei = input()
v_lakes = []  
idx_stack = []  

for i, c in enumerate(chikei):
    if c is '\\':
        idx_stack.append(i)
    elif c is '/' and idx_stack:
        j = idx_stack.pop()  
        v = i-j
        
        
        while v_lakes and j < v_lakes[-1][0]:
            
            v += v_lakes.pop()[1]
        v_lakes.append((j, v))

ans = [len(v_lakes)]
v = [v[1] for v in v_lakes]
ans.extend(v)

print(sum(v))
print(*ans)

Solution (Python):
n = input()

s1 = []
s2 = []

for i in range(len(n)):
    if n[i] == '\\':
        s1.append(i)
    elif n[i] == '/' and len(s1) > 0:
        a = s1.pop(-1)
        s2.append([a, i - a])

i = 0
while len(s2) > 1:
    if i == len(s2) - 1:
        break
    elif s2[i][0] > s2[i + 1][0]:
        s2[i + 1][1] += s2.pop(i)[1]
        i = 0
    else:
        i += 1

s = []
total = 0
for i in s2:
    s.append(str(int(i[1])))
    total += int(i[1])
print(total)
if len(s2) == 0:
    print('0')
else:
    print('{} {}'.format(len(s2), ' '.join(s)))

Solution (Python):
"""
スタックのデータ構造の定義
"""

class Stack:
    def __init__(self):
        self.stack = []

    def push(self, num):
        self.stack.append(num)

    def individual_push(self, num):
        self.stack.append(num)

    def pop(self):
        if len(self.stack) > 0:
            return True, self.stack.pop(-1)
        else:
            return False, 0
    
    def push_individual(self, left_index, current_index):
        sum_a = 0
        for pair in reversed(self.stack):
            if pair[0] > left_index:
                _, a = self.pop()
                sum_a += a[1]
            else:
                break
        self.push((left_index, sum_a + (current_index - left_index)))

    def print_individual_volume(self):
        volume_list = [str(s[1]) for s in self.stack]
        if len(volume_list) == 0:
            print(0)
        else:
            print("{} ".format(len(volume_list)) + " ".join(volume_list))


if __name__=="__main__":
    input_values = input()

    stack1 = Stack()
    stack2 = Stack()
    area_sum = 0

    for i, v in enumerate(input_values):
        

        if v == "\\":
            stack1.push(i)
        elif v == "/":
            result, pop_value = stack1.pop()
            if result:
                area = i - pop_value
                stack2.push_individual(pop_value, i)
            else:
                area = 0
            area_sum += area

    print(area_sum)
    stack2.print_individual_volume()

Solution (Python):
from collections import deque

if __name__ == '__main__':
    s = input()
    s1 = deque()
    s2 = deque()
    summ = 0
    for i, c in enumerate(s):
        if c == '\\':
            s1.append(i)
        elif s[i] == '/' and len(s1) > 0:
            j = s1.pop()
            summ += i-j
            a = i-j
            while len(s2) > 0 and s2[-1][0] > j:
                a+= s2.pop()[1]
            s2.append([j, a])
    
    ans = []
    while len(s2) > 0:
        ans.append(s2.pop()[1])
    ans.reverse()
    print(sum(ans))
    counter = len(ans)
    ans.insert(0, counter)
    a = list(map(str, ans))
    print(' '.join(a))

Solution (Python):


s = input()
s = list(s)  

s1 = []  


class S2:
    
    def __init__(self):
        self.point = []
        self.size = []

    def append(self, x, y):
        lake_size = y
        if not self.point:  
            self.point.append(x)
            self.size.append(lake_size)
        else:
            if self.point[-1] < x:
                self.point.append(x)
                self.size.append(lake_size)
            else:
                while self.point[-1] > x:
                    
                    self.point.pop()
                    lake_size += self.size[-1]
                    self.size.pop()
                    if not self.point:
                        break
                self.point.append(x)
                self.size.append(lake_size)
        
        return self

    def pop(self):
        x = self.point.pop()
        y = self.size.pop()
        return x, y

    def sum_size(self):
        sum_size = sum(self.size)
        return sum_size


s2 = S2()

for i in range(len(s)):
    if s[i] is '\\':
        s1.append(i)
    elif s[i] is '/':
        if s1:  
            lake_point = s1.pop()
            lake_size = i - lake_point
            

            s2.append(lake_point, lake_size)

total = s2.sum_size()
lake_num = len(s2.size)


print(total)
print(lake_num, end='')
for i in range(len(s2.size)):
    print('', s2.size[i], end='')
print('')

Solution (Python):
s=input()
stack_all=[]
stack_A=[]
point=0

for i,j in enumerate(s):
    if j=="\\":
        stack_all.append(i)
    elif j=="/":
        try:
            left=stack_all.pop()
            po=i-left
            point +=po
            stack_A.append([left,po])
        except:continue
print(point)



stack_A.insert(0,[-1,-1])
stack_B=[]
if len(stack_A)==1:print(0)
else:
    for i in range(len(stack_A)-1,-1,-1):
        x,y=stack_A[i]
        px,py=stack_A[i-1]
        if x<px:
            stack_A[i-1]=[x,y+py]
        else:
            stack_B.append(stack_A[i])
    print(len(stack_B),*[j for i,j in stack_B[::-1]])

Solution (Python):
s = input()

length = len(s)

a = [0] * (length + 1)
b = [0] * length
y = 0
for i in range(length):
    if s[i] == '/':
        y += 1
    elif s[i] == '\\':
        y -= 1
    a[i + 1] = y

m = -30000
for i in range(length, 0, -1):
    m = max(m, a[i])
    b[i - 1] = m

i = 0
memory = []
while i < length:
    if a[i] > b[i]:
        i += 1
        continue

    start = a[i]
    i += 1
    base = 1
    d_from = s[i - 1]
    ws_part = 0
    while i < length + 1 and a[i] < start:
        d_to = s[i]
        ws_part += base
        if d_from == '\\' and d_to == '\\':
            base += 2
        if d_from == '\\' and d_to == '_':
            base += 1
        if d_from == '/' and d_to == '/':
            base -= 2
        if d_from == '/' and d_to == '_':
            base -= 1
        if d_from == '_' and d_to == '\\':
            base += 1
        if d_from == '_' and d_to == '/':
            base -= 1
        d_from = d_to
        i += 1

    if ws_part > 0:
        ws_part += 1
        memory.append(ws_part // 2)

print(sum(memory))
if memory:
    print(len(memory), ' '.join(map(str, memory)))
else:
    print(len(memory))

Solution (Python):


def areas_calc(strings):
    stack1 = []
    stack2 = []
    total_m = 0
    for i, s in enumerate(strings):
        if s == "\\":
            stack1.append(i)
        elif s == "_":
            continue
        elif s == '/':
            if len(stack1) > 0:
                previous_i = stack1.pop()
                m = i - previous_i
                total_m += m

                while len(stack2) > 0:
                    stacked_i, stacked_m = stack2.pop()
                    if previous_i < stacked_i:
                        m += stacked_m
                    else:
                        stack2.append((stacked_i, stacked_m))
                        stack2.append((previous_i, m))
                        break

                else:
                    stack2.append((previous_i, m))
    print(total_m)
    k = len(stack2)
    for_output = [str(k)] + [str(m) for i, m in stack2]
    print(' '.join(for_output))
    

if __name__ == "__main__":
    areas_calc(input())

Solution (Python):
import sys
from collections import deque

def test():

	EleList = deque()
	sublist = []
	output = []
	areas_from_left = list(sys.stdin.readline())
	sum = 0
	depth = 0

	for element in areas_from_left:

		if element == '\\':
			depth += 1
			EleList.append(element)

		elif element == '_':
			if EleList:
				EleList.append(element)

		elif element == '/':
			depth -= 1
			if EleList:
				for pop_count in range(len(EleList)):
				
					pop_ele = EleList.pop()
					if pop_ele == '\\' and EleList:
						for i in range(pop_count+2):
							EleList.append('_')
						break
				lake = pop_count + 1
				sum += lake

				if len(EleList) == 0:
					if len(sublist) == 0:
						output.append(lake)
					else:
						tmp = 0
						for i in sublist:
							tmp += i[0]
						output.append(tmp + lake)
						sublist.clear()
				else:
					
					if not sublist or sublist[len(sublist)-1][1] < depth:
						sublist_element = [0,0]
						sublist_element[0] = lake
						sublist_element[1] = depth
						sublist.append(sublist_element)
					
					else:

						sublist_element = [lake,depth]

						while True:
							
							if not sublist:
								break

							tmp = sublist.pop()
							if tmp[1] > depth:
								sublist_element[0] += tmp[0]
							else:
								sublist.append(tmp)
								break

						sublist.append(sublist_element)
				

	output_sublist = []
	for tmp in sublist:
		output_sublist.append(tmp[0])

	output = output + output_sublist
	length = len(output)

	print(sum)
	if length != 0:
		print(f"{length} ",end='')
	else:
		print(length)
	

	for i in range(length - 1):
		print(f"{output[i]} ",end='')
	if output:
		print(output[length-1])

if __name__ == "__main__":
	test()

Solution (Python):
s=input()
s1=[]
s2=[]
ans=[]
a=0
a1=0
for i in range(len(s)):
    if s[i]=="\\":
        s1.append(i)
    elif s[i]=="/" and s1:
        i2=s1[-1]
        a1=i-i2
        a+=a1
        while s2 and s2[-1][0]>i2:
            a1+=s2[-1][1]
            s2.pop()
        s2.append([i2,a1])
        s1.pop()


n=len(s2)
for j in range(n):
  ans.append(s2[j][1])
print(a)
print(n,*(ans))

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):
pos_latest = []

surface = input()

total = []
total_x = []
y = 0
x = 0
total_tmp = 0
for i in range(len(surface)):
    if surface[i] == "\\":
        pos_latest.append(x)
    if surface[i] == "/":
        if pos_latest:
            pos = pos_latest.pop()
            total.append(x-pos)
            total_x.append([pos, x, x-pos])
    x += 1

if sum(total) > 0:
    sorted_total_x = sorted(total_x)
    t_base = sorted_total_x[0][1]
    tmp = sorted_total_x[0][2]
    res = []
    
    for f, t, v in sorted_total_x[1:]:
        if t <= t_base:
            tmp += v
        else:
            res.append(int(tmp))
            tmp = v
            t_base = t
        if sum(res)>=sum(total):
            break
    res.append(int(tmp))

    print(sum(res))
    print(len(res), *res, sep=" ")
    
else:
    print(sum(total))
    print(0)

Solution (Python):
data =input()
s1 =[]
ans =[]
memo=-1
for i in range(len(data)):
	if data[i]=='\\':
		s1.append(i)
	if data[i]=='/':
		if len(s1)==0:pass
		
		
		else:
			a = i-s1[-1]
			while len(ans)!=0:
				if ans[-1][1]<=s1[-1]:break
				a+=ans.pop()[0]
			ans.append([a,s1.pop()])

	
ans2=[int(ans[i][0]) for i in range(len(ans))]
print(sum(ans2))
print(len(ans),end='')
if len(ans):
	print('',end=' ')
print(' '.join(list(map(str,ans2))))

Solution (Python):
S = raw_input()

areas = []
stack = []
for i,c in enumerate(S):
    if c == "\\":
        stack.append(i)
    elif c == "/":
        if len(stack) > 0:
            j = stack.pop()
            area = i-j
            while len(areas) > 0:
                p,a = areas.pop()
                if j < p:
                    area += a
                else:
                    areas.append((p, a))
                    break
            areas.append((j, area))

A = map(lambda x:x[1], areas)
print sum(A)
if len(A) == 0:
    print "0"
else:
    print len(A), " ".join(map(str, A))

Solution (Python):
import sys
from collections import deque


def input(): return sys.stdin.readline().strip()


L = []
T = deque()
A = deque()
left = 0
total = 0

s = input()
for i, c in enumerate(s):
    if c == '\\':
        T.append(i)
    elif c == '/':
        if len(T) == 0:
            continue
        if i == 0:
            continue
        left = T.pop()
        area = (left, i - left)
        A.append(area)
        total += area[1]

while len(A) > 0:
    if len(A) == 1:
        a1 = A.pop()
        L.append(str(a1[1]))
        break
    a1 = A.pop()
    a2 = A.pop()
    if a1[0] < a2[0]:
        A.append((a1[0], a1[1] + a2[1]))
    else:
        L.append(str(a1[1]))
        A.append(a2)

print(total)
L.reverse()
print((str(len(L)) + ' ' + ' '.join(L)).strip())

Solution (Python):
total_stack = []
single_stack = []

def main():
    input_line = input()
    total = 0

    for i,s in enumerate(input_line):
        if s == "\\":
            total_stack.append(i)
        elif s == "/" and len(total_stack) != 0:
            a = total_stack.pop()
            total += i - a
            area = 0
            while len(single_stack) != 0 and a < single_stack[-1][0]:
                area += single_stack.pop()[1]
            single_stack.append([a, area + i - a])

    print(total)
    print(' '.join([str(len(single_stack))] + [str(i[1]) for i in single_stack]))

if __name__ == '__main__':
    main()

Solution (Python):
S = input()
A = []
down = [] 
Asum = 0

for i, line in enumerate(S):
    if line == "\\":  
        down.append(i)
    elif line == "/" and down:
        j = down.pop()
        temp = i - j
        Asum += temp
        while A and A[-1][0] > j:
            temp += A.pop()[1]
        A.append([j, temp])

print(Asum)
print(len(A), *[S for i, S in A])

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):
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()

Solution (Python):
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()

Solution (Python):
from collections import deque


def main():
    sequence = input()
    stack = deque()
    pools = deque()
    for i, e in enumerate(sequence):
        if e == '\\':
            stack.append(i)
        elif e == '_':
            continue
        else:
            if len(stack) == 0:
                continue
            pre = stack.pop()
            s = 0
            while len(pools) > 0 and pre < pools[-1][1]:
                tmp = pools.pop()
                s += tmp[0]
            pools.append((s + i - pre, i))
    length = str(len(pools))
    results = list(map(lambda x: x[0], pools))
    print(sum(results))
    print(' '.join([length] + [str(r) for r in results]))


if __name__ == '__main__':
    main()

Solution (Python):
from typing import List


class Info:
    def __init__(self, arg_start, arg_end, arg_area):
        self.start = arg_start
        self.end = arg_end
        self.area = arg_area


if __name__ == "__main__":
    LOC: List[int] = []
    POOL: List[Info] = []
    all_symbols = input()
    loc = 0
    total_area = 0

    for symbol in all_symbols:
        if symbol == '\\':
            LOC.append(loc)

        elif symbol == '/':
            if len(LOC) == 0:
                continue

            tmp_start = int(LOC.pop())
            tmp_end = loc
            tmp_area = tmp_end - tmp_start
            total_area += tmp_area

            while len(POOL) > 0:
                
                
                if tmp_start < POOL[-1].start and POOL[-1].end < tmp_end:
                    tmp_area += POOL[-1].area
                    POOL.pop()
                else:
                    break

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

        else:
            pass

        loc += 1

    print(f"{total_area}")
    print(f"{len(POOL)}", end="")
    while len(POOL) > 0:
        print(f" {POOL[0].area}", end="")
        POOL.pop(0)
    print()

Solution (Python):
if __name__ == '__main__':
    s1 = []
    s2 = []

    data = input()
    total_sum = 0
    for i in range(len(data)):
        if data[i] == '\\':
            s1.append(i)
        elif data[i] == '/' and len(s1) > 0:
            j = s1.pop()
            a = i - j
            total_sum += a

            while (len(s2) and s2[-1][0] > j):
                temp = s2.pop()
                a += temp[1]
            s2.append([j, a])

    print(total_sum)
    length = len(s2)
    if not length:
        print(length)
    else:
        print(length, end=' ')
    for i in range(0, length):
        endl = ' '
        if i == length - 1:
            endl = '\n'
        print(s2[i][1], end=endl)

Solution (Python):
"""


 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())


 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  


a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

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

Solution (Python):
from collections import deque
from sys import stdin
data = list(stdin.readline().rstrip())
i_stack, a_stack, b_stack = deque(), deque(), deque()
ans = 0
for i, c in enumerate(data):
    if c == '\\':
        i_stack.append(i)
    elif c == '/' and len(i_stack) != 0:
        j = i_stack.pop()
        diff = i - j
        ans += diff 
        while a_stack and a_stack[-1] > j:
            diff += b_stack.pop()
            a_stack.pop()
        a_stack.append(j)
        b_stack.append(diff)
print(ans)
print(len(a_stack), *b_stack)