ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

1574. Mathematicians and brackets

Time limit: 1.0 second
Memory limit: 64 MB
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.
  1. An empty string is a regular sequence of brackets.
  2. If a string a is a regular sequence of brackets, then the string (a) is also a regular sequence of brackets.
  3. If strings a and b are regular sequences of brackets, then the string ab is also a regular sequence of brackets.
  4. 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

inputoutput
)(()
1
)()(
2
()
1
Problem Author: Alexander Toropov
Problem Source: USU Junior Contest, October 2007