Once upon a time three mathematicians met…
- The first of them wrote a sequence of brackets on a chalkboard.
- The second one wondered if there was a cyclic shift turning that sequence into a regular one.
- After thinking for a while, the third mathematician told the number of such shifts.
You are given the sequence of brackets written by the first mathematician and you are to find the number
told by the third mathematician. A regular sequence of brackets is defined as follows.
- An empty string is a regular sequence of brackets.
- If a string a is a regular sequence of brackets, then the string (a) is also a regular sequence of brackets.
- If strings a and b are regular sequences of brackets, then the string ab is also a regular sequence of brackets.
- There are no other regular sequences of brackets.
A string
a is a cyclic shift of a string
b if
a and
b have
the same lengths and
a consists of some (possibly empty) suffix from
b
followed by a prefix from
b.
Input
The only line of the input contains the sequence of brackets written by the first mathematician.
The sequence is non-empty and its length doesn't exceed 105.
Output
Output the number of cyclic shifts turning the given sequence into a regular one.
Samples
input | output |
---|
)(()
| 1 |
)()(
| 2 |
()
| 1 |
Problem Author: Alexander Toropov
Problem Source: USU Junior Contest, October 2007