Subtraction is not associative. For example (5−2)−1=2 but 5−(2−1)=4, so (5−2)−1=5−(2−1). This means the value of an expression such as 5−2−1 depends on the order in which the subtractions are performed. When there are no brackets we agree to evaluate from left to right, so 5−2−1 means (5−2)−1.
You are given an expression of the form x1±x2±⋯±xn, where each ± is either + or −, and x1,x2,…,xn are pairwise distinct variables.
We want to insert brackets into the all-minus expression x1−x2−⋯−xn so that it becomes equivalent to the given expression (the two expressions are equal for every value of the variables). At most n−1 pairs of brackets may be inserted, and no pair of brackets may enclose zero or one variable.
For example, to match x1−x2−x3+x4+x5−x6+x7 we may bracket x1−x2−x3−x4−x5−x6−x7 as ((x1−x2)−(x3−x4−x5))−(x6−x7). This is only one of many possible bracketings, and it is not necessarily one that uses the fewest pairs. Determine the minimum number of bracket pairs over all valid bracketings.
The first line contains an integer n (2≤n≤106), the number of variables in the given expression. Each of the next n−1 lines contains a single character, + or −. The k-th of these lines (1≤k≤n−1) is the sign between xk and xk+1 in the given expression. You may assume that a valid bracketing always exists for the input.
Print a single integer: the minimum number of bracket pairs that must be inserted into x1−x2−⋯−xn to obtain an expression equivalent to the given one.