fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define GG ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  4. int main () { GG;
  5. string s;
  6. cin>>s; int n=s.size(),lb=0,ans=0;
  7. for(int i=0;i<n;i++)
  8. { if(s[i]=='(') lb++;
  9. else if(lb>0)
  10. {lb--; ans++;
  11. }
  12.  
  13. }
  14.  
  15. cout<<ans*2<<"\n";
  16. return 0;}
Success #stdin #stdout 0.01s 5308KB
stdin
((()())
stdout
6