#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main(){
    w(t){
        ll a,b,n,m;
        cin>>a>>b>>n>>m;
        if((a+b)<(n+m) || n+m==0){
            cout<<"No"<<endl;
        }else{
            if(a>b){
                n=a-b;
                a-=a-b;
                if(n<0){
                    cout<<"No"<<endl;
                }else{
                    a-=m;
                if(a<0){
                    cout<<"No"<<endl;
                }else{
                   if(b>=n){
                    cout<<"Yes"<<endl;
                }  else{
                    cout<<"No"<<endl;
                }
                }
                }
                }else if(a==b){
                a-=m;
                if(a<0){
                    cout<<"No"<<endl;
                }else{
                   if(b>=n){
                    cout<<"Yes"<<endl;
                }  else{
                    cout<<"No"<<endl;
                }
                }
            }
            else if(a<b){
                 a-=n;
                if(a<0){
                    cout<<"No"<<endl;
                }else{
                   if(a<b && a==0){
                    cout<<"No"<<endl;
                }  else{
                    cout<<"Yes"<<endl;
                }
                }
            }
        }
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main(){
    w(t){
        ll a,b,n,m;
        cin>>a>>b>>n>>m;
        if((a+b)<(n+m) || n+m==0){
            cout<<"No"<<endl;
        }else{
            if(a>b){
                n-=a-b;
                a-=a-b;
                if(n<0){
                    cout<<"No"<<endl;
                }else{
                    a-=m;
                if(a<0){
                    cout<<"No"<<endl;
                }else{
                   if(b>=n){
                    cout<<"Yes"<<endl;
                }  else{
                    cout<<"No"<<endl;
                }
                }
                }
                }else if(a==b){
                a-=m;
                if(a<0){
                    cout<<"No"<<endl;
                }else{
                   if(b>=n){
                    cout<<"Yes"<<endl;
                }  else{
                    cout<<"No"<<endl;
                }
                }
            }
            else if(a<b){
                 b-=n;
                if(b<0){
                    cout<<"No"<<endl;
                }else{
                   if(a<b && a==0){
                    cout<<"No"<<endl;
                }  else{
                    cout<<"Yes"<<endl;
                }
                }
            }
        }
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main(){
    w(t){
        ll a,b,n,m;
        cin>>a>>b>>n>>m;
        if((a+b)<(n+m) || n+m==0){
            cout<<"No"<<endl;
        }else{
            if(a>b){
                n-=a-b;
                a-=a-b;
                if(n<0){
                    cout<<"No"<<endl;
                }else{
                    a-=m;
                if(a<0){
                    cout<<"No"<<endl;
                }else{
                   if(b>=n){
                    cout<<"Yes"<<endl;
                }  else{
                    cout<<"No"<<endl;
                }
                }
                }
                }else if(a==b){
                a-=m;
                if(a<0){
                    cout<<"No"<<endl;
                }else{
                   if(b>=n){
                    cout<<"Yes"<<endl;
                }  else{
                    cout<<"No"<<endl;
                }
                }
            }
            else if(a<b){
                 a-=n;
                if(a<0){
                    cout<<"No"<<endl;
                }else{
                   if(a<b && a==0){
                    cout<<"No"<<endl;
                }  else{
                    cout<<"Yes"<<endl;
                }
                }
            }
        }
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main(){
    w(t){
        ll a,b,n,m;
        cin>>a>>b>>n>>m;
        if((a+b)<(n+m)){
            cout<<"No"<<endl;
        }else{
            if(a>b){
                n-=a-b;
                a-=n;
                if(n<0){
                    cout<<"No"<<endl;
                }else{
                    a-=m;
                if(a<0){
                    cout<<"No"<<endl;
                }else{
                   if(b>=n){
                    cout<<"Yes"<<endl;
                }  else{
                    cout<<"No"<<endl;
                }
                }
                }
                }else if(a==b){
                a-=m;
                if(a<0){
                    cout<<"No"<<endl;
                }else{
                   if(b>=n){
                    cout<<"Yes"<<endl;
                }  else{
                    cout<<"No"<<endl;
                }
                }
            }
            else if(a<b){
                 a-=n;
                if(a<=0){
                    cout<<"No"<<endl;
                }else{
                   if(b>=m){
                    cout<<"Yes"<<endl;
                }  else{
                    cout<<"No"<<endl;
                }
                }
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n"
#define print(a) for(auto x : a) cout << x << " "; cout << endl;

const int MAX = 2e5;
const int MOD = 1e9 + 7;
const int inf = 1e18 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void solve()
{
    int a,b,n,m;
    cin>>a>>b>>n>>m;
    if(a+b<n+m)
    {
        cout<<"NO"<<endl;
        return;
    }
    if(min(a,b)<m)
    {
        cout<<"NO"<<endl;
        return;
    }
    cout<<"YES"<<endl;
}

int32_t main()
{
	DESYNC
	int t = 1;
	cin >> t;
	while (t--)
		solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

void solve()
{
	int a, b;
	cin >> a >> b;
	int ans = 0;
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t = 1;
	cin >> t;
	while(t--)
		solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n"
#define print(a) for(auto x : a) cout << x << " "; cout << endl;

const int MAX = 2e5;
const int MOD = 1e9 + 7;
const int inf = 1e18 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void solve()
{
	int a, b, n, m;
	cin >> a >> b >> n >> m;
	if(a == 0 && b == 0)
	{
		cout << "No\n";
		return;
	}
	if(a == b)
	{
		a--;
		m--;
	}
	if(a > b)
	{
		if(b > m)
		{
			b = b - m;
			m  = 0;
		}
		else
		{
			m = m - b;
			b = 0;
		}
		if(m || n > a)
		{
			cout << "No\n";
			return;
		}
	}
	else
	{
		// deb("hi");
		// deb(a); deb(b); deb(n); deb(m);
		if(a > m)
		{
			a = a - m;
			m = 0;
		}
		else
		{
			m = m - a;
			a = 0;
		}
		// deb(a); deb(b); deb(n); deb(m);
		if(m || n > b)
		{
			cout << "No\n";
			return;
		}
	}
	cout << "Yes\n";
}

int32_t main()
{
	DESYNC
	int t = 1;
	cin >> t;
	while (t--)
		solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n"
#define print(a) for(auto x : a) cout << x << " "; cout << endl;

const int MAX = 2e5;
const int MOD = 1e9 + 7;
const int inf = 1e18 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void solve()
{
	int a[3][3];
	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
			cin >> a[i][j];

	for(int i = 0; i < 3; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			if(a[i][j] & 1)
			{
				a[i][j] = a[i][j] % 2;
				if(i != 0 && j != 0)
			}
		}
	}
	for(int i = 0; i < n; i++)
	{

	}
}

int32_t main()
{
	DESYNC
	int t = 1;
	cin >> tt;
	while(t--)
		solve();
	return 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
#define M 1000000007
#define P 1000003
#define all(v) v.begin(),v.end()
#define pi 3.1415926536
#define pb push_back
using namespace std;
// void solve()
// {
//     ll a,b,n,m;
//     cin>>a>>b>>n>>m;
//     if(a+b<n+m)
//     {
//         cout<<"NO"<<endl;
//         return;
//     }
//     if(min(a,b)<m)
//     {
//         cout<<"NO"<<endl;
//         return;
//     }
//     cout<<"YES"<<endl;
// }
void solve()
{
    ll a,b,n,m;
    cin>>a>>b>>n>>m;
    if(a+b<n+m)
    {
        cout<<"NO"<<endl;
        return;
    }
    if(min(a,b)<m)
    {
        cout<<"NO"<<endl;
        return;
    }
    cout<<"YES"<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
typedef long long int ll;
#define M 1000000007
#define P 1000003
#define all(v) v.begin(),v.end()
#define pi 3.1415926536
#define pb push_back
using namespace std;
void solve()
{
    ll x, y, z;
    ll a,b,n,m;
    cin>>a>>b>>n>>m;
    if(a+b<n+m)
    {
        cout<<"NO"<<endl;
        return;
    }
    if(min(a,b)<m)
    {
        cout<<"NO"<<endl;
        return;
    }
    cout<<"YES"<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n";
#define print(a) for(auto x : a) cout << x << " "; cout << "\n";

const int inf = 1e18 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void solve()
{
    int n;
    cin >> n;
    int ans = (n - 1) / 2 + 1;
    cout << ans << endl;
}

int32_t main()
{
    DESYNC
    int t = 1;
    cin >> t;
    while(t--)
        solve();
    return 0;
}


    #include <bits/stdc++.h>
    typedef long long int ll;
    #define M 1000000007
    #define P 1000003
    #define all(v) v.begin(),v.end()
    #define pi 3.1415926536
    #define pb push_back
    using namespace std;
    void solve()
    {
        ll a,b,n,m;
        cin>>a>>b>>n>>m;
        if(a+b<n+m)
        {
            cout<<"NO"<<endl;
            return;
        }
        if(min(a,b)<m)
        {
            cout<<"NO"<<endl;
            return;
        }
        cout<<"YES"<<endl;
    }
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        int t=1;
        cin>>t;
        while(t--)
            solve();
    }


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n"
#define print(a) for(auto x : a) cout << x << " "; cout << endl;

const int MAX = 2e5;
const int MOD = 1e9 + 7;
const int inf = 1e18 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void solve()
{
	int a, b;
	cin >> a >> b;
	int ans = a + b;
	cout << ans << endl;
}

int main()
{
	DESYNC
	int t = 1;
	cin >> t;
	while(t--)
		solve();
	return 0;
}


#include <iostream>
using namespace std;

void solve()
{
    int a, b;
    cin >> a >> b;
    int ans = 0;
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--)
        solve();
    return 0;
}


#include <bits/stdc++.h>
#define int long long
#define deb(x) cerr << ">> " << #x << " : " << x << "\n"
#define allr(x) x.rbegin(), x.rend()
#define PI 3.14159265
#define MOD 1000000007
#define print(a) for(auto x : a) cout << x << " "; cout << endl;
#define all(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
const int maxx = 1e7 + 5;
const int maxx2 = 1e9 + 5;
const int inf = 1e18 + 42;
void solve1();
void solve2();
void solve3();

int32_t main()
{
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve3();
    }
    return 0;
}

void solve3()
{
    int a, b, n, m;
    cin >> a >> b >> n >> m;
    if(a == 0 && b == 0)
    {
        cout << "No\n";
        return;
    }
    if(a == b)
    {
        if(n > m)
        {
            b--;
            n--;
        }
        else
        {
            a--;
            m--;
        }
    }
    if(a > b)
    {
        if(b > m)
        {
            b = b - m;
            m  = 0;
        }
        else
        {
            m = m - b;
            b = 0;
        }
        if(m || n > a)
        {
            cout << "No\n";
            return;
        }
    }
    else
    {
        // deb("hi");
        // deb(a); deb(b); deb(n); deb(m);
        if(a > m)
        {
            a = a - m;
            m = 0;
        }
        else
        {
            m = m - a;
            a = 0;
        }
        // deb(a); deb(b); deb(n); deb(m);
        if(m || n > b)
        {
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";
}

void solve2()
{
    string s;
    cin >> s;
    int res = 0;
    // int i = 0;
    for(int i = 0; i < inf; i++)
    {
        int cur = i;
        bool ok = 1;
        for(int j = 0; j < s.size(); j++)
        {
            res = res + 1;
            if(s[j] == '+')
            {
                cur = cur + 1;
            }
            else cur = cur - 1;
            if(cur < 0)
            {
                ok = 0;
                break;
            }
        }
        if(ok) break;
    }
    cout << res << endl;
}

void solve1() {
    string b;
    cin >> b;
    if(b.size() == 2) {
        cout << b << endl;
        return;
    }
    cout << b[0];
    for(int i = 1; i < b.size(); i += 2) {
        cout << b[i];
    }
    cout << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n"
#define print(a) for(auto x : a) cout << x << " "; cout << endl;

const int MAX = 2e5;
const int MOD = 1e9 + 7;
const int inf = 1e18 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void solve()
{
	int a[3][3];
	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
			cin >> a[i][j];

	for(int i = 0; i < 3; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			if(a[i][j] & 1)
			{
				a[i][j] = a[i][j] % 2;
				if(i != 0 && j != 0)
			}
		}
	}
	for(int i = 0; i < n; i++)
	{

	}
}

int32_t main()
{
	DESYNC
	int t = 1;
	// cin >> t;
	while (t--)
		solve();
	return 0;
}


#include <iostream>
using namespace std;

void solve()
{
    int a, b;
    cin >> a >> b;
    int ans = a + b;
    cout << a + b << endl;
}

int main()
{
    DESYNC
    int t = 1;
    cin >> t;
    while(t--)
        solve()
    return 0;
}


#include <iostream>
using namespace std;

void solve()
{
	int a, b;
	cin >> a >> b;
	int ans = 0;
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t = 1;
	cin >> t;
	while(t--)
		solve();
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
    cout << a + b << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n"
#define print(a) for(auto x : a) cout << x << " "; cout << endl;

const int MAX = 2e5;
const int MOD = 1e9 + 7;
const int inf = 1e18 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void solve()
{
	int a[3][3];
	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
			cin >> a[i][j];

	for(int i = 0; i < 3; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			if(a[i][j] & 1)
			{
				a[i][j] = a[i][j] % 2;
				if(i != 0 && j != 0)
			}
		}
	}
	for(int i = 0; i < n; i++)
	{

	}
}

int32_t main()
{
	DESYNC
	int t = 1;
	cin >> t;
	while(t--)
		solve();
	return 0;
}


#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

void solve(ll a, ll b, ll n, ll m) {
  cout << a << " " << b << " " << n << " " << m << endl;
  if ((a + b) < (n + m)) {
    cout << "No" << endl;
    return;
  } else if (min(a, b) >= max(m, n)) {
    cout << "Yes" << endl;
    return;
  } else if (a <= b) {
    if (n >= b - a + 1) {
      if (b < n || a < m) {
        if (a == b) {
          ll x = n / 2;
          solve(a - x, b - x, n - (2 * x), m);
          return;
        } else {
          solve(a, b - (b - a + 1), n - (b - a + 1), m);
          return;
        }
      } else {
        cout << "Yes" << endl;
        return;
      }
    } else {
      if (b < n || a < m) {
        cout << "No" << endl;
        return;
      } else {
        cout << "Yes" << endl;
        return;
      }
    }
  } else if (a > b) {
    if (n >= a - b) {
      if (a < n || b < m) {
        solve(a - (a - b), b, n - (a - b), m);
        return;
      } else {
        cout << "Yes" << endl;
        return;
      }
    } else {
      if (a < n || b < m) {
        cout << "No" << endl;
        return;
      } else {
        cout << "Yes" << endl;
        return;
      }
    }
  }
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int n;
  cin >> n;
  REP(i, n) {
    ll a, b, n, m;
    cin >> a >> b >> n >> m;
    solve(a, b, n, m);
  }
}


#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

void solve(ll a, ll b, ll n, ll m) {
  // cout << a << " " << b << " " << n << " " << m << endl;
  if ((a + b) < (n + m)) {
    cout << "No" << endl;
    return;
  } else if (min(a, b) >= max(m, n)) {
    cout << "Yes" << endl;
    return;
  } else if (a <= b) {
    if (n >= b - a + 1) {
      if (b < n || a < m) {
        if (a == b && n > 1) {
          ll x = n / 2;
          solve(a - x, b - x, n - (2 * x), m);
          return;
        } else {
          solve(a, b - (b - a + 1), n - (b - a + 1), m);
          return;
        }
      } else {
        cout << "Yes" << endl;
        return;
      }
    } else {
      if (b < n || a < m) {
        cout << "No" << endl;
        return;
      } else {
        cout << "Yes" << endl;
        return;
      }
    }
  } else if (a > b) {
    if (n >= a - b) {
      if (a < n || b < m) {
        solve(a - (a - b), b, n - (a - b), m);
        return;
      } else {
        cout << "Yes" << endl;
        return;
      }
    } else {
      if (a < n || b < m) {
        cout << "No" << endl;
        return;
      } else {
        cout << "Yes" << endl;
        return;
      }
    }
  }
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int n;
  cin >> n;
  REP(i, n) {
    ll a, b, n, m;
    cin >> a >> b >> n >> m;
    solve(a, b, n, m);
  }
}


#include <iostream>
#include <string>
using namespace std;

int main() {
string a;
cin>>a;
int p=0;
for(long long int  ii=0;ii<10000;++ii){
for(int i=0;i<a.size();++i)
{
    if(a[i]=='(' && a[i+1]==')'){
    a.replace(i,2,"std",0);
p+=2;}
}}
cout<<p;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main() {
string a;
cin>>a;
int p=0;
for(long long int  ii=0;ii<1000;++ii){
for(int i=0;i<a.size();++i)
{
    if(a[i]=='(' && a[i+1]==')'){
    a.replace(i,2,"std",0);
p+=2;}
}}
cout<<p;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main() {
string a;
cin>>a;
int p=0;
for(long long int  ii=0;ii<100;++ii){
for(int i=0;i<a.size();++i)
{
    if(a[i]=='(' && a[i+1]==')'){
    a.replace(i,2,"std",0);
p+=2;}
}}
cout<<p;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main() {
string a;
cin>>a;
int p=0;
for(long long int  ii=0;ii<1000000;++ii){
for(int i=0;i<a.size();++i)
{
    if(a[i]=='(' && a[i+1]==')'){
    a.replace(i,2,"std",0);
p+=2;}
}}
cout<<p;
    return 0;
}


#include <iostream>
#include <string>
#include <stack>
#include <algorithm>

using namespace std;
//a.empty()
int main() {
string v;
cin>>v;
int p=0;
stack <char> s;
for(int i=0;i<v.size();++i){
 if(s.empty())
 {
 s.push(v[i]);
 continue;
 }
 if(s.top()=='(' && v[i]==')' )
 {
s.pop();
p+=2;
}
else
{
s.push(v[i]);
}}

//
string ans;
    while(!s.empty()){
        ans += s.top();

    //cout<<s.top();
        s.pop();

    }
cout<< p;

        return 0;
}


#include <stdio.h>
#include <stack>
#include <string.h>
using namespace std;
int main (){
    int i,count=0;
    stack <char> Q;
    char b[1000001];
    scanf ("%s",&b);
    int len = strlen(b);
        for (i=0;i<len;i++){
            if (b[i]=='(')
                Q.push(b[i]);
            if (!Q.empty() && b[i]==')'){
                Q.pop(); count=count+2;
            }
        }
    if (len)>count)
    printf ("%d",count);
    else
    printf ("%d",count-2);
    //for(;;);
    return 0;
}


#include <stdio.h>
#include <stack>
#include <string.h>
using namespace std;
int main (){
    int i,count=0;
    stack <char> a;
    char b;
    scanf ("%s",b);
        for (i=0;i<strlen(b);i++){
            if (b[i]=='(')
                a.push(b[i]);
            if (!a.empty() && b[i]==')'){
                a.pop(); count=count+2;
            }
        }
    if (strlen(b)>count)
    printf ("%d",count);
    else
    printf ("%d",count-2);
    return 0;
}


#include <stdio.h>
#include <stack>
#include <string.h>
using namespace std;
int main (){
    int i,count=0;
    stack <char> Q;
    char b[1000001];
    scanf ("%s",&b);
    int len = strlen(b);
        for (i=0;i<len;i++){
            if (b[i]=='(')
                Q.push(b[i]);
            if (!Q.empty() && b[i]==')'){
                Q.pop(); count=count+2;
            }
        }
    if ((len)>=count)
    printf ("%d",count);
    else
    printf ("%d",count-2);
    //for(;;);
    return 0;
}


#include <stdio.h>
#include <stack>
#include <string.h>
using namespace std;
int main (){
    int i,count=0;
    stack <char> Q;
    char b[100001];
    scanf ("%s",&b);
        for (i=0;i<strlen(b);i++){
            if (b[i]=='(')
                Q.push(b[i]);
            if (!Q.empty() && b[i]==')'){
                Q.pop(); count=count+2;
            }
        }
    if (strlen(b)>count)
    printf ("%d",count);
    else
    printf ("%d",count-2);
    return 0;
}


#include <stdio.h>
#include <stack>
#include <string.h>
using namespace std;
int main (){
    int i,count=0;
    stack <char> Q;
    char b[1000001];
    scanf ("%s",&b);
    int len = strlen(b);
        for (i=0;i<len;i++){
            if (b[i]=='(')
                Q.push(b[i]);
            if (!Q.empty() && b[i]==')'){
                Q.pop(); count=count+2;
            }
        }
    if ((len)>count)
    printf ("%d",count);
    else
    printf ("%d",count-2);
    //for(;;);
    return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define     pb               push_back
#define     popb             pop_back
#define     ll               long long int
#define     ull              unsigned long long int
#define     fst                first
#define     sec                second
#define     mem(a,v)         memset(a,v,sizeof(a))
#define     mp               make_pair
#define     ps                push
#define     fnt              front
#define     pf               push_front
#define     vec1             vector < long int >
#define     vt               vector <long int >:: iterator
#define     list1            list < long int >
#define     lt               list <long int >:: iterator
#define     map1             map <long int,long int>
#define     mt               map <long int >:: iterator
#define     set1             set <long int >
#define     st               set <long int>::iterator
#define     que              queue <long int>
#define     qt               queue <long int>::iterator
#define     stk              stack <long int>
#define     sit              stack <long int>::iterator
#define     MAX              100006
#define     pii              pair <int,int>
void fastIO (){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
}

int main ()
{

    ///freopen("output.txt","w",stdout);

    fastIO ();

    char s[1000006];

    int Count=0;

    cin>>s;

    int len=strlen(s);

    for (int i=0;i<len;i++){
        for (int j=i+1;j<len;j++){
            if ((s[i]==40)&&(s[j]==41)){
                Count++;
                //char ch;
                s[i]=Count+'0';
                s[j]=Count+'1';
            }
        }

    }
    cout<<Count*2<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define     pb               push_back
#define     popb             pop_back
#define     ll               long long int
#define     ull              unsigned long long int
#define     fst                first
#define     sec                second
#define     mem(a,v)         memset(a,v,sizeof(a))
#define     mp               make_pair
#define     ps                push
#define     fnt              front
#define     pf               push_front
#define     vec1             vector < long int >
#define     vt               vector <long int >:: iterator
#define     list1            list < long int >
#define     lt               list <long int >:: iterator
#define     map1             map <long int,long int>
#define     mt               map <long int >:: iterator
#define     set1             set <long int >
#define     st               set <long int>::iterator
#define     que              queue <long int>
#define     qt               queue <long int>::iterator
#define     stk              stack <long int>
#define     sit              stack <long int>::iterator
#define     MAX              100006
#define     pii              pair <int,int>
void fastIO (){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
}

char s[1000006];
stack <char>S;

int main ()
{

    ///freopen("output.txt","w",stdout);

    fastIO ();

    scanf("%s",s);
    int counter=0;

    int len=strlen(s);
    int len1=len;
    int check=1;

    for (int i=0;i<len;i++){
        if (s[i]=='('){
                S.push(s[i]);
            }
            if (s[i]==')'&&S.size()!=0){
                S.pop();
                counter += 2;
                //cout<<counter<<endl;
            }
    }

    cout<<counter<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define     pb               push_back
#define     popb             pop_back
#define     ll               long long int
#define     ull              unsigned long long int
#define     fst                first
#define     sec                second
#define     mem(a,v)         memset(a,v,sizeof(a))
#define     mp               make_pair
#define     ps                push
#define     fnt              front
#define     pf               push_front
#define     vec1             vector < long int >
#define     vt               vector <long int >:: iterator
#define     list1            list < long int >
#define     lt               list <long int >:: iterator
#define     map1             map <long int,long int>
#define     mt               map <long int >:: iterator
#define     set1             set <long int >
#define     st               set <long int>::iterator
#define     que              queue <long int>
#define     qt               queue <long int>::iterator
#define     stk              stack <long int>
#define     sit              stack <long int>::iterator
#define     MAX              100006
#define     pii              pair <int,int>
void fastIO (){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
}

int main ()
{

    ///freopen("output.txt","w",stdout);

    fastIO ();

    char s[1000006];

    int Count=0;

    cin>>s;

    int len=strlen(s);

    for (int i=0;i<len;i++){
        for (int j=i+1;j<len;j++){
            if (s[i]==s[j]){
                Count++;
                //char ch;
                s[i]=Count+'0';
                s[j]=Count+'1';
            }
        }

    }
    cout<<Count*2<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define     pb               push_back
#define     popb             pop_back
#define     ll               long long int
#define     ull              unsigned long long int
#define     fst                first
#define     sec                second
#define     mem(a,v)         memset(a,v,sizeof(a))
#define     mp               make_pair
#define     ps                push
#define     fnt              front
#define     pf               push_front
#define     vec1             vector < long int >
#define     vt               vector <long int >:: iterator
#define     list1            list < long int >
#define     lt               list <long int >:: iterator
#define     map1             map <long int,long int>
#define     mt               map <long int >:: iterator
#define     set1             set <long int >
#define     st               set <long int>::iterator
#define     que              queue <long int>
#define     qt               queue <long int>::iterator
#define     stk              stack <long int>
#define     sit              stack <long int>::iterator
#define     MAX              100006
#define     pii              pair <int,int>
void fastIO (){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
}

    char s[1000006];

int main ()
{

    ///freopen("output.txt","w",stdout);

    fastIO ();

    int Count=0;

    cin>>s;

    int len=strlen(s);

    for (int i=0;i<len;i++){
        for (int j=i+1;j<len;j++){
            if ((s[i]=='(')&&(s[j]==')')){
                Count++;
                //char ch;
                s[i]='*';
                s[j]='#';
            }
        }

    }
    cout<<Count*2<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define     pb               push_back
#define     popb             pop_back
#define     ll               long long int
#define     ull              unsigned long long int
#define     fst                first
#define     sec                second
#define     mem(a,v)         memset(a,v,sizeof(a))
#define     mp               make_pair
#define     ps                push
#define     fnt              front
#define     pf               push_front
#define     vec1             vector < long int >
#define     vt               vector <long int >:: iterator
#define     list1            list < long int >
#define     lt               list <long int >:: iterator
#define     map1             map <long int,long int>
#define     mt               map <long int >:: iterator
#define     set1             set <long int >
#define     st               set <long int>::iterator
#define     que              queue <long int>
#define     qt               queue <long int>::iterator
#define     stk              stack <long int>
#define     sit              stack <long int>::iterator
#define     MAX              100006
#define     pii              pair <int,int>
void fastIO (){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
}

char s[1000006];
stack <char>S;

int main ()
{

    ///freopen("output.txt","w",stdout);

    fastIO ();

    scanf("%s",s);
    int counter=0;

    int len=strlen(s);
    int len1=len;
    int check=1;

    for (int i=0;i<len;i++){
        if (s[i]=='('){
                S.push(s[i]);
            }
            if (s[i]==')'&&S.size()!=0){
                S.pop();
                counter += 2;
                cout<<counter<<endl;
            }
    }

    cout<<counter<<endl;
    return 0;
}


/* ********************************************
*    *     *      *    * * * *     * * * *    *
*   * *   * *   ***    *     *    *       *   *
*   *  * *  *  ****    * * *      *       *   *
*   *   *   *     *    * *        *       *   *
*   *       *     *    *  *       *       *   *
*   *       *     *    *   *      *       *   *
*   *       *     *    *    *      * * * *    *
********************************************* */
#include <fstream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <string>
#include <cassert>

#define MP make_pair
#define FOR(v,p,k) for(v=p;v<=k;++v)
#define FORD(v,p,k) for(v=p;v>=k;--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define VAR(v,i) __typeof(i) v=(i)
#define FOREACH(i,c) for(__typeof(c.begin()) i=(c.begin());i!=(c).end();++i)
#define PB push_back
#define FI first
#define SE second
#define ABS(x)(x < 0)?(-x):(x)
#define SIZE(x) (int)x.size()
#define ALL(c) c.begin(),c.end()
#define MAX(a,b)(a > b)?(a):(b)
#define MIN(a,b)(a > b)?(b):(a)
#define ZERO(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-13
#define MOD 1000000007
#define NMAX 1000
#define INF -1

using namespace std;
typedef long long LL;

string s;
int a , b , i;

int main(){
 //freopen("INPUT.TXT","r",stdin);
 //freopen("OUTPUT.TXT","w",stdout);
 cin >> s;
 a = b = 0;
 FOR(i,0,SIZE(s))
   if(s[i] == '(') a++;
     else if(a) a--,b += 2;
 cout << b << endl;
 return 0;
}


/* ********************************************
*    *     *      *    * * * *     * * * *    *
*   * *   * *   ***    *     *    *       *   *
*   *  * *  *  ****    * * *      *       *   *
*   *   *   *     *    * *        *       *   *
*   *       *     *    *  *       *       *   *
*   *       *     *    *   *      *       *   *
*   *       *     *    *    *      * * * *    *
********************************************* */
#include <fstream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <string>
#include <cassert>

#define MP make_pair
#define FOR(v,p,k) for(v=p;v<=k;++v)
#define FORD(v,p,k) for(v=p;v>=k;--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define VAR(v,i) __typeof(i) v=(i)
#define FOREACH(i,c) for(__typeof(c.begin()) i=(c.begin());i!=(c).end();++i)
#define PB push_back
#define FI first
#define SE second
#define ABS(x)(x < 0)?(-x):(x)
#define SIZE(x) (int)x.size()
#define ALL(c) c.begin(),c.end()
#define MAX(a,b)(a > b)?(a):(b)
#define MIN(a,b)(a > b)?(b):(a)
#define ZERO(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-13
#define MOD 1000000007
#define NMAX 1000
#define INF -1

using namespace std;
typedef long long LL;

string s;
int a , b , i;

int main(){
 //freopen("INPUT.TXT","r",stdin);
 //freopen("OUTPUT.TXT","w",stdout);
 cin >> s;
 a = b = 0;
 FOR(i,0,SIZE(s))
   if(s[i] == ')') a++;
     else if(a) a--,b += 2;
 cout << b << endl;
 return 0;
}


/* ********************************************
*    *     *      *    * * * *     * * * *    *
*   * *   * *   ***    *     *    *       *   *
*   *  * *  *  ****    * * *      *       *   *
*   *   *   *     *    * *        *       *   *
*   *       *     *    *  *       *       *   *
*   *       *     *    *   *      *       *   *
*   *       *     *    *    *      * * * *    *
********************************************* */
#include <fstream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <string>
#include <cassert>

#define MP make_pair
#define FOR(v,p,k) for(v=p;v<=k;++v)
#define FORD(v,p,k) for(v=p;v>=k;--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define VAR(v,i) __typeof(i) v=(i)
#define FOREACH(i,c) for(__typeof(c.begin()) i=(c.begin());i!=(c).end();++i)
#define PB push_back
#define FI first
#define SE second
#define ABS(x)(x < 0)?(-x):(x)
#define SIZE(x) (int)x.size()
#define ALL(c) c.begin(),c.end()
#define MAX(a,b)(a > b)?(a):(b)
#define MIN(a,b)(a > b)?(b):(a)
#define ZERO(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-13
#define MOD 1000000007
#define NMAX 1000
#define INF -1

using namespace std;
typedef long long LL;

string s;
int a , b , i;

int main(){
 //freopen("INPUT.TXT","r",stdin);
 //freopen("OUTPUT.TXT","w",stdout);
 cin >> s;
 a = b = 0;
 FOR(i,0,SIZE(s) - 1)
   if(s[i] == '(') a++;
     else if(a) a--,b += 2;
 cout << b << endl;
 return 0;
}


/* ********************************************
*    *     *      *    * * * *     * * * *    *
*   * *   * *   ***    *     *    *       *   *
*   *  * *  *  ****    * * *      *       *   *
*   *   *   *     *    * *        *       *   *
*   *       *     *    *  *       *       *   *
*   *       *     *    *   *      *       *   *
*   *       *     *    *    *      * * * *    *
********************************************* */
#include <fstream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <string>
#include <cassert>

#define MP make_pair
#define FOR(v,p,k) for(v=p;v<=k;++v)
#define FORD(v,p,k) for(v=p;v>=k;--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define VAR(v,i) __typeof(i) v=(i)
#define FOREACH(i,c) for(__typeof(c.begin()) i=(c.begin());i!=(c).end();++i)
#define PB push_back
#define FI first
#define SE second
#define ABS(x)(x < 0)?(-x):(x)
#define SIZE(x) (int)x.size()
#define ALL(c) c.begin(),c.end()
#define MAX(a,b)(a > b)?(a):(b)
#define MIN(a,b)(a > b)?(b):(a)
#define ZERO(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-13
#define MOD 1000000007
#define NMAX 1000
#define INF -1

using namespace std;
typedef long long LL;

string s;
int a , b , i;

int main(){
 //freopen("INPUT.TXT","r",stdin);
 //freopen("OUTPUT.TXT","w",stdout);
 cin >> s;
 a = b = 0;
 FOR(i,1,SIZE(s))
   if(s[i] == ')') a++;
     else if(a) a--,b += 2;
 cout << b << endl;
 return 0;
}


#include<iostream>

using namespace std;

int main()
{
	string bseq;
	cin >> bseq;
	int len = bseq.length();
	int cls =0  , opn =0 , bal = 0;
	int res =0;
	for(int i=0 ; i<len ; i++)
	{
		if(bseq[i] == '(')
		{
			bal++;
			opn++;
		}
		else
		{
			bal--;
			cls++;
		}
		if(bal<0)
		{
			opn=0;
		       	cls=0;
		}
		if(opn>0 && opn==cls)
		{
			res+=opn+cls;
			opn=0;
			cls=0;
		}
		if(i==len-1 && opn!=cls)
		{
			if(opn > cls)
				res+=cls*2;
			else
				res+=opn*2;
		}
	}
	cout<< res << endl;
}


#include<iostream>

using namespace std;

int main()
{
	string sen;
	cin >> sen;
	int len = sen.length() , res = 0;
	int bal =0;
	for(int i=0 ; i<len ; i++)
	{
		int q=bal;
		if(sen[i] == '(')
			bal++ ;
		else
			bal--;
		if(bal < q && bal >= 0)
			res +=2;
		else if(bal<0)
			bal =0;
	}
	cout<< res << endl;
}


#include<iostream>

using namespace std;

int main()
{
	string bseq;
	cin >> bseq;
	int len = bseq.length();
	int bal=0 , res=0;
	int opn =0 , cls=0;
	for(int i=0 ; i<len ; i++)
	{
		if(bseq[i]=='(')
			opn++;
		else
			cls++;
	}
	//if(len%2 == 1)
	//{
	if(opn > cls)
	{
		while(opn!=cls)
		{
			for(int i=1 ; i<len ; i++)
			{
				bseq[i-1]=bseq[i];
			}
			opn--;
			len--;
		}
	}
	else
	{
		while(cls!=opn)
		{
			cls--;
			len--;
		}
	}
	//}

	for(int i=0 ; i<len; i++)
	{
		//cout<< "here  " << i << endl;
		if(bseq[i] == '(')
		{
			bal++;
			//	cout<< 1 << endl;
		}
		else if(bseq[i] == ')' && bal>0)
		{
			bal--;
			//	cout << 2 << endl;
		}
		if (bal==0)
		{
			res=i+1;
			//	cout<< 3 << endl;
			break;
		}
	}
	cout<< res << endl;
}


#include<iostream>

using namespace std;

int main()
{
	string bseq;
	cin >> bseq;
	int len = bseq.length();
	int bal=0 , res=0;
	int opn =0 , cls=0;
	for(int i=0 ; i<len ; i++)
	{
		if(bseq[i]=='(')
			opn++;
		else
			cls++;
	}
	//if(len%2 == 1)
	//{
	if(opn > cls)
	{
		while(opn!=cls)
		{
			if(bseq[0]=='(')
				opn--;
			for(int i=1 ; i<len ; i++)
			{
				bseq[i-1]=bseq[i];
			}
			len--;
		}
	}
	else
	{
		while(cls!=opn)
		{
			if(bseq[len-1]==')')
				cls--;
			len--;
		}
	}
	//}

	for(int i=0 ; i<len; i++)
	{
		//cout<< "here  " << i << endl;
		if(bseq[i] == '(')
		{
			bal++;
			//	cout<< 1 << endl;
		}
		else if(bseq[i] == ')' && bal>0)
		{
			bal--;
			//	cout << 2 << endl;
		}
		if (bal==0)
		{
			res=i+1;
			//	cout<< 3 << endl;
			break;
		}
	}
	cout<< res << endl;
}


#include<iostream>

using namespace std;

int main()
{
	string bseq;
	cin >> bseq;
	int len = bseq.length();
	int bal=0 , res=0;
	int opn =0 , cls=0;
	for(int i=0 ; i<len ; i++)
	{
		if(bseq[i]=='(')
			opn++;
		else
			cls++;
	}
	//if(len==1)
	//{
	//	cout<< 0 << endl;
	//	return 0;
	//}
	//if(len%2 == 1)
	//{

	int p=0;
	while(bseq[p] != '(' && p<len)
	{
		bseq[p] = '#';
		if(bseq[p] == ')')
			cls--;
		p++;
	}
	p=len-1;
	while(bseq[p] != ')' && p>=0)
	{
		bseq[p]='#';
		if(bseq[p] == ')')
			opn++;
		p--;
	}

	if(opn > cls)
	{

		for(int i=len-1 ; i>=0 ; i--)
		{
			if(bseq[i] == '(')
			{
				opn--;
				bseq[i]='#';
			}
			if(cls==opn)
				break;
		}

	}
	else
	{
		for(int i=0 ; i<len ; i++)
		{
			if(bseq[i] == ')')
			{
				cls--;
				bseq[i]='#';
			}
			if(cls==opn)
				break;
		}
	}

	p=0;
	while(bseq[p] != '(' && p<len)
	{
		bseq[p] = '#';
		if(bseq[p] == ')')
			cls--;
		p++;
	}
	p=len-1;
	while(bseq[p] != ')' && p >=0)
	{
		bseq[p]='#';
		if(bseq[p] == '(')
			opn--;
		p--;
	}

	//cout<< "bseq  " << bseq << endl;
	int q=0;
	int a=0 , b=0;
	for(int i=0 ; i<len; i++)
	{
		//cout<< "here  " << i << endl;
		if(bseq[i] == '(')
		{
			a++;
			//bal++;
			q++;
			//	cout<< 1 << endl;
		}
		else if(bseq[i] == ')')
		{
			b++;
			q++;
			//bal--;
			//	cout << 2 << endl;
		}
		//cout<< "a   " << a << " b  " << b << endl;
		if (b==a && a>0)
		{
			res=q;
			//	cout<< 3 << endl;
			break;
		}
	}
	cout<< res << endl;
}


#include <iostream>
using namespace std;
int t,k,l;
string s;
main()
{
      cin>>s;
      int maxsig=s.size();
      for(int i=0;i<s.size();i++)

      { if(t==0&&s[i]==')'){s[i]='1';    continue;}   else {t=1;
        if(k<0)k=0;
       if (k==0&&s[i]==')')s[i]='1';
              if(s[i]=='(')k=k+1;
               if(s[i]==')')k=k-1;
               }
               }

               for(int i=0;i<s.size();i++)
                if(s[i]==')')l=l+1;
               cout<<l*2;
     //system("pause");
               }


#include <iostream>
using namespace std;
int t,k,l;
string s;
main()
{
      cin>>s;
      int maxsig=s.size();
      for(int i=0;i<s.size();i++)

      { if(t==0&&s[i]==')'){continue;maxsig--;}   else t=1;
       if (k<=0&&s[i]==')')s[i]='1';
              if(s[i]=='(')k=k+1;
               if(s[i]==')')k=k-1;

               }

               for(int i=0;i<s.size();i++)
                if(s[i]==')')l=l+1;
               cout<<l*2;
     //system("pause");
               }


#include <iostream>
using namespace std;
int t,k,l;
string s;
main()
{
      cin>>s;
      int maxsig=s.size();
      for(int i=0;i<s.size();i++)

      { if(t==0&&s[i]==')'){continue;maxsig--;}   else t=1;
              if(s[i]=='(')k=k+1;
               if(s[i]==')')k=k-1;
               if (k==0&&s[i]==')')s[i]='1';
               }

               for(int i=0;i<s.size();i++)
                if(s[i]==')')l=l+1;
               cout<<l*2;
               //system("pause");
               }


#include <iostream>
using namespace std;
int t,k,l;
string s;
main()
{
      cin>>s;
      int maxsig=s.size();
      for(int i=0;i<s.size();i++)

      { if(t==0&&s[i]==')'){continue;maxsig--;}   else t=1;
              if(s[i]=='(')k=k+1;
               if(s[i]==')')k=k-1;
               if (k<=0&&s[i]==')')s[i]='1';
               }

               for(int i=0;i<s.size();i++)
                if(s[i]==')')l=l+1;
               cout<<l*2;
               //system("pause");
               }


#include <bits/stdc++.h>
using namespace std;
int n, v, x, st[1000002], f[1000002];
string s;
int main(){
    cin >> s;
    for ( int i = 0; i < s.size(); i++ ){
    	if ( s[i] == '(' ) st[++v] = i;
        else if( v > 0 ){
            f[i] = f[st[v]] + i - st[v] + 1;
            v--;
        }
    }
    for ( int i = 0; i <= s.size(); i++ )
    x = max ( x, f[i] );
    printf ( "%d\n", x );
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
char c[100005];
int main()
{
	cin>>c;
	int i,j,n=strlen(c),pq=0,sum=0;
	for (i=0;i<n;i++)
	{
		if (c[i]=='(')
			pq++;
		else
		if (pq>0)
		{
			sum+=2;
			pq--;
		}
	}
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, v, x, st[1000001], f[1000001];
string s;
int main(){
    cin >> s;
    for ( int i = 0; i < s.size(); i++ ){
    	if ( s[i] == '(' ) st[++v] = i;
        else if( v > 0 ){
            f[i+1] = f[st[v]] + i - st[v] + 1;
            v--;
        }
    }
    for ( int i = 0; i <= s.size(); i++ )
    x = max ( x, f[i] );
    printf ( "%d\n", x );
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<sstream>
#include<cctype>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<set>
#include<functional>
#define in(x) x=read()
#define qr read()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read()
{
	char ch=' ';
	int f=1,x=0;
	while(!isdigit(ch)){ch=getchar();if(ch=='-')f*=-1;}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return f*x;
}
int main()
{
	char ch=' ';
	int now=0,ans=0;
	while(1)
	{
		ch=getchar();
		if(ch==EOF||ch=='\n')break;
		if(ch=='(')now++;
		else if(now)now--,ans+=2;
	}
	cout<<ans;
	return 0;
}


//***************************************
//**copyright @HARSH RANJAN ... \m/******
//***************************************

//  ****HEADER FILES***

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<utility>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<limits>
#include<memory>
#include<cstdlib>
#include<cassert>
#include<cctype>
#include<cfloat>
#include<stack>
#include<queue>
#include<deque>
#include<iterator>
#include<list>
#include<vector>
#include<map>
#include<set>
#include<numeric>
#include<ctime>
#include<sstream>

using namespace std;

// ***COMMONLY USED MACROS***
#define MOD 1000000007
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define minr min_element
#define maxr max_element
#define mh make_heap
#define ph push_heap
#define poh pop_heap
#define Sd(n) scanf("%d",&n)
#define Pd(n) printf("%d\n",n)
#define Sld(n) scanf("%lld",&n)
#define Pld printf("%lld\n",n)
#define Ss(s) scanf("%s\n",s)
#define Ps(s) printf("%s\n",s)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define ford(i,n) for(int i=int(n);i>=0;i--)
#define all(a) a.begin(),a.end()
#define set(a,x) memset(a,x,sizeof(a))
#define mod 10000007
//  ***FEW TYPEDEFINES**
typedef unsigned long long int uint64;
typedef long long int int64;
typedef pair<int64,int64> pii;

const long double pi = 3.1415926535897932384626433832795;
const long double eps = 1e-9;
stack<int>s;
char c[1000001];
int main(){
    int ans=0,i;
    gets(c);
    for(i=0;i<strlen(c);i++){
        if(c[i]=='(')
        s.push(1);
        if(c[i]==')'){
            if(!s.empty()){
                s.pop();
                ans=ans+2;
            }
        }
    }
    cout<<ans;
    return 0;
}


//***************************************
//**copyright @HARSH RANJAN ... \m/******
//***************************************

//  ****HEADER FILES***

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<utility>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<limits>
#include<memory>
#include<cstdlib>
#include<cassert>
#include<cctype>
#include<cfloat>
#include<stack>
#include<queue>
#include<deque>
#include<iterator>
#include<list>
#include<vector>
#include<map>
#include<set>
#include<numeric>
#include<ctime>
#include<sstream>

using namespace std;

// ***COMMONLY USED MACROS***
#define MOD 1000000007
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define minr min_element
#define maxr max_element
#define mh make_heap
#define ph push_heap
#define poh pop_heap
#define Sd(n) scanf("%d",&n)
#define Pd(n) printf("%d\n",n)
#define Sld(n) scanf("%lld",&n)
#define Pld printf("%lld\n",n)
#define Ss(s) scanf("%s\n",s)
#define Ps(s) printf("%s\n",s)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define ford(i,n) for(int i=int(n);i>=0;i--)
#define all(a) a.begin(),a.end()
#define set(a,x) memset(a,x,sizeof(a))
#define mod 10000007
//  ***FEW TYPEDEFINES**
typedef unsigned long long int uint64;
typedef long long int int64;
typedef pair<int64,int64> pii;

const long double pi = 3.1415926535897932384626433832795;
const long double eps = 1e-9;
stack<int>s;
char c[10000001];
int main(){
    int ans=0,i;
    scanf("%s",c);
    for(i=0;i<strlen(c);i++){
        if(c[i]=='(')
        s.push(1);
        if(c[i]==')'){
            if(!s.empty()){
                s.pop();
                ans=ans+2;
            }
        }
    }
    cout<<ans;
    return 0;
}


//***************************************
//**copyright @HARSH RANJAN ... \m/******
//***************************************

//  ****HEADER FILES***

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<utility>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<limits>
#include<memory>
#include<cstdlib>
#include<cassert>
#include<cctype>
#include<cfloat>
#include<stack>
#include<queue>
#include<deque>
#include<iterator>
#include<list>
#include<vector>
#include<map>
#include<set>
#include<numeric>
#include<ctime>
#include<sstream>

using namespace std;

// ***COMMONLY USED MACROS***
#define MOD 1000000007
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define minr min_element
#define maxr max_element
#define mh make_heap
#define ph push_heap
#define poh pop_heap
#define Sd(n) scanf("%d",&n)
#define Pd(n) printf("%d\n",n)
#define Sld(n) scanf("%lld",&n)
#define Pld printf("%lld\n",n)
#define Ss(s) scanf("%s\n",s)
#define Ps(s) printf("%s\n",s)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define ford(i,n) for(int i=int(n);i>=0;i--)
#define all(a) a.begin(),a.end()
#define set(a,x) memset(a,x,sizeof(a))
#define mod 10000007
//  ***FEW TYPEDEFINES**
typedef unsigned long long int uint64;
typedef long long int int64;
typedef pair<int64,int64> pii;

const long double pi = 3.1415926535897932384626433832795;
const long double eps = 1e-9;
//stack<int>s;
char c[10000001];
int main(){
    int ans=0,i,l=0,r=0;
    scanf("%s",c);
    for(i=0;i<strlen(c);i++){
        if(c[i]=='(')
        l++;
        if(c[i]==')'){
        r++;
        int chck=(l-r);
        if(chck>=0)
        ans++;}
    }
    cout<<2*ans;
    return 0;
}


#include<iostream>
#include<string>
#include<stack>
#include<algorithm>
using namespace std;
int main()
{
    stack<char>s;
    string a;
    cin>>a;
    int i;
   int k=a.length();
    s.push(a[0]);
    for(i=1;i<k;i++)
        {
            if(s.empty())
                s.push(a[i]);
           else if(s.top()=='(' && a[i]==')')
                s.pop();
            else
            s.push(a[i]);
        }
        cout<<k-s.size()<<endl;
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
string s;
int len;
int main()
{
	int i,j,n;
	//freopen("a.txt","r",stdin);
	cin>>s;
	len=0;
	n=0;
	for(i=0;i<s.size();i++)
	{
		if(s[i]=='(')
		{
			len++;
		}
		else
		{
			if(len!=0)
			{
				len--;
				n+=2;
			}
		}
	}
	printf("%d\n",n);
}


#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
#define maxn 1000002
char a[maxn];
int len;
int main()
{
	int i,j,n;
	//freopen("a.txt","r",stdin);
	scanf("%s",&a);
	len=0;
	n=0;
	for(i=0;i<strlen(a);i++)
	{
		if(a[i]=='(')
		{
			len++;
		}
		else
		{
			if(len!=0)
			{
				len--;
				n+=2;
			}
		}
	}
	printf("%d\n",n);
}


#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
string s;
int len;
int main()
{
	int i,j,n;
	//freopen("a.txt","r",stdin);
	cin>>s;
	len=0;
	n=0;
	for(i=0;i<s.size();i++)
	{
		if(s[i]=='(')
		{
			len++;
		}
		else
		{
			if(len!=0)
			{
				len--;
				n+=2;
			}
		}
	}
	printf("%d\n",n);
}


#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
char  s[1000005];
int len;
int main()
{
	int i,j,n;
	//freopen("a.txt","r",stdin);
	cin>>s;
	len=0;
	n=0;
	for(i=0;i<strlen(s);i++)
	{
		if(s[i]=='(')
		{
			len++;
		}
		else
		{
			if(len!=0)
			{
				len--;
				n+=2;
			}
		}
	}
	printf("%d\n",n);
}


#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
char  s[1000005];
int len;
int main()
{
	int i,j,n;
	//freopen("a.txt","r",stdin);
	cin>>s;
	len=0;
	n=0;
	for(i=0;i<strlen(s);i++)
	{
		if(s[i]=='(')
		{
			len++;
		}
		else
		{
			if(len!=0)
			{
				len--;
				n+=2;
			}
		}
	}
	printf("%d\n",n);
}


// stack::push/pop
#include <iostream>
#include <stack>
#include <string.h>
#include <algorithm>
  using namespace std;

  char a[1000005];
  stack<char> b;

main ()
{
  int i,le;

  cin>>a;

  le=strlen(a);

  for(i=0;i<le;i++)
    if(a[i]==')')
    {
      if(!b.empty())
      {
        if(b.top()=='(')b.pop();
          else b.push(a[i]);
      }else b.push(a[i]);
    }else b.push(a[i]);

  printf("%d\n",le-b.size());
}


// stack::push/pop
#include <iostream>
#include <stack>
#include <string.h>
#include <algorithm>
  using namespace std;

  string a;

main ()
{
  int i,le;

  stack<char> b;

  cin>>a;

  le=a.size();

  for(i=0;i<le;i++)
    if(a[i]==')')
    {
      if(!b.empty())
      {
        if(b.top()=='(')b.pop();
          else b.push(a[i]);
      }else b.push(a[i]);
    }else b.push(a[i]);

  printf("%d\n",a.size()-b.size());
}


// stack::push/pop
#include <iostream>
#include <stack>
#include <string.h>

  using namespace std;

  string a;
int main ()
{
  int i;

  stack<char> b;

  cin>>a;

  for(i=0;i<a.size();i++)
    if(a[i]==')')
    {
      if(!b.empty())
      {
        if(b.top()=='(')b.pop();
          else b.push(a[i]);
      }
          else b.push(a[i]);
    }else b.push(a[i]);

  printf("%d\n",a.size()-b.size());

  return 0;
}


// stack::push/pop
#include <iostream>
#include <stack>
#include <string.h>
#include <algorithm>
  using namespace std;

  char a[1000005];

main ()
{
  int i,le;

  stack<char> b;

  cin>>a;

  le=strlen(a);

  for(i=0;i<le;i++)
    if(a[i]==')')
    {
      if(!b.empty())
      {
        if(b.top()=='(')b.pop();
          else b.push(a[i]);
      }else b.push(a[i]);
    }else b.push(a[i]);

  printf("%d\n",le-b.size());
}


// stack::push/pop
#include <iostream>
#include <stack>
#include <string.h>
#include <algorithm>
#include<stdio.h>
  using namespace std;

  char a[1000005];
  stack<char> b;

main ()
{
  int i,le;

  cin>>a;

  le=strlen(a);

  for(i=0;i<le;i++)
    if(a[i]==')')
    {
      if(!b.empty())
      {
        if(b.top()=='(')b.pop();
          else b.push(a[i]);
      }else b.push(a[i]);
    }else b.push(a[i]);

  printf("%d\n",le-b.size());
}


using namespace std;
#include<bits/stdc++.h>
typedef long long  ll;
typedef   pair<ll,ll>  pii;
typedef   vector< pii > vpii;
typedef   vector<long long>   vi;
typedef   map<string,ll>  msi;
typedef   map<ll,ll>  mii;
///Print
#define P(a)  printf("%lld",a)
#define PP(a,b)  printf("%lld %lld",a,b)
#define PPP  (a,b,c)  printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define case(no) printf("Case %lld: ",++no)
#define casenl(no) printf("Case %lld:\n",++no)
#define caseh(no) printf("Case #%lld: ",++no)
#define casehnl(no) printf("Case #%lld:\n",++no)
///Scanf
#define I(n)       scanf("%lld", &n)
#define II(a,b)    scanf("%lld %lld", &a, &b)
#define III(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
///LOOP
#define rep(x,n) for(__typeof(n) x=0;x<(n);x++)
#define reps(i,x) for(int  i=0;i<(x.size());i++)
#define repp(x,n) for(__typeof(n) x=1;x<=(n);x++)
#define foreach(x,n) for(__typeof(n.begin()) x=n.begin();x!=n.end();x++)
///Shortcut
#define mem(ar,value) memset(ar,value,sizeof(ar))
#define all(x) x.begin(),x.end()
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define len(s) s.size()
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
///Min AND Max
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define inf (1e15)
#define eps (1e-9)
#define PI acos(-1.0)
#define pi 3.14159265358979323846
#define isEq(a,b) (fabs((a)-(b))<eps)
#define Dist(x1,y1,x2,y2) (sqrt(sqr((x1)-(x2))+sqr((y1)-(y2))))
#define spDist(lat1,long1,lat2,long2,r) ((r)*acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos((long1)-(long2))))
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define dist4adj(x1,y1,x2,y2) ( abs(x1-x2) + abs(y1-y2) )
#define dist8adj(x1,y1,x2,y2) max( abs(x1-x2) , abs(y1-y2) )
///File
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
/**Define Bitwise operation**/
#define check(n, pos) (n & (1<<(pos)))
#define biton(n, pos) (n | (1<<(pos)))
#define bitoff(n, pos) (n & ~(1<<(pos)))
#define ledzero(n) (__builtin_clz(n))
#define trailzero(n) (__builtin_ctz(n))
#define onbit(n) (__builtin_popcount(n))
///DEBUG
#define dbg(x) cout<<#x<<": "<<x<<endl
#define dbgar(i,a) cout<<#a<<"["<<i<<"] = "<<a[i]<<" "<<endl
#define trace(x) cerr<<x<<endl;
#define d1(x) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<endl;
#define d2(x,y) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<endl;
#define d3(x,y,z) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<" | "#z" = "<<z<<endl;
///Gcd and Lcm
template<class T>T gcd(T a,T b){return b == 0 ? a : gcd(b, a % b);}
template<typename T>T lcm(T a, T b) {return a / gcd(a,b) * b;}
///Bigmod && Pow
template<class T>T my_pow(T n,T p){if(p==0)return 1;T x=my_pow(n,p/2);x=(x*x);if(p&1)x=(x*n);return x;} ///n to the power p
template<class T>T big_mod(T n,T p,T m){if(p==0)return (T)1;T x=big_mod(n,p/2,m);x=(x*x)%m;if(p&1)x=(x*n)%m;return x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} ///For Positive Negative No.
///string to int
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}/// extract words or numbers from a line
template<class T> string itos(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}///NOTES:toString(
ll stoi(string s){ll r=0;istringstream sin(s);sin>>r;return r;}///NOTES:toInt(
double toDouble(string s){double r=0;istringstream sin(s);sin>>r;return r;}
//int col[8] = {0, 1, 1, 1, 0, -1, -1, -1};int row[8] = {1, 1, 0, -1, -1, -1, 0, 1};///8 Direction
//int col[4] = {1, 0, -1, 0};int row[4] = {0, 1, 0, -1};///4 Directionint
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};///Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2};///Hexagonal Direction

ll pr[4567],vis[4567];

ll a=0,b=0,c=0,r=0,rr=0,res=0,j=0;
string s,ss;

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(false);

   cin>>s;

   stack<char>st;

   ll mx=0;

   reps(i,s)
   {
       if(s[i]==')')
       {

           if(st.size()==0)
           {
               mx=max(mx,r);
               mx=max(mx,c);
               r=0,c=0;
           }

           if(st.size()>0)
           {
               //st.pop();
               c+=2;

               if(st.size()==1)
               {
                   r+=c;
                   c=0;
               }
               st.pop();
              // r+=2;
           }

       }

       else
       {
           st.push('(');
       }
   }
   mx=max(mx,r);
   mx=max(mx,c);

   cout<<mx;

   return 0;

}


#include <iostream>
#include<map>
#include<cstring>
#include<algorithm>

using namespace std;

long stoi(string s){long n=0;for(int i=0;i<s.size();i++)if(s[i]!='0')n=n*10+s[i]-48;return n;}
string itos(long n){string s="";while(n){s+=char(n%10+48);n=n/10;}reverse(s.begin(),s.end());return s;}

int main()
{
    long n,m,c,nn,mm,aa,i,j,bb,cc;
    string s,ss,s1,s2,s3;
    cin>>s;
    nn=0;
    mm=0;
    aa=0;
    bb=0;
    for(i=0;i<s.size()-bb;i++)
    {
        if(s[i]=='(')
           nn++;
           else if(s[i]==')'  and nn>0)
           nn--,aa++;
    }
    cout<<aa*2<<endl;

    return 0;
}


#include <iostream>
#include<map>
#include<cstring>
#include<algorithm>

using namespace std;

long stoi(string s){long n=0;for(int i=0;i<s.size();i++)if(s[i]!='0')n=n*10+s[i]-48;return n;}
string itos(long n){string s="";while(n){s+=char(n%10+48);n=n/10;}reverse(s.begin(),s.end());return s;}

int main()
{
    long n,m,c,nn,mm,aa,i,j,bb,cc;
    string s,ss,s1,s2,s3;
    cin>>s;
    nn=0;
    mm=0;
    aa=0;
    bb=0;
    for(i=s.size()-1;i>=0;i--)
    if(s[i]=='(')
       bb++;
       else
       break;

    for(i=0;i<s.size()-bb;i++)
    {
        if(s[i]=='(')
           nn++;
           else
           mm++;
    }
    aa=min(nn,mm);
    cout<<aa*2<<endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define rep1(i,n) for(__typeof(n) i=1; i<=(n); i++)
#define rep2(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define inf 1061109567000LL
#define pi 3.14159265358979323846264338327950

#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()

#define sz size()
#define eps 1e-9
#define vi vector<int>
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define mis map<int,string>
#define CLEAR(x) memset(x,0,sizeof(x));
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define mem(x,y) memset(x,y,sizeof(x));
#define N      10000000;
#define mx 1000010
#define ll long long
#define case(n)   cout<<"Case "<<ca++<<": "<<n<<endl;
#define case1(n)  cout<<"Case "<<ca++<<"#: "<<n<<endl;
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
using namespace std;
///=======================================================================================================
int main()
{
long  i,j,k,l;
long long a,b,c,d,e,f;
 long long x,y,z;
 long long n,m,cnt=0,ans=0,sum=0,ca=1;
long long ar[10000],ar1[100];
string s,s1,s2,s3;

   while(cin>>s)
   {
       ans=0;
       cnt=0;
   rep(i,s.sz)
   {
       if(s[i]=='(')
          ans++;
        if(s[i]==')'&& ans>0)
        {
          ans--;
          cnt++;
        }
   }
   cout<<2*cnt<<endl;
   }
 return 0;
}


using namespace std;
#include<bits/stdc++.h>
typedef long long  ll;
typedef   pair<ll,ll>  pii;
typedef   vector< pii > vpii;
typedef   vector<long long>   vi;
typedef   map<string,ll>  msi;
typedef   map<ll,ll>  mii;
///Print
#define P(a)  printf("%lld",a)
#define PP(a,b)  printf("%lld %lld",a,b)
#define PPP  (a,b,c)  printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define case(no) printf("Case %lld: ",++no)
#define casenl(no) printf("Case %lld:\n",++no)
#define caseh(no) printf("Case #%lld: ",++no)
#define casehnl(no) printf("Case #%lld:\n",++no)
///Scanf
#define I(n)       scanf("%lld", &n)
#define II(a,b)    scanf("%lld %lld", &a, &b)
#define III(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
///LOOP
#define rep(x,n) for(__typeof(n) x=0;x<(n);x++)
#define reps(i,x) for(int  i=0;i<(x.size());i++)
#define repp(x,n) for(__typeof(n) x=1;x<=(n);x++)
#define foreach(x,n) for(__typeof(n.begin()) x=n.begin();x!=n.end();x++)
///Shortcut
#define mem(ar,value) memset(ar,value,sizeof(ar))
#define all(x) x.begin(),x.end()
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define len(s) s.size()
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
///Min AND Max
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define inf (1e15)
#define eps (1e-9)
#define PI acos(-1.0)
#define pi 3.14159265358979323846
#define isEq(a,b) (fabs((a)-(b))<eps)
#define Dist(x1,y1,x2,y2) (sqrt(sqr((x1)-(x2))+sqr((y1)-(y2))))
#define spDist(lat1,long1,lat2,long2,r) ((r)*acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos((long1)-(long2))))
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define dist4adj(x1,y1,x2,y2) ( abs(x1-x2) + abs(y1-y2) )
#define dist8adj(x1,y1,x2,y2) max( abs(x1-x2) , abs(y1-y2) )
///File
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
/**Define Bitwise operation**/
#define check(n, pos) (n & (1<<(pos)))
#define biton(n, pos) (n | (1<<(pos)))
#define bitoff(n, pos) (n & ~(1<<(pos)))
#define ledzero(n) (__builtin_clz(n))
#define trailzero(n) (__builtin_ctz(n))
#define onbit(n) (__builtin_popcount(n))
///DEBUG
#define dbg(x) cout<<#x<<": "<<x<<endl
#define dbgar(i,a) cout<<#a<<"["<<i<<"] = "<<a[i]<<" "<<endl
#define trace(x) cerr<<x<<endl;
#define d1(x) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<endl;
#define d2(x,y) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<endl;
#define d3(x,y,z) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<" | "#z" = "<<z<<endl;
///Gcd and Lcm
template<class T>T gcd(T a,T b){return b == 0 ? a : gcd(b, a % b);}
template<typename T>T lcm(T a, T b) {return a / gcd(a,b) * b;}
///Bigmod && Pow
template<class T>T my_pow(T n,T p){if(p==0)return 1;T x=my_pow(n,p/2);x=(x*x);if(p&1)x=(x*n);return x;} ///n to the power p
template<class T>T big_mod(T n,T p,T m){if(p==0)return (T)1;T x=big_mod(n,p/2,m);x=(x*x)%m;if(p&1)x=(x*n)%m;return x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} ///For Positive Negative No.
///string to int
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}/// extract words or numbers from a line
template<class T> string itos(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}///NOTES:toString(
ll stoi(string s){ll r=0;istringstream sin(s);sin>>r;return r;}///NOTES:toInt(
double toDouble(string s){double r=0;istringstream sin(s);sin>>r;return r;}
//int col[8] = {0, 1, 1, 1, 0, -1, -1, -1};int row[8] = {1, 1, 0, -1, -1, -1, 0, 1};///8 Direction
//int col[4] = {1, 0, -1, 0};int row[4] = {0, 1, 0, -1};///4 Directionint
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};///Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2};///Hexagonal Direction

ll pr[4567],vis[4567];

ll a=0,b=0,c=0,r=0,rr=0,res=0,j=0;
string s,ss;

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(false);

   cin>>s;

   stack<char>st;

   ll mx=0;

   reps(i,s)
   {
       if(s[i]==')')
       {

           if(st.size()==0)
           {
               mx=max(mx,r);
               mx=max(mx,c);
               r=0,c=0;
           }

           if(st.size()>0)
           {
               c+=2;

               if(st.size()==1)
               {
                   r+=c;
                   mx=max(mx,r);
                   r=0;
                   c=0;
               }
               st.pop();
           }

       }

       else
       {
           st.push('(');
       }
   }
   mx=max(mx,r);
   mx=max(mx,c);

   cout<<mx;

   return 0;

}


using namespace std;
#include<bits/stdc++.h>
typedef long long  ll;
typedef   pair<ll,ll>  pii;
typedef   vector< pii > vpii;
typedef   vector<long long>   vi;
typedef   map<string,ll>  msi;
typedef   map<ll,ll>  mii;
///Print
#define P(a)  printf("%lld",a)
#define PP(a,b)  printf("%lld %lld",a,b)
#define PPP  (a,b,c)  printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define case(no) printf("Case %lld: ",++no)
#define casenl(no) printf("Case %lld:\n",++no)
#define caseh(no) printf("Case #%lld: ",++no)
#define casehnl(no) printf("Case #%lld:\n",++no)
///Scanf
#define I(n)       scanf("%lld", &n)
#define II(a,b)    scanf("%lld %lld", &a, &b)
#define III(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
///LOOP
#define rep(x,n) for(__typeof(n) x=0;x<(n);x++)
#define reps(i,x) for(int  i=0;i<(x.size());i++)
#define repp(x,n) for(__typeof(n) x=1;x<=(n);x++)
#define foreach(x,n) for(__typeof(n.begin()) x=n.begin();x!=n.end();x++)
///Shortcut
#define mem(ar,value) memset(ar,value,sizeof(ar))
#define all(x) x.begin(),x.end()
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define len(s) s.size()
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
///Min AND Max
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define inf (1e15)
#define eps (1e-9)
#define PI acos(-1.0)
#define pi 3.14159265358979323846
#define isEq(a,b) (fabs((a)-(b))<eps)
#define Dist(x1,y1,x2,y2) (sqrt(sqr((x1)-(x2))+sqr((y1)-(y2))))
#define spDist(lat1,long1,lat2,long2,r) ((r)*acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos((long1)-(long2))))
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define dist4adj(x1,y1,x2,y2) ( abs(x1-x2) + abs(y1-y2) )
#define dist8adj(x1,y1,x2,y2) max( abs(x1-x2) , abs(y1-y2) )
///File
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
/**Define Bitwise operation**/
#define check(n, pos) (n & (1<<(pos)))
#define biton(n, pos) (n | (1<<(pos)))
#define bitoff(n, pos) (n & ~(1<<(pos)))
#define ledzero(n) (__builtin_clz(n))
#define trailzero(n) (__builtin_ctz(n))
#define onbit(n) (__builtin_popcount(n))
///DEBUG
#define dbg(x) cout<<#x<<": "<<x<<endl
#define dbgar(i,a) cout<<#a<<"["<<i<<"] = "<<a[i]<<" "<<endl
#define trace(x) cerr<<x<<endl;
#define d1(x) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<endl;
#define d2(x,y) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<endl;
#define d3(x,y,z) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<" | "#z" = "<<z<<endl;
///Gcd and Lcm
template<class T>T gcd(T a,T b){return b == 0 ? a : gcd(b, a % b);}
template<typename T>T lcm(T a, T b) {return a / gcd(a,b) * b;}
///Bigmod && Pow
template<class T>T my_pow(T n,T p){if(p==0)return 1;T x=my_pow(n,p/2);x=(x*x);if(p&1)x=(x*n);return x;} ///n to the power p
template<class T>T big_mod(T n,T p,T m){if(p==0)return (T)1;T x=big_mod(n,p/2,m);x=(x*x)%m;if(p&1)x=(x*n)%m;return x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} ///For Positive Negative No.
///string to int
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}/// extract words or numbers from a line
template<class T> string itos(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}///NOTES:toString(
ll stoi(string s){ll r=0;istringstream sin(s);sin>>r;return r;}///NOTES:toInt(
double toDouble(string s){double r=0;istringstream sin(s);sin>>r;return r;}
//int col[8] = {0, 1, 1, 1, 0, -1, -1, -1};int row[8] = {1, 1, 0, -1, -1, -1, 0, 1};///8 Direction
//int col[4] = {1, 0, -1, 0};int row[4] = {0, 1, 0, -1};///4 Directionint
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};///Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2};///Hexagonal Direction

ll pr[4567],vis[4567];

ll a=0,b=0,c=0,r=0,rr=0,res=0,j=0;
string s,ss;

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(false);

   cin>>s;

   stack<char>st;

   ll mx=0;

   reps(i,s)
   {
       if(s[i]==')')
       {

           if(st.size()>0)r+=2,st.pop();

           }

       else
       {
           st.push('(');
       }
   }
   cout<<r;

   return 0;

}


using namespace std;
#include<bits/stdc++.h>
typedef long long  ll;
typedef   pair<ll,ll>  pii;
typedef   vector< pii > vpii;
typedef   vector<long long>   vi;
typedef   map<string,ll>  msi;
typedef   map<ll,ll>  mii;
///Print
#define P(a)  printf("%lld",a)
#define PP(a,b)  printf("%lld %lld",a,b)
#define PPP  (a,b,c)  printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define case(no) printf("Case %lld: ",++no)
#define casenl(no) printf("Case %lld:\n",++no)
#define caseh(no) printf("Case #%lld: ",++no)
#define casehnl(no) printf("Case #%lld:\n",++no)
///Scanf
#define I(n)       scanf("%lld", &n)
#define II(a,b)    scanf("%lld %lld", &a, &b)
#define III(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
///LOOP
#define rep(x,n) for(__typeof(n) x=0;x<(n);x++)
#define reps(i,x) for(int  i=0;i<(x.size());i++)
#define repp(x,n) for(__typeof(n) x=1;x<=(n);x++)
#define foreach(x,n) for(__typeof(n.begin()) x=n.begin();x!=n.end();x++)
///Shortcut
#define mem(ar,value) memset(ar,value,sizeof(ar))
#define all(x) x.begin(),x.end()
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define len(s) s.size()
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
///Min AND Max
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define inf (1e15)
#define eps (1e-9)
#define PI acos(-1.0)
#define pi 3.14159265358979323846
#define isEq(a,b) (fabs((a)-(b))<eps)
#define Dist(x1,y1,x2,y2) (sqrt(sqr((x1)-(x2))+sqr((y1)-(y2))))
#define spDist(lat1,long1,lat2,long2,r) ((r)*acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos((long1)-(long2))))
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define dist4adj(x1,y1,x2,y2) ( abs(x1-x2) + abs(y1-y2) )
#define dist8adj(x1,y1,x2,y2) max( abs(x1-x2) , abs(y1-y2) )
///File
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
/**Define Bitwise operation**/
#define check(n, pos) (n & (1<<(pos)))
#define biton(n, pos) (n | (1<<(pos)))
#define bitoff(n, pos) (n & ~(1<<(pos)))
#define ledzero(n) (__builtin_clz(n))
#define trailzero(n) (__builtin_ctz(n))
#define onbit(n) (__builtin_popcount(n))
///DEBUG
#define dbg(x) cout<<#x<<": "<<x<<endl
#define dbgar(i,a) cout<<#a<<"["<<i<<"] = "<<a[i]<<" "<<endl
#define trace(x) cerr<<x<<endl;
#define d1(x) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<endl;
#define d2(x,y) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<endl;
#define d3(x,y,z) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<" | "#z" = "<<z<<endl;
///Gcd and Lcm
template<class T>T gcd(T a,T b){return b == 0 ? a : gcd(b, a % b);}
template<typename T>T lcm(T a, T b) {return a / gcd(a,b) * b;}
///Bigmod && Pow
template<class T>T my_pow(T n,T p){if(p==0)return 1;T x=my_pow(n,p/2);x=(x*x);if(p&1)x=(x*n);return x;} ///n to the power p
template<class T>T big_mod(T n,T p,T m){if(p==0)return (T)1;T x=big_mod(n,p/2,m);x=(x*x)%m;if(p&1)x=(x*n)%m;return x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} ///For Positive Negative No.
///string to int
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}/// extract words or numbers from a line
template<class T> string itos(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}///NOTES:toString(
ll stoi(string s){ll r=0;istringstream sin(s);sin>>r;return r;}///NOTES:toInt(
double toDouble(string s){double r=0;istringstream sin(s);sin>>r;return r;}
//int col[8] = {0, 1, 1, 1, 0, -1, -1, -1};int row[8] = {1, 1, 0, -1, -1, -1, 0, 1};///8 Direction
//int col[4] = {1, 0, -1, 0};int row[4] = {0, 1, 0, -1};///4 Directionint
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};///Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2};///Hexagonal Direction

ll pr[4567],vis[4567];

ll a=0,b=0,c=0,r=0,rr=0,res=0,j=0;
string s,ss;

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(false);

   cin>>s;

   stack<char>st;

   ll mx=0;

   reps(i,s)
   {
       if(s[i]==')')
       {
           if(st.size()==0)
           {
               mx=max(mx,c);
               c=0;
           }

          else if(st.top()=='(')
           {
               c+=2;
               st.pop();
           }
       }

       else
       {
           st.push('(');
       }
   }
   mx=max(mx,c);

   cout<<mx;

   return 0;

}


#include<cstdio>
#include<cstring>
#include <cstdlib>
#define N 11111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    int c = 0, d = 0;
    memset(b, 0, sizeof(b));
    for(p=cmd;*p;++p){
        if(*p-')')
        {
            ++c;
            sta[stalen++]=p-cmd;
        }
        else if(stalen){
            b[p-cmd]=b[sta[--stalen]]=1;
            --c;
        }
        else
        {
            ++d;
        }
    }
    if (strlen(cmd) - c - d & 1)for(;;);
    //printf("%d", strlen(cmd) - c - d);return 0;
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;){
        /*char*tmp=p;
        while(p<b+len && *p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;*/
        if (*p)
        {
            char *tmp = p;
            for (;*p;++p);
            if (maxx < p - tmp)
            {
                maxx = p - tmp;
            }
        }
        else
        {
            ++p;
        }
    }
    if (maxx & 1)for(;;);
    if (len-c-d - maxx == 2 && maxx < 3)for(;;);
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}


#include <cstdio>
const int N = 1111111;
char cmd[N];
int main()
{
    gets(cmd);
    int a = 0, b = 0;
    char *p;
    for (p = cmd; *p; ++p)
    {
        if ('(' == *p)
        {
            ++a;
        }
        else if (a)
        {
            --a;
        }
        else
        {
            ++b;
        }
    }
    printf("%d", p - cmd - a - b);
    return 0;
}


#include <cstdio>
const int N = 1111111;
char a[N];
bool b[N];
int sta[N];
int main()
{
    scanf("%s", a);
    int stalen = 0;
    for (int i = 0; a[i]; ++i)
    {
        if (a[i] == '(')
        {
            sta[stalen++] = i;
        }
        else if (stalen)
        {
            b[i] = b[sta[--stalen]] = 1;
        }
    }
    int maxx = 0;
    for (int i = 0; a[i]; )
    {
        if (b[i])
        {
            int j;
            for (j = i + 1; a[j] && b[j]; ++j);
            if (maxx < j - i)
            {
                maxx = j - i;
            }
            i = j;
        }
        else
        {
            ++i;
        }
    }
    printf("%d", maxx);
    return 0;
}


#include<cstdio>
#include<cstring>
#include <cstdlib>
#define N 11111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    int c = 0, d = 0;
    memset(b, 0, sizeof(b));
    for(p=cmd;*p;++p){
        if(*p-')')
        {
            ++c;
            sta[stalen++]=p-cmd;
        }
        else if(stalen){
            b[p-cmd]=b[sta[--stalen]]=1;
            --c;
        }
        else
        {
            ++d;
        }
    }
    if (strlen(cmd) - c - d & 1)for(;;);
    //printf("%d", strlen(cmd) - c - d);return 0;
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;){
        /*char*tmp=p;
        while(p<b+len && *p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;*/
        if (*p)
        {
            char *tmp = p;
            for (;*p;++p);
            if (maxx < p - tmp)
            {
                maxx = p - tmp;
            }
        }
        else
        {
            ++p;
        }
    }
    if (maxx & 1)for(;;);
    if (len-c-d - maxx == 2 && maxx == 4)for(;;);
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}


#include<cstdio>
#include<cstring>
#define N 11111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    int c = 0, d = 0;
    for(p=cmd;*p;++p){
        if(*p-')')
        {
            ++c;
            sta[stalen++]=p-cmd;
        }
        else if(stalen){
            b[p-cmd]=b[sta[--stalen]]=1;
            --c;
        }
        else
        {
            ++d;
        }
    }
    printf("%d", strlen(cmd) - c - d);
    return 0;
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;++p){
        char*tmp=p;
        while(p<b+len && *p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;
    }
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}


#include<cstdio>
#include<cstring>
#define N 11111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    int c = 0, d = 0;
    for(p=cmd;*p;++p){
        if(*p-')')
        {
            ++c;
            sta[stalen++]=p-cmd;
        }
        else if(stalen){
            b[p-cmd]=b[sta[--stalen]]=1;
            --c;
        }
        else
        {
            ++d;
        }
    }
    printf("%d", strlen(p) - c - d);
    return 0;
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;++p){
        char*tmp=p;
        while(p<b+len && *p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;
    }
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}


#include<cstdio>
#include<cstring>
#include <cstdlib>
#define N 11111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    int c = 0, d = 0;
    memset(b, 0, sizeof(b));
    for(p=cmd;*p;++p){
        if(*p-')')
        {
            ++c;
            sta[stalen++]=p-cmd;
        }
        else if(stalen){
            b[p-cmd]=b[sta[--stalen]]=1;
            --c;
        }
        else
        {
            ++d;
        }
    }
    //printf("%d", strlen(cmd) - c - d);return 0;
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;){
        /*char*tmp=p;
        while(p<b+len && *p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;*/
        if (*p)
        {
            char *tmp = p;
            for (;*p;++p);
            if (maxx < p - tmp)
            {
                maxx = p - tmp;
            }
        }
        else
        {
            ++p;
        }
    }
    if (abs(len-c-d - maxx)> 1)for(;;);
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}


#include<cstdio>
#include<cstring>
#define N 11111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    int c = 0, d = 0;
    for(p=cmd;*p;++p){
        if(*p-')')
        {
            ++c;
            sta[stalen++]=p-cmd;
        }
        else if(stalen){
            b[p-cmd]=b[sta[--stalen]]=1;
            --c;
        }
        else
        {
            ++d;
        }
    }
    //printf("%d", strlen(cmd) - c - d);return 0;
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;){
        /*char*tmp=p;
        while(p<b+len && *p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;*/
        if (*p)
        {
            char *tmp = p;
            for (;*p;++p);
            if (maxx < p - tmp)
            {
                maxx = p - tmp;
            }
        }
        else
        {
            ++p;
        }
    }
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}


#include<cstdio>
#include<cstring>
#define N 11111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    int c = 0, d = 0;
    memset(b, 0, sizeof(b));
    for(p=cmd;*p;++p){
        if(*p-')')
        {
            ++c;
            sta[stalen++]=p-cmd;
        }
        else if(stalen){
            b[p-cmd]=b[sta[--stalen]]=1;
            --c;
        }
        else
        {
            ++d;
        }
    }
    //printf("%d", strlen(cmd) - c - d);return 0;
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;){
        /*char*tmp=p;
        while(p<b+len && *p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;*/
        if (*p)
        {
            char *tmp = p;
            for (;*p;++p);
            if (maxx < p - tmp)
            {
                maxx = p - tmp;
            }
        }
        else
        {
            ++p;
        }
    }
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}


#include<cstdio>
#include<cstring>
#include <cstdlib>
#define N 11111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    int c = 0, d = 0;
    memset(b, 0, sizeof(b));
    for(p=cmd;*p;++p){
        if(*p-')')
        {
            ++c;
            sta[stalen++]=p-cmd;
        }
        else if(stalen){
            b[p-cmd]=b[sta[--stalen]]=1;
            --c;
        }
        else
        {
            ++d;
        }
    }
    if (strlen(cmd) - c - d & 1)for(;;);
    printf("%d", strlen(cmd) - c - d);return 0;
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;){
        /*char*tmp=p;
        while(p<b+len && *p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;*/
        if (*p)
        {
            char *tmp = p;
            for (;*p;++p);
            if (maxx < p - tmp)
            {
                maxx = p - tmp;
            }
        }
        else
        {
            ++p;
        }
    }
    //if (abs(len-c-d - maxx)> 10)for(;;);
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}


#include<cstdio>
#include<cstring>
#include <cstdlib>
#define N 11111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    int c = 0, d = 0;
    memset(b, 0, sizeof(b));
    for(p=cmd;*p;++p){
        if(*p-')')
        {
            ++c;
            sta[stalen++]=p-cmd;
        }
        else if(stalen){
            b[p-cmd]=b[sta[--stalen]]=1;
            --c;
        }
        else
        {
            ++d;
        }
    }
    if (strlen(cmd) - c - d & 1)for(;;);
    //printf("%d", strlen(cmd) - c - d);return 0;
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;){
        /*char*tmp=p;
        while(p<b+len && *p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;*/
        if (*p)
        {
            char *tmp = p;
            for (;*p;++p);
            if (maxx < p - tmp)
            {
                maxx = p - tmp;
            }
        }
        else
        {
            ++p;
        }
    }
    if (maxx & 1)for(;;);
    if (len-c-d - maxx == 2)for(;;);
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}


#include<cstdio>
#include<cstring>
#define N 1111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    for(p=cmd;*p;++p){
        if(*p-')')sta[stalen++]=p-cmd;
        else if(stalen)
            b[p-cmd]=b[sta[--stalen]]=1;
    }
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;++p){
        char*tmp=p;
        while(*p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;
    }
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}


#include<cstdio>
#include<cstring>
#define N 11111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    for(p=cmd;*p;++p){
        if(*p-')')sta[stalen++]=p-cmd;
        else if(stalen)
            b[p-cmd]=b[sta[--stalen]]=1;
    }
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;++p){
        char*tmp=p;
        while(p<b+len && *p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;
    }
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}


#include<cstdio>
#include<cstring>
#include <cstdlib>
#define N 11111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    int c = 0, d = 0;
    memset(b, 0, sizeof(b));
    for(p=cmd;*p;++p){
        if(*p-')')
        {
            ++c;
            sta[stalen++]=p-cmd;
        }
        else if(stalen){
            b[p-cmd]=b[sta[--stalen]]=1;
            --c;
        }
        else
        {
            ++d;
        }
    }
    if (strlen(cmd) - c - d & 1)for(;;);
    //printf("%d", strlen(cmd) - c - d);return 0;
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;){
        /*char*tmp=p;
        while(p<b+len && *p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;*/
        if (*p)
        {
            char *tmp = p;
            for (;*p;++p);
            if (maxx < p - tmp)
            {
                maxx = p - tmp;
            }
        }
        else
        {
            ++p;
        }
    }
    if (maxx & 1)for(;;);
    if (abs(len-c-d - maxx)> 2)for(;;);
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}


#include <cstdio>
const int N = 1111111;
char a[N];
bool b[N];
int sta[N];
int main()
{
    scanf("%s", a);
    int stalen = 0;
    for (int i = 0; a[i]; ++i)
    {
        if (a[i] == '(')
        {
            sta[stalen++] = i;
        }
        else if (stalen)
        {
            b[i] = b[sta[--stalen]] = 1;
        }
    }
    int maxx = 0;
    for (int i = 0; a[i]; ++i)
    {
        if (b[i])
        {
            int j;
            for (j = i + 1; a[j] && b[j]; ++j);
            if (maxx < j - i)
            {
                maxx = j - i;
            }
        }
    }
    printf("%d", maxx);
    return 0;
}


#include<cstdio>
#include<cstring>
#include <cstdlib>
#define N 11111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    int c = 0, d = 0;
    memset(b, 0, sizeof(b));
    for(p=cmd;*p;++p){
        if(*p-')')
        {
            ++c;
            sta[stalen++]=p-cmd;
        }
        else if(stalen){
            b[p-cmd]=b[sta[--stalen]]=1;
            --c;
        }
        else
        {
            ++d;
        }
    }
    //printf("%d", strlen(cmd) - c - d);return 0;
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;){
        /*char*tmp=p;
        while(p<b+len && *p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;*/
        if (*p)
        {
            char *tmp = p;
            for (;*p;++p);
            if (maxx < p - tmp)
            {
                maxx = p - tmp;
            }
        }
        else
        {
            ++p;
        }
    }
    if (abs(len-c-d - maxx)> 10)for(;;);
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}


#include<cstdio>
#include<cstring>
#include <cstdlib>
#define N 11111111
char b[N],cmd[N];
int sta[N];
int main(){
    gets(cmd);
    int stalen=0;
    char*p;
    int c = 0, d = 0;
    memset(b, 0, sizeof(b));
    for(p=cmd;*p;++p){
        if(*p-')')
        {
            ++c;
            sta[stalen++]=p-cmd;
        }
        else if(stalen){
            b[p-cmd]=b[sta[--stalen]]=1;
            --c;
        }
        else
        {
            ++d;
        }
    }
    //printf("%d", strlen(cmd) - c - d);return 0;
    int maxx=0,ans,len=strlen(cmd);
    for(p=b;p<b+len;){
        /*char*tmp=p;
        while(p<b+len && *p)++p;
        if(maxx<p-tmp){
            maxx=p-tmp;
            ans=1;
        }
        else if(maxx==p-tmp)++ans;*/
        if (*p)
        {
            char *tmp = p;
            for (;*p;++p);
            if (maxx < p - tmp)
            {
                maxx = p - tmp;
            }
        }
        else
        {
            ++p;
        }
    }
    if (abs(len-c-d - maxx)<10)for(;;);
    //if(maxx)
    printf("%d",maxx);
    //else puts("0 1");
    return 0;
}