# [Solution] Higher Order Functions solution codeforces | ICPC WF Moscow Invitational Contest

## Higher Order Functions solution codeforces

Helen studies functional programming and she is fascinated with a concept of higher order functions — functions that are taking other functions as parameters. She decides to generalize the concept of the function order and to test it on some examples.

For her study, she defines a simple grammar of types. In her grammar, a type non-terminal TT is defined as one of the following grammar productions, together with order(T)order(T), defining an order of the corresponding type:

• ()” is a unit type, order(())=0order(“()”)=0.
• “(” TT “)” is a parenthesized type, order((T))=order(T)order(“(“T”)”)=order(T).
• T1T1 “->” T2T2 is a functional type, order(T1->T2)=max(order(T1)+1,order(T2))order(T1″->”T2)=max(order(T1)+1,order(T2)). The function constructor T1T1 “->” T2T2 is right-to-left associative, so the type “()->()->()” is the same as the type “()->(()->())” of a function returning a function, and it has an order of 11. While “(()->())->()” is a function that has an order-1 type “(()->())” as a parameter, and it has an order of 22.

Helen asks for your help in writing a program that computes an order of the given type.

### Higher Order Functions solution codeforces

Input

The single line of the input contains a string consisting of characters ‘(‘, ‘)‘, ‘‘, and ‘>‘ that describes a type that is valid according to the grammar from the problem statement. The length of the line is at most 104104 characters.

Output

Print a single integer — the order of the given type.

### Higher Order Functions solution codeforces

Examples

input

Copy
()

output

Copy
0


### Higher Order Functions solution codeforces

input

Copy
()->()

output

Copy
1


### Higher Order Functions solution codeforces

input

Copy
()->()->()

output

Copy
1


### Higher Order Functions solution codeforces

input

Copy
(()->())->()

output

Copy
2


### Higher Order Functions solution codeforces

input

Copy
()->(((()->())->()->())->())

output

Copy
3    