def calcs(s):
s = '+'+s
out = 0
i = 0
one = act = ''
while i <=len(s)-1:
if s[i] == '+':
act = '+'
i+=1
continue
elif s[i] == '-':
act = '-'
i+=1
continue
else:
while s[i].isdigit():
one += s[i]
i+=1
if i > len(s)-1:
break
if act == '+':
out += int(one)
else:
out-= int(one)
one = ''
return out
print(calcs('1+2+3-2-1+0+13-16'))
ZGVmIGNhbGNzKHMpOgogICAgcyA9ICcrJytzCiAgICBvdXQgPSAwCiAgICBpID0gMAogICAgb25lID0gYWN0ID0gJycKICAgIHdoaWxlIGkgPD1sZW4ocyktMToKICAgICAgICBpZiBzW2ldID09ICcrJzoKICAgICAgICAgICAgYWN0ID0gJysnCiAgICAgICAgICAgIGkrPTEKICAgICAgICAgICAgY29udGludWUKICAgICAgICBlbGlmIHNbaV0gPT0gJy0nOgogICAgICAgICAgICBhY3QgPSAnLScKICAgICAgICAgICAgaSs9MQogICAgICAgICAgICBjb250aW51ZQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHdoaWxlIHNbaV0uaXNkaWdpdCgpOgogICAgICAgICAgICAgICAgb25lICs9IHNbaV0KICAgICAgICAgICAgICAgIGkrPTEKICAgICAgICAgICAgICAgIGlmIGkgPiBsZW4ocyktMToKICAgICAgICAgICAgICAgICAgICBicmVhawogICAgICAgIGlmIGFjdCA9PSAnKyc6CiAgICAgICAgICAgIG91dCArPSBpbnQob25lKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIG91dC09IGludChvbmUpCiAgICAgICAgb25lID0gJycKICAgIHJldHVybiBvdXQKcHJpbnQoY2FsY3MoJzErMiszLTItMSswKzEzLTE2Jykp