f=open(’24_2024_3.txt’)
s=f.read().strip()
# s = s.replace(«++»,»$»).replace(«+*»,»$»).replace(«*+»,»$»).replace(«**»,»$»)
# s2 = s.split(«$»)
# # print(s2)
# st = «»
# st2 = «»
# st3=»»
# kmax = 0
# for i in range (len(s2)):
# st = s2[i]
# st = st.strip(«+*»)
# # if len(st) > kmax:
# # kmax = len(st)
# # if len(st) == 189:
# # print (st)
# st2 = st.split(«+»)
# # print (st)
# for j in range (len(st2)):
# if st2[j].find(«*0») or st2[j].find(«0*») or st2[j] == («0»):
# st3 = st3 + st2[j]
# else:
# st3 == «»
# print(len(st3))
def F(s):
if s!=» and ((s.find(‘*’)!=-1 and (s.find(‘*0*’)!=-1 or s[:2]==’0*’ or s[-2:]==’*0′)) or (s==’0′)):
return True
else:
return False
s = s.replace(‘+*’, ‘$’).replace(‘**’, ‘$’).replace(‘++’, ‘$’).replace(‘*+’, ‘$’)
kmax=0
a = s.split(‘$’)
for i in range(len(a)):
b = a[i].strip(‘*+’).split(‘+’)
st=»
for j in range(len(b)):
if F(b[j]) == 1:
# Формируем цепочку-кандидата
if st!=»:
st = st + ‘+’ + b[j]
else:
st = st + b[j]
kmax=max(kmax, len(st))
else:
# К новой цепочке пытаемся добавить начало
st = »
kmax=max(kmax, len(st))
print(kmax)