#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <algorithm>
using namespace std;
#define rep(_m,s,e) for(int _m=s;_m<e;_m++)
typedef long long ll;
int  toInt(string s)   {int r=0; istringstream sin(s); sin>>r; return r;}
ll   toInt64(string s) {ll r=0; istringstream sin(s); sin>>r; return r;}
double  toDouble(string s){double r=0; istringstream sin(s); sin>>r; return r;}
string toString(ll n) {string s,s1; while (n / 10 > 0){ s += (char)((n%10) + 48); n/=10;} s += (char)((n%10) + 48); n/=10; s1 = s; rep(i,0,s.length()) s1[(s.length()-1)-i] = s[i]; return s1;}
bool isUpperCase(char c){return c >= 'A' && c <= 'Z';}
bool isLowerCase(char c){return c >= 'a' && c <= 'z';}
bool isLetter(char c)   {return c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z';}
bool isDigit(char c)    {return c >= '0' && c <= '9';}
char toLowerCase(char c){return (isUpperCase(c))?(c + 32) : c;}
char toUpperCase(char c){return (isLowerCase(c))?(c - 32) : c;}
ll gcd(ll a, ll b) {if(!a) return b; return gcd(b%a, a);}

int x[100001];
int n;

const int MAXN = 100001;

struct fenwick{
	int fen[100001];
	int get(int andis)
	{

		if (andis == 0)
			return 0;
		return fen[andis] + get(andis - (andis & (-andis)));
	}
	void add(int x, int val)
	{
		for (;x <= MAXN; x += x & -x)
			fen[x] += val;
	}
	void clear()
	{
		fill(fen, fen+MAXN, 0);
	}
};

int L[100001], R[100001];
fenwick F;
fenwick fL, fR;

map<int, int> MAP;

int y[MAXN];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll k;
	cin >> n >> k;
	rep(i,0,n)
		cin >> x[i], y[i] = x[i];
	sort(y, y + n);
	for (int i = 1; i <= n; i++)
		if (MAP[y[i-1]] == 0) MAP[y[i-1]] = i;
	L[0] = 0;
	F.add(MAP[x[0]], 1);
	for (int i = 1; i < n; i++)
	{
		L[i] = L[i-1];
		F.add(MAP[x[i]], 1);
		L[i] += (i+1)-F.get(MAP[x[i]]);
	}
	F.clear();
	R[n-1] = 0;
	F.add(MAP[x[n-1]], 1);
	for (int i = n-2; i >= 0; i--)
	{
		R[i] = R[i+1];
		F.add(MAP[x[i]], 1);
		R[i] += F.get(MAP[x[i]])-1;
	}
	ll cnt = 0;
	int l = 0, r = 1;
	for (int i = 1; i < n; i++)
		fR.add(MAP[x[i]], 1);
	fL.add(MAP[x[0]], 1);
	ll ans = 0;
	fR.add(MAP[x[0]], 1);
	cnt += fR.get(MAP[x[0]])-1;
	cnt += L[0] + R[1];
	fR.add(MAP[x[0]], -1);
	while (l < n && r < n)
	{
		int tmpR = r, tmpL = l;
		if (cnt <= k)
		{
			ans += n - r;
			l++;
			if (l == r)
			{
				fR.add(MAP[x[r]], -1);
				fL.add(MAP[x[r]], 1);
				cnt -= (l+2) - fL.get(MAP[x[r]]);
				fL.add(MAP[x[r]], -1);
				r++;
			}
			fL.add(MAP[x[l]], 1);

			fR.add(MAP[x[l]], 1);
			cnt += fR.get(MAP[x[l]])-1;
			fR.add(MAP[x[l]], -1);

		}
		else {
			fR.add(MAP[x[r]], -1);
			fL.add(MAP[x[r]], 1);
			cnt -= (l+2) - fL.get(MAP[x[r]]);
			fL.add(MAP[x[r]], -1);
			r++;
		}
		cnt -= L[tmpL] + R[tmpR];
		cnt += L[l] + R[r];
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define PII pair<int,int>

using namespace std;

const int N = 100000;
int n;
long long a[N+5];
long long sum[N+5];
long long mi[2];
long long ma[2];
long long an;
int main(){
    scanf("%d",&n);
    for(int i=1; i<=n; i++){
        scanf("%lld",&a[i]);
    }
    for(int i=2; i<=n; i++){
        if(i%2==0){
            sum[i] = sum[i-1]+abs(a[i]-a[i-1]);
            an = max(an, sum[i]-mi[0]);
            an = max(an, ma[1]-sum[i]);
            mi[0] = min(sum[i], mi[0]);
            ma[0] = max(sum[i], ma[0]);
        }
        else{
            sum[i] = sum[i-1]-abs(a[i]-a[i-1]);
            an = max(an, sum[i]-mi[1]);
            an = max(an, ma[0]-sum[i]);
            mi[1] = min(sum[i], mi[1]);
            ma[1] = max(sum[i], ma[1]);
        }
    }
    printf("%lld",an);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<algorithm>
using namespace std;

#define INF 0x3f3f3f3f
#define M 100010

long long a[M];
long long dp[M];
int main()
{

    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        {
            scanf("%I64d",&a[i]);
        }
    for(int i=0;i<n-1;i++)
        {
            a[i]=abs(a[i]-a[i+1]);
        }
        long long ans=0;
    dp[0]=a[0];
    ans=max(ans,dp[0]);
    for(int i=1;i<n-1;i++)
        {
            if(dp[i-1]>0)
                {if(!(i&1))
                {dp[i]=dp[i-1]+a[i];
                }
                else
                {dp[i]=dp[i-1]-a[i];
                }}
                else
                    dp[i]=a[i];
                ans=max(ans,dp[i]);
        }
        if(n>2)
        {dp[1]=a[1];
        ans=max(ans,dp[1]);
        for(int i=2;i<n-1;i++)
        {
            if(dp[i-1]>0)
                {if((i&1))
                {dp[i]=dp[i-1]+a[i];
                }
                else
                {dp[i]=dp[i-1]-a[i];
                }}
                else
                    dp[i]=a[i];
                ans=max(ans,dp[i]);
        }}
        if(ans<0)
            ans=0;
        cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<algorithm>
using namespace std;

#define INF 0x3f3f3f3f
#define M 100010

int a[M];

int main()
{

    int dp[M];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
    for(int i=0;i<n-1;i++)
        {
            a[i]=abs(a[i]-a[i+1]);
        }
        unsigned long long ans=0;
    dp[0]=a[0];
    ans=max(ans,dp[0]);
    for(int i=1;i<n-1;i++)
        {
            if(dp[i-1]>0)
                {if(!(i&1))
                {dp[i]=dp[i-1]+a[i];
                }
                else
                {dp[i]=dp[i-1]-a[i];
                }}
                else
                    dp[i]=a[i];
                ans=max(ans,dp[i]);
        }
        if(n>2)
        {dp[1]=a[1];
        ans=max(ans,dp[1]);
        for(int i=2;i<n-1;i++)
        {
            if(dp[i-1]>0)
                {if((i&1))
                {dp[i]=dp[i-1]+a[i];
                }
                else
                {dp[i]=dp[i-1]-a[i];
                }}
                else
                    dp[i]=a[i];
                ans=max(ans,dp[i]);
        }}
        if(ans<0)
            ans=0;
        cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<algorithm>
using namespace std;

#define INF 0x3f3f3f3f
#define M 100010

int a[M];

int main()
{

    int dp[M];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
    for(int i=0;i<n-1;i++)
        {
            a[i]=abs(a[i]-a[i+1]);
        }
        int ans=-1;
    dp[0]=a[0];
    for(int i=1;i<n-1;i++)
        {
            if(dp[i-1]>0)
                {if(!(i&1))
                {dp[i]=dp[i-1]+a[i];
                }
                else
                {dp[i]=dp[i-1]-a[i];
                }}
                else
                    dp[i]=a[i];
                ans=max(ans,dp[i]);
        }
        dp[1]=a[1];
        for(int i=2;i<n-1;i++)
        {
            if(dp[i-1]>0)
                {if((i&1))
                {dp[i]=dp[i-1]+a[i];
                }
                else
                {dp[i]=dp[i-1]-a[i];
                }}
                else
                    dp[i]=a[i];
                ans=max(ans,dp[i]);
        }
        cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<algorithm>
using namespace std;

#define INF 0x3f3f3f3f
#define M 100010
typedef long long LL;

/*
5
1000000000 0 0 1000000000 -1000000000
*/
int main()
{
    LL a[M];
    LL dp[M];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        {
            scanf("%I64d",&a[i]);
        }
    for(int i=0;i<n-1;i++)
        {
            a[i]=abs(a[i]-a[i+1]);
        }
        LL ans=-1;
    dp[0]=a[0];
    ans=max(ans,dp[0]);
    for(int i=1;i<n-1;i++)
        {
            if(dp[i-1]>=0)
                {if(!(i&1))
                {dp[i]=dp[i-1]+a[i];
                }
                else
                {dp[i]=dp[i-1]-a[i];
                }}
                else
                    dp[i]=a[i];
                ans=max(ans,dp[i]);
        }
        if(n>2)
        {dp[1]=a[1];
        ans=max(ans,dp[1]);
        for(int i=2;i<n-1;i++)
        {
            if(dp[i-1]>=0)
                {if((i&1))
                {dp[i]=dp[i-1]+a[i];
                }
                else
                {dp[i]=dp[i-1]-a[i];
                }}
                else
                    dp[i]=a[i];
                ans=max(ans,dp[i]);
        }}
        if(ans<0)
            ans=0;
        cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<algorithm>
using namespace std;

#define INF 0x3f3f3f3f
#define M 100010

int a[M];

int main()
{

    int dp[M];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
    for(int i=0;i<n-1;i++)
        {
            a[i]=abs(a[i]-a[i+1]);
        }
        int ans=-1;
    dp[0]=a[0];
    ans=max(ans,dp[0]);
    for(int i=1;i<n-1;i++)
        {
            if(dp[i-1]>0)
                {if(!(i&1))
                {dp[i]=dp[i-1]+a[i];
                }
                else
                {dp[i]=dp[i-1]-a[i];
                }}
                else
                    dp[i]=a[i];
                ans=max(ans,dp[i]);
        }
        if(n>2)
        {dp[1]=a[1];
        ans=max(ans,dp[1]);
        for(int i=2;i<n-1;i++)
        {
            if(dp[i-1]>0)
                {if((i&1))
                {dp[i]=dp[i-1]+a[i];
                }
                else
                {dp[i]=dp[i-1]-a[i];
                }}
                else
                    dp[i]=a[i];
                ans=max(ans,dp[i]);
        }}
        if(ans<0)
            ans=0;
        cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n,i;
	cin>>n;
	ll a[n];
	ll b[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	ll p=1;
	for(i=1;i<n;i++)
	{
		b[i]=p*abs(a[i]-a[i-1]);
		p*=-1;
	}
	ll ans=-1e9;
    ll sum=0;
    for(i=0;i<n;i++){
        sum+=b[i];
        ans=max(ans,sum);
        if(sum<0)sum=0;
    }
    for(i=0;i<n;i++){
        b[i]*=-1;
    }
    sum=0;
    for( i=0;i<n;i++){
        sum+=b[i];
        ans=max(ans,sum);
        if(sum<0)sum=0;
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int nmax=5*1e5+9;
long long psum[nmax];
int a;
int n;
vector<int> idx;
vector<int> idx2;
int main()
{
	ll n,i;
	cin>>n;
	ll a[n];
	ll b[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	ll p=1;
	for(i=1;i<n;i++)
	{
		b[i]=p*abs(a[i]-a[i-1]);
		p*=-1;
	}
	ll ans=-1e9;
    ll sum=0;
    for(i=0;i<n;i++){
        sum+=b[i];
        ans=max(ans,sum);
        if(sum<0)sum=0;
    }
    for(i=0;i<n;i++){
        b[i]*=-1;
    }
    sum=0;
    for( i=0;i<n;i++){
        sum+=b[i];
        ans=max(ans,sum);
        if(sum<0)sum=0;
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n,i;
	cin>>n;
	ll a[n];
	ll b[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	ll p=1;
	for(i=1;i<n;i++)
	{
		b[i]=p*abs(a[i]-a[i-1]);
		p*=-1;
	}
	ll ans=-1e9;
    ll sum=0;
    for(i=1;i<n;i++){
        sum+=b[i];
        ans=max(ans,sum);
        if(sum<0)sum=0;
    }
    for(i=1;i<n;i++){
        b[i]*=-1;
    }
    sum=0;
    for( i=1;i<n;i++){
        sum+=b[i];
        ans=max(ans,sum);
        if(sum<0)sum=0;
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int nmax=5*1e5+9;
long long psum[nmax];
int a;
int n;
vector<int> idx;
vector<int> idx2;
int main()
{
	ll n,i;
	cin>>n;
	ll a[n];
	ll b[n+5];
	for(i=0;i<n;i++)
		cin>>a[i];
	ll p=1;
	for(i=1;i<n;i++)
	{
		b[i]=p*abs(a[i]-a[i-1]);
		p*=-1;
	}
	ll ans=-1e9;
    ll sum=0;
    for(ll i=0;i<n;i++){
        sum+=b[i];
        ans=max(ans,sum);
        if(sum<0)sum=0;
    }
    for(ll i=0;i<n;i++){
        b[i]*=-1;
    }
    sum=0;
    for(ll i=0;i<n;i++){
        sum+=b[i];
        ans=max(ans,sum);
        if(sum<0)sum=0;
    }
    cout<<ans;

}


#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 105000
#define inf (int)1e9
#define ll long long
#define eps 1e-9
#define mm 998244353LL
#define low(x) x&(-x)
#define pb push_back
#define mp make_pair
#define PII pair<int,int>
using namespace std;
ll read(){
    ll x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
int n;
ll f[maxn],a[maxn],ans;
int main(){
	n=read();
	rep(i,1,n) a[i]=read();
	rep(i,1,n-1) a[i]=a[i]-a[i+1];
	f[0]=0;
	rep(i,1,n-1) f[i]=max(0ll,f[i-1]+a[i]),ans=max(ans,f[i]);
	rep(i,1,n-1) a[i]=-a[i];
	f[0]=0;
	rep(i,1,n-1) f[i]=max(0ll,f[i-1]+a[i]),ans=max(ans,f[i]);
	printf("%lld\n",ans);
 	return 0;
}


#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 105000
#define inf (int)1e9
#define ll long long
#define eps 1e-9
#define mm 998244353LL
#define low(x) x&(-x)
#define pb push_back
#define mp make_pair
#define PII pair<int,int>
using namespace std;
ll read(){
    ll x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
int n;
ll f[maxn],a[maxn],b[maxn],ans;
int main(){
	n=read();
	rep(i,1,n) b[i]=read();
	rep(i,1,n-1) a[i]=abs(b[i]-b[i+1]);
	rep(i,1,n-1) if (i&1) a[i]=-a[i];
	f[0]=0;
	rep(i,1,n-1) f[i]=max(0ll,f[i-1]+a[i]),ans=max(ans,f[i]);
	rep(i,1,n-1) a[i]=-a[i];
	f[0]=0;
	rep(i,1,n-1) f[i]=max(0ll,f[i-1]+a[i]),ans=max(ans,f[i]);
	printf("%lld\n",ans);
 	return 0;
}


#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<cmath>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 100500
#define mm 1000000007
#define ll long long
using namespace std;
ll read(){
	ll x=0,f=1; char ch=getchar();
	while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
	while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
ll get(int x){
	if (x%2==0) return -1;
	else return 1;
}
ll a[maxn],f[maxn];
int n;
int main(){
//	freopen("in.txt","r",stdin);
	n=read();
	rep(i,1,n) a[i]=read();
	ll ans;
	rep(i,1,n-1) f[i]=abs(a[i]-a[i+1])*get(i);
	ll x=0; int flag=0;
	rep(i,1,n-1) {
		x+=f[i];
		if (!flag) ans=x,flag=1; else ans=max(ans,x);
		if (x<0) x=0;
	}
	rep(i,1,n-1) f[i]=-f[i];
	x=0;
	rep(i,1,n-1){
		x+=f[i];
		ans=max(ans,x);
		if (x<0) x=0;
	}
	printf("%lld\n",ans);
	return 0;
}


#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<cmath>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 100500
#define mm 1000000007
#define ll long long
using namespace std;
ll read(){
	ll x=0,f=1; char ch=getchar();
	while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
	while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
ll get(int x){
	if (x%2) return -1;
	else return 1;
}
struct data{ll x;int y;
bool friend operator <(data a,data b){
	return a.x<b.x;
}
};
struct data2{ll x;int y;
bool friend operator <(data2 a,data2 b){
	return a.x>b.x;
}
};
priority_queue<data> q1;
priority_queue<data2> q2;
ll a[maxn],f[maxn];
int n;
int main(){
//	freopen("in.txt","r",stdin);
	n=read();
	rep(i,1,n) a[i]=read();
	ll ans;
	rep(i,2,n) {f[i]=f[i-1]+abs(a[i]-a[i-1])*get(i); if (i==2) ans=f[2]; ans=max(ans,f[i]);}
	rep(i,2,n) {
		ll x,y;
		while (!q1.empty()) {x=q1.top().x,y=q1.top().y; q1.pop(); ans=max(ans,get(y+1)*(f[i]-x));}
		while (!q2.empty()) {x=q2.top().x,y=q2.top().y; q2.pop(); ans=max(ans,get(y+1)*(f[i]-x));}
		q1.push((data){f[i],i}); q2.push((data2){f[i],i});
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long ll;

const int N = 11111;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;

ll n, arr[N], maxi[N], mini[N];

int main(){
    while(cin >> n){
        for(int i = 0; i < n; ++i){
            cin >> arr[i];
            if(i) arr[i-1] = abs(arr[i] - arr[i-1]);
        }
        ll ans = 0;
        for(int i = n - 1; i > 0; --i){
            maxi[i] = max(arr[i], arr[i] - mini[i+1]);
            mini[i] = min(arr[i], arr[i] - maxi[i+1]);
            ans = max(ans, maxi[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


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

typedef long long ll;

const int N = 11111;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;

ll n, arr[N], maxi[N], mini[N];

int main(){
    while(cin >> n){
        for(int i = 0; i < n; ++i){
            cin >> arr[i];
            if(i) arr[i-1] = abs(arr[i] - arr[i-1]);
        }
        ll ans = 0;
        for(int i = n - 2; i > 0; --i){
            maxi[i] = max(arr[i], arr[i] - mini[i+1]);
            mini[i] = min(arr[i], arr[i] - maxi[i+1]);
            ans = max(ans, maxi[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


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

typedef long long ll;

const int N = 11111;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;

ll n, arr[N], maxi[N], mini[N];

int main(){
    while(cin >> n){
        for(int i = 0; i < n; ++i){
            cin >> arr[i];
            if(i) arr[i-1] = abs(arr[i] - arr[i-1]);
        }
        ll ans = 0;
        for(int i = n - 1; i > 0; ++i){
            maxi[i] = max(arr[i], arr[i] - mini[i+1]);
            mini[i] = min(arr[i], arr[i] - maxi[i+1]);
            ans = max(ans, maxi[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


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

typedef long long ll;

const int N = 11111;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;

ll n, arr[N], maxi[N], mini[N];

int main(){
    while(cin >> n){
        for(int i = 0; i < n; ++i){
            cin >> arr[i];
            if(i) arr[i-1] = abs(arr[i] - arr[i-1]);
        }
        ll ans = 0;
        for(int i = n - 2; i >= 0; --i){
            maxi[i] = max(arr[i], arr[i] - mini[i+1]);
            mini[i] = min(arr[i], arr[i] - maxi[i+1]);
            ans = max(ans, maxi[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


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

typedef long long ll;

const int N = 111111;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;

ll n, arr[N], maxi[N], mini[N];

int main(){
    while(cin >> n){
        for(int i = 0; i < n; ++i){
            cin >> arr[i];
            if(i) arr[i-1] = abs(arr[i] - arr[i-1]);
        }
        ll ans = 0;
        for(int i = n - 2; i >= 0; --i){
            maxi[i] = max(arr[i], arr[i] - mini[i+1]);
            mini[i] = min(arr[i], arr[i] - maxi[i+1]);
            ans = max(ans, maxi[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<string>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<iomanip>
using namespace std;

#define getT long long t;scanf("%lld",&t)
#define getN long long n;scanf("%lld",&n)
#define for0n(n) getN; for(long long i=0;i<n;i++)
#define for1n(n) getN; for(long long i=1;i<=n;i++)
#define for0(n) for(long long i=0;i<n;i++)
#define for1(n)  for(long long i=1;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f3f3f
#define maxn 10000
typedef long long ll;
const ll mod=1e9+7;
ll gcd(ll a, ll b) {
	return a % b == 0 ? b : gcd(b, a%b);
}

ll pow(ll a, ll b) {
	ll an = 1;
	ll base = a % mod;
	while (b > 0) {
		if (b & 1 != 0) {
			an = (an*base) % mod;
		}
		base = (base*base) % mod;
		b >>= 1;
	}
	return an % mod;
}

ll inv(ll a) {
	return pow(a, mod - 2);
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll Arithmetic(ll a1, ll n, ll d) {
	ll sum = 0;
	sum += n * a1;
	sum %= mod;
	ll temp = n * (n - 1);
	temp %= mod;
	temp *= d;
	temp %= mod;
	temp /= 2;
	temp %= mod;
	return (sum + temp) % mod;
}
char s[200005];
ll le[200005], ri[200005];
ll fac[500005], in[500005];
void init(int n) {
	n *= 2;
	n += 5;
	fac[0]=in[0] = 1;
	for (int i = 1; i <= n; i++) {
		fac[i] = (fac[i - 1] * i) % mod;
		in[i] =inv(fac[i]);
	}
	return;
}
ll C(ll N, ll M)
{
	if (M == 0) return 1;
	return fac[N] * in[M] % mod*in[N - M] % mod;
}
int main(void) {
	scanf("%s", s+1);
	int len = strlen(s+1);
	init(len);
	ll l = 0, r = 0;
	for (int i = 1; i <= len; i++) {
		if (s[i] == '(') {
			l++;
		}
		le[i+1] = l;
	}
	for (int i = len; i > 0; i--) {
		if (s[i] == ')') {
			r++;
		}
		ri[i] = r;
	}
	ll ans = 0;
	for (int i = 2; i <= len; i++) {
		if (s[i - 1] == '('&&ri[i] && le[i]) {//左边不是（则不算贡献
			ans += C(le[i-1] + ri[i], ri[i] - 1);
			ans %= mod;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<string>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<iomanip>
using namespace std;

#define getT long long t;scanf("%lld",&t)
#define getN long long n;scanf("%lld",&n)
#define for0n(n) getN; for(long long i=0;i<n;i++)
#define for1n(n) getN; for(long long i=1;i<=n;i++)
#define for0(n) for(long long i=0;i<n;i++)
#define for1(n)  for(long long i=1;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f3f3f
#define maxn 10000
typedef long long ll;
const ll mod=1e9+7;
ll gcd(ll a, ll b) {
	return a % b == 0 ? b : gcd(b, a%b);
}

ll pow(ll a, ll b) {
	ll an = 1;
	ll base = a % mod;
	while (b > 0) {
		if (b & 1 != 0) {
			an = (an*base) % mod;
		}
		base = (base*base) % mod;
		b >>= 1;
	}
	return an % mod;
}

ll inv(ll a) {
	return pow(a, mod - 2);
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll Arithmetic(ll a1, ll n, ll d) {
	ll sum = 0;
	sum += n * a1;
	sum %= mod;
	ll temp = n * (n - 1);
	temp %= mod;
	temp *= d;
	temp %= mod;
	temp /= 2;
	temp %= mod;
	return (sum + temp) % mod;
}
char s[200005];
ll le[200005], ri[200005];
ll fac[500005], in[500005];
void init(int n) {
	n *= 2;
	n += 5;
	fac[0]=in[0] = 1;
	for (int i = 1; i <= n; i++) {
		fac[i] = (fac[i - 1] * i) % mod;
		in[i] =inv(fac[i]);
	}
	return;
}
ll C(ll N, ll M)
{
	if (M == 0) return 1;
	return fac[N] * in[M] % mod*in[N - M] % mod;
}
int main(void) {
	scanf("%s", s+1);
	int len = strlen(s+1);
	init(len);
	ll l = 0, r = 0;
	for (int i = 1; i <= len; i++) {
		if (s[i] == '(') {
			l++;
		}
		le[i+1] = l;
	}
	for (int i = len; i > 0; i--) {
		if (s[i] == ')') {
			r++;
		}
		ri[i] = r;
	}
	ll ans = 0;
	for (int i = 2; i <= len; i++) {
		if (s[i - 1] == '('&&ri[i] && le[i]) {//左边不是（则不算贡献
			ans += C(le[i-1] + ri[i], le[i]);
			ans %= mod;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


//सत्यान्न प्रमदितव्यम्  ||
//Still, Taking my time to perfect the beats
//And I still got love for the streets, it's the A-D-D-U

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define nt _int128
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debugged cout<<"debugged\n";
#define inf 0x3f3f3f3f
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end()

const ll mod = 1000000007;
#define mx 1000005
const ll mxi = 200005;

ll fact[mx];

void fac()
{
	fact[0] = 1;
	for(ll i=1;i<mx;i++)
	{
		fact[i] = (i%mod*fact[i-1]%mod)%mod;
	}
}

ll shakti(ll x,ll y,ll mod)
{
	ll res = 1;
	while(y>0)
	{
		if(y&1)
		{
			res = (res%mod*x%mod);
			res%=mod;
		}
		y = y>>2;
		y%=mod;
		x = (x%mod*x%mod);
		x%mod;
	}
}

ll inv_mod(ll n,ll mod)
{
	return shakti(n,mod-2,mod);
}

ll C(ll n,ll k,ll mod)
{
// 	return (fact[n]*(inv_mod(fact[k],mod)%mod*(inv_mod(fact[n-k],mod)%mod)%mod))%mod;
	return fact[n] / (fact[n-k]*fact[k]);
}

int main()
{
    fast_as_levi;
    string str;
    cin>>str;
    ll n = str.length();
    fac();
    ll l=0,r=0;
    for(int i=0;i<n;i++)
    {
    	if(str[i]==')')
    	{
    		r++;
    	}
    }
    ll ans = 0;
    for(ll i=0;i<n;i++)
    {
    	if(str[i]==')')
    	{
    		r--;
    	}
    	else
    	{
    		l++;
    		ans = (ans + C(l+r-1,l,mod))%mod;
    	}
    }
    cout<<ans;
}


//सत्यान्न प्रमदितव्यम्  ||
//Still, Taking my time to perfect the beats
//And I still got love for the streets, it's the A-D-D-U

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define nt _int128
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debugged cout<<"debugged\n";
#define inf 0x3f3f3f3f
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end()

const ll mod = 1000000007;
#define mx 1000005
const ll mxi = 200005;

ll fact[mx];

void fac()
{
	fact[0] = 1;
	for(ll i=1;i<mx;i++)
	{
		fact[i] = (i%mod*fact[i-1]%mod)%mod;
	}
}

ll shakti(ll a, ll b, ll mod)
{
	ll x = 1, y = a;
	while (b > 0)
	{
		if (b%2)
		{
			x = (x*y)%mod;
		}
		y = (y*y)%mod;
		b /= 2;
	}
	return x%mod;
}

ll inv_mod(ll n,ll mod)
{
	return shakti(n,mod-2,mod);
}

ll C(ll n,ll k,ll mod)
{
	return (fact[n]*(inv_mod(fact[k],mod)%mod*(inv_mod(fact[n-k],mod)%mod)%mod))%mod;
// 	return fact[n] / (fact[n-k]*fact[k]);
}

int main()
{
    fast_as_levi;
    string str;
    cin>>str;
    ll n = str.length();
    fac();
    ll l=0,r=0;
    for(int i=0;i<n;i++)
    {
    	if(str[i]==')')
    	{
    		r++;
    	}
    }
    ll ans = 0;
    for(ll i=0;i<n;i++)
    {
    	if(str[i]==')')
    	{
    		r--;
    	}
    	else
    	{
    		l++;
    		ans = (ans + C(l+r-1,l,mod))%mod;
    	}
    }
    cout<<ans;
}


//सत्यान्न प्रमदितव्यम्  ||
//Still, Taking my time to perfect the beats
//And I still got love for the streets, it's the A-D-D-U

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define nt _int128
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debugged cout<<"debugged\n";
#define inf 0x3f3f3f3f
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end()

const ll mod = 1000000007;
#define mx 1000005
const ll mxi = 200005;

ll fact[mx];

void fac(ll n)
{
	fact[0] = 1;
	for(ll i=1;i<=n;i++)
	{
		fact[i] = (i%mod*fact[i-1]%mod)%mod;
	}
}

ll shakti(ll x,ll y,ll mod)
{
	ll res = 1;
	while(y>0)
	{
		if(y&1)
		{
			res = (res%mod*x%mod);
			res%=mod;
		}
		y = y>>1;
		y%=mod;
		x = (x%mod*x%mod);
		x%=mod;
	}
	return res;
}

ll inv_mod(ll n,ll mod)
{
	return shakti(n,mod-2,mod);
}

ll C(ll n,ll k,ll mod)
{
	return (fact[n]*(inv_mod(fact[k],mod)%mod*(inv_mod(fact[n-k],mod)%mod)%mod))%mod;
// 	return fact[n] / (fact[n-k]*fact[k]);
}

int main()
{
    fast_as_levi;
    string str;
    cin>>str;
    ll n = str.length();
    fac(n);
    ll l=0,r=0;
    for(int i=0;i<n;i++)
    {
    	if(str[i]==')')
    	{
    		r++;
    	}
    }
    ll ans = 0;
    for(ll i=0;i<n;i++)
    {
    	if(str[i]==')')
    	{
    		r--;
    	}
    	else
    	{
    		l++;
    		ans = (ans + C(l+r-1,l,mod))%mod;
    	}
    }
    cout<<ans;
}


/*
 *  Author: blondie
 */

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

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = int(n)-1; i >= 0; i--)
#define fore(x, v) for(const auto& x : v)

namespace modular {
   const int mod = 1e9+7;
   // const int mod = 998244353;

   inline int add(int a, int b) {
      a += b;
      while(a >= mod) a -= mod;
      while(a < 0) a += mod;
      return a;
   }
   inline void add_self(int& a, int b) {
      a = add(a, b);
   }
   inline int mul(int a, int b) {
      return 1LL * a * b % mod;
   }
   inline void mul_self(int& a, int b) {
      a = mul(a, b);
   }
   inline int mpow(int a, int n) {
      int res = 1;
      while(n > 0) {
        if(n & 1) {
           res = mul(res, a);
        }
        a = mul(a, a);
        n >>= 1;
      }
      return res;
   }
   inline int divide(int a, int b) {
      assert(b != 0);
      return mul(a, mpow(b, mod-2));
   }

   const int mxN = 200*1000+5;
   int fact[mxN], finv[mxN];

   inline int binomial(int n, int k) {
      return mul(fact[n], mul(finv[n-k], finv[k]));
   }

   inline void init_fact() {
      fact[0] = finv[0] = 1;
      for(int i = 1; i < mxN; i++) {
         fact[i] = mul(i, fact[i-1]);
         finv[i] = mpow(fact[i], mod-2);
      }
   }
}

using namespace modular;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    modular::init_fact();
    string s;
    cin >> s;
    int cl = 0;
    fore(c, s) {
        if(c == ')') {
            ++cl;
        }
    }

    int ans = 0;
    int op = 0;
    fore(c, s) {
        if(c == '(') {
            ++op;
            if(cl > 0) {
                add_self(ans, binomial(op+cl-1, cl-1));
            }
        }
        else {
            --cl;
        }
    }

    cout << ans << endl;
}


#include <bits/stdc++.h>
#include <string>
#define ll long long
using namespace std;
const int p = 1e9 + 7;
ll calc(int x, int y)
{
    if(x+y-1<x)
    {
        return 0;
    }
    ll ret = 1;
    for(int i = 1; i<= y-1 ; i++)
    {
        ret *= x+i;
        ret %= p;
        ret /= i;
        //ret %= p;

    }
    return ret%p;
}

int main()
{
    string s;
    cin>>s;
    vector<int> a(s.size(),0);
    vector<int> b(s.size(),0);
    //vector<int> ind;
    int open =0,close =0;
    for(int i = 0;i< s.size(); i++)
    {
        if(s[i] == '(')
        {
            //ind.push_back(i);
            open++;

        }
        else
        {
            close++;

        }
        a[i] = open;
        b[i] = close;

    }
    ll ans = 0;
    for(int i =0; i<s.size(); i++)
    {
        if(s[i]=='(')
        {
            int x = a[i];
            int y = b[s.size()-1]-b[i];
            //cout<<x<<" "<<y<<endl;
            ans += calc(x,y);
            ans %= p;
        }

    }
    cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
#include <string>
#define ll long long
using namespace std;
const ll p=1000000007;
vector<ll> fact(1000001,1);
vector<ll> inv_fact(1000001,1);
ll modExponent(ll x,ll y){
	if(y==0){
		return 1;
	}
	else{
		if(y%2==0){
			ll res=modExponent(x,y/2);
			return (res*res)%p;
		}
		else{
			ll res=modExponent(x,y/2);
			return (((res*res)%p)*x)%p;
		}
	}
}
void inialize(ll len)
{
	fact[0] = 1;
	for (ll i = 1; i <=len; i++){
		fact[i] = (fact[i - 1] * i) % p;
	}

	inv_fact[len] = modExponent(fact[len], p - 2);

	for (ll i = len-1; i >= 0; i--){
		inv_fact[i] = (inv_fact[i + 1] * (i + 1)) % p;
	}
}

ll calc(ll n,ll r){
	if(n<r){
		return 0;
	}
	else{
		ll a=fact[n],b=inv_fact[r],c=inv_fact[n-r];
		return (((a*b)%p) * c)%p;
	}
}

int main()
{
    string s;
    cin>>s;
    vector<int> a(s.size(),0);
    vector<int> b(s.size(),0);
    inialize(s.size()+1);
    //vector<int> ind;
    int open =0,close =0;
    for(int i = 0;i< s.size(); i++)
    {
        if(s[i] == '(')
        {
            //ind.push_back(i);
            open++;

        }
        else
        {
            close++;

        }
        a[i] = open;
        b[i] = close;

    }
    ll ans = 0;
    for(int i =0; i<s.size(); i++)
    {
        if(s[i]=='(')
        {
            int x = a[i];
            int y = b[s.size()-1]-b[i];
            //cout<<x<<" "<<y<<endl;
            ans =( ans + calc(x+y-1,x)%p)%p;
            //ans %= p;
        }

    }
    cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
#include <string>
#define ll long long
using namespace std;
const int p = 1e9 + 7;
ll calc(int x, int y)
{
    if(x+y-1<x)
    {
        return 0;
    }
    ll ret = 1;
    for(int i = 1; i<= y-1 ; i++)
    {
        ret *= x+i;
        ret /= i;
        ret %= p;

    }
    return ret;
}

int main()
{
    string s;
    cin>>s;
    vector<int> a(s.size(),0);
    vector<int> b(s.size(),0);
    //vector<int> ind;
    int open =0,close =0;
    for(int i = 0;i< s.size(); i++)
    {
        if(s[i] == '(')
        {
            //ind.push_back(i);
            open++;

        }
        else
        {
            close++;

        }
        a[i] = open;
        b[i] = close;

    }
    ll ans = 0;
    for(int i =0; i<s.size(); i++)
    {
        if(s[i]=='(')
        {
            int x = a[i];
            int y = b[s.size()-1]-b[i];
            //cout<<x<<" "<<y<<endl;
            ans += calc(x,y);
            ans %= p;
        }

    }
    cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
#include <string>
#define ll long long
using namespace std;
const int p = 1e9 + 7;
ll calc(int x, int y)
{
    if(x+y-1<x)
    {
        return 0;
    }
    ll ret = 1;
    for(int i = 1; i<= y-1 ; i++)
    {
        ret *= x+i;
        ret %= p;
        ret /= i;
        //ret %= p;

    }
    return ret;
}

int main()
{
    string s;
    cin>>s;
    vector<int> a(s.size(),0);
    vector<int> b(s.size(),0);
    //vector<int> ind;
    int open =0,close =0;
    for(int i = 0;i< s.size(); i++)
    {
        if(s[i] == '(')
        {
            //ind.push_back(i);
            open++;

        }
        else
        {
            close++;

        }
        a[i] = open;
        b[i] = close;

    }
    ll ans = 0;
    for(int i =0; i<s.size(); i++)
    {
        if(s[i]=='(')
        {
            int x = a[i];
            int y = b[s.size()-1]-b[i];
            //cout<<x<<" "<<y<<endl;
            ans += calc(x,y);
            ans %= p;
        }

    }
    cout<<ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll, ll> ii;
typedef pair <ll, ii> iii;

const ll N = 1e6 + 5;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

ll n, ans = 0, F[N], A[N], B[N];
char s[N];

inline ll Pow(const ll &a, const ll &b) {
    if (b == 0) return 1;
    if (b == 1) return a % mod;
    ll t = Pow(a, b / 2) % mod;
    if (b % 2 == 0) return t * t % mod;
    return t * t % mod * a % mod;
}

inline ll comb(const ll &n, const ll &k) {
    return F[n] * Pow(F[n - k] * F[k] % mod, mod - 2) % mod;
}

int main() {
    //freopen("785D.INP", "r", stdin);
    //freopen("785D.OUT", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> s + 1;
    n = strlen(s + 1);
    //********************
    F[0] = 1;
    for (ll i = 1; i <= n; i++) F[i] = F[i - 1] * i % mod;
    for (ll i = 1; i <= n; i++) A[i] = A[i - 1] + (s[i] == '(');
    for (ll i = n; i >= 1; i--) B[i] = B[i + 1] + (s[i] == ')');
    for (ll i = 1; i <= n; i++)
        if (s[i] == '(') {
            ll t = min(A[i - 1], B[i + 1]) + 1;
            for (ll j = 1; j <= t; j++)
                ans = (ans + max(1LL, comb(A[i - 1], j - 1)) * comb(B[i + 1], j)) % mod;
        } else {
            ll t = min(A[i - 1], B[i + 1]) + 1;
            for (ll j = 1; j <= t; j++)
                ans = (ans + comb(A[i - 1], j) * max(1LL, comb(B[i + 1], j - 1))) % mod;
        }
    //********************
    cout << ans * Pow(2, mod - 2) % mod;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll, ll> ii;
typedef pair <ll, ii> iii;

const ll N = 1e6 + 5;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

ll n, ans = 0, F[N], A[N], B[N];
char s[N];

inline ll Pow(const ll &a, const ll &b) {
    if (b == 0) return 1;
    if (b == 1) return a % mod;
    ll t = Pow(a, b / 2) % mod;
    if (b % 2 == 0) return t * t % mod;
    return t * t % mod * a % mod;
}

inline ll comb(const ll &n, const ll &k) {
    return F[n] * Pow(F[n - k] * F[k] % mod, mod - 2) % mod;
}

int main() {
    //freopen("785D.INP", "r", stdin);
    //freopen("785D.OUT", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> s + 1;
    n = strlen(s + 1);
    //********************
    F[0] = 1;
    for (ll i = 1; i <= n; i++) F[i] = F[i - 1] * i % mod;
    for (ll i = 1; i <= n; i++) A[i] = A[i - 1] + (s[i] == '(');
    for (ll i = n; i >= 1; i--) B[i] = B[i + 1] + (s[i] == ')');
    for (ll i = 1; i <= n; i++)
        if (s[i] == '(')
            ans = (ans + comb(A[i] + B[i] - 1, A[i])) % mod;
    //********************
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
//#include<unordered_map>

//кодеры класс и информатика тоже!!! © Мейбл

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//
//#ifdef  LOCAL
//
//
//
//#if defined(_WIN32)
//#include <Windows.h>
//#endif
//#if defined(_WIN32)
//struct CPU {
//	FILETIME createTime;
//	FILETIME exitTime;
//	FILETIME kernelTime;
//	FILETIME userTime;
//
//	SYSTEMTIME userSystemTime;
//
//	int Start_Time;
//	CPU() {
//		if (GetProcessTimes(GetCurrentProcess(),
//			&createTime, &exitTime, &kernelTime, &userTime) != -1)
//		{
//
//			if (FileTimeToSystemTime(&userTime, &userSystemTime) != -1)
//				Start_Time = userSystemTime.wMilliseconds;
//		}
//	}
//	inline int getCPUTime()
//	{
//
//
//		if (GetProcessTimes(GetCurrentProcess(),
//			&createTime, &exitTime, &kernelTime, &userTime) != -1)
//		{
//
//			if (FileTimeToSystemTime(&userTime, &userSystemTime) != -1)
//				return  userSystemTime.wMilliseconds;
//		}
//
//		return 0;
//	}
//};
//#endif
//#endif //  LOCAL

typedef long long   ll;
typedef unsigned long long ull;
typedef double ld;

#define pii pair<int,int >
#define pll pair<ll ,ll >
#define pdd pair<ld ,ld >
#define pbb pair<bool,bool>
#define plll pair<long long,pair<long long ,long long > >
#define sefi second.first
#define sese second.second
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz(x) (int)x.size()
#define sqr(x) (x)*(x)
#define cont continue
#define endln '\n'
#define YES cout<<"YES"<<endln
#define Yes cout<<"Yes"<<endln
#define OK cout<<"OK"<<endln
#define NO cout<<"NO"<<endln
#define No cout<<"No"<<endln
#define PS system("pause");
//#define min(a,b) ((a) < (b)? (a) : (b))
//#define max(a,b) ((a) > (b)? (a) : (b))
#define rep(x,a,b) for(int x = a; x < b; x++)
#define per(x,a,b) for(int x = a; x > b; x--)

//#define int long long

const ll  md = 1e9 + 7;
const ll Inf = 1e9;
const long long Inf64 = 1e18;
const ll MaxN = 2e3 + 100;
const ll LogN = 20;
const ll MaxM = 5e5 + 10;
const ld eps = 1e-3;
const int dx[8] = { 0,1,0,-1,-1,1,-2,-2 };
const int dy[8] = { 1,0,-1,0,-2,-2,1,-1 };
const int ddx[4] = { 1,1,-1,-1 };
const int ddy[4] = { 1,-1,1,-1 };
const ld Pi = acos(-1);

using namespace std;

template <typename T>
istream & operator>> (istream & in, pair<T, T> & a) {
	in >> a.first >> a.second;
	return in;
}

template <typename T>
ostream & operator<< (ostream & out, pair<T, T> a) {
	out << a.first << ' ' << a.second;
	return out;
}

template <typename T>
istream & operator>> (istream & in, vector<T> & Mt) {
	for (T & a : Mt) in >> a;
	return in;
}

template <typename T>
ostream & operator<< (ostream & out, vector<T> Mt) {

	for (int i = 0;i < sz(Mt);i++) {
		out << Mt[i];
		if (i != sz(Mt)) out << ' ';
	}
	out << endln;
	return out;
}

inline ll Mod(ll &a, ll m = md) {
	while (a >= m)
		a -= m;
	return a;
}

inline ll gcd(ll a, ll b) {
	while (a) {
		b %= a;
		swap(a, b);
	}
	return b;
}

inline ll gcdex(ll a, ll mod = md) {
	ll g = mod, r = a, x = 0, y = 1;
	while (r != 0) {
		ll q = g / r;
		g %= r;
		swap(g, r);
		x -= q * y;
		swap(x, y);
	}
	return x < 0 ? x + mod : x;
}

inline ll binpow(ll a, ll n, ll m = md) {
	ll res = 1;
	while (n) {
		if (n & 1) {
			res *= a;
			res %= m;
		}
		a *= a;
		a %= m;
		n >>= 1;
	}
	return res % md;
}

// ///////
/// ////
// //////

signed main() {
	ios_base::sync_with_stdio(0);
#ifdef LOCAL
	ifstream cin("input.txt");
	ofstream cout("output.txt");
	//ifstream lin("");
	//ofstream cerr("errput.txt");
//#if defined(_WIN32)
//	CPU cpu;
//#endif
#else
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
#endif // !LOCAL
	cin.tie(0);
	cout.tie(0);
	//cerr.tie(0);
	cout << fixed, cout.precision(20);
	// //

	{

		string s;
		cin >> s;
		ll N = sz(s);
		vector<ll > Mt(N, 0);
		vector<ll > Kt(N, 0);
		for (int i = 0;i < N;i++) {
			if (s[i] == '(')Mt[i]++;
			if (s[N - i - 1] == ')') Kt[N - 1 - i]++;
			if (i != 0) {
				Mt[i] += Mt[i - 1];
				Kt[N - 1 - i] += Kt[N - i];
			}
		}
		vector<ll > Fct(N + 1);
		vector<ll > InvFct(N + 1);

		Fct[0] = 1;
		InvFct[0] = gcdex(1);
		for (int i = 1;i <= N;i++) {
			Fct[i] = i * Fct[i - 1];
			Fct[i] %= md;
			InvFct[i] = gcdex(Fct[i]);

		}
		ll Ans = 0;
		for (int i = 0;i < N;i++) {
			if (s[i] == '(') {
				Ans += (Fct[Mt[i] + Kt[i] - 1] * InvFct[Mt[i] - 1] % md) * InvFct[Kt[i]] % md;
				Ans %= md;

			}
		}
		cout << Ans;

	}

	// //////////////

END:
#ifdef LOCAL
	//cerr << CLOCKS_PER_SEC << endln;
	cerr << '\n' << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << '\n';
//#if defined(_WIN32)
//	cerr << "CPU time: " << cpu.getCPUTime() / (double)1000 << " sec" << '\n';
//#endif
	//system("pause");
	//ll o;
	//cin >> o;
#endif

	return 0;

}

/*

*/


#include<bits/stdc++.h>
//#include<unordered_map>

//кодеры класс и информатика тоже!!! © Мейбл

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//
//#ifdef  LOCAL
//
//
//
//#if defined(_WIN32)
//#include <Windows.h>
//#endif
//#if defined(_WIN32)
//struct CPU {
//	FILETIME createTime;
//	FILETIME exitTime;
//	FILETIME kernelTime;
//	FILETIME userTime;
//
//	SYSTEMTIME userSystemTime;
//
//	int Start_Time;
//	CPU() {
//		if (GetProcessTimes(GetCurrentProcess(),
//			&createTime, &exitTime, &kernelTime, &userTime) != -1)
//		{
//
//			if (FileTimeToSystemTime(&userTime, &userSystemTime) != -1)
//				Start_Time = userSystemTime.wMilliseconds;
//		}
//	}
//	inline int getCPUTime()
//	{
//
//
//		if (GetProcessTimes(GetCurrentProcess(),
//			&createTime, &exitTime, &kernelTime, &userTime) != -1)
//		{
//
//			if (FileTimeToSystemTime(&userTime, &userSystemTime) != -1)
//				return  userSystemTime.wMilliseconds;
//		}
//
//		return 0;
//	}
//};
//#endif
//#endif //  LOCAL

typedef long long   ll;
typedef unsigned long long ull;
typedef double ld;

#define pii pair<int,int >
#define pll pair<ll ,ll >
#define pdd pair<ld ,ld >
#define pbb pair<bool,bool>
#define plll pair<long long,pair<long long ,long long > >
#define sefi second.first
#define sese second.second
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz(x) (int)x.size()
#define sqr(x) (x)*(x)
#define cont continue
#define endln '\n'
#define YES cout<<"YES"<<endln
#define Yes cout<<"Yes"<<endln
#define OK cout<<"OK"<<endln
#define NO cout<<"NO"<<endln
#define No cout<<"No"<<endln
#define PS system("pause");
//#define min(a,b) ((a) < (b)? (a) : (b))
//#define max(a,b) ((a) > (b)? (a) : (b))
#define rep(x,a,b) for(int x = a; x < b; x++)
#define per(x,a,b) for(int x = a; x > b; x--)

//#define int long long

const ll  md = 1e9 + 7;
const ll Inf = 1e9;
const long long Inf64 = 1e18;
const ll MaxN = 2e3 + 100;
const ll LogN = 20;
const ll MaxM = 5e5 + 10;
const ld eps = 1e-3;
const int dx[8] = { 0,1,0,-1,-1,1,-2,-2 };
const int dy[8] = { 1,0,-1,0,-2,-2,1,-1 };
const int ddx[4] = { 1,1,-1,-1 };
const int ddy[4] = { 1,-1,1,-1 };
const ld Pi = acos(-1);

using namespace std;

template <typename T>
istream & operator>> (istream & in, pair<T, T> & a) {
	in >> a.first >> a.second;
	return in;
}

template <typename T>
ostream & operator<< (ostream & out, pair<T, T> a) {
	out << a.first << ' ' << a.second;
	return out;
}

template <typename T>
istream & operator>> (istream & in, vector<T> & Mt) {
	for (T & a : Mt) in >> a;
	return in;
}

template <typename T>
ostream & operator<< (ostream & out, vector<T> Mt) {

	for (int i = 0;i < sz(Mt);i++) {
		out << Mt[i];
		if (i != sz(Mt)) out << ' ';
	}
	out << endln;
	return out;
}

inline ll Mod(ll &a, ll m = md) {
	while (a >= m)
		a -= m;
	return a;
}

inline ll gcd(ll a, ll b) {
	while (a) {
		b %= a;
		swap(a, b);
	}
	return b;
}

inline ll gcdex(ll a, ll mod = md) {
	ll g = mod, r = a, x = 0, y = 1;
	while (r != 0) {
		ll q = g / r;
		g %= r;
		swap(g, r);
		x -= q * y;
		swap(x, y);
	}
	return x < 0 ? x + mod : x;
}

inline ll binpow(ll a, ll n, ll m = md) {
	ll res = 1;
	while (n) {
		if (n & 1) {
			res *= a;
			res %= m;
		}
		a *= a;
		a %= m;
		n >>= 1;
	}
	return res % md;
}

// ///////
/// ////
// //////

signed main() {
	ios_base::sync_with_stdio(0);
#ifdef LOCAL
	ifstream cin("input.txt");
	ofstream cout("output.txt");
	//ifstream lin("");
	//ofstream cerr("errput.txt");
//#if defined(_WIN32)
//	CPU cpu;
//#endif
#else
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
#endif // !LOCAL
	cin.tie(0);
	cout.tie(0);
	//cerr.tie(0);
	cout << fixed, cout.precision(20);
	// //

	{

		string s;
		cin >> s;
		ll N = sz(s);
		vector<ll > Mt(N, 0);
		vector<ll > Kt(N, 0);
		for (int i = 0;i < N;i++) {
			if (s[i] == '(')Mt[i]++;
			if (s[N - i - 1] == ')') Kt[N - 1 - i]++;
			if (i != 0) {
				Mt[i] += Mt[i - 1];
				Kt[N - 1 - i] += Kt[N - i];
			}
		}
		vector<ll > Fct(N + 1);
		vector<ll > InvFct(N + 1);

		Fct[0] = 1;
		InvFct[0] = gcdex(1);
		for (int i = 1;i <= N;i++) {
			Fct[i] = i * Fct[i - 1];
			Fct[i] %= md;
			InvFct[i] = gcdex(Fct[i]);

		}
		ll Ans = 0;
		for (int i = 0;i < N;i++) {
			if (s[i] == '(') {
				Ans += (Fct[Mt[i] + Kt[i] - 1] * InvFct[Mt[i]] % md) * InvFct[Kt[i] - 1] % md;
				Ans %= md;

			}
		}
		cout << Ans;

	}

	// //////////////

END:
#ifdef LOCAL
	//cerr << CLOCKS_PER_SEC << endln;
	cerr << '\n' << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << '\n';
//#if defined(_WIN32)
//	cerr << "CPU time: " << cpu.getCPUTime() / (double)1000 << " sec" << '\n';
//#endif
	//system("pause");
	//ll o;
	//cin >> o;
#endif

	return 0;

}

/*

*/


#include<bits/stdc++.h>
//#include<unordered_map>

//кодеры класс и информатика тоже!!! © Мейбл

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//
//#ifdef  LOCAL
//
//
//
//#if defined(_WIN32)
//#include <Windows.h>
//#endif
//#if defined(_WIN32)
//struct CPU {
//	FILETIME createTime;
//	FILETIME exitTime;
//	FILETIME kernelTime;
//	FILETIME userTime;
//
//	SYSTEMTIME userSystemTime;
//
//	int Start_Time;
//	CPU() {
//		if (GetProcessTimes(GetCurrentProcess(),
//			&createTime, &exitTime, &kernelTime, &userTime) != -1)
//		{
//
//			if (FileTimeToSystemTime(&userTime, &userSystemTime) != -1)
//				Start_Time = userSystemTime.wMilliseconds;
//		}
//	}
//	inline int getCPUTime()
//	{
//
//
//		if (GetProcessTimes(GetCurrentProcess(),
//			&createTime, &exitTime, &kernelTime, &userTime) != -1)
//		{
//
//			if (FileTimeToSystemTime(&userTime, &userSystemTime) != -1)
//				return  userSystemTime.wMilliseconds;
//		}
//
//		return 0;
//	}
//};
//#endif
//#endif //  LOCAL

typedef long long   ll;
typedef unsigned long long ull;
typedef double ld;

#define pii pair<int,int >
#define pll pair<ll ,ll >
#define pdd pair<ld ,ld >
#define pbb pair<bool,bool>
#define plll pair<long long,pair<long long ,long long > >
#define sefi second.first
#define sese second.second
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz(x) (int)x.size()
#define sqr(x) (x)*(x)
#define cont continue
#define endln '\n'
#define YES cout<<"YES"<<endln
#define Yes cout<<"Yes"<<endln
#define OK cout<<"OK"<<endln
#define NO cout<<"NO"<<endln
#define No cout<<"No"<<endln
#define PS system("pause");
//#define min(a,b) ((a) < (b)? (a) : (b))
//#define max(a,b) ((a) > (b)? (a) : (b))
#define rep(x,a,b) for(int x = a; x < b; x++)
#define per(x,a,b) for(int x = a; x > b; x--)

//#define int long long

const ll  md = 1e9 + 7;
const ll Inf = 1e9;
const long long Inf64 = 1e18;
const ll MaxN = 2e3 + 100;
const ll LogN = 20;
const ll MaxM = 5e5 + 10;
const ld eps = 1e-3;
const int dx[8] = { 0,1,0,-1,-1,1,-2,-2 };
const int dy[8] = { 1,0,-1,0,-2,-2,1,-1 };
const int ddx[4] = { 1,1,-1,-1 };
const int ddy[4] = { 1,-1,1,-1 };
const ld Pi = acos(-1);

using namespace std;

template <typename T>
istream & operator>> (istream & in, pair<T, T> & a) {
	in >> a.first >> a.second;
	return in;
}

template <typename T>
ostream & operator<< (ostream & out, pair<T, T> a) {
	out << a.first << ' ' << a.second;
	return out;
}

template <typename T>
istream & operator>> (istream & in, vector<T> & Mt) {
	for (T & a : Mt) in >> a;
	return in;
}

template <typename T>
ostream & operator<< (ostream & out, vector<T> Mt) {

	for (int i = 0;i < sz(Mt);i++) {
		out << Mt[i];
		if (i != sz(Mt)) out << ' ';
	}
	out << endln;
	return out;
}

inline ll Mod(ll &a, ll m = md) {
	while (a >= m)
		a -= m;
	return a;
}

inline ll gcd(ll a, ll b) {
	while (a) {
		b %= a;
		swap(a, b);
	}
	return b;
}

inline ll gcdex(ll a, ll mod = md) {
	ll g = mod, r = a, x = 0, y = 1;
	while (r != 0) {
		ll q = g / r;
		g %= r;
		swap(g, r);
		x -= q * y;
		swap(x, y);
	}
	return x < 0 ? x + mod : x;
}

inline ll binpow(ll a, ll n, ll m = md) {
	ll res = 1;
	while (n) {
		if (n & 1) {
			res *= a;
			res %= m;
		}
		a *= a;
		a %= m;
		n >>= 1;
	}
	return res % md;
}

// ///////
/// ////
// //////

signed main() {
	ios_base::sync_with_stdio(0);
#ifdef LOCAL
	ifstream cin("input.txt");
	ofstream cout("output.txt");
	//ifstream lin("");
	//ofstream cerr("errput.txt");
//#if defined(_WIN32)
//	CPU cpu;
//#endif
#else
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
#endif // !LOCAL
	cin.tie(0);
	cout.tie(0);
	//cerr.tie(0);
	cout << fixed, cout.precision(20);
	// //

	{

		string s;
		cin >> s;
		ll N = sz(s);
		vector<ll > Mt(N, 0);
		vector<ll > Kt(N, 0);
		for (int i = 0;i < N;i++) {
			if (s[i] == '(')Mt[i]++;
			if (s[N - i - 1] == ')') Kt[N - 1 - i]++;
			if (i != 0) {
				Mt[i] += Mt[i - 1];
				Kt[N - 1 - i] += Kt[N - i];
			}
		}
		vector<ll > Fct(N + 1);
		vector<ll > InvFct(N + 1);

		Fct[0] = 1;
		InvFct[0] = gcdex(1);
		for (int i = 1;i <= N;i++) {
			Fct[i] = i * Fct[i - 1];
			Fct[i] %= md;
			InvFct[i] = gcdex(Fct[i]);

		}
		ll Ans = 0;
		for (int i = 0;i < N;i++) {
			if (Kt[i] == 0) cont;
			if (s[i] == '(') {

				Ans += (Fct[Mt[i] + Kt[i] - 1] * InvFct[Mt[i]] % md) * InvFct[Kt[i] - 1] % md;
				Ans %= md;

			}
		}
		cout << Ans;

	}

	// //////////////

END:
#ifdef LOCAL
	//cerr << CLOCKS_PER_SEC << endln;
	cerr << '\n' << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << '\n';
//#if defined(_WIN32)
//	cerr << "CPU time: " << cpu.getCPUTime() / (double)1000 << " sec" << '\n';
//#endif
	//system("pause");
	//ll o;
	//cin >> o;
#endif

	return 0;

}

/*

*/


#include <iostream>
#include <ctime>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <cassert>
#include <queue>
#include <deque>
#include <climits>
#include <cstring>
#include <random>
#include <bitset>

using namespace std;

const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;

struct segment_tree {
    int size;
    vector<int> t;

    void pull(int v) {
        t[v] = t[2 * v + 1] + t[2 * v + 2];
    }

    void build(int v, int l, int r, const vector<int> &a, int s) {
        if (l + 1 == r) {
            t[v] = (a[l] == s ? 1 : 0);
        } else {
            int m = (r + l) >> 1;
            build(2 * v + 1, l, m, a, s);
            build(2 * v + 2, m, r, a, s);
            pull(v);
        }
    }

    segment_tree(const vector<int> &a, int s) {
        size = (int)a.size();
        t.resize(4 * size);
        build(0, 0, size, a, s);
    }

    int query(int v, int l, int r, int ql, int qr) {
        if (ql >= r || qr <= l) {
            return 0;
        }
        if (ql <= l && r <= qr) {
            return t[v];
        } else {
            int m = (r + l) >> 1;
            auto f = query(2 * v + 1, l, m, ql, qr);
            auto s = query(2 * v + 2, m, r, ql, qr);
            return f + s;
        }
    }

    int query(int l, int r) {
        if (l >= r) {
            return 0;
        } else {
            return query(0, 0, size, l, r);
        }
    }
};

vector<int> fact;

int mul(int a, int b) {
    return (long long)a * b % mod;
}

int add(int a, int b) {
    long long tmp = a + b;
    return tmp % mod;
}

int binpow(int a, int b) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 1) {
        auto f = binpow(a, b - 1);
        return mul(a, f);
    } else {
        auto f = binpow(a, b / 2);
        return mul(f, f);
    }
}

int divv(int a, int b) {
    auto tmp = binpow(b, mod - 2);
    return mul(a, tmp);
}

void precalc() {
    fact.resize(maxn);
    fact[0] = 1;
    for (int i = 1; i < maxn; i++) {
        fact[i] = mul(fact[i - 1], i);
    }
}

int get_c(int n, int k) {
    auto m = mul(fact[k], fact[n - k]);
    return divv(fact[n], m);
}

int get(int a, int b) {
    if (a == 0 || b == 0) {
        return 0;
    }
    return get_c(a + b - 1, a);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    #ifdef LOCAL
    assert(freopen("input.txt", "r", stdin));
    assert(freopen("output.txt", "w", stdout));
    #endif

    precalc();

    string s;
    cin >> s;
    int n = (int)s.size();
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        a[i] = (s[i] == ')' ? -1 : 1);
    }
    segment_tree op(a, 1);
    segment_tree cl(a, -1);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) {
            auto f = op.query(0, i) + 1;
            auto s = cl.query(i, n);
            auto tmp = get(f, s);
            ans = add(ans, tmp);
        }
    }
    cout << ans << '\n';
}


#include <iostream>
#include <ctime>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <cassert>
#include <queue>
#include <deque>
#include <climits>
#include <cstring>
#include <random>
#include <bitset>

using namespace std;

const int maxn = 10;
const int mod = 1e9 + 7;

struct segment_tree {
    int size;
    vector<int> t;

    void pull(int v) {
        t[v] = t[2 * v + 1] + t[2 * v + 2];
    }

    void build(int v, int l, int r, const vector<int> &a, int s) {
        if (l + 1 == r) {
            t[v] = (a[l] == s ? 1 : 0);
        } else {
            int m = (r + l) >> 1;
            build(2 * v + 1, l, m, a, s);
            build(2 * v + 2, m, r, a, s);
            pull(v);
        }
    }

    segment_tree(const vector<int> &a, int s) {
        size = (int)a.size();
        t.resize(4 * size);
        build(0, 0, size, a, s);
    }

    int query(int v, int l, int r, int ql, int qr) {
        if (ql >= r || qr <= l) {
            return 0;
        }
        if (ql <= l && r <= qr) {
            return t[v];
        } else {
            int m = (r + l) >> 1;
            auto f = query(2 * v + 1, l, m, ql, qr);
            auto s = query(2 * v + 2, m, r, ql, qr);
            return f + s;
        }
    }

    int query(int l, int r) {
        if (l >= r) {
            return 0;
        } else {
            return query(0, 0, size, l, r);
        }
    }
};

vector<int> fact;

int mul(int a, int b) {
    return (long long)a * b % mod;
}

int add(int a, int b) {
    long long tmp = a + b;
    return tmp % mod;
}

int binpow(int a, int b) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 1) {
        auto f = binpow(a, b - 1);
        return mul(a, f);
    } else {
        auto f = binpow(a, b / 2);
        return mul(f, f);
    }
}

int divv(int a, int b) {
    auto tmp = binpow(b, mod - 2);
    return mul(a, tmp);
}

void precalc() {
    fact.resize(maxn);
    fact[0] = 1;
    for (int i = 1; i < maxn; i++) {
        fact[i] = mul(fact[i - 1], i);
    }
}

int get_c(int n, int k) {
    auto m = mul(fact[k], fact[n - k]);
    return divv(fact[n], m);
}

int get(int a, int b) {
    if (a == 0 || b == 0) {
        return 0;
    }
    return get_c(a + b - 1, a);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    #ifdef LOCAL
    assert(freopen("input.txt", "r", stdin));
    assert(freopen("output.txt", "w", stdout));
    #endif

    precalc();

    string s;
    cin >> s;
    int n = (int)s.size();
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        a[i] = (s[i] == ')' ? -1 : 1);
    }
    segment_tree op(a, 1);
    segment_tree cl(a, -1);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) {
            auto f = op.query(0, i) + 1;
            auto s = cl.query(i, n);
            auto tmp = get(f, s);
            ans = add(ans, tmp);
        }
    }
    cout << ans << '\n';
}


#include<bits/stdc++.h>
using namespace std;
#define _for(i,a,b) for( int i=(a);i<=(b);i++)
typedef long long ll;
const ll N = 2e5 + 7;
const ll mod = 1e9 + 7;
char x[N];
ll l[N], r[N];
ll fac[N], inv[N];
ll quick(ll m, ll n) {
    ll ans = 1;
    while(n) {
        if(n & 1)
            ans = ans * m % mod;
        m = m * m % mod;
        n >>= 1;
    }
    return ans;
}
ll C(ll n, ll m) {
    return (((fac[n] % mod) * (inv[m] % mod))%mod * (inv[n - m] % mod) % mod);
}
int main() {
    memset(l, 0, sizeof l);
    memset(r, 0, sizeof r);
    ll ans = 0;
    fac[0] = inv[0] = 1;
    _for(i, 1, N - 3) {
        fac[i] = (fac[i - 1] * i) % mod;
        inv[i] = quick(fac[i], mod - 2)%mod;
    }
    scanf("%s", x + 1);
    int len = 0;
    for(int i = 1; x[i] != '\0'; i++) {
        if(x[i] == '(') {
            l[i] = l[i - 1] + 1;
        } else
            l[i] = l[i - 1];
        len++;
    }
    for(int i = len; i >= 1; i--) {
        if(x[i] == ')') {
            r[i] = r[i + 1] + 1;
        } else
            r[i] = r[i + 1];
    }
    _for(i, 1, len) {
        if(x[i] == '(') {
            ans = (ans + C(l[i] + r[i] - 1, l[i]) % mod) % mod;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define _for(i,a,b) for( int i=(a);i<=(b);i++)
typedef long long ll;
const ll N = 2e5 + 7;
const ll mod = 1e9 + 7;
char x[N];
ll l[N], r[N];
ll fac[N], inv[N];
ll quick(ll m, ll n) {
    ll ans = 1;
    while(n) {
        if(n & 1)
            ans = ans * m % mod;
        m = m * m % mod;
        n >>= 1;
    }
    return ans;
}
ll C(ll n, ll m) {
    return (fac[n] % mod) * (inv[m] % mod) * (inv[n - m] % mod) % mod;
}
int main() {
    memset(l, 0, sizeof l);
    memset(r, 0, sizeof r);
    ll ans = 0;
    fac[0] = inv[0] = 1;
    _for(i, 1, N - 3) {
        fac[i] = (fac[i - 1] * i) % mod;
        inv[i] = quick(fac[i], mod - 2);
    }
    scanf("%s", x + 1);
    int len = 0;
    for(int i = 1; x[i] != '\0'; i++) {
        if(x[i] == '(') {
            l[i] = l[i - 1] + 1;
        } else
            l[i] = l[i - 1];
        len++;
    }
    for(int i = len; i >= 1; i--) {
        if(x[i] == ')') {
            r[i] = r[i + 1] + 1;
        } else
            r[i] = r[i + 1];
    }
    _for(i, 1, len) {
        if(x[i] == '(') {
            ans = (ans + C(l[i] + r[i] - 1, l[i]) % mod) % mod;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define forn(i,n) for(ll i=0;i < ll (n); i++)
#define scan(n) scanf("%lld", &n);
#define print(n) printf("%lld", n);
#define pb(n) push_back(n)
ll mod=1000000007;

int main()
{
    ll fac[200007];
    fac[0]=1;
    forn(i,200007)
    {
        if(i==0) continue;
        fac[i]=(fac[i-1]*i)%mod;
    }
    string s;
    cin>>s;
    ll n=s.size();
    ll cnt[n];
    ll cn=0;
    forn(i,n)
    {
        if(s[n-1-i]==')') cn++;
        cnt[n-1-i]=cn;
    }
    ll ans=0;
    cn=0;
    forn(i,n)
    {
        if(s[i]==')') continue;
        if(s[i]=='(') cn++;
        ans+=(fac[cn+cnt[i]-1]/(fac[cn]*fac[cnt[i]-1]))%mod;
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define forn(i,n) for(ll i=0;i < ll (n); i++)
#define scan(n) scanf("%lld", &n);
#define print(n) printf("%lld", n);
#define pb(n) push_back(n)
ll mod=1000000007;
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(ll a, ll m)
{
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);
    ll res = (x%m + m) % m;
    return res;
}

int main()
{
    ll fac[200007];
    fac[0]=1;
    forn(i,200007)
    {
        if(i==0) continue;
        fac[i]=(fac[i-1]*i)%mod;
    }
    string s;
    cin>>s;
    ll n=s.size();
    ll cnt[n];
    ll cn=0;
    forn(i,n)
    {
        if(s[n-1-i]==')') cn++;
        cnt[n-1-i]=cn;
    }
    ll ans=0;
    cn=0;
    forn(i,n)
    {
        if(s[i]==')' || cnt[i]==0) continue;
        if(s[i]=='(') cn++;
        ll x=modInverse(fac[cn], mod);
        ll y=modInverse(fac[cnt[i]-1], mod);
        x=(x*y)%mod;
        ans+=((fac[cn+cnt[i]-1]*x)%mod);
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define forn(i,n) for(ll i=0;i < ll (n); i++)
#define scan(n) scanf("%lld", &n);
#define print(n) printf("%lld", n);
#define pb(n) push_back(n)
ll mod=1000000007;
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(ll a, ll m)
{
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);
    ll res = (x%m + m) % m;
    return res;
}

int main()
{
    ll fac[200007];
    fac[0]=1;
    forn(i,200007)
    {
        if(i==0) continue;
        fac[i]=(fac[i-1]*i)%mod;
    }
    string s;
    cin>>s;
    ll n=s.size();
    ll cnt[n];
    ll cn=0;
    forn(i,n)
    {
        if(s[n-1-i]==')') cn++;
        cnt[n-1-i]=cn;
    }
    ll ans=0;
    cn=0;
    forn(i,n)
    {
        if(s[i]==')' || cnt[i]==0) continue;
        if(s[i]=='(') cn++;
        ll x=modInverse(fac[cn], mod);
        ll y=modInverse(fac[cnt[i]-1], mod);
        x=(x*y)%mod;
        ans+=(fac[cn+cnt[i]-1]*x)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
const int N = 4e5+1;
const ll mod = 1e9+7;
ll fac[N],inv[N];
ll binpow(ll x,ll pow)
{
	ll res=1ll;
	while(pow)
	{
		if(pow&1)	res=res*x%mod;
		x=x*x%mod;
		pow/=2;
	}
	return res;
}
void build()
{
	int i;fac[0]=1ll;
	for(i=1;i<N;i++)	fac[i]=1ll*fac[i-1]*i%mod;
	inv[N-1]=binpow(fac[N-1],mod-2);
	for(i=N-2;i>=0;i--)	inv[i]=inv[i+1]*(i+1)%mod;
}
ll nCk(int n,int k)	{return fac[n]*inv[k]%mod*inv[n-k]%mod;}
int main()
{
	build();
	string s;
	cin >> s;
	int i,l=0,r=0,n=s.size();
	for(i=0;i<n;i++)	if(s[i]==')')	r++;
	ll ans=0ll;
	for(i=0;i<n;i++)
	{
		if(s[i]=='(')	l++;
		else	r--;
		if(s[i]=='(')	ans=ans+nCk(l+r-1,r-1)%mod;
	}
	printf("%lld",ans);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
const int N = 4e5+1;
const ll mod = 1e9+7;
ll fac[N],inv[N];
ll binpow(ll x,ll pow)
{
	ll res=1ll;
	while(pow)
	{
		if(pow&1)	res=res*x%mod;
		x=x*x%mod;
		pow/=2;
	}
	return res;
}
void build()
{
	int i;fac[0]=1ll;
	for(i=1;i<N;i++)	fac[i]=1ll*fac[i-1]*i%mod;
	inv[N-1]=binpow(fac[N-1],mod-2);
	for(i=N-2;i>=0;i--)	inv[i]=inv[i+1]*(i+1)%mod;
}
ll nCk(int n,int k)	{return fac[n]*inv[k]%mod*inv[n-k]%mod;}
int main()
{
	build();
	string s;
	cin >> s;
	int i,l=0,r=0,n=s.size();
	for(i=0;i<n;i++)	if(s[i]==')')	r++;
	ll ans=0ll;
	for(i=0;i<n;i++)
	{
		if(s[i]=='(')	l++;
		else	r--;
		if(s[i]=='(')	ans=(ans+nCk(l+r-1,r-1)%mod)%mod;
	}
	printf("%lld",ans);
}


// Vaqte Codasto Konkur be chap chap !!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int maxn = 2e5+10, mod = 1e9+7;
string s;
ll fac[maxn], rfac[maxn], ans;
int pre[maxn], suf[maxn];

ll Pow (ll a, ll b) {
	ll ret = 1;
	for(; b; b >>= 1, a = a * a % mod)
		if(b & 1)
			ret = ret * a % mod;
	return ret;
}

int c(int n, int r){
	if(r > n) return 0;
	return (ll) fac[n] * rfac[n - r] % mod * rfac[r] % mod;
}

inline void init (int n) {
	for (int i = n - 1; i >= 0; i--)
		suf[i] = s[i] == ')' ? suf[i + 1] + 1 : suf[i + 1];
	fac[0] = rfac[0] = 1;
	for(int i = 1; i < maxn; i++){
		fac[i] = (ll) fac[i - 1] * i % mod;
		rfac[i] = (ll) Pow(fac[i], mod - 2) % mod;
	}
}

int main () {
	cin >> s;
	int n = s.size();
	init (n);
	for (int i = 0, j = 0; i < n; i++) {
		if (s[i] == '(') {
			ans += c (j + suf[i], suf[i] - 1);
			ans %= mod;
			++j;
		}
	}
	cout << ans << endl;
	return 0;
}


// Vaqte Codasto Konkur be chap chap !!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int maxn = 2e5+10, mod = 1e9+7;
char s[maxn];
ll fac[maxn], rfac[maxn], ans;
int pre[maxn], suf[maxn];

ll Pow (ll a, ll b) {
	ll ret = 1;
	for(; b; b >>= 1, a = a * a % mod)
		if(b & 1)
			ret = ret * a % mod;
	return ret;
}

int c(int n, int r){
	if(r > n) return 0;
	return (ll) fac[n] * rfac[n - r] % mod * rfac[r] % mod;
}

inline void init () {
	fac[0] = rfac[0] = 1;
	for(int i = 1; i < 20000; i++){
		fac[i] = (ll) fac[i - 1] * i % mod;
		rfac[i] = (ll) Pow(fac[i], mod - 2) % mod;
	}
}

int main () {
	init ();
	int n = 0;
	while (scanf("%c", &s[++n]) != EOF)
    		pre[n] = pre[n - 1] + (s[n] == '(');
	for (int i = n; i >= 0; i--)
		suf[i] = suf[i + 1] + (s[i] == ')');
	for (int i = 1; i <= n; i++) {
		if (s[i] == '(') {
			ans += c (pre[i] + suf[i] - 1, suf[i] - 1);
			ans %= mod;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int mn=2e5+10;
ll fact[mn];
int l[mn],r[mn];
ll inv(ll x){
    ll ans=1;
    for(ll i=mod-2;i;i>>=1,x=x*x%mod)if(i&1)ans=ans*x%mod;
    return ans;
}
ll ch(ll a,ll b){
    if(a<0||b<0||b>a)return 0;
    return fact[a]*inv(fact[a-b])%mod*inv(fact[b])%mod;
}
int main()
{
    string s;
    cin>>s;
    int n=s.size(),i;
    fact[0]=1;
    for(i=1;i<=n;i++)fact[i]=fact[i-1]*i%mod;
    l[0]=(s[0]=='(');
    r[n-1]=(s[n-1]==')');
    for(i=1;i<n;i++)l[i]=l[i-1]+(s[i]=='(');
    for(i=n-2;i>=0;i--)r[i]=r[i+1]+(s[i]==')');
    ll ans=0;
    for(i=0;i<n-1;i++)if(s[i]=='(')ans+=ch(l[i]+r[i+1],l[i])-ch(l[i]+r[i+1]-1,l[i]-1);
    ans%=mod;
    if(ans<0)ans+=mod;
    printf("%lld",ans);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int mn=2e5+10;
ll fact[mn];
int l[mn],r[mn];
ll inv(ll x){
    ll ans=1;
    for(ll i=mod-2;i;i>>=1,x=x*x%mod)if(i&1)ans=ans*x%mod;
    return ans;
}
ll ch(ll a,ll b){
    if(a<0||b<0||b>a)return 0;
    return fact[a]*inv(fact[a-b])%mod*inv(fact[b])%mod;
}
int main()
{
    string s;
    cin>>s;
    int n=s.size(),i;
    fact[0]=1;
    for(i=1;i<=n;i++)fact[i]=fact[i-1]*i%mod;
    l[0]=(s[0]=='(');
    r[n-1]=(s[n-1]==')');
    for(i=1;i<n;i++)l[i]=l[i-1]+(s[i]=='(');
    for(i=n-2;i>=0;i--)r[i]=r[i+1]+(s[i]==')');
    ll ans=0;
    for(i=0;i<n-1;i++)if(s[i]=='(')ans+=ch(l[i]+r[i+1],l[i])-ch(l[i]+r[i+1]-1,l[i]-1);
    ans%=mod;
    printf("%lld",ans);
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

long long modpow(long long x, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    p >>= 1;
  }
  return ret;
}

const long long MOD = 1e9 + 7;
long long f[200001];
long long rf[200001];

long long comb(int n, int k) {
  if (k < 0 || n < k) return 0;
  long long ret = f[n] * rf[n-k] % MOD;
  ret = ret * rf[k] % MOD;
  return ret;
}

void init() {
  f[0] = rf[0] = 1;
  for (int i = 1; i <= 200000; i++) {
    f[i] = i * f[i-1] % MOD;
    rf[i] = modpow(f[i], MOD-2, MOD);
  }
}

long long l[200000], r[200000];

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

  init();
  string s;
  cin >> s;

  int n = s.length();
  REP (i, n) {
    if (s[i] == '(')
      l[i] = 1;
    if (i - 1 >= 0)
      l[i] += l[i-1];
  }

  for (int i = n-1; i >= 0; i--) {
    if (s[i] == ')')
      r[i] = 1;
    if (i+1 < n)
      r[i] += r[i+1];
  }

  long long ret = 0;
  REP (i, n-1) {
    if (s[i] == '(') {
      ret += comb(l[i] + r[i+1] - 1, l[i]);
    }
  }

  cout << ret << endl;

  return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

long long modpow(long long x, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    p >>= 1;
  }
  return ret;
}

const long long MOD = 1e9 + 7;
long long f[200001];
long long rf[200001];

long long comb(int n, int k) {
  if (k < 0 || n < k) return 0;
  long long ret = f[n] * rf[n-k] % MOD;
  ret = ret * rf[k] % MOD;
  return ret;
}

void init() {
  f[0] = rf[0] = 1;
  for (int i = 1; i <= 200000; i++) {
    f[i] = i * f[i-1] % MOD;
    rf[i] = modpow(f[i], MOD-2, MOD);
  }
}

long long l[200000], r[200000];

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

  init();
  string s;
  cin >> s;

  int n = s.length();
  REP (i, n) {
    if (s[i] == '(')
      l[i] = 1;
    if (i - 1 >= 0)
      l[i] += l[i-1];
  }

  for (int i = n-1; i >= 0; i--) {
    if (s[i] == ')')
      r[i] = 1;
    if (i+1 < n)
      r[i] += r[i+1];
  }

  long long ret = 0;
  REP (i, n-1) {
    if (s[i] == '(') {
      ret += comb(l[i] + r[i+1] - 1, l[i]);
      ret %= MOD;
    }
  }

  cout << ret << endl;

  return 0;
}


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

int mod=1000000007;

int64_t extGcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {
	if (!a) {
		x = 0;
		y = 1;
		return b;
	}
	int64_t x1, y1;
	int64_t d = extGcd(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}

inline int addMod(int a, int b, int m = mod) {
	return ((int64_t)a + b) % m;
}

inline int mulMod(int a, int b, int m = mod) {
	return ((int64_t)a * b) % m;
}

inline int divMod(int a, int b, int m = mod) {
	int64_t x, y;
	int64_t g = extGcd(b, m, x, y);
	if (g != 1) {
		cerr << "Bad gcd!" << endl;
		for (;;);
	}
	x = (x % m + m) % m;
	return mulMod(a, x, m);
}

const int factRange = 1000000;
int fact[factRange];

inline void precalcFactorials() {
	fact[0] = 1;
	for (int i = 1; i < factRange; i++) {
		fact[i] = mulMod(fact[i-1], i);
	}
}

inline int F(int n) {
	return (n < 0) ? 0 : fact[n];
}

inline int C(int k, int n) {
	return divMod(F(n), mulMod(F(n-k), F(k)));
}

int main()
{
    string str;
    cin>>str;

    int n;
    n=str.size();

    precalcFactorials();

    vector<int> op(n,0);
    vector<int> cl(n,0);

    int o=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='(')
        {
            o++;
        }
        op[i]=o;
    }

    int c=0;
    for(int i=n-1;i>=0;i--)
    {
        if(str[i]==')')
        {
            c++;
        }
        cl[i]=c;
    }

    long long int ans=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='(' && cl[i]>0)
        {
            int x=op[i];
            int y=cl[i];
            ans=(ans+C(op[i], op[i] + cl[i] - 1))%MOD;
        }
    }

    cout<<ans<<endl;

    return 0;
}


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

long long int func(int x,int y)
{
    long long int ans=0;

    //cal ncr

    double temp_ans=1;
    int n=x+y-1;
    int r=x;

    for(int i=0;i<x;i++)
    {
        temp_ans=(temp_ans*(n-i))/(r-i);
    }

    ans=temp_ans+0.01;

    ans=ans%MOD;

    return ans;
}

int main()
{
    string str;
    cin>>str;
    int n;
    cin>>n;
    vector<int> op(n);
    vector<int> cl(n);

    int o=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='(')
        {
            o++;
        }
        op[i]=o;
    }

    int c=0;
    for(int i=n-1;i>=0;i--)
    {
        if(str[i]==')')
        {
            c++;
        }
        cl[i]=c;
    }

    long long int ans=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='(')
        {
            int x=op[i];
            int y=cl[i];
            ans=(ans+func(x,y))%MOD;
        }
    }

    cout<<ans<<endl;

    return 0;
}


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

long long int func(int x,int y)
{
    long long int ans=0;

    //cal ncr

    double temp_ans=1;
    int n=x+y-1;
    int r=x;

    for(int i=0;i<x;i++)
    {
        temp_ans=(temp_ans*(n-i))/(r-i);
    }

    ans=temp_ans+0.01;

    ans=ans%MOD;

    return ans;
}

int main()
{
    string str;
    cin>>str;

    int n;
    n=str.size();

    vector<int> op(n,0);
    vector<int> cl(n,0);

    int o=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='(')
        {
            o++;
        }
        op[i]=o;
    }

    int c=0;
    for(int i=n-1;i>=0;i--)
    {
        if(str[i]==')')
        {
            c++;
        }
        cl[i]=c;
    }

    long long int ans=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='(')
        {
            int x=op[i];
            int y=cl[i];
            ans=(ans+func(x,y))%MOD;
        }
    }

    cout<<ans<<endl;

    return 0;
}


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

long long int func(int x,int y)
{
    long long int ans=0;

    //cal ncr

    double temp_ans=1;
    int n=x+y-1;
    int r=x;

    for(int i=0;i<x;i++)
    {
        temp_ans=(temp_ans*(n-i))/(r-i);
    }

    unsigned long long int ans1=temp_ans+0.01;
    ans1=ans1%MOD;
    ans=ans1;
    ans=ans%MOD;

    return ans;
}

int main()
{
    string str;
    cin>>str;

    int n;
    n=str.size();

    vector<int> op(n,0);
    vector<int> cl(n,0);

    int o=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='(')
        {
            o++;
        }
        op[i]=o;
    }

    int c=0;
    for(int i=n-1;i>=0;i--)
    {
        if(str[i]==')')
        {
            c++;
        }
        cl[i]=c;
    }

    long long int ans=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='(')
        {
            int x=op[i];
            int y=cl[i];
            ans=(ans+func(x,y))%MOD;
        }
    }

    cout<<ans<<endl;

    return 0;
}


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

vector<long long int> fact(200005,0);

void func1()
{
    fact[0]=1;
    fact[1]=1;

    for(int i=2;i<=200000;i++)
    {
        fact[i]=fact[i-1]*i%MOD;
    }
}

vector<long long int> inv(200005);

void func2()
{
    inv[1]=1;

    for(int i = 2; i <= 200000;++i)
        inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;
}

long long int func(int x,int y)
{
    //cout<<"x="<<x<<" y="<<y;
    long long int ans=0;
    int n=x+y-1;
    int r=x;
    //cout<<"  n="<<n<<" r="<<r<<endl;
    if(n==r)
    {
        return 1;
    }
    ans=(fact[n]*inv[r])%MOD;
    ans=(ans*inv[n-r])%MOD;
    return ans;
}

int main()
{
    string str;
    cin>>str;

    int n=str.size();
    vector<int> op(n);
    vector<int> cl(n);

    func1();
    func2();

    int o=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='(')
        {
            o++;
        }
        op[i]=o;
    }

    int c=0;
    for(int i=n-1;i>=0;i--)
    {
        if(str[i]==')')
        {
            c++;
        }
        cl[i]=c;
    }

    long long int ans=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='(' && cl[i]>0)
        {
            int x=op[i];
            int y=cl[i];
            int int_ans=func(x,y);
            //cout<<"int_ans="<<int_ans<<endl;
            ans=(ans+int_ans)%MOD;
        }
    }

    cout<<ans<<endl;

    return 0;
}


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

long long int func(int x,int y)
{
    long long int ans=0;

    //cal ncr

    double temp_ans=1;
    int n=x+y-1;
    int r=x;

    for(int i=0;i<x;i++)
    {
        temp_ans=(temp_ans*(n-i))/(r-i);
    }

    ans=temp_ans+0.01;

    ans=ans%MOD;

    return ans;
}

int main()
{
    string str;
    cin>>str;
    int n;
    cin>>n;
    vector<int> op(n,0);
    vector<int> cl(n,0);

    int o=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='(')
        {
            o++;
        }
        op[i]=o;
    }

    int c=0;
    for(int i=n-1;i>=0;i--)
    {
        if(str[i]==')')
        {
            c++;
        }
        cl[i]=c;
    }

    long long int ans=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='(')
        {
            int x=op[i];
            int y=cl[i];
            ans=(ans+func(x,y))%MOD;
        }
    }

    cout<<ans<<endl;

    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"iostream"
#include"cassert"
#include"cmath"
#include"cstdio"
#include"cstdlib"
#include"map"
#include"set"
#include"queue"
#include"vector"
#include"algorithm"
#include"numeric"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
inline int in(){int x;scanf("%lld",&x);return x;}
const int mod=1e9+7;
const int N=2e5+10;
int f[2*N],inv[2*N];
int modp(int a, int b)
{
	if(b==0)return 1;
	int u=modp(a,b/2);
	u=(u*u)%mod;
	if(b&1)return (a*u)%mod;
	return u;
}
int ncr(int n, int r)
{
	if(n<r)return 0;
	int res=f[n]*inv[r];res%=mod;
	res*=inv[n-r];res%=mod;
	return res;
}
int32_t main()
{
	string s;
	cin>>s;
	int n=s.length();
	f[0]=1;
	for(int i=1;i<=2*n;i++)
	f[i]=(i*f[i-1])%mod;

	inv[2*n]=modp(f[2*n],mod-2);

	for(int i=2*n-1;i>=0;i--)inv[i]=(inv[i+1]*(i+1))%mod;
	int cl=count(all(s),')');
	int o=0,ans=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='(')
		{
			o++;
			ans+=ncr(o+cl-1,o);
			ans%=mod;
		}
		else
		cl--;
	}
	cout<<ans<<"\n";

}


#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"iostream"
#include"cassert"
#include"cmath"
#include"cstdio"
#include"cstdlib"
#include"map"
#include"set"
#include"queue"
#include"vector"
#include"algorithm"
#include"numeric"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
inline int in(){int x;scanf("%lld",&x);return x;}
const int mod=1e9+7;
const int N=2e5+10;
int op[N], cl[N], f[2*N],inv[2*N];
int modp(int a, int b)
{
	if(b==0)return 1;
	int u=modp(a,b/2);
	u=(u*u)%mod;
	if(b&1)return (a*u)%mod;
	return u;
}
int ncr(int n, int r)
{
	if(n<r)return 0;
	int res=f[n]*inv[r];res%=mod;
	res*=inv[n-r];res%=mod;
	return res;
}
int calc(int x)
{
	int res=ncr(2*x,x);
	res--;res%=mod;res+=mod;return res%mod;
}
int32_t main()
{
	string s;
	cin>>s;
	int n=s.length();
	f[0]=1;
	for(int i=1;i<=2*n;i++)
	f[i]=(i*f[i-1])%mod;

	inv[2*n]=modp(f[2*n],mod-2);

	for(int i=2*n-1;i>=0;i--)inv[i]=(inv[i+1]*(i+1))%mod;

	for(int i=0;i<n;i++)
	{
		if(i-1>=0)op[i]=op[i-1];
		if(s[i]=='(')op[i]++;
	}
	for(int i=n-1;i>=0;i--)
	{
		if(i+1<n)cl[i]=cl[i+1];
		if(s[i]==')')cl[i]++;
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		//if(s[i]=='(')
		//{
		//	ans+=calc(min(op[i],cl[i+1]));
		//	ans%=mod;
		//}
		if(s[i]==')'){int d=0;if(i>0)d=op[i-1];d=min(d,cl[i]);ans+=calc(d);ans%=mod;}
	}
//	ans*=inv[2];ans%=mod;
	cout<<ans<<"\n";
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define len(a) (int)(a.size())
#define Pi acos(-1.)
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef unsigned long long ull;
typedef long double ld;
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAXN = 1e5+5;
const int MAXM = 9e4+500;
const int N = 500 + 5;
const double EPS = 1e-9;

int dx[] = {-1,1,0,0};
int dy[] = {0,0,1,-1};
int i,j,d;
ll n,k,m;

ll fact[MAXN];

void initfact() {
        fact[0] = 1;
        for(int i = 1; i < MAXN; i++) {
                fact[i] = (fact[i-1] * i);
                fact[i] %= MOD;
        }
}

ll binpow(ll val, ll deg) {
        if (!deg) return 1;
        if (deg & 1) return binpow(val, deg - 1) * val % MOD;
        ll res = binpow(val ,deg >> 1);
        return (res*res) % MOD;
}

ll C(ll n, ll k)
{
        ll res = fact[n];
        ll div = fact[n-k] * fact[k];
        div %= MOD;  div = binpow(div, MOD - 2); // inv(div)
        return (res * div) % MOD;
}

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

    string w;
    cin>>w;

    initfact();
    n = w.size();
    vector<ll> openleft(n),closeright(n);

    openleft[0] = (w[0] == '(');

    for(i=1;i<n;i++)
    {
        openleft[i] = openleft[i-1] + (w[i]=='(');
    }

    closeright[n-1] = ( w[n-1] == ')' );

    for(i=n-2;i>=0;i--)
    {
        closeright[i] = closeright[i+1] + (w[i] == ')');
    }

    ll res = 0;

    for(i=0;i<n;i++)
    {
        if(w[i] != '('  || closeright[i] == 0)
            continue;

        ll add = C(openleft[i] + closeright[i] - 1 , openleft[i] );

        res = (res + add)%MOD;
    }

    cout<<res;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define len(a) (int)(a.size())
#define Pi acos(-1.)
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef unsigned long long ull;
typedef long double ld;
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAXN = 1e6+5;
const int MAXM = 9e4+500;
const int N = 500 + 5;
const double EPS = 1e-9;

int dx[] = {-1,1,0,0};
int dy[] = {0,0,1,-1};
int i,j,d;
ll n,k,m;

ll fact[MAXN];

void initfact() {
        fact[0] = 1;
        for(int i = 1; i < MAXN; i++) {
                fact[i] = (fact[i-1] * i);
                fact[i] %= MOD;
        }
}

ll binpow(ll val, ll deg) {
        if (!deg) return 1;
        if (deg & 1) return binpow(val, deg - 1) * val % MOD;
        ll res = binpow(val ,deg >> 1);
        return (res*res) % MOD;
}

ll C(ll n, ll k)
{
        ll res = fact[n];
        ll div = fact[n-k] * fact[k];
        div %= MOD;  div = binpow(div, MOD - 2); // inv(div)
        return (res * div) % MOD;
}

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

    string w;
    cin>>w;

    initfact();
    n = w.size();
    vector<ll> openleft(n),closeright(n);

    openleft[0] = (w[0] == '(');

    for(i=1;i<n;i++)
    {
        openleft[i] = openleft[i-1] + (w[i]=='(');
    }

    closeright[n-1] = ( w[n-1] == ')' );

    for(i=n-2;i>=0;i--)
    {
        closeright[i] = closeright[i+1] + (w[i] == ')');
    }

    ll res = 0;

    for(i=0;i<n;i++)
    {
        if(w[i] != '('  || closeright[i] == 0)
            continue;

        ll add = C(openleft[i] + closeright[i] - 1 , openleft[i] );

        res = (res + add)%MOD;
    }

    cout<<res;
    return 0;

}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 200005
#define INF 0x3f3f3f3f
#define ll long long
#define MOD 1000000007
char s[N];
int n;
int suml[N],sumr[N];
ll fac[N];
void Init()
{
	fac[0]=1LL;
	for(int i=1;i<N;i++)
		fac[i]=fac[i-1]*i%MOD;
	return ;
}
ll qmd(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return ans;
}
ll calc(int a,int b)
{
	return fac[a]*qmd(fac[a-b],MOD-2)%MOD*qmd(fac[b],MOD-2)%MOD;
}
int main()
{
	Init();
	scanf("%s",s);
	n=strlen(s);
	for(int i=0;i<n;i++)
	{
		if(i) suml[i]=suml[i-1];
		if(s[i]=='(') suml[i]++;
	}
	for(int i=n-1;i>=0;i--)
	{
		if(i<n-1) sumr[i]=sumr[i+1];
		if(s[i]==')') sumr[i]++;
	}
	ll ans=0;
	for(int i=0;i<n;i++)
		if(s[i]=='(')
		{
			int l=suml[i],r=sumr[i];
			ans=(ans+calc(l+r-1,r-1))%MOD;
		}
	printf("%lld\n",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 200005
#define INF 0x3f3f3f3f
#define ll long long
#define MOD 1000000009
char s[N];
int n;
int suml[N],sumr[N];
ll fac[N];
void Init()
{
	fac[0]=1LL;
	for(int i=1;i<N;i++)
		fac[i]=fac[i-1]*i%MOD;
	return ;
}
ll qmd(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return ans;
}
ll calc(int a,int b)
{
	return fac[a]*qmd(fac[a-b],MOD-2)%MOD*qmd(fac[b],MOD-2)%MOD;
}
int main()
{
	Init();
	scanf("%s",s);
	n=strlen(s);
	for(int i=0;i<n;i++)
	{
		if(i) suml[i]=suml[i-1];
		if(s[i]=='(') suml[i]++;
	}
	for(int i=n-1;i>=0;i--)
	{
		if(i<n-1) sumr[i]=sumr[i+1];
		if(s[i]==')') sumr[i]++;
	}
	ll ans=0;
	for(int i=0;i<n;i++)
		if(s[i]=='(')
		{
			int l=suml[i],r=sumr[i];
			ans=(ans+calc(l+r-1,r-1))%MOD;
		}
	printf("%lld\n",ans);
	return 0;
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long;
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>;

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (200006)
string S;
ll ans,c,o,f[MAXN],mod=1e9+7,inv[MAXN];
ll C(ll n,ll k){
	return n < k ? 0 : f[n] * inv[k] % mod * inv[n-k] % mod;
}
ll qexp(ll x,ll e){
	ll sum=1;for(;e;e>>=1,x*=x,x%=mod)if(e&1)sum*=x,sum%=mod;return sum;
}
int main(){
	f[0]=1; FOR(i,1,MAXN)f[i]=f[i-1]*i%mod;
	inv[MAXN-1]=qexp(f[MAXN-1],mod-2); DEC(i,MAXN-2,0)inv[i]=inv[i+1]*(i+1)%mod;
	FAST
	cin>>S;
	c=count(all(S),')');
	FOR(i,0,siz(S)-1){
		if(S[i]==')') {
			-- c;
			continue;
		}
		++ o;
		ans+=C(c+o-1,o),ans%=mod;
	}
	cout<<ans<<'\n';
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long;
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>;

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (200006)
string S;
ll ans,c,o,f[MAXN],mod=1e9+7,inv[MAXN];
ll C(ll n,ll k){
	return n < k ? 0 : f[n] * inv[k] % mod * inv[n-k] % mod;
}
ll qexp(ll x,ll e){
	ll sum=1;for(;e;e>>=1,x*=x,x%=mod)if(e&1)sum*=x,sum%=mod;return sum;
}
int main(){
	f[0]=1; FOR(i,1,MAXN-1)f[i]=f[i-1]*i%mod;
	inv[MAXN-1]=qexp(f[MAXN-1],mod-2); DEC(i,MAXN-2,0)inv[i]=inv[i+1]*(i+1)%mod;
	FAST
	cin>>S;
	c=count(all(S),')');
	FOR(i,0,siz(S)-1){
		if(S[i]==')') {
			-- c;
			continue;
		}
		++ o;
		ans+=C(c+o-1,o),ans%=mod;
	}
	cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
const long long maxn = 200005, mod = 1000000007;
long long Jc[maxn], ny[maxn], ans;
int n, L[maxn], R[maxn];
char s[maxn];
inline long long pow(long long a, long long b)
{
	long long ans = 1;
	while (b)
	{
		if (b & 1) ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}
inline void init()
{
	Jc[0] = 1;
	for (long long i = 1; i < maxn; i++)	Jc[i] = Jc[i - 1] * i % mod;
	ny[maxn - 1] = pow(Jc[maxn - 1], mod - 2);
	for (int i = maxn - 1; i > 0; --i)		ny[i - 1] = ny[i] * i % mod;
}

inline long long C(int a, int b)
{
	if (a == b)
		return 1;
	else if (a < 0 || b < 0 || a < b)
		return 0;
	else
		return Jc[a] * ny[b] % mod * ny[a - b] % mod;
}
inline long long sum(int x)
{
	int len = min(L[x - 1], R[x]);
	long long res = 0;
	for (int i = 0; i <= len; ++i)
		res = (res + C(L[x - 1], i)*C(R[x], i + 1) % mod) % mod;
	return res % mod;
}
int main()
{
	init();
	scanf("%s", s + 1);
	n = strlen(s + 1);
	L[0] = R[n + 1] = 0;
	for (int i = 1; i <= n; ++i)	L[i] = L[i - 1] + (s[i] == '(');
	for (int i = n; i > 0; --i)	R[i] = R[i + 1] + (s[i] == ')');

	for (int i = 1; i <= n; ++i)
	{
		if (s[i] == '(')
		{
			ans = (ans + sum(i)) % mod;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long maxn = 200005, mod = 1000000007;
long long Jc[maxn], ny[maxn], ans;
int n, L[maxn], R[maxn], cnt;
char s[maxn];
inline long long pow(long long a, long long b)
{
	long long ans = 1;
	while (b)
	{
		if (b & 1) ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}
inline void init()
{
	Jc[0] = 1;
	for (long long i = 1; i < maxn; i++)	Jc[i] = Jc[i - 1] * i % mod;
	ny[maxn - 1] = pow(Jc[maxn - 1], mod - 2);
	for (int i = maxn - 1; i > 0; --i)		ny[i - 1] = ny[i] * i % mod;
}
inline long long C(int a, int b)
{
	if (a == b)
		return 1;
	else if (a < 0 || b < 0 || a < b)
		return 0;
	else
		return Jc[a] * ny[b] % mod * ny[a - b] % mod;
}
int main()
{
	init();
	scanf("%s", s + 1);
	n = strlen(s + 1);
	L[0] = R[n + 1] = 0;
	//for (int i = 1; i <= n; ++i)	L[i] = L[i - 1] + (s[i] == '(');
	for (int i = n; i > 0; --i)	R[i] = R[i + 1] + (s[i] == ')');

	for (int i = 1; i <= n; ++i)
		if (s[i] == '(')
			ans = (ans + C((cnt++) + R[i], R[i] - 1)) % mod;

	printf("%lld\n", ans);
	return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <stdlib.h>

using namespace std;
// vector push_back push front top empty pop make_pair long long insert begin end
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair <int,int> > vpi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin()
#define rB rbegin()
#define E end()
#define rE rend()
#define Z size()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define L length()
#define show(a) cerr << " *** " << a << endl;
#define show1(a) cerr << " /// " << a << endl;

const int mod = 1e9 +7;
const int me = 200 * 1000 + 10;
ll fact[me];
ll inv[me];

ll binp(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (a == 0)
		return 0;
	ll res = binp(a, b/2);
	ll out;
	if (b%2)
		out = (((res*res)%mod)*a)%mod;
	else
		out = (res*res)%mod;
	return out %mod;
}

void fac()
{
	fact[0] = 1;
	inv[0] = 1;
	REP(i, 1, me)
	{
		fact[i] = fact[i-1]*i;
		fact[i] %= mod;
		inv[i] = binp(fact[i], mod-2);
	}

}

ll C(int a, int b)
{
	ll one = fact[a];
	ll two = inv[b];
	ll to = inv[a - b];
	two *= to;
	two %= mod;
	one *= two;
	one %= mod;
	return one;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	fac();
	string str;
	cin >> str;
	vi pre(str.L, 0);
	vi suf(str.L, 0);
	pre[0] = (str[0] == '(' ? 1 :0);
	REP(i, 1, str.L)
		pre[i] = pre[i -1] + (str[i] == '(' ? 1 : 0);
	suf[str.L - 1] = (str[str.L -1] == ')' ? 1 : 0);
	for (int i= str.L - 2; i >= 0; i--)
		suf[i] = suf[i +1] + (str[i] == ')' ? 1 : 0);
	ll ans = 0;
	for (int i= 0; i < str.L; i++)
	{
		if (str[i] == '(' && suf[i] != 0)
		{
			ans += C(suf[i]+pre[i] -1, pre[i]);
		}
	}
	cout << ans;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <stdlib.h>

using namespace std;
// vector push_back push front top empty pop make_pair long long insert begin end
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair <int,int> > vpi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin()
#define rB rbegin()
#define E end()
#define rE rend()
#define Z size()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define L length()
#define show(a) cerr << " *** " << a << endl;
#define show1(a) cerr << " /// " << a << endl;

const int mod = 1e9 +7;
const int me = 200 * 1000 + 10;
ll fact[me];
ll inv[me];

ll binp(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (a == 0)
		return 0;
	ll res = binp(a, b/2);
	ll out;
	if (b%2)
		out = (((res*res)%mod)*a)%mod;
	else
		out = (res*res)%mod;
	return out %mod;
}

void fac()
{
	fact[0] = 1;
	inv[0] = 1;
	REP(i, 1, me)
	{
		fact[i] = fact[i-1]*i;
		fact[i] %= mod;
		inv[i] = binp(fact[i], mod-2);
	}

}

ll C(int a, int b)
{
	ll one = fact[a];
	ll two = inv[b];
	ll to = inv[a - b];
	two *= to;
	two %= mod;
	one *= two;
	one %= mod;
	return one;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	fac();
	string str;
	cin >> str;
	vi pre(str.L, 0);
	vi suf(str.L, 0);
	pre[0] = (str[0] == '(' ? 1 :0);
	REP(i, 1, str.L)
		pre[i] = pre[i -1] + (str[i] == '(' ? 1 : 0);
	suf[str.L - 1] = (str[str.L -1] == ')' ? 1 : 0);
	for (int i= str.L - 2; i >= 0; i--)
		suf[i] = suf[i +1] + (str[i] == ')' ? 1 : 0);
	ll ans = 0;
	for (int i= 0; i < str.L; i++)
	{
		if (str[i] == '(' && suf[i] != 0)
		{
			ans += C(suf[i]+pre[i] -1, pre[i]);
			ans %= mod;
		}
	}
	cout << ans%mod;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <stdlib.h>

using namespace std;
// vector push_back push front top empty pop make_pair long long insert begin end
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair <int,int> > vpi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin()
#define rB rbegin()
#define E end()
#define rE rend()
#define Z size()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define L length()
#define show(a) cerr << " *** " << a << endl;
#define show1(a) cerr << " /// " << a << endl;

const int mod = 1e9 +7;
const int me = 200 * 1000 + 10;
ll fact[me];
ll inv[me];

ll binp(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (a == 0)
		return 0;
	ll res = binp(a, b/2);
	ll out;
	if (b%2)
		out = (((res*res)%mod)*a)%mod;
	else
		out = (res*res)%mod;
	return out %mod;
}

void fac()
{
	fact[0] = 1;
	inv[0] = 1;
	REP(i, 1, me)
	{
		fact[i] = fact[i-1]*i;
		fact[i] %= mod;
		inv[i] = binp(fact[i], mod-2);
	}

}

ll C(int a, int b)
{
	ll one = fact[a];
	ll two = inv[b];
	ll to = inv[a - b];
	two *= to;
	two %= mod;
	one *= two;
	one %= mod;
	return one;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	fac();
	string str;
	cin >> str;
	vi pre(str.L, 0);
	vi suf(str.L, 0);
	pre[0] = (str[0] == '(' ? 1 :0);
	REP(i, 1, str.L)
		pre[i] = pre[i -1] + (str[i] == '(' ? 1 : 0);
	suf[str.L - 1] = (str[str.L -1] == ')' ? 1 : 0);
	for (int i= str.L - 2; i >= 0; i--)
		suf[i] = suf[i +1] + (str[i] == ')' ? 1 : 0);
	ll ans = 0;
	for (int i= 0; i < str.L; i++)
	{
		if (str[i] == '(')
		{
			for (int k = 1; k <= pre[i]; k++)
			{
				if (k > suf[i])
					break;
				ans += C(suf[i], k);
				ans %= mod;
			}
		}
	}
	cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define sz(a) (int)((a).size())
#define fuck() cout<<"--------"<<endl
#define see(x) cout<<#x<<" = "<<x<<endl
#define see2(x,y) cout<<#x<<" = "<<x<<"::"<<#y<<" = "<<y<<endl
const int mod=1000000007;
typedef pair<int,int> pii;
const int inf=1e17;
const int N=1e5+5;
int fac[N],ifac[N];
int mult(int a,int b){
	int res=a;
	res*=b;
	if(res>=mod){
		res%=mod;
	}
	return res;
}
int add(int a,int b){
	int res=a+b;
	if(res>=mod){
		res%=mod;
	}
	return res;
}
int expo(int base,int exponent){
    int ans=1;
    base%=mod;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
int inv_mod(int k){
	return expo(k,mod-2);
}
void fac_process(){
	fac[0]=1;
	for(int i=1;i<N;i++){
		fac[i]=fac[i-1]*i;
		fac[i]%=mod;
	}
	ifac[N-1]=inv_mod(fac[N-1]);
	for(int i=N-2;i>=0;i--){
		ifac[i]=ifac[i+1]*(i+1);
		ifac[i]%=mod;
	}
}
int nCr(int n,int r){
	if(r>n)return 0;
	int ans=fac[n];
	ans%=mod;
	ans*=ifac[n-r];
	ans%=mod;
	ans*=ifac[r];
	ans%=mod;
	return ans;
}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	//Think at least once about dp and bs;
	fac_process();
	string s;
	cin>>s;
	int open=0,close=0;
	for(auto to:s){
		close+=(to==')');
	}
	int ans=0;
	for(auto to:s){
		if(to=='(')open++;
		else close--;
		if(to==')')continue;
		ans+=(nCr(open+close-1,open));
		ans%=mod;
	}
	cout<<ans<<endl;
}