#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
pair<ll,ll> Solve(string s)
{
if (s.size()==1)
return {1,n};
ll t=0;
if (s[1]=='a')
t=1;
string arg0="",arg1="";
ll pos=4,cnt=0;
while (pos<s.size())
{
if (s[pos]=='(')
cnt++;
else if (s[pos]==')')
cnt--;
if (!cnt && s[pos]==',')
{
pos++;
break;
}
arg0+=s[pos++];
}
while (pos<s.size()-1)
arg1+=s[pos++];
pair<ll,ll> x=Solve(arg0),y=Solve(arg1);
if (t)
return {x.first+y.first,max(x.second,y.second)};
return {min(x.first,y.first),x.second+y.second-n-1};
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
string s;
cin >> s;
for (ll i=0;i<s.size();i++)
n+=s[i]=='?';
pair<ll,ll> ans=Solve(s);
cout << ans.second-ans.first+1;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |