#include <iostream>
#include<stack>
#include<string>
#include<vector>

using namespace std;

int main() {
    stack<int> a;
    stack<int> b;
    int k=0,t=0;
    string x;
    vector<int> r;
    vector<int> s;
    vector<int> e;
    cin >>x;
    for(int i=0;i<x.size();i++)
    {
        if(x[i]==40)
        {
            a.push(i);
        }
        if(x[i]==41)
        {
            if(i-a.top()==1)
            {
                 r.push_back(i);   
            }
            else
            {
                s.push_back(a.top());
                e.push_back(i);
            }
            a.pop();
        }
    }
    int c=0;
    for(int i=0;i<s.size();i++)
    {
        for(int j=0;j<r.size();j++)
        {
            if(s[i]<r[j] && r[j]<e[i])
            {
                if(c==0)
                {
                    k++;
                }
                k++;
                c++;
            }
        }
        c=0;
    }
    cout<<k;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: