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: Time Limit Exceeded

Solution code:
from time import process_time
import sys

t1 = process_time()

input_list = list(sys.stdin.readline())
input_list.remove('\n')

#print("input_list created")

height_list = [0]
height = 0
for d in input_list:
    if d == '\\':
        height += -1
        height_list.append(height)
    if d == '/':
        height += 1
        height_list.append(height)
    if d == '_':
        height_list.append(height)

highest = max(height_list)
lowest = min(height_list)
flag = False
left_side_index = 0
right_side_index = 0
left_and_right_dict = {} # key = left_side_index, value = right_side_index
skip_indices = []
while highest != lowest:
    for i in range(len(height_list)):
        if i in skip_indices:
            continue
        else:
            if height_list[i] != highest:
                continue
            else:
                if i != len(height_list) - 1 and input_list[i] == '\\':
                    for k in range(i + 1, len(height_list)):
                        if height_list[k] != highest:
                            continue
                        else:
                            if input_list[k-1] == '/':
                                left_side_index = i
                                right_side_index = k
                                flag = True
                                break
                # Get the width of a puddle
                if flag:
                    left_and_right_dict[left_side_index] = right_side_index
                    for j in range(left_side_index, right_side_index):
                        skip_indices.append(j)
                    flag = False
    highest += -1

area_list = []
for left in sorted(left_and_right_dict.keys()):
    area = 0
    surface = height_list[left]
    for i in range(left, left_and_right_dict[left]):
        if input_list[i] == '\\':
            area += abs(surface - height_list[i+1]) - 0.5
        if input_list[i] == '/':
            area += abs(surface - height_list[i]) - 0.5
        if input_list[i] == '_':
            area += abs(surface - height_list[i])
    area_list.append(int(area))

print(sum(area_list))
if area_list != []:
    print(len(area_list), end = ' ')
    print(*area_list)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
#! python3
# areas_on_the_cross_section_diagram.py

cross_section = input()
cross_section_height = [0]
for i in range(len(cross_section)):
    if cross_section[i] == '\\':
        cross_section_height.append(cross_section_height[i]-1)
    elif cross_section[i] == '_':
        cross_section_height.append(cross_section_height[i])
    elif cross_section[i] == '/':
        cross_section_height.append(cross_section_height[i]+1)

# 水たまりを探す
# 左から探す
puddles = []
width = len(cross_section_height)
i = 0
while i < width-2:
    # i とペアとなる高さ
    is_down = False
    for j in range(i+1, width):
        if cross_section_height[j] > cross_section_height[i]:
            i += 1
            break
        elif cross_section_height[j] < cross_section_height[i]:
            is_down = True
        else:
            if is_down:
                puddles.append([i, j])
            i = j
            break

        if j == width-1:
            i += 1

# 面積の計算
puddle_areas = []
for start, end in puddles:
    area = 0
    for i in range(start+1, end+1):
        if cross_section[i-1] == '_':
            area += cross_section_height[start] - cross_section_height[i]
        elif cross_section[i-1] == '/':
            area += cross_section_height[start] - cross_section_height[i] + 0.5
        else:
            area +=cross_section_height[start] - cross_section_height[i] -  0.5
    puddle_areas.append(int(area))


if len(puddle_areas) == 0:
    print("0\n0")
else:
    print(sum(puddle_areas))
    print(len(puddle_areas), ' '.join([str(x) for x in puddle_areas]))

Submission status: Time Limit Exceeded

Solution code:
def print_list_split_whitespace(a):
    for x in a[:-1]:
        print(x, end=' ')
    print(a[-1])


def calc_puddle(map, l, r):
    ans = 0
    top = map[l]
    before = map[l]
    for i in range(l + 1, r + 1):
        be_ans = ans
        if map[i] == before:
           ans += top - map[i]
        elif map[i] < before:
            ans += top - map[i] - 0.5
            before = map[i]
        else:
            ans += top - map[i] + 0.5
            before = map[i]
        #print(ans - be_ans)
    return int(ans)


cross_section = list(input())
map = [0]
y = 0
for c in cross_section:
    if c == "/":
        y += 1
        map.append(y)
    elif c == "\\":
        y += -1
        map.append(y)
    else:
        map.append(y)
max_right = len(map) - 1
#print(map)
#print(len(map))

left = 0
right = 1
ans = []
while left < max_right:
    #print(left, right)
    if map[left] <= map[right]:
        left = right
        right += 1
        if right == max_right:
            left = max_right
    elif right == max_right:
        break
    else:
        right += 1
        if map[left] == map[right]:
            ans.append(calc_puddle(map, left, right))
        elif right == max_right:
            left += 1
            right = left + 1
            if right == max_right:
                left = max_right

print(sum(ans))
ans.insert(0, len(ans))
print_list_split_whitespace(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    altitutes = [0]
    for s in stdinput():
        if s == '\\':
            altitutes.append(altitutes[-1] - 1)
        elif s == '_':
            altitutes.append(altitutes[-1])
        elif s == '/':
            altitutes.append(altitutes[-1] + 1)

    edges = []
    n = len(altitutes)
    for i in range(n):
        level = altitutes[i]
        m_idx = i - 1
        for j in range(i - 1, -1, -1):
            if altitutes[j] > level:
                break
            if altitutes[j] == level:
                m_idx = j
                break
        edges.append([m_idx, i])

    areas = []
    begin, end = edges[-1]
    while begin != -1:
        area = calc_area(altitutes, begin, end)
        if area > 0:
            areas.append(area)
        begin, end = edges[begin]
    areas = areas[::-1]

    print(int(sum(areas)))
    print(*([len(areas)] + [*map(int, areas)]))

def calc_area(A, begin, end):
    if A[begin] != A[end]:
        return 0
    b_level = A[begin]
    area = 0
    for l1, l2 in zip(range(begin, end), range(begin+1, end + 1)):
        a1 = A[l1]
        a2 = A[l2]
        area += (b_level - a1 + b_level - a2) * 1 / 2
    return area

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    altitutes = load_data()

    edges = create_edges(altitutes)

    areas = calc_areas(altitutes, edges)

    print(int(sum(areas)))
    print(*([len(areas)] + [*map(int, areas)]))

def load_data():
    A = [0]
    for s in stdinput():
        if s == '\\':
            A.append(A[-1] - 1)
        elif s == '_':
            A.append(A[-1])
        elif s == '/':
            A.append(A[-1] + 1) 
    return A

def create_edges(A):
    edges = []
    n = len(A)
    i = 0
    while i < n - 1:
        j = i + 1
        while  j < n and A[i] > A[j]:
            j += 1
        if j == n:
            j = i + 1
        edges.append([i, j])
        i = j
    return edges

def calc_areas(A, edges):
    areas = []

    for begin, end in edges:
        area = calc_area(A, begin, end)
        if area > 0:
            areas.append(area)
    return areas

def calc_area(A, begin, end):
    if A[begin] != A[end]:
        return 0
    b_level = A[begin]
    area = 0
    for l1, l2 in zip(range(begin, end), range(begin+1, end + 1)):
        a1 = A[l1]
        a2 = A[l2]
        area += (b_level - a1 + b_level - a2) * 1 / 2
    return area

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')

Submission status: Time Limit Exceeded

Solution code:
MAP = {'\\': 1, '_': 0, '/': -1}

input_str = input()
this_depth = 0
depth_list = [this_depth]
for c in input_str:
    this_depth += MAP[c]
    depth_list.append(this_depth)

min_depth = min(depth_list)
max_depth = max(depth_list)
length = len(depth_list)
holes = [(-1, -1)] * length
for target_depth in range(min_depth, max_depth + 1):
    i = 0
    l = [i for i in range(len(depth_list)) if depth_list[i] == target_depth]
    for j in range(len(l) - 1):
        area = 0
        for k in range(l[j] + 1, l[j + 1]):
            area += depth_list[k] - target_depth
            depth_list[k] = target_depth
        holes.append((l[j], area))

cnt = 0
sum = 0
holes = [h for h in holes if h[1] and h[1] > 0]
holes = sorted(holes, key=lambda hole: hole[0])
areas = []
for h in holes:
    cnt += 1
    sum += h[1]
    areas.append(h[1])
print(sum)
print(" ".join(map(str, [cnt] + areas)))

Submission status: Time Limit Exceeded

Solution code:
MAP = {'\\': 1, '_': 0, '/': -1}

input_str = input()
this_depth = 0
depth_list = [this_depth]
for c in input_str:
    this_depth += MAP[c]
    depth_list.append(this_depth)

min_depth = min(depth_list)
max_depth = max(depth_list)
length = len(depth_list)
holes = [(-1, -1)] * length
for target_depth in range(min_depth, max_depth + 1):
    i = 0
    l = [i for i in range(len(depth_list)) if depth_list[i] == target_depth]
    for j in range(len(l) - 1):
        area = 0
        for k in range(l[j] + 1, l[j + 1]):
            area += depth_list[k] - target_depth
            depth_list[k] = target_depth
        holes.append((l[j], area))

holes = [h[1]for h in sorted(
    [h for h in holes if h[1] and h[1] > 0], key=lambda hole: hole[0])]
print(sum(holes))
print(" ".join(map(str, [len(holes)] + holes)))

Submission status: Time Limit Exceeded

Solution code:
MAP = {'\\': 1, '_': 0, '/': -1}

input_str = input()
this_depth = 0
depth_list = [this_depth]
for c in input_str:
    this_depth += MAP[c]
    depth_list.append(this_depth)

min_depth = min(depth_list)
max_depth = max(depth_list)
length = len(depth_list)
holes = [(-1, -1)] * length
for target_depth in range(min_depth, max_depth + 1):
    i = 0
    l = [i for i in range(len(depth_list)) if depth_list[i] == target_depth]
    for j in range(len(l) - 1):
        area = 0
        for k in range(l[j] + 1, l[j + 1]):
            area += depth_list[k] - target_depth
            depth_list[k] = target_depth
            if area <= 0:
                break
        holes.append((l[j], area))

holes = [h[1]for h in sorted(
    [h for h in holes if h[1] and h[1] > 0], key=lambda hole: hole[0])]
print(sum(holes))
print(" ".join(map(str, [len(holes)] + holes)))

Submission status: Time Limit Exceeded

Solution code:
input_str = input()
this_depth = 0
depth_list = [this_depth]
for c in input_str:
    if c == '\\':
        this_depth += 1
    elif c == '_':
        this_depth += 0
    else:
        this_depth += -1
    depth_list.append(this_depth)

min_depth = min(depth_list)
max_depth = max(depth_list)
length = len(depth_list)
holes = [(-1, -1)] * length
for target_depth in range(min_depth, max_depth + 1):
    i = 0
    l = [i for i in range(len(depth_list)) if depth_list[i] == target_depth]
    for j in range(len(l) - 1):
        area = 0
        for k in range(l[j] + 1, l[j + 1]):
            area += depth_list[k] - target_depth
            depth_list[k] = target_depth
        holes.append((l[j], area))

holes = [h[1]for h in sorted(
    [h for h in holes if h[1] and h[1] > 0], key=lambda hole: hole[0])]
print(sum(holes))
print(" ".join(map(str, [len(holes)] + holes)))

Submission status: Time Limit Exceeded

Solution code:
hlist = list(str(input()))
ch = 0
hh = 0
f = 0 #홍수구역인지 아닌지 판단
s = 0
slist = []
chlist = []
for i in range(len(hlist)):
    if (hlist[i] == '/'):
        ch += 1
    elif (hlist[i] == '\\' ):
        ch -= 1
    chlist.append(ch)
ch = 0
for i in range(len(hlist)):
    if (hlist[i] == '/'):
        ch += 1
    elif (hlist[i] == '\\' ):
        ch -= 1
    
    if (hh > max(chlist[i:])):
        hh = max(chlist[i:])
    elif (ch > hh):
        hh = ch
    elif (ch < hh):
        f = 1
    elif (ch == hh and chlist[i] == chlist[i-1] + 1):
        f = 0
        s += 1/2
        slist.append(s)
    
    if (f == 1):
        if (hlist[i] == '/'):
            s += (hh - ch + 1/2)
        elif (hlist[i] == '\\'):
            s += (hh - ch - 1/2)
        elif (hlist[i] == '_'):
            s += (hh - ch)
    elif (f == 0):
        s = 0

print(int(sum(slist)))
if len(slist) != 0:
    print(len(slist), end = ' ')
else:
    print(len(slist), end = '')
for i in range(len(slist)):
    if (i == len(slist) - 1):
        print(int((slist[i])), end = '')
    else:
        print(int((slist[i])), end = ' ')
print()

Submission status: Time Limit Exceeded

Solution code:
hlist = list(str(input()))
ch = 0
hh = 0
f = 0 #홍수구역인지 아닌지 판단
s = 0
slist = []
chlist = []
for i in range(len(hlist)):
    if (hlist[i] == '/'):
        ch += 1
    elif (hlist[i] == '\\' ):
        ch -= 1
    chlist.append(ch)
for i in range(len(hlist)):
    ch = chlist[i]
    
    if (hh > max(chlist[i:])):
        hh = max(chlist[i:])
    elif (ch > hh):
        hh = ch
    elif (ch < hh):
        f = 1
    elif (ch == hh and chlist[i] == chlist[i-1] + 1):
        f = 0
        s += 1/2
        slist.append(s)
    
    if (f == 1):
        if (hlist[i] == '/'):
            s += (hh - ch + 1/2)
        elif (hlist[i] == '\\'):
            s += (hh - ch - 1/2)
        elif (hlist[i] == '_'):
            s += (hh - ch)
    elif (f == 0):
        s = 0

print(int(sum(slist)))
if len(slist) != 0:
    print(len(slist), end = ' ')
else:
    print(len(slist), end = '')
for i in range(len(slist)):
    if (i == len(slist) - 1):
        print(int((slist[i])), end = '')
    else:
        print(int((slist[i])), end = ' ')
print()

Submission status: Time Limit Exceeded

Solution code:
hlist = list(str(input()))
ch = 0
hh = 0
f = 0 #홍수구역인지 아닌지 판단
s = 0
slist = []
chlist = [0]
for i in range(len(hlist)):
    if (hlist[i] == '/'):
        ch += 1
    elif (hlist[i] == '\\' ):
        ch -= 1
    chlist.append(ch)
for i in range(len(hlist)):
    ch = chlist[i+1]
    d = ch - chlist[i]
    if (hh > max(chlist[i+1:])):
        hh = max(chlist[i+1:])
    elif (ch > hh):
        hh = ch
    elif (ch < hh):
        s += ((hh - ch) + d * 0.5)
    elif (ch == hh and chlist[i+1] == chlist[i] + 1):
        f = 0
        s += 1/2
        slist.append(s)
        s = 0


print(int(sum(slist)))
if len(slist) != 0:
    print(len(slist), end = ' ')
else:
    print(len(slist), end = '')
for i in range(len(slist)):
    if (i == len(slist) - 1):
        print(int((slist[i])), end = '')
    else:
        print(int((slist[i])), end = ' ')
print()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
hlist = list(str(input()))
ch = 0
hh = 0
f = 0 #홍수구역인지 아닌지 판단
s = 0
slist = deque()
chlist = [0]
for i in range(len(hlist)):
    if (hlist[i] == '/'):
        ch += 1
    elif (hlist[i] == '\\' ):
        ch -= 1
    chlist.append(ch)
for i in range(len(hlist)):
    ch = chlist[i+1]
    d = ch - chlist[i]
    if (hh > max(chlist[i+1:])):
        hh = max(chlist[i+1:])
    elif (ch > hh):
        hh = ch
    elif (ch < hh):
        s += ((hh - ch) + d * 0.5)
    elif (ch == hh and chlist[i+1] == chlist[i] + 1):
        f = 0
        s += 1/2
        slist.append(int(s))
        s = 0


print(int(sum(slist)))
if len(slist) != 0:
    print(len(slist), end = ' ')
else:
    print(len(slist), end = '')
print(*slist)

Submission status: Time Limit Exceeded

Solution code:
class Cell(object):
    def __init__(self, direction, x, y):
        self.direction = direction
        self.x = x
        self.y = y
        self.is_pond = False
        self.start_of_pond = False
        self.end_of_pond = False

    def get_area(self, pond_height):
        h = pond_height - self.y + 1
        if self.direction == 'f':
            return h - 1
        else:
            return h - 0.5

    @property
    def char(self):
        if self.direction == 'd':
            return '/'
        elif self.direction == 'u':
            return '\\'
        elif self.direction == 'f':
            return '|'

class Area(object):
    def __init__(self):
        self.cells = []
        self.before_c = ''
        self.x = 0
        self.height = 0
        
    @property
    def top(self):
        return max([c.y for c in self.cells])
    
    def put(self, c):
        if c == '\\':
            if self.before_c == '\\':
                self.height -= 1
            self.cells.append(Cell('d', self.x, self.height))
        elif c == '/':
            if self.before_c == '/' or self.before_c == '_':
                self.height += 1
            self.cells.append(Cell('u', self.x, self.height))
        elif c == '_':
            if self.before_c == '\\':
                self.height -= 1
            self.cells.append(Cell('f', self.x, self.height))
        self.x += 1
        self.before_c = c

    def adjust_height(self):
        lowest = min([c.y for c in self.cells])
        for c in self.cells:
            c.y -= lowest
    
    def is_pond(self):
        start_of_pond = None
        for i_start in range(len(self.cells)):
            c_start = self.cells[i_start]
            if c_start.direction == 'u':
                if start_of_pond:
                    if start_of_pond.y == c_start.y:
                        start_of_pond = None
                        c_start.end_of_pond = True
                continue
            if c_start.direction == 'f' and 0 == i_start:
                continue
            if c_start.direction == 'f' and not self.cells[i_start - 1].is_pond:
                continue
            if c_start.direction == 'f' and self.cells[i_start - 1].end_of_pond:
                continue

            for i_end in range(i_start+1, len(self.cells)):
                c_end = self.cells[i_end]
                if c_start.y <= c_end.y:
                    if c_end.direction == 'u':
                        c_start.is_pond = True
                        c_end.is_pond = True
                    elif c_end.direction == 'd':
                        continue
                    elif c_end.direction == 'f':
                        continue
                    break
            if not start_of_pond and c_start.is_pond:
                c_start.start_of_pond = True
                start_of_pond = c_start

    def get_pond_area(self):
        area = []
        _area = 0
        _height = 0
        for c in self.cells:
            if c.start_of_pond:
                _height = c.y
            if c.is_pond:
                _area += c.get_area(_height)
            if c.end_of_pond:
                area.append(int(_area))
                _area = 0
                _height = 0
        return area

    def show(self):
        for i, c in enumerate(self.cells):
            p = 'p' if c.is_pond else ' '
            e = 'E' if c.end_of_pond else ''
            s = 'S' if c.start_of_pond else ''
            print('{0:02d}'.format(i) + p + c.char * (c.y+1) + e + s)

def run():
    area = Area()
    for l in input():
        area.put(l)
    area.adjust_height()
    area.is_pond()
    # area.show()
    pond_area = area.get_pond_area()
    print(sum(pond_area))
    if pond_area:
        print(len(pond_area), ' '.join([str(a) for a in pond_area]))
    else:
        print(0)

if __name__ == '__main__':
    run()

Submission status: Time Limit Exceeded

Solution code:
class Cell(object):
    def __init__(self, direction, x, y):
        self.direction = direction
        self.x = x
        self.y = y
        self.is_pond = False
        self.start_of_pond = False
        self.end_of_pond = False

    def get_area(self, pond_height):
        h = pond_height - self.y + 1
        if self.direction == 'f':
            return h - 1
        else:
            return h - 0.5

    @property
    def char(self):
        if self.direction == 'd':
            return '/'
        elif self.direction == 'u':
            return '\\'
        elif self.direction == 'f':
            return '|'

class Area(object):
    def __init__(self):
        self.cells = {}
        self.before_c = ''
        self.x = 0
        self.height = 0
        
    def put(self, c):
        if c == '\\':
            if self.before_c == '\\':
                self.height -= 1
            self.cells[self.x] = Cell('d', self.x, self.height)
        elif c == '/':
            if self.before_c == '/' or self.before_c == '_':
                self.height += 1
            self.cells[self.x] = Cell('u', self.x, self.height)
        elif c == '_':
            if self.before_c == '\\':
                self.height -= 1
            self.cells[self.x] = Cell('f', self.x, self.height)
        self.x += 1
        self.before_c = c

    def adjust_height(self):
        lowest = min([c.y for i,c in self.cells.items()])
        for i, c in self.cells.items():
            c.y -= lowest
    
    def is_pond(self):
        start_of_pond = None
        for i_start in range(len(self.cells)):
            c_start = self.cells[i_start]
            if c_start.direction == 'u':
                if start_of_pond:
                    if start_of_pond.y == c_start.y:
                        start_of_pond = None
                        c_start.end_of_pond = True
                continue
            if c_start.direction == 'f' and 0 == i_start:
                continue
            if c_start.direction == 'f' and not self.cells[i_start - 1].is_pond:
                continue
            if c_start.direction == 'f' and self.cells[i_start - 1].end_of_pond:
                continue

            for i_end in range(i_start+1, len(self.cells)):
                c_end = self.cells[i_end]
                if c_start.y <= c_end.y:
                    if c_end.direction == 'u':
                        c_start.is_pond = True
                        c_end.is_pond = True
                    elif c_end.direction == 'd':
                        continue
                    elif c_end.direction == 'f':
                        continue
                    break
            if not start_of_pond and c_start.is_pond:
                c_start.start_of_pond = True
                start_of_pond = c_start

    def get_pond_area(self):
        area = []
        _area = 0
        _height = 0
        for i, c in self.cells.items():
            if c.start_of_pond:
                _height = c.y
            if c.is_pond:
                _area += c.get_area(_height)
            if c.end_of_pond:
                area.append(int(_area))
                _area = 0
                _height = 0
        return area

    def show(self):
        for i, c in self.cells.items():
            p = 'p' if c.is_pond else ' '
            e = 'E' if c.end_of_pond else ''
            s = 'S' if c.start_of_pond else ''
            print('{0:02d}'.format(i) + p + c.char * (c.y+1) + e + s)

def run():
    area = Area()
    for l in input():
        area.put(l)
    area.adjust_height()
    area.is_pond()
    # area.show()
    pond_area = area.get_pond_area()
    print(sum(pond_area))
    if pond_area:
        print(len(pond_area), ' '.join([str(a) for a in pond_area]))
    else:
        print(0)

if __name__ == '__main__':
    run()

Submission status: Time Limit Exceeded

Solution code:
class Cell(object):
    def __init__(self, direction, x, y):
        self.direction = direction
        self.x = x
        self.y = y
        self.is_pond = False
        self.start_of_pond = False
        self.end_of_pond = False

    def get_area(self, pond_height):
        h = pond_height - self.y + 1
        if self.direction == 'f':
            return h - 1
        else:
            return h - 0.5

    @property
    def char(self):
        if self.direction == 'd':
            return '/'
        elif self.direction == 'u':
            return '\\'
        elif self.direction == 'f':
            return '|'

class Area(object):
    def __init__(self):
        self.cells = {}
        self.before_c = ''
        self.x = 0
        self.height = 0
        self.lowest = 0
        self.pond_area = []

    def put(self, c):
        if c == '\\':
            if self.before_c == '\\':
                self.height -= 1
            self.cells[self.x] = Cell('d', self.x, self.height)
        elif c == '/':
            if self.before_c == '/' or self.before_c == '_':
                self.height += 1
            self.cells[self.x] = Cell('u', self.x, self.height)
        elif c == '_':
            if self.before_c == '\\':
                self.height -= 1
            self.cells[self.x] = Cell('f', self.x, self.height)
        
        if self.cells[self.x].y < self.lowest:
            self.lowest = self.cells[self.x].y
        self.x += 1
        self.before_c = c

    def adjust_height(self):
        for i, c in self.cells.items():
            c.y -= self.lowest
    
    def is_pond(self):
        start_of_pond = None
        ponds = []
        for i_start in range(len(self.cells)):
            c_start = self.cells[i_start]
            
            if c_start.is_pond:
                ponds.append(c_start)
            if c_start.direction == 'u':
                if start_of_pond:
                    if start_of_pond.y == c_start.y:
                        start_of_pond = None
                        c_start.end_of_pond = True
                        self.pond_area.append(self.calc_area(ponds))
                        ponds = []
                continue
            if c_start.direction == 'f' and 0 == i_start:
                continue
            if c_start.direction == 'f' and not self.cells[i_start - 1].is_pond:
                continue
            if c_start.direction == 'f' and self.cells[i_start - 1].end_of_pond:
                continue

            for i_end in range(i_start+1, len(self.cells)):
                c_end = self.cells[i_end]
                if c_start.y <= c_end.y:
                    if c_end.direction == 'u':
                        c_start.is_pond = True
                        c_end.is_pond = True
                    elif c_end.direction == 'd':
                        continue
                    elif c_end.direction == 'f':
                        continue
                    break
            if not start_of_pond and c_start.is_pond:
                c_start.start_of_pond = True
                start_of_pond = c_start
            if c_start.is_pond:
                ponds.append(c_start)

    def calc_area(self, ponds):
        area = 0
        height = ponds[0].y
        for c in ponds:
            area += c.get_area(height)
        return int(area)

    def show(self):
        for i, c in self.cells.items():
            p = 'p' if c.is_pond else ' '
            e = 'E' if c.end_of_pond else ''
            s = 'S' if c.start_of_pond else ''
            print('{0:02d}'.format(i) + p + c.char * (c.y+1) + e + s)

def run():
    area = Area()
    for l in input():
        area.put(l)
    area.adjust_height()
    area.is_pond()
    # area.show()
    print(sum(area.pond_area))
    if area.pond_area:
        print(len(area.pond_area), ' '.join([str(a) for a in area.pond_area]))
    else:
        print(0)

if __name__ == '__main__':
    run()