System.in.eachLine{l,n->i=0 n<2?s=l.grep{1}:l.each{it<33?:it>43?--s[i]:++s[i];++i}} print s.sum()