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: WA: Presentation Error

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)))
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 = ' ')

Submission status: WA: Presentation Error

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(str(int(sum(slist))))
print(len(slist), end = ' ')
for i in range(len(slist)):
    if (i == len(slist) - 1):
        print(str(int((slist[i]))), end = '')
    else:
        print(str(int((slist[i]))), end = ' ')

Submission status: WA: Presentation Error

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)))
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: WA: Presentation Error

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

Submission status: WA: Presentation Error

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

    def get_area(self, pond_height):
        h = pond_height - self.y + 1
        if self.direction == 'f':
            return h
        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.x = 0
        self.height = 0
        self.pond_idx = []
        self.area_list = []

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

    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):
        for i_start in range(len(self.cells)):
            c_start = self.cells[i_start]
            if c_start.direction == 'u':
                continue
            if c_start.direction == 'f' and 0 == i_start:
                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 == 'f':
                        continue
                    break

    def collect_pond_idx(self):
        start = None
        start_c = None
        for c in self.cells:
            if c.is_pond and start == None:
                start = c.x
                start_c = c
            elif not c.is_pond and start != None:
                self.pond_idx.append((start, c.x - 1))
                start = None
                start_c = None
            elif c.is_pond and c.direction == 'd' and c.y == start_c.y:
                self.pond_idx.append((start, c.x - 1))
                start = c.x
                start_c = c
        if start != None:
            self.pond_idx.append((start, self.cells[-1].x))

    def get_area(self, idx):
        area = 0
        pond_height = self.cells[idx[0]].y
        for i in range(idx[0], idx[1]+1):
            area += self.cells[i].get_area(pond_height)
        return int(area)

    def get_area_list(self):
        for pond in self.pond_idx:
            self.area_list.append(self.get_area(pond))

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

def run():
    area = Area()
    for l in input():
        area.put(l)
    area.adjust_height()
    area.is_pond()
    area.collect_pond_idx()
    area.get_area_list()
    print(sum(area.area_list))
    print(len(area.area_list), ' '.join([str(a) for a in area.area_list]))

if __name__ == '__main__':
    run()