fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. string S;
  9. cin >> S;
  10. long long open = 0, ans = 0;
  11. for (char c : S) {
  12. if (c == '(') {
  13. open++;
  14. } else if (c == ')') {
  15. if (open > 0) {
  16. open--;
  17. ans += 2;
  18. }
  19. }
  20. }
  21. cout << ans << "\n";
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
0