import itertools
def count_plus_minusminus(s):
c = 0
best = 0;
for ch, g in itertools.groupby(s):
count = sum(1 for _ in g)
if ch == '-':
c = c + count // 2
if count % 2 == 1:
best = max(best, c)
c = count // 2
elif ch == '+':
c = c + count
return max(best, c)
for t in ["-+--+", "--+---+-", "++-+--+----+-+", "+--+++-------+-+++-+"]:
print(f"{t} = {count_plus_minusminus(t)}")
aW1wb3J0IGl0ZXJ0b29scwoKZGVmIGNvdW50X3BsdXNfbWludXNtaW51cyhzKToKCWMgPSAwCgliZXN0ID0gMDsKCWZvciBjaCwgZyBpbiBpdGVydG9vbHMuZ3JvdXBieShzKToKCQljb3VudCA9IHN1bSgxIGZvciBfIGluIGcpCgkJaWYgY2ggPT0gJy0nOgoJCQljID0gYyArIGNvdW50IC8vIDIKCQkJaWYgY291bnQgJSAyID09IDE6CgkJCQliZXN0ID0gbWF4KGJlc3QsIGMpCgkJCQljID0gY291bnQgLy8gMgoJCWVsaWYgY2ggPT0gJysnOgoJCQljID0gYyArIGNvdW50CglyZXR1cm4gbWF4KGJlc3QsIGMpCgkJCQkKCQpmb3IgdCBpbiBbIi0rLS0rIiwgIi0tKy0tLSstIiwgIisrLSstLSstLS0tKy0rIiwgIistLSsrKy0tLS0tLS0rLSsrKy0rIl06CglwcmludChmInt0fSA9IHtjb3VudF9wbHVzX21pbnVzbWludXModCl9IikK