Parenthesis

Write a program that reads a sequence of lines, and for each line prints
the number of clean parenthesized regions it contains.

A clean parenthesized region is a segment of the string that is
immediatly after an open parenthesis, is immediately followed by a
closed parenthesis, and contains no open or closed parenthesis.

For instance the substring  "heha"  is a clean parenthesized region in
the string:  "hello (heha) he said"
While in the string  "hello (he(ha))) he said"  the only clean
parenthesized region corresponds to the substring  "ha"  since any
larger parenthesized region contains other parenthesis.

Input

The input is a sequence of strings, each in one line.

Output

The output must contain, for each input line with at least one clean
parenthesized region, the number of such regions in the line. Follow the
format of the examples.

Problem information

Author: ProAl professors

Generation: 2026-01-25T16:53:19.678Z

© Jutge.org, 2006–2026.
https://jutge.org
