Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.

On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.

Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.


-----Input-----

The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.


-----Output-----

Print the sought minimum number of people


-----Examples-----
Input
+-+-+

Output
1

Input
---
Output
3

Source: codeforces | Difficulty: MEDIUM
Tags: Implementation

Greedy algorithms


Solutions:
def main():
	s = input()
	cnt = 0
	ans = 0
	for x in s:
		if x == '+':
			cnt += 1
			ans = max(ans, cnt)
		elif cnt == 0:
			ans += 1
		else:
			cnt -= 1
	print(ans)

def __starting_point():
	main()
__starting_point()


string_name = input()
plus = 0
minus = 0
max = 0
for i in range(0, len(string_name)):
	if string_name[i] == '+':
		plus = plus + 1
		if minus >= 1:
			minus = minus - 1
	elif string_name[i] == '-':
		minus = minus + 1
		if plus >= 1:
			plus = plus - 1
	if plus > minus and max < plus - minus:
		max = plus - minus
	elif plus < minus and max < minus - plus:
		max = minus - plus
	if max == 0:
		max = 1
print(max)


s = input()
s = list(s)
s1 = [0] * len(s)
for i in range(len(s)):
	if s[i] == '-':
		s[i] = 1
		s1[i] = -1
	else:
		s[i] = -1
		s1[i] = 1

def kadane(s):
	maxi = -1
	curr = 0
	for i in s:
		curr = max(curr + i, i)
		maxi = max(maxi, curr)
	return maxi
print(max(kadane(s), kadane(s1)))


inp = input()
inclb = 0
outclb = 0
seen = 0
i = 0
for i in range(0, len(inp)):
	if inp[i] == '-':
		outclb += 1
		if inclb > 0:
			inclb -= 1
		else:
			seen += 1
	else:
		inclb += 1
		if outclb > 0:
			outclb -= 1
		else:
			seen += 1
print(seen)


s = input()
inside = 0
outside = 0
seen = 0
for letter in s:
	if letter == '+':
		if outside == 0:
			inside += 1
			seen += 1
		else:
			inside += 1
			outside -= 1
	elif inside == 0:
		outside += 1
		seen += 1
	else:
		outside += 1
		inside -= 1
print(seen)


S = input()
ans = 0
(p, n) = (0, 0)
for i in range(len(S)):
	if S[i] == '+':
		p += 1
		n -= 1
	else:
		n += 1
		p -= 1
	n = max(0, n)
	p = max(0, p)
	ans = max(ans, max(n, p))
print(ans)


s = input()
n = len(s)
(x, a, b) = (0, 0, 0)
for i in range(n):
	if s[i] == '-':
		x -= 1
	else:
		x += 1
	a = min(a, x)
	b = max(b, x)
print(b - a)


t = input()
inPerson = 0
outPerson = 0
for i in range(0, len(t)):
	if t[i] == '+':
		inPerson += 1
		if outPerson:
			outPerson -= 1
	elif t[i] == '-':
		outPerson += 1
		if inPerson:
			inPerson -= 1
print(inPerson + outPerson)


s = input()
p = m = ans = 0
for i in s:
	if i == '+':
		if m == 0:
			ans += 1
		else:
			m -= 1
		p += 1
	else:
		if p == 0:
			ans += 1
		else:
			p -= 1
		m += 1
print(ans)


p = [0] + [1 if i == '+' else -1 for i in input()]
for i in range(1, len(p)):
	p[i] += p[i - 1]
print(max(p) - min(p))


n = input()
in_visit = 0
out_visit = 0
for i in range(len(n)):
	if n[i] == '+':
		in_visit += 1
		if out_visit:
			out_visit -= 1
	elif n[i] == '-':
		out_visit += 1
		if in_visit:
			in_visit -= 1
print(in_visit + out_visit)


s = input()
c = 1
n = len(s)
inside = 0
outside = 0
for i in range(n):
	if s[i] == '+':
		inside += 1
		if outside > 0:
			outside -= 1
	else:
		outside += 1
		if inside > 0:
			inside -= 1
	c = max(c, inside, outside)
print(c)


def rainy(S):
	IN = 0
	OUT = 0
	for i in S:
		if i == '+':
			if OUT == 0:
				IN += 1
			else:
				IN += 1
				OUT -= 1
		elif IN == 0:
			OUT += 1
		else:
			OUT += 1
			IN -= 1
	return IN + OUT
S = input()
print(rainy(S))


a = input()
n = len(a)
ans = []
cnt = 1
m = 1
mm = 0
ans.append(1)
for i in range(1, n):
	if a[i] == a[0]:
		cnt += 1
	else:
		cnt -= 1
	ans.append(cnt)
	m = max(m, cnt)
	mm = min(mm, cnt)
print(m + abs(mm))


import math
import re
from fractions import Fraction
from collections import Counter

class Task:
	signs = ''
	answer = 0

	def __init__(self):
		self.signs = input()

	def solve(self):
		counter = 0
		(leftBound, rightBound) = (0, 0)
		for x in self.signs:
			counter += 1 if x == '+' else -1
			leftBound = min(leftBound, counter)
			rightBound = max(rightBound, counter)
		self.answer = rightBound - leftBound

	def printAnswer(self):
		print(self.answer)
task = Task()
task.solve()
task.printAnswer()


(m, p, c) = (0, 0, 0)
s = input()
for i in s:
	if i == '-':
		c -= 1
	else:
		c += 1
	m = min(m, c)
	p = max(p, c)
print(p - m)


s = input()
low = 0
high = 0
sum = 0
for i in s:
	if i == '+':
		sum += 1
	else:
		sum -= 1
	if sum < low:
		low = sum
	if sum > high:
		high = sum
print(high - low)


s = input()
ans = a1 = a2 = 0
for i in s:
	if i == '+':
		ans += 1
	else:
		ans -= 1
	a1 = max(a1, ans)
	a2 = min(a2, ans)
print(a1 + abs(a2))


inside = outside = 0
for c in list(input()):
	if c == '+':
		if outside:
			outside -= 1
		inside += 1
	else:
		if inside:
			inside -= 1
		outside += 1
print(inside + outside)


import sys

def get_string():
	return sys.stdin.readline().strip()
inNOut = get_string()
pluses = 0
minuses = 0
for i in range(len(inNOut)):
	if inNOut[i] == '+':
		pluses += 1
		if minuses != 0:
			minuses -= 1
	elif inNOut[i] == '-':
		minuses += 1
		if pluses != 0:
			pluses -= 1
print(pluses + minuses)


s = input()
plus = 0
minus = 0
seen = 0
for letter in s:
	if letter == '+':
		if minus == 0:
			plus += 1
			seen += 1
		else:
			plus += 1
			minus -= 1
	elif plus == 0:
		minus += 1
		seen += 1
	else:
		minus += 1
		plus -= 1
print(seen)


s = input()
(d, f, r) = (0, 0, 0)
for c in s:
	if c == '-':
		f += 1
		if d >= 1:
			d -= 1
		else:
			r += 1
	elif c == '+':
		d += 1
		if f >= 1:
			f -= 1
		else:
			r += 1
print(r)


def N5():
	seq = input()
	inside = outside = 0
	for i in seq:
		if i == '+':
			inside += 1
			if outside:
				outside -= 1
		else:
			outside += 1
			if inside:
				inside -= 1
		suspects = abs(inside + outside)
	print(suspects)
N5()


s = input()
count = 0
(a, b) = (0, 0)
for i in s:
	if i == '+':
		count += 1
	else:
		count -= 1
	a = min(a, count)
	b = max(b, count)
print(b - a)


s = list(input())
ans = 0
while s.count('+') != 0 and s.count('-') != 0:
	flag = 0
	ans += 1
	if s.index('+') < s.index('-'):
		s[s.index('+')] = 0
		for i in range(1, len(s)):
			if flag == 0 and s[i] == '-':
				flag = 1
				s[i] = 0
			elif flag == 1 and s[i] == '+':
				flag = 0
				s[i] = 0
	elif s.index('-') < s.index('+'):
		s[s.index('-')] = 0
		for i in range(1, len(s)):
			if flag == 0 and s[i] == '+':
				flag = 1
				s[i] = 0
			elif flag == 1 and s[i] == '-':
				flag = 0
				s[i] = 0
print(max(ans + s.count('+'), ans + s.count('-')))


a = [1 if x == '+' else -1 for x in input()]
b = list(map(lambda i: sum(a[0:i]), range(len(a) + 1)))
print(max(b) - min(b))


s = input()
p = 0
m = 0
for i in s:
	if i == '+':
		p += 1
		m = max(m - 1, 0)
	elif i == '-':
		m += 1
		p = max(p - 1, 0)
print(p + m)


s = input()
(a, b) = (0, 0)
for i in range(len(s)):
	if s[i] == '-':
		a = a - 1
		if a < b:
			b = a
	else:
		a = a + 1
a = -b
ans = a
for i in range(len(s)):
	if s[i] == '-':
		a = a - 1
	else:
		a = a + 1
	if a > ans:
		ans = a
print(ans)


s = input()
t = mx = 0
for i in s:
	if i == '-' and t > 0:
		t -= 1
	elif i == '+':
		t += 1
		mx = max(mx, t)
	else:
		mx += 1
print(mx)


(c, v1, v2) = (0, 0, 0)
for ch in input():
	c += 1 if ch == '+' else -1
	(v1, v2) = (min(v1, c), max(v2, c))
print(v2 - v1)


suspects = input()
minSus = 0
maxSus = 0
counter = 0
for x in suspects:
	if x == '+':
		counter += 1
		minSus = min(minSus, counter)
		maxSus = max(maxSus, counter)
	else:
		counter -= 1
		minSus = min(minSus, counter)
		maxSus = max(maxSus, counter)
print(maxSus - minSus)


def solve(s):
	n = len(s)
	if n == 1:
		return 1
	else:
		start = 0
		prev = s[0]
		ans = 0
		f = 1
		for i in range(1, n):
			f = 1
			if s[i] == prev:
				continue
			else:
				f = 0
				ans = max(ans, i - start)
				start = i
				prev = s[i]
		if f:
			ans = max(ans, n - start)
			start = i
			prev = s[i]
		return ans

def solve1(s):
	st = []
	ans = 0
	maxx = 0
	for i in s:
		if st:
			ans = 0
		if i == '+':
			st.append('+')
		elif st:
			st.pop()
		else:
			ans += 1
			maxx = max(maxx, ans)
		maxx = max(maxx, len(st))
	maxx = max(maxx, len(st))
	return maxx

def solve2(s):
	st = []
	ans = 0
	maxx = 0
	for i in s:
		if st:
			ans = 0
		if i == '-':
			st.append('-')
		elif st:
			st.pop()
		else:
			ans += 1
			maxx = max(maxx, ans)
		maxx = max(maxx, len(st))
	maxx = max(maxx, len(st))
	return maxx
l = input()
ans = solve(l)
ans1 = solve1(l)
ans2 = solve2(l)
print(max(ans, ans1, ans2))


n = input()
inside_count = 0
outside_count = 0
for element in n:
	if element == '+':
		inside_count += 1
		outside_count -= 1
		if outside_count < 0 or inside_count > 100:
			outside_count = 0
	else:
		inside_count -= 1
		outside_count += 1
		if inside_count < 0 or outside_count > 100:
			inside_count = 0
print(inside_count + outside_count)


s = input()
mx = 0
mn = 0
cur = 0
for i in s:
	if i == '+':
		cur += 1
	else:
		cur -= 1
	mx = max(mx, cur)
	mn = min(mn, cur)
print(abs(mx - mn))


l = list(input())
j = 0
c = 0
k = 0
l1 = 0
e = 0
p = 0
while j < len(l):
	if l[j] == '+':
		p += 1
		k += 1
	else:
		l1 += 1
		if k >= e:
			c += k - e
			e = k
		k -= 1
		if l1 > p:
			l1 -= 1
			c += 1
	j += 1
if k > e:
	c += k - e
print(c)


input_var = input()
counter1 = 0
counter2 = 0
for temp in input_var:
	if temp == '+':
		counter1 += 1
		if counter2 > 0:
			counter2 -= 1
	else:
		counter2 += 1
		if counter1 > 0:
			counter1 -= 1
print(counter1 + counter2)


inp = input()
plusCount = 0
minusCount = 0
for i in inp:
	if i == '+':
		plusCount += 1
		if minusCount > 0:
			minusCount -= 1
	else:
		minusCount += 1
		if plusCount > 0:
			plusCount -= 1
print(plusCount + minusCount)


def puts(s):
	print(s, end='')
s = input()
a = mi = ma = 0
for c in s:
	if c == '+':
		a = a + 1
		ma = max(ma, a)
	else:
		a = a - 1
		mi = min(mi, a)
print(ma - mi)