我不会写公式……….
#include<cstdio>
#include<cstring>
#include<iostream>
#define maxn 200020
#define LL long long
using namespace std;
char s[maxn];
LL inv[maxn],fac[maxn];
int N=200002;
LL mod=1e9+7;
LL pow(LL x,LL y)
{
if(y==0) return 1;
if(y==1) return x;
LL a=pow(x,y/2)%mod;
a=(a*a)%mod;
if(y%2) return (a*x)%mod;
return a;
}
void init()
{
fac[1]=1;
for(int i=2;i<=N;i++)
fac[i]=(fac[i-1]*i)%mod;
inv[N]=pow(fac[N],mod-2)%mod;
for(int i=N-1;i>=1;i--)
inv[i]=(inv[i+1]*(i+1))%mod;
inv[0]=1;
}
LL calc(int x,int y)
{
int n=x+y-1;
LL ans=((fac[n]*inv[x])%mod)*inv[n-x];
return ans%mod;
}
int main()
{
init();
scanf("%s",s+1);
int n=strlen(s+1);
int ans1=0,ans2=0;
for(int i=1;i<=n;i++)
if(s[i]==41) ans2++;
LL ans=0;
for(int i=1;i<=n;i++)
{
if(s[i]==41)
{ans2--;continue;}
ans1++;
ans+=calc(ans1,ans2);
ans%=mod;
}
cout<<ans;
return 0;
}