Lang:G++
Edit123456789101112131415161718192021222324252627#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>#define ll long longusing namespace std;char str[1000006];int len,dat[100006],tot;int main(){scanf("%s",str+1);len=strlen(str+1);int cnt=0;ll ans=0;;for(int i=1;i<=len;i++){if(str[i]=='(')dat[++cnt]=0;if(str[i]==')'){--cnt;if(cnt<0)dat[cnt=0]=0;else{dat[cnt]++;ans+=dat[cnt];}}}cout<<ans<<endl;return 0;}