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: Runtime Error

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

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

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

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

Submission status: Runtime Error

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

import sys

I = list(input())

A = 0
L = []
k = 0
while len(I) > 0:
    i = I.pop()

    if i == '/':
        d = 1
        a = 0.5
        tmp_I = ['/']

        # print("[{}] d: {}".format(i, d))

        while len(I) > 0:
            i = I.pop()

            tmp_I.append(i)

            if i == '/':
                d += 1
                a += 0.5 + d - 1
            elif i == '\\':
                a += 0.5 + d - 1
                d -= 1
                if d == 0:
                    A += a
                    L.append(a)
                    k += 1
                    tmp_I = []
                    break
            elif i == '_':
                a += d

            # print("[{}] d: {}".format(i, d))

        # print("{}".format(tmp_I))

        LH = []
        if len(tmp_I) > 0:
            d = a = 0
            while len(tmp_I) > 0:
                i = tmp_I.pop()
                # print("{}".format(i))
                if i == '\\':
                    d += 1
                    a += 0.5 + d - 1
                elif i == '_':
                    a += d
                elif i == '/' and d > 0:
                    a += 0.5 + d - 1
                    d -= 1

                    if d == 0:
                        # print("Add tmp: {} ({})".format(a, tmp_I))
                        A += a
                        LH.append(a)
                        k += 1
                        a = 0

print(int(A))
sys.stdout.write(str(k))
for l in LH:
    sys.stdout.write(" {}".format(int(l)))
while len(L) > 0:
    sys.stdout.write(" {}".format(int(L.pop())))
sys.stdout.write('\n')

Submission status: Runtime Error

Solution code:
#coding:UTF-8
def checkDepth(A):
    depth=0
    for i in range(len(A)):
        if A[i]=="\\":
            depth+=1
        elif A[i]=="/":
            depth-=1
        else:
            continue
        if depth==0:
            return True
    return False

def SD(a):
    A=list(a)
    areaList=[]
    areaAll=0
    start=0
    for i in range(len(A)):
        area=0
        if A[i]=="\\":
            Flag=checkDepth(A[i:])
            if Flag==True:
                count=0
                for j in range(i,len(A)):
                    if A[j]=="\\":
                        area+=(count)+0.5
                        count+=1
                    elif A[j]=="/":
                        count-=1
                        area+=(count)+0.5
                    else:
                        area+=count
                    if count==0:
                        for k in range(i,j):
                            A[k]="_"
                        break
                areaList.append(int(area))
                areaAll+=int(area)
                continue
            else:
                continue
        else:
            continue
    print(areaAll)
    for i in range(len(areaList)):
        areaList[i]=str(areaList[i])
    print(len(areaList)+" "+" ".join(areaList))
        
                    
  
if __name__=="__main__":
    a=input()
    SD(a)

Submission status: Runtime Error

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D
#?°´??????????????¢????¨????
import re

def cal_puddle(diagram_list):
    score = 0
    depth = 0
    
    for i, symbol in enumerate(diagram_list):
        
        if symbol == "\\":
            score += depth + 0.5
            depth += 1
        elif symbol == "/":
            depth = depth - 1
            score += depth + 0.5
        elif symbol == "_":
            score += depth
            continue
        
        if depth == 0:
            return int(score)

    return None

def cal(diagram):
    
    puddle_areas = []
    diagram_list = []

    puddle_list = []
    i = 0
    score = []
    while i < len(diagram):
        if diagram[i] == "\\":
            res = cal_puddle(diagram[i:])
            if res[1]:
                i = i + res[1]
                score.append(res[0])
        i += 1

    return score
def cal_revision(diagram):

    hight = 0
    hight_list = []
    hight_index_list = []
    in_puddle = False
    for i, s in enumerate(diagram + "\\"):
        if s == "\\":
            if not in_puddle:
                in_puddle = True
                hight_list.append(hight)
                hight_index_list.append(i)
            hight -= 1
        elif s == "/":
            in_puddle = False
            hight += 1

    puddle_list = []
    i = 0
    while i < len(hight_list) - 1:
        if hight_list[i] <= hight_list[i + 1]:
            puddle_list.append((hight_index_list[i], hight_index_list[i + 1]))
            i = i + 1
        else:
            hight_list[i] -= 1
            hight_index_list[i] += 1
            if hight_list[i] in hight_list[i + 1:]:
                index = i + hight_list[i + 1:].index(hight_list[i]) + 1
                puddle_list.append((hight_index_list[i], hight_index_list[index]))
                i = index

    result = [cal_puddle(diagram[s:e]) for s, e in puddle_list]
    print(sum(result))
    print(len(result), " ".join([str(a) for a in result]))
if __name__ == "__main__":
    a = input()
    cal_revision(a)
    #print(sum(result))
    #print(str(len(result)) + "".join([" " + str(a) for a in result]))

Submission status: Runtime Error

Solution code:
from collections import deque

input_list = input()
area = 0
depth_arr = deque()
area_arr = deque()
flag = false;

for i, input_str in enumerate(input_list):
    if "\\" == input_str:
        flag = true;
        depth_arr.append(i)
    elif "/" == input_str and flag:
        if len(depth_arr):
            position = depth_arr.pop()
            pool = i - position
            area += pool

            while len(area_arr):
                pre_position, pre_pool = area_arr.pop()
                if position <= pre_position:
                    pool += pre_pool
                else:
                    area_arr.append((pre_position, pre_pool))
                    break
            area_arr.append((position, pool))

areas = 0
for pos, pool in area_arr:
    areas += pool
print(areas)
print(len(area_arr), end=" ")
print(*[list[1] for list in area_arr])

Submission status: Runtime Error

Solution code:
# l = open('input.txt').readline()
l = input()

k = 0
S1, S2 = [], []
for i in range(len(l)):
    if l[i] == '\\':
        S1.append(i)
    elif l[i] == '/':
        j = S1.pop()
        a = i - j
        k += i - j

        while S2 and S2[-1][0] > j:
            a += S2.pop()[1]
        S2.append((j, a))
print(k)
print(len(S2), *(a for j, a in S2))

Submission status: Runtime Error

Solution code:
def water(square, depth, line):
    if line == '?\':
        square = square + 0.5 + depth
        depth += 1
        return square, depth
    elif line == '_':
        square += depth
        return square, depth
    elif line == '/':
        if depth > 0:
            depth -= 1
            square = square + 0.5 + depth
        return square, depth

line = input()
square = 0
squares = []
depth = 0
counter = 0
water_flag = False

for i in line:
    if depth == 0 and i == '?\':
        counter += 1
        water_flag = True
    # print(square,depth,i)
    square, depth = water(square, depth, i)
    if water_flag == True and depth == 0 and i == '/':
        squares.append(square)
        square = 0

all_squares = 0
for i in range(len(squares)):
    all_squares += squares[i]

print(all_squares)
print(str(counter)+' ',end='')
for i in range(len(squares)):
    print(squares[i]) if i == len(squares)-1 else print(str(squares[i])+' ',end='')

Submission status: Runtime Error

Solution code:
def water(square, depth, line):
    if line == '\':
        square = square + 0.5 + depth
        depth += 1
        return square, depth
    elif line == '_':
        square += depth
        return square, depth
    elif line == '/':
        if depth > 0:
            depth -= 1
            square = square + 0.5 + depth
        return square, depth

line = input()
square = 0
squares = []
depth = 0
counter = 0
water_flag = False

for i in line:
    if depth == 0 and i == '\':
        counter += 1
        water_flag = True
    # print(square,depth,i)
    square, depth = water(square, depth, i)
    if water_flag == True and depth == 0 and i == '/':
        squares.append(square)
        square = 0

all_squares = 0
for i in range(len(squares)):
    all_squares += squares[i]

print(all_squares)
print(str(counter)+' ',end='')
for i in range(len(squares)):
    print(squares[i]) if i == len(squares)-1 else print(str(squares[i])+' ',end='')

Submission status: Runtime Error

Solution code:
import sys

class Area:
    def __init__(self, start, end, area):
        self.start = start
        self.end = end
        self.area = area
    def addArea(self, area):
        self.area += area

if __name__ == "__main__":
    line = sys.stdin.readline().strip()
    
    area_stack = []
    field_stack = []
    
    for i in range(0, len(line)):
        c = line[i]
        if (c == "\\"):
            field_stack.append((c, i))
        elif (c == "/"):
            if len(field_stack) == 0:
                continue
            cc = field_stack.pop()
            current_area = Area(cc[1], i, (i - cc[1]))
            if len(area_stack) == 0:
                area_stack.append(current_area)
                continue
            prev_area = area_stack.pop()
            flag = True
            while (prev_area.start > current_area.start) and (prev_area.end < current_area.end):
                current_area.addArea(prev_area.area)
                if len(area_stack) == 0:
                    flag = False
                    break
                prev_area = area_stack.pop()
            if flag:
                area_stack.append(prev_area)
            area_stack.append(current_area)
    print str(reduce(lambda x, y: x + y, map(lambda x: x.area, area_stack)))
    s = ""
    s += str(len(area_stack)) + " "
    for item in area_stack:
        s += str(item.area) + " "
    s = s.strip()
    print s

Submission status: Runtime Error

Solution code:
data = input()
#data = '\\\\///\\_/\\/\\\\\\\\/_/\\\\///__\\\\\\_\\\\/_\\/_/\\'
diff = {'\\':-1, '_':0, '/':1}
height = [0]
[height.append(height[-1]+diff[i]) for i in data]
bottom = min(height)
height = [h-bottom for h in height]

m = max(height)
water = [m for h in height]

height00 = [0] + height + [0]
water00 = [0] + water + [0]

roop = True
while roop:
	temp = water00[:]
	for i in range(1,len(water00)-1):
		water00[i] = max(height00[i],min(water00[i-1:i+2]))
	roop = temp != water00

water = water00[1:-1]
depth = [w-h for w,h in zip(water,height)]

paddles = []
for d1,d2 in zip(depth[:-1],depth[1:]):
	if d1==0 and d2>0:
		paddles.append(0)
	paddles[-1] += min(d1,d2) + 0.5*abs(d1-d2)
	
paddles = [int(p) for p in paddles]
print(sum(paddles))
print(len(paddles), *paddles)

Submission status: Runtime 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])

St2.insert(0, len(St2))

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

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    stack <int> s1;
    stack < pair <int, int> > s2;
    char ch;
    int sum = 0;

    for (int i = 0; cin >> ch; i++) {
        if (ch == '\\') s1.push(i);
        else if (ch == '/' && s1.size() > 0) {
            int j = s1.top();
            s1.pop();
            sum += i - j;
            int a = i - j;

            while (s2.size() > 0 && s2.top().first > j) {
                a += s2.top().second;
                s2.pop();
            }
            s2.push(make_pair(j, a));
        }
    }

    vector<int> ans;

    while (s2.size() > 0) {
        ans.push_back(s2.top().second);
        s2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for (int i = 0; i < ans.size(); i++) {
        cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

Submission status: Runtime Error

Solution code:
a = input()
slope = []
pool = []
ridge = []
for i in range(len(a)):
    if a[i] == '\\':
        slope.append(i)
    if a[i] == '/' and slope:
        down = slope.pop()
        s = i - down

        while ridge:
            if ridge[-1] > down:
                ridge.pop()
                s += pool.pop()
    ridge.append(down)
    pool.append(s)
print(sum(pool))
print(len(pool), *pool)

Submission status: Runtime Error

Solution code:
def main():
    line = input()

    s1 = []
    s2 = []
    sum = 0
    for i, s in enumerate(line):
        if s == "\\":
            # 谷の位置をスタックに積む
            s1.append(i)
        elif s == "/" and len(s1) > 0:
            # 山で対応する谷があるなら、面積に追加
            j = s1.pop()
            sum += i - j  # 谷から山の距離を水たまりの面積に追加
            # jより前に位置する水たまりの面積を追加
            a = i - j
            while len(s2) > 0 and s2[-1][0] > j:
                a += s2.pop()[1]
            # (水たまりの左端の位置, 水たまりの面積)のタプルをスタックに積む
            s2.append((j, a))

    print(sum)
    print(len(s2), s2[0][1])


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.readline
li = []
for i, s in enumerate(readline().replace("_").strip()):
    if s == "\\":
        li.append([i, 0])
    elif s == "/":
        if li:
            if li[-1][1] == 0:
                li[-1][1] = i - li[-1][0]
            else:
                for j in range(len(li) - 1, -1, -1):
                    if li[j][1] == 0:
                        li = li[:j] + [[li[j][0], sum(tuple(zip(*li[j + 1:]))[1]) + i - li[j][0]]]
                        break
ans = []
for a in li:
    if a[1] != 0:
        ans.append(a[1])
print(sum(ans))
print(len(ans), *ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def cross_section_area(data):
    area = 0;
    k = 0;
    section_areas = [];
    section_area = 0;
    stack = [];
    for i in range(len(data)):
        if data[i] == '\\':
            stack.append(i);
        elif data[i] == '/':
            section_area += i - stack.pop();
            if len(stack) == 0:
                k += 1;
                section_areas.append(section_area);
                area += section_area;
    print(area);
    print(k, *section_areas);

cross_section_area(input());

Submission status: Runtime Error

Solution code:
class dllist:

    def __init__(self):
        self._list = []
        self._fp = 0
        self._bp = 0

    def insert(self, x):
        self._list.append(x)
        self._fp += 1

    def delete(self, x):
        t = self._list[::-1]
        if x in t[:-self._bp]:
            self._list.remove(x)
            self._fp -= 1

    def deleteFirst(self):
        self._list.pop()

    def deleteLast(self):
        self._bp += 1

    def disp(self):
        print(" ".join([str(x) for x in self._list[self._bp:][::-1]]))


if __name__ == '__main__':

    q = dllist()

    n = int(input())

    for _ in range(n):
        inst = input().split()

        if inst[0] == "insert":
            q.insert(int(inst[1]))
        elif inst[0] == "delete":
            q.delete(int(inst[1]))
        elif inst[0] == "deleteFirst":
            q.deleteFirst()
        elif inst[0] == "deleteLast":
            q.deleteLast()

    q.disp()

Submission status: Runtime Error

Solution code:
s=[]
p=[]
a=i=0
for c in input():
 if"\\"==c:s+=[i]
 elif c=="/"and s:
  j=p.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(ans)
if p:print(len(p),*list(zip(*p))[1])
else:print(0)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime 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
        
    
        while len(d2)!=0 and j<d2[-1][0]:
            a+=d2[-1][1]
            d2.pop()
            
        tupja=(j,a)   
        d2.append(tupja)

ans=[]
for i in d2:
    ans.append(i[1])

print(sum)
print(len(ans),end=' ')
length=len(ans)
for i in range(0,length-1,1):
    print(ans[i],end=' ')
print(ans[length-1])

Submission status: Runtime 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
        
        if len(d2)!=0:
            while len(d2)!=0 and j<d2[-1][0]:
                a+=d2[-1][1]
                d2.pop()
            
        tupja=(j,a)   
        d2.append(tupja)

ans=[]
for i in d2:
    ans.append(i[1])

print(sum)
print(len(ans),end=' ')
length=len(ans)
for i in range(0,length-1,1):
    print(ans[i],end=' ')
print(ans[length-1])

Submission status: Runtime Error

Solution code:
#coding:utf-8
data = input()
xmax = len(data)
data_list = list(data)
data_list.reverse()
reverse_data = []
for sig in data_list:
    if sig == "\\":
        reverse_data.append("/")
    elif sig == "/":
        reverse_data.append("\\")
    else:
        reverse_data.append(sig)

reverse_data = "".join(reverse_data)


def partialSqu(h, sig):
    if sig == "\\":
        squ = h + 1/2
        h += 1
    elif sig == "/":
        squ = h - 1/2
        h -= 1
    elif sig == "_":
        squ = h
    return squ, h


x_squ_dict = {}
cnt = 0
sw, x, h, totalSqu = 0, 0, 0, 0
for sig in data:
    x += 1
    if sw == 0 and sig == "\\":
        sw = 1
    if sw == 1 :
        squ, h = partialSqu(h, sig)
        totalSqu += squ
        
        if h == 0:
            x_squ_dict[x] = totalSqu
            totalSqu = 0
            sw = 0



keys = x_squ_dict.keys()
sw, x, h, totalSqu = 0, 0, 0, 0
for sig in reverse_data:
    x += 1
    if sw == 0 and sig == "\\" :
        sw = 1
        x_p = xmax - x +1
    if sw == 1 :
        squ, h = partialSqu(h, sig)
        totalSqu += squ            
        if h == 0:
            x_squ_dict[x_p] = totalSqu
            totalSqu = 0
            sw = 0

)
keys = x_squ_dict.keys()
keys = list(keys)
keys.sort()
squ_list = []
for key in keys:
    squ_list.append(x_squ_dict[key])
    
a = int(sum(squ_list))
print(a)    
squ_list.insert(0,len(keys))

squ_list = " ".join([str(int(num)) for num in squ_list])
print(squ_list)

Submission status: Runtime Error

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
    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: Runtime Error

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

Solution code:
from collections import deque

if __name__ == "__main__":
    slopes = input()
    total_area = 0
    slope_queue = deque()
    area_queue = deque()

    for i, slope in enumerate(slopes):
        if slope == '\\':
            slope_queue.append(i)
        elif slope == '/' and len(slope_queue) != 0:
            target = slope_queue.pop()
            area = i - target
            total_area += area
            if len(area_queue) == 0:
                area_queue.append((target, area))
            else:
                temp_area = area
                while True:
                    target_area = area_queue.pop()
                    if target < target_area[0]:
                        temp_area += target_area[1]
                        if len(area_queue) == 0:
                            area_queue.append((target, temp_area))
                            break
                    else:
                        area_queue.append(target_area)
                        area_queue.append((target, temp_area))
                        break

    print(total_area)
    print(len(area_queue), end=' ')
    for i, area in enumerate(area_queue):
        if i < len(area_queue) - 1:
            print(area[1], end=' ')
        else:
            print(area[1], end='\n')

Submission status: WA: Presentation Error

Solution code:
def calcAreas(sections):
    areas = []

    for s in sections:
        if len(s) <= 1:
            continue;

        areas.append(toArea(s))

    return areas

def toArea(section):
    a = 0
    b, _ = section[0]

    for s, e in section:
        a += (max(s, e) - b) - (0.5 if s != e else 0)

    return int(a)

def toDelta(p):
    if '/' == p:
        return -1
    if '\\' == p:
        return 1
    return 0

def toPaths(path):
    h = 0
    ph = 0
    paths = []

    for p in path:
        h += toDelta(p)
        paths.append((ph,h))
        ph = h

    return paths

def update(sections):
    [(lf, ll)] = sections.pop()

    n = None

    for i in range(len(sections)-1, -1, -1):
        if sections[i][0][0] == ll:
            n = i
            break

    if n == None:
        sections.append([(lf, ll)])
        return

    lst = [(lf, ll)]
    for i in range(len(sections)-1, n-1, -1):
        s = sections.pop()
        lst = s + lst

    sections.append(lst)

def main():
    paths = toPaths(input())

    prev = -1
    sections = []

    for f, l in paths:
        sections.append([(f, l)])
        if l < prev:
            update(sections)
        prev = l

    areas = calcAreas(sections)

    print(sum(areas))
    print('{} {}'.format(len(areas), ' '.join([str(x) for x in areas])))

if __name__ == '__main__':
    main()

Submission status: WA: Presentation Error

Solution code:
arr = list(input())
down = list()
areas = list()

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

areas = [areas[i][1] for i in range(len(areas))]
print(sum(areas))
print(len(areas), " ".join(map(str,areas)))

Submission status: WA: Presentation Error

Solution code:
def main():
    line = input()
    deepen_x = []
    cur_x = 0
    ponds = []      # [(水たまりの最初の位置, 水量)]
    while len(line) > 0:
        #print(cur_x, ponds, deepen_x)
        tmp_char = line[0]
        if tmp_char == '\\':
            deepen_x.append(cur_x)
        elif tmp_char == '/' and len(deepen_x) != 0:
            pre_x = deepen_x.pop()
            volume = cur_x - pre_x
            if len(ponds) == 0:
                ponds.append([pre_x, volume])
            else:
                if pre_x < ponds[-1][0]:
                    # 前の水たまりと結合する
                    a = list(filter(lambda x: x[0] > pre_x, ponds))
                    pond = 0
                    for item in a:
                        pond += item[1]
                    [ponds.pop() for x in range(len(a))]
                    ponds.append([pre_x, pond + volume])
                else:
                    # 新しい水たまりを作成
                    ponds.append([pre_x, volume])
        cur_x += 1
        line = line[1:]

    print(sum([x[1] for x in ponds]))
    print("{} ".format(len(ponds)) + " ".join([str(x[1]) for x in ponds]))

    return


main()

Submission status: WA: Presentation Error

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

count = 0
backslash_index = []
area_pond = []
pending_area=[]
for index,symbol in enumerate(input()):
	if symbol == "\\":
		backslash_index += [index]
	elif symbol == '/' and backslash_index:
		last_bs_index = backslash_index.pop()
		diff = index - last_bs_index 
		count += diff 
		while area_pond and area_pond[-1] > last_bs_index:
			diff += pending_area.pop()
			area_pond.pop()

		area_pond += [last_bs_index]
		pending_area += [diff]

print(count)
#print(len(area_pond),*(pending_area))
print(len(area_pond), ' '.join(map(str, pending_area)))