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:
A = 0
left = []
Lake = []
s = input()
for i in range(len(s)):
    if s[i] == "\\":
        left.append(i)
    elif s[i] == "/":
        if len(left) > 0:
            w = left.pop()
            goukei = i - w
            A += goukei
            for i in range(len(Lake)-1,-1,-1):
                if Lake[i][0] > w:
                    x = Lake.pop()
                    goukei += x[1]
            Lake.append([w, goukei])
print(A)
print(len(Lake),end=" ")
for i in range(len(Lake)):
    if i == len(Lake) - 1:
        print(Lake[i][1])

Submission status: WA: Presentation Error

Solution code:
s = input()

st = []
leftn = 0

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

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

print(sum(st))
print(len(st), ' '.join([str(x) for x in st]))

Submission status: WA: Presentation Error

Solution code:
ss = input()

S1 = []
S2 = []

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

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

Submission status: WA: Presentation Error

Solution code:
ss = input()

S1 = []
S2 = []

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

print(a)
print(str(len(S2))+' '.join(map(lambda x: str(x[1]), S2)))

Submission status: WA: Presentation Error

Solution code:
def main():
    """ ????????? """
    S1 = [] # ????????????1(??????????????????)
    S2 = [] # ????????????2(??????????°´????????????????????¨??¢???)
    A = 0 # ?????¢???

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


if __name__ == '__main__':
    main()

Submission status: WA: Presentation Error

Solution code:
def main():
    """ ????????? """
    S1 = [] # ????????????1(??????????????????)
    S2 = [] # ????????????2(??????????°´????????????????????¨??¢???)
    A = 0 # ?????¢???

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


if __name__ == '__main__':
    main()

Submission status: WA: Presentation Error

Solution code:
s = raw_input()

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

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

        St2.append([j, a])

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

Submission status: WA: Presentation Error

Solution code:
from collections import deque

def main():
    s1 = deque()
    s2 = deque()
    total = 0

    string = input()

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

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

            s2.append((j, a))

    ans = []
    while (len(s2) > 0):
        ans.append(s2[-1][1])
        s2.pop()


    print("{}\n{} ".format(total, len(ans)), end="")

    print(*ans[::-1])

if __name__ == "__main__":
    main()

Submission status: WA: Presentation Error

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


def cross_section_diagram(diagram):
    stack = []
    area = []
    for i, ch in enumerate(diagram):
        if ch == "\\":
            stack.append(i)
        elif ch == "/":
            if stack:
                point = stack.pop()
                area.insert(0, (point, i - point))
        else:
            pass
    result = []
    if area:
        p1, cnt1 = area.pop(0)
        for p2, cnt2 in area:
            if p1 < p2:
                cnt1 += cnt2
            else:
                result.insert(0, cnt1)
                p1 = p2
                cnt1 = cnt2
        result.insert(0, cnt1)

    print(sum(result))
    print(len(result), " ".join([str(n)for n in result]))
    return result


if __name__ == "__main__":
    diagram = [val for val in sys.stdin.read().splitlines()]
    cross_section_diagram(diagram[0])

Submission status: WA: Presentation Error

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


def cross_section_diagram(diagram):
    stack = []
    area = []
    for i, ch in enumerate(diagram):
        if ch == "\\":
            stack.append(i)
        elif ch == "/":
            if stack:
                point = stack.pop()
                area.insert(0, (point, i - point))
        else:
            pass
    result = []
    if area:
        p1, cnt1 = area.pop(0)
        for p2, cnt2 in area:
            if p1 < p2:
                cnt1 += cnt2
            else:
                result.insert(0, cnt1)
                p1 = p2
                cnt1 = cnt2
        result.insert(0, cnt1)

    print(sum(result))
    print(str(len(result)) + " ".join([str(n)for n in result]))
    return result


if __name__ == "__main__":
    diagram = [val for val in sys.stdin.read().splitlines()]
    cross_section_diagram(diagram[0])

Submission status: WA: Presentation Error

Solution code:
s=input()
slash=[]
area=0

slash_2=[]
area_2=[]

for i in range(len(s)):
    if s[i]=="\\":
        slash.append(i)
    elif s[i]=="/":
        try: 
            j=slash.pop()
            area=area+i-j
            a=i-j
            while len(area_2) > 0 and slash_2[len(slash_2)-1] >j:
                a=a+area_2[len(slash_2)-1]
                area_2.pop()
                slash_2.pop() 
            slash_2.append(j)     
            area_2.append(a)
        except: pass

print(area)

print(str(len(area_2))+" "+" ".join(map(str, area_2)))

Submission status: WA: Presentation Error

Solution code:
hoge1 = list()
hoge2 = list()
total = 0
for num, c in enumerate(input()):
    if c == '\\':
        hoge1.append(num)
    elif c == '/':
        if not hoge1:
            continue
        last_index = hoge1.pop()
        S = num - last_index
        if not hoge2:
            hoge2.append((last_index, S))
        else:
            if last_index >= hoge2[-1][0]:
                hoge2.append((last_index, S))
            else:
                new_S = S
                for i, j in hoge2[::-1]:
                    if last_index >= i:
                        break
                    else:
                        new_S += hoge2.pop()[1] 
                hoge2.append((last_index, new_S))

totals = [x[1] for x in hoge2]
print (sum(totals))
print ('{} '.format(len(hoge2)) + ' '.join([str(x) for x in totals]))

Submission status: WA: Presentation Error

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

import sys

class peak():
    def __init__(self, loc, elevation):
        self.loc = loc
        self.elevation = elevation
        self.next_high = None


def peak_append(peak_list, loc, elevation):
    p = peak(loc, elevation)
    peak_list.append(p)
    return

def peak_set_next_high(peak_list):
    next_high = peak_list[-1]   # last peak
    for i in range(len(peak_list)-2, -1, -1):
        peak_list[i].next_high = next_high
        if peak_list[i].elevation >= next_high.elevation:
            next_high = peak_list[i]


def find_flood(elev_list, peak_list):
    peak_p = peak_list.pop(0)
    next_high = peak_p.next_high
    if not next_high:
        return None, None
    q_elev = next_high.elevation
    p_elev = peak_p.elevation

    if p_elev > q_elev:
        q_offset = next_high.loc
        p_offset = peak_p.loc
        while p_offset < len(elev_list):
            if elev_list[p_offset] == elev_list[q_offset]:
                return p_offset, q_offset
            p_offset += 1
        else:
            return None, None
    else:
        p_offset = peak_p.loc
        q_offset = elev_list.index(p_elev, p_offset+1)
        return p_offset, q_offset
    raise "Logic Error"


def calc_area(p, q, elev_list):
    elev_0 = elev_list[p]
    area = 0

    prev_elev = 0
    for x in range(p, q+1):
        elev = elev_list[x] - elev_0
        area += elev

    return (abs(area))


def adjust_peak_list(q, peak_list):
    while peak_list:
        if peak_list[0].loc >= q:
            return
        peak_list.pop(0)


s = list(sys.stdin.readline().strip())

flood_area = list()
peak_list = list()

ascending = True
elevation = 0
elev_list = list()

for i in range(len(s)):
    elev_list.append(elevation)

    if s[i] == '_':
        pass
    elif s[i] == '/':
        ascending = True
        elevation += 1
    elif s[i] == '\\':
        if ascending:
            peak_append(peak_list, i, elevation)
        ascending = False
        elevation -= 1

elev_list.append(elevation)

if ascending:
    peak_append(peak_list, len(s), elevation)

peak_set_next_high(peak_list)

while peak_list:
    p, q = find_flood(elev_list, peak_list)
    if p == None:
        break
    flood_area.append(calc_area(p, q, elev_list))
    adjust_peak_list(q, peak_list)
    
print(sum(flood_area))
print(len(flood_area), end=' ')
print(' '.join(map(str, flood_area)))

Submission status: WA: Presentation Error

Solution code:
a = input()
height = 0
elevation = []
# 各地点の標高を求める
for i in a:
    if i == "/":
        height += 1
        elevation.append((height - 1, height))
    elif i == "\\":
        height -= 1
        elevation.append((height + 1, height))
    elif i == "_":
        elevation.append((height, height))

is_puddle = False
deeper = "\\"
shallower = "/"
flat = "_"
depth = 0
puddle_area = 0.0
areas = []
for idx, x in enumerate(a):
    if is_puddle:
        if x == deeper:
            puddle_area += depth + 0.5
            depth += 1
        elif x == flat:
            puddle_area += depth
        elif x == shallower:
            puddle_area += depth - 0.5
            depth -= 1
            if depth == 0:
                is_puddle = False
                areas.append(int(puddle_area))
                puddle_area = 0
    else:
        if x == deeper:
            puddle_able = False # puddleに向こう岸があるか
            for i in range(idx, len(a)):
                if elevation[idx][0] == elevation[i][1]:
                    puddle_able = True
                    break
            if puddle_able:
                puddle_area += 0.5
                depth += 1
                is_puddle = True
print(sum(areas))
print(len(areas), end = " ")
print(*areas)

Submission status: WA: Presentation Error

Solution code:
a = input()
height = 0
elevation = []
# 各地点の標高を求める
for i in a:
    if i == "/":
        height += 1
        elevation.append((height - 1, height))
    elif i == "\\":
        height -= 1
        elevation.append((height + 1, height))
    elif i == "_":
        elevation.append((height, height))

is_puddle = False
deeper = "\\"
shallower = "/"
flat = "_"
depth = 0
puddle_area = 0.0
areas = []
for idx, x in enumerate(a):
    if is_puddle:
        if x == deeper:
            puddle_area += depth + 0.5
            depth += 1
        elif x == flat:
            puddle_area += depth
        elif x == shallower:
            puddle_area += depth - 0.5
            depth -= 1
            if depth == 0:
                is_puddle = False
                areas.append(int(puddle_area))
                puddle_area = 0
    else:
        if x == deeper:
            puddle_able = False # puddleに向こう岸があるか
            for i in range(idx, len(a)):
                if elevation[idx][0] == elevation[i][1]:
                    puddle_able = True
                    break
            if puddle_able:
                puddle_area += 0.5
                depth += 1
                is_puddle = True
print(sum(areas))
print(len(areas), end = " ")
if len(areas) == 0:
    print("")
else:
    print(*areas)

Submission status: WA: Presentation Error

Solution code:
def find_lakes(diagram):
    """Find lakes in diagram.

    >>> pat = str.maketrans('ufd', '/_\\\\')
    >>> find_lakes('ddfuu'.translate(pat))
    [6]
    >>> find_lakes('dduuudfududdddufudduuuffdddfddufdufud'.translate(pat))
    [4, 2, 1, 19, 9]
    >>> find_lakes('ff'.translate(pat))
    []
    """
    def calc_areas(ls):
        areas = []
        e1, e2 = 0, 0
        for n, m in reversed(ls):
            if e1 < n and e2 > m:
                area = areas.pop()
                areas.append(area + (m - n))
            else:
                areas.append(m - n)
                e1, e2 = n, m
        return areas[::-1]

    lakes = []
    slopes = []

    for i, c in enumerate(diagram):
        if c == '\\':
            slopes.append(i)
        elif c == '/':
            if len(slopes) > 0:
                lakes.append((slopes.pop(), i))

    return calc_areas(lakes)


def run():
    ls = find_lakes(input())
    print(sum(ls))
    print(len(ls), " ".join([str(i) for i in ls]))


if __name__ == '__main__':
    run()

Submission status: WA: Presentation Error

Solution code:
input_list = list(input())

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))
print(len(area_list), end = ' ')
print(*area_list)

Submission status: WA: Presentation Error

Solution code:
input_list = list(input())

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))
print(len(area_list), end = ' ')
if area_list != []:
    print(*area_list)

Submission status: WA: Presentation Error

Solution code:
from collections import deque
s = input()
g = deque()
p = deque()
for i in range(len(s)):
    if s[i] == "\\":
        g.append(i)
    elif s[i] == "/":
        a = 0
        if len(g) > 0:
            while True:
                if len(p) > 0 and p[-1][0] > g[-1]:
                    a += p[-1][1]
                    p.pop()
                else:
                    break
            a += i - g[-1]
            p.append([g[-1], a])
            g.pop()
for i in range(len(p)):
    p[i] = p[i][1]
print(sum(p))
print(len(p), end = " ")
print(" ".join(map(str, p)))

Submission status: WA: Presentation Error

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

print(sum(puddle_areas))
print(len(puddle_areas), ' '.join([str(x) for x in puddle_areas]))

Submission status: WA: Presentation Error

Solution code:
cross_section = input()

stack = []
areas_stack = []
area = 0
for i in range(len(cross_section)):
    c = cross_section[i]
    if c == '\\':
        stack.append(i)
    elif c == '/' and len(stack) != 0:
        j = stack.pop()
        a = i - j
        area += a
        while len(areas_stack) != 0 and areas_stack[-1][0] > j:
            a += areas_stack.pop()[1]
        areas_stack.append([j, a])

print(area)
print(len(areas_stack), ' '.join([str(x[1]) for x in areas_stack]))

Submission status: WA: Presentation Error

Solution code:
from collections import deque
d1 = deque()
d2 = deque()
ss=input()
lenss=len(ss)
sum=0

for i in range(lenss): 
    if ss[i]=='\\':
        try:
            d1.append(i)
        except:
            pass
        
    elif ss[i]=='/' and len(d1)!=0: 
        try:
            j=d1.pop()
        except:
            pass
        a=i-j
        sum+=a
        
        while len(d2)!=0: 
            if j<d2[-1][0]:
                a+=d2[-1][1]
                try:
                    d2.pop()
                except:
                    pass
            else:
                break
            
        tupja=(j,a)   
        try:
            d2.append(tupja)
        except:
            pass
        
ans=[]
for i in d2:
    try:
        ans.append(i[1])
    except:
        pass
    
print(sum)
length=len(ans)
print(length,end=' ')
if length!=0:   
    for i in range(0,length-1,1):
        print(ans[i],end=' ')
    print(ans[-1])

Submission status: WA: Presentation Error

Solution code:
from collections import deque
d1 = deque()
d2 = deque()
ss=input()
lenss=len(ss)
sum=0

for i in range(lenss): 
    if ss[i]=='\\':
        d1.append(i)
        
    elif ss[i]=='/' and len(d1)!=0: 
        j=d1.pop()
        a=i-j
        sum+=a
        
        try:
            while len(d2)!=0 and j<d2[-1][0]:
                a+=d2[-1][1]
                d2.pop()
        except:
            pass
        
        tupja=(j,a)   
        d2.append(tupja)
        
ans=[]
for i in d2:
    ans.append(i[1])
    
print(sum)
length=len(ans)
print(length,end=' ')
if length!=0:   
    for i in range(0,length-1,1):
        print(ans[i],end=' ')
    print(ans[length-1],end='')

print()

Submission status: WA: Presentation Error

Solution code:
from collections import deque
d1 = deque()
d2 = deque()
ss=input()
lenss=len(ss)
sum=0

for i in range(lenss): 
    if ss[i]=='\\':
        d1.append(i)
        
    elif ss[i]=='/' and len(d1)!=0: 
        j=d1.pop()
        a=i-j
        sum+=a
        
        try:
            while len(d2)!=0 and j<d2[-1][0]:
                a+=d2[-1][1]
                d2.pop()
        except:
            pass
        
        tupja=(j,a)   
        d2.append(tupja)
        
ans=[]
for i in d2:
    ans.append(i[1])
    
print(sum)
length=len(ans)
print(length,end=' ')

if length!=0:   
    for i in range(0,length,1):
        print(' {}'.format(ans[i]),end='')   
print()

Submission status: WA: Presentation Error

Solution code:
inputs = list(input())
stack = []
L = []
tmp_total = 0
counter = 0
upper = 0
for i,x in enumerate(inputs):
    if(x == '\\'):
        stack.append(i)
    elif(x == '/') and stack:
        tmp = stack.pop()
        total_layer = i-tmp
        if L:
            while L and L[-1][0] > tmp:
                cal = L.pop()
                total_layer += cal[1]
        L.append((i, total_layer))

print(sum([j[1] for j in L]))
print(str(len(L))+ ' ' + ' '.join([str(i[1]) for i in L]))

Submission status: WA: Presentation Error

Solution code:
inputs = list(input())
stack = []
L = []
tmp_total = 0
counter = 0
upper = 0
for i,x in enumerate(inputs):
    if(x == '\\'):
        stack.append(i)
    elif(x == '/') and stack:
        tmp = stack.pop()
        total_layer = i-tmp
        if L:
            while L and L[-1][0] > tmp:
                cal = L.pop()
                total_layer += cal[1]
        L.append((i, total_layer))

print(sum([j[1] for j in L]))
print(str(len(L))+ ' ' + ' '.join([str(i[1]) for i in L]))

Submission status: WA: Presentation Error

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), end=' ')
    print(*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()

Submission status: WA: Presentation Error

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), end='')
    if len(areas) > 0:
        print('',end=' ')
        print(*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: WA: Presentation Error

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(len(holes), " ".join(map(str, holes)))

Submission status: WA: Presentation Error

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

S = input()

# 各地点の高さを求める
v = {'\\': -1, '_': 0, '/': 1}
h = 0  # 左端の高さ
H = [h]
for s in S:
    h += v[s]
    H.append(h)

# 右部分列の最大値
R = [0] * len(H)
R[-1] = -float('inf')
for i in range(len(R) - 2, -1, -1):
    R[i] = max(R[i+1], H[i+1])

A = []
i = 0
while True:
    # 左端の左斜面をスキップ
    while i < len(S) and S[i] != '\\':
        i += 1

    # 右側の縁と同じ高さまでスキップ
    while i < len(S) and (H[i] > R[i] or S[i] == '_'):
        i += 1

    if i >= len(S):
        break

    # 水たまりの面積を求める
    h = H[i]  # 左端の高さ
    a = 0     # 面積
    while i < len(S):
        a += (h - H[i]) + (H[i] - H[i+1])/2
        i += 1
        if H[i] == h: break
    A.append(int(a))

print(sum(A))
print(len(A), ' '.join(map(str, A)))