All problems

Problem 712

Maximum Nesting Depth of the Parentheses

Easy · 10 pts · String, Stack

Problem

You are given a valid expression made of digits, the operators + - * / and balanced parentheses. Its nesting depth is the largest number of parentheses that are open at the same moment while reading it from left to right. Print the nesting depth (0 if there are no parentheses). Keep a counter that goes up at every '(' and down at every ')', and record its largest value.

Input

A single string S with digits, + - * / and balanced parentheses (no spaces).

Output

Print the maximum nesting depth.

Constraints

1 <= |S| <= 100000; the parentheses in S are balanced

Example input

(1+(2*3)+((8)/4))+1

Example output

3

Explanation

In (1+(2*3)+((8)/4))+1, the digit 8 is inside three open parentheses at once, and nothing is deeper. So the answer is 3.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Largest Odd Number in a String Next: Sum of Beauty of All Substrings