using
System;
using
System.Collections.Generic;
class
GFG{
static
Dictionary<
int
,
int
> endIndex =
new
Dictionary<
int
,
int
>();
public
static
void
getClosingIndex(
string
s)
{
int
n = s.Length;
Stack<
int
> st =
new
Stack<
int
>();
for
(
int
i = 0; i < n; i++)
{
if
(s[i] ==
')'
)
{
int
startIndex = st.Pop();
endIndex.Add(startIndex, i);
}
else
{
st.Push(i);
}
}
}
public
static
int
calcWeight(
string
s,
int
low,
int
high)
{
if
(low + 1 == high)
{
return
1;
}
else
{
int
mid = endIndex[low];
if
(mid == high)
{
return
2 * calcWeight(s, low + 1,
high - 1);
}
else
{
return
calcWeight(s, low, mid) +
calcWeight(s, mid + 1, high);
}
}
}
public
static
void
Main(
string
[] args)
{
string
input =
"(()(()))"
;
int
n = input.Length;
getClosingIndex(input);
Console.Write(calcWeight(input, 0, n - 1));
}
}