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

const int MOD = 1e9 + 7;
string s;
typedef long long ll;
ll C(int n,int k)
{
	ll res = 1;
	for(int i = n - k + 1 ; i <= n ; i++) res *= i;
	for(int i = 2 ; i <= k ; i++) res /= i;
	return res;
}

ll addMOD(ll a,ll b){
	return (a + b)%MOD;
}

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

	cin >> s;
	int _length = s.length();
	vector<int> opnL(_length,0);
	vector<int> clsR(_length,0);
	opnL[0] = (s[0] == '(') ? 1 : 0;
	for(int i = 1 ; i < _length ; i++){
		opnL[i] = opnL[i-1];
		if(s[i] == '(')opnL[i]++;
	}
	clsR[_length-1] = (s[_length-1] == ')') ? 1 : 0;
	for(int i = _length - 2 ; i >= 0 ; i--){
		clsR[i] = clsR[i+1];
		if(s[i] == ')')clsR[i]++;
	}
	int ans = 0;
	for(int i = 0 ; i < _length ; i++){
		if(s[i] == ')' || clsR[i] == 0)continue;
		ll cnt = C(opnL[i] + clsR[i] - 1,opnL[i]);
		ans = addMOD(ans,cnt);
	}
	cout << ans << '\n';
	return 0;
}


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

const int md = (int)1e9 + 7;
inline void add(int &a, int b) {
	a += b;
	if (a >= md) a -= md;
}
inline void sub(int &a, int b) {
	a -= b;
	if (a < 0) a += md;
}
inline int mul(int a, int b) {
	return (int) ((long long) a * b % md);
}
inline int power(int a, long long b) {
	int res = 1;
	while (b > 0) {
		if (b & 1) {
			res = mul(res, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}
inline int inver(int a) {
	a %= md;
	if (a < 0) a += md;
	int b = md, u = 0, v = 1;
	while (a) {
		int t = b / a;
		b -= t * a; swap(a, b);
		u -= t * v; swap(u, v);
	}
	assert(b == 1);
	if (u < 0) u += md;
	return u;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	string s;
	cin >> s;
	int n = s.size();
	vector<int> pre(n + 1), suf(n + 2);
	for (int i = 0; i < n; i++) {
		pre[i + 1] = pre[i] + (s[i] == '(');
	}
	for (int i = n - 1; i >= 0; i--) {
		suf[i + 1] = suf[i + 2] + (s[i] == ')');
	}
	vector<int> fact(n + 1);
	vector<int> inv(n + 1);
	fact[0] = inv[0] = 1;
	for (int i = 1; i <= n; i++) {
		fact[i] = mul(fact[i - 1], i);
		inv[i] = inver(fact[i]);
	}
	auto comb = [&](int n, int m) {
		if (n < 0 || m < 0 || n < m) return 0;
		return mul(fact[n], mul(inv[m], inv[n - m]));
	};
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == ')') continue;
		int x = pre[i + 1], y = suf[i + 1];
		add(ans, comb(x + y - 1, y - 1));
	}
	cout << ans << '\n';

	return 0;
}


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

const int md = (int)1e9 + 7;
inline void add(int &a, int b) {
	a += b;
	if (a >= md) a -= md;
}
inline void sub(int &a, int b) {
	a -= b;
	if (a < 0) a += md;
}
inline int mul(int a, int b) {
	return (int) ((long long) a * b % md);
}
inline int power(int a, long long b) {
	int res = 1;
	while (b > 0) {
		if (b & 1) {
			res = mul(res, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}
inline int inver(int a) {
	a %= md;
	if (a < 0) a += md;
	int b = md, u = 0, v = 1;
	while (a) {
		int t = b / a;
		b -= t * a; swap(a, b);
		u -= t * v; swap(u, v);
	}
	assert(b == 1);
	if (u < 0) u += md;
	return u;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	string s;
	cin >> s;
	int n = s.size();
	vector<int> pre(n + 1), suf(n + 2);
	for (int i = 0; i < n; i++) {
		pre[i + 1] = pre[i] + (s[i] == '(');
	}
	for (int i = n - 1; i >= 0; i--) {
		suf[i + 1] = suf[i + 2] + (s[i] == ')');
	}
	vector<int> fact(n + 1);
	fact[0] = 1;
	for(int i = 1; i <= n; i++) {
		fact[i] = mul(fact[i - 1], i);
	}
	vector<int> inv(n + 1);
	for(int i = 1; i <= n; i++) {
		inv[i] = inver(fact[i]);
	}
	int ans = 1;
	for (int i = 0; i < n; i++) {
		if(s[i] == ')') continue;
		int x = pre[i + 1], y = suf[i + 1];
		cerr << x << ' ' << y << '\n';
		add(ans, mul(fact[x + y - 1], mul(inv[x], inv[y - 1])));
	}
	cout << ans << '\n';

	return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repi(i, a, b) for(int i=(a); i>(b); i--)
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define gcd __gcd
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)); (v).erase(unique(all(v)), (v).end())
#define pii pair<int, int>
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vi>
#define fi first
#define se second
#define pqueue priority_queue
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007
using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<typename T1, typename T2>
ostream& operator << (ostream& os, const pair<T1, T2>& p) { return os << '(' << p.fi << ", " << p.se << ')'; }

template<typename T>
void printv(const T& v) { for(auto i : v) cerr << i << ' '; cerr << '\n'; }

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;

//All indexing is 0-based
using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
//methods: find_by_order(k); & order_of_key(k);
//To make it an ordered_multiset, use pairs of (value, time_of_insertion)
//to distinguish values which are similar

template<class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

//Returns no. of values x for which ceil(n / x) == y (y must be > 1).
inline ll CC(ll n, ll y) { return iceil(n, y-1) - iceil(n, y); }

//Returns no. of values x for which floor(n / x) == y
inline ll FF(ll n, ll y) { return n / y - n / (y+1); }

//a and b are assumed to be taken modulo p
inline int add(int a, int b, int p = mod){ int c = a + b; if(c >= p) c -= p; return c; }
inline int sub(int a, int b, int p = mod){ int c = a - b; if(c < 0) c += p; return c; }
inline int mul(int a, int b, int p = mod){ return (a * 1ll * b) % p; }

#define inv Fermat
#define div Div

int power(int a, ll b,int p = mod)
{
    int res = 1;
    while(b > 0){
        if(b & 1) res = mul(res, a, p);
        a = mul(a, a, p);
        b >>= 1;
    }
    return res;
}

//Computes a^(-1) mod p
// p must be a prime no.
// Fermat's little theorem: a^(p-1) = 1(mod p)
//So, we have a^(p-2) = a^(-1) (mod p)
inline int Fermat(int a, int p = mod){ return power(a, p-2, p);}

inline int div(int a, int b, int p = mod) {
    return mul(a, Fermat(b, p), p);
}

#define N 400005
#define int ll
// #define trace(...) 42

int fact[N], ifact[N];

void prep() {
    fact[0] = ifact[0] = 1;
    rep(i, 1, N) {
        fact[i] = mul(fact[i-1], i);
        ifact[i] = inv(fact[i]);
    }
    // ifact[N-1] = inv(fact[N-1]);
    // repi(i, N-2, -1) ifact[i] = mul(i+1, ifact[i+1]);
}

int nCr(int n, int r) {
    if(r > n) return 0;
    int ans = fact[n];
    ans = mul(ans, ifact[n-r]);
    ans = mul(ans, ifact[r]);
    return ans;
}

int n;
string s;

int L[N], R[N];

int value(int n, int m) {
    return sub(nCr(n+m, n), 1);
}

main()
{
    #ifndef ONLINE_JUDGE
        freopen("/home/tarun/Desktop/input.txt", "r", stdin);
     // freopen("/home/tarun/Desktop/output.txt", "w", stdout);
    #endif
    sync;
    clock_t clk = clock();
    cerr << "I will return...\n";

    prep();
    cin >> s; n = s.size();
    rep(i, 0, n) {
        L[i] = s[i] == '(';
        if(i) L[i] += L[i-1];
    }

    repi(i, n-1, -1) {
        R[i] = s[i] == ')';
        if(i != n-1) R[i] += R[i+1];
    }

    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == '(') {
            ans = add(ans, sub(value(L[i], R[i]), value(L[i]-1, R[i])));
            // trace(i, value(L[i], R[i]));
        }
    }

    cout << ans << '\n';

    cerr << "...don't you ever hang your head.\n";
    cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / cps << '\n';
}

//Compile using:
//g++ -o filename.exe --std=c++11 filename.cpp
//Use -D CP for defining a macro CP in the local environment


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repi(i, a, b) for(int i=(a); i>(b); i--)
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define gcd __gcd
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)); (v).erase(unique(all(v)), (v).end())
#define pii pair<int, int>
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vi>
#define fi first
#define se second
#define pqueue priority_queue
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007
using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<typename T1, typename T2>
ostream& operator << (ostream& os, const pair<T1, T2>& p) { return os << '(' << p.fi << ", " << p.se << ')'; }

template<typename T>
void printv(const T& v) { for(auto i : v) cerr << i << ' '; cerr << '\n'; }

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;

//All indexing is 0-based
using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
//methods: find_by_order(k); & order_of_key(k);
//To make it an ordered_multiset, use pairs of (value, time_of_insertion)
//to distinguish values which are similar

template<class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

//Returns no. of values x for which ceil(n / x) == y (y must be > 1).
inline ll CC(ll n, ll y) { return iceil(n, y-1) - iceil(n, y); }

//Returns no. of values x for which floor(n / x) == y
inline ll FF(ll n, ll y) { return n / y - n / (y+1); }

//a and b are assumed to be taken modulo p
inline int add(int a, int b, int p = mod){ int c = a + b; if(c >= p) c -= p; return c; }
inline int sub(int a, int b, int p = mod){ int c = a - b; if(c < 0) c += p; return c; }
inline int mul(int a, int b, int p = mod){ return (a * 1ll * b) % p; }

#define inv Fermat
#define div Div

int power(int a, ll b,int p = mod)
{
    int res = 1;
    while(b > 0){
        if(b & 1) res = mul(res, a, p);
        a = mul(a, a, p);
        b >>= 1;
    }
    return res;
}

//Computes a^(-1) mod p
// p must be a prime no.
// Fermat's little theorem: a^(p-1) = 1(mod p)
//So, we have a^(p-2) = a^(-1) (mod p)
inline int Fermat(int a, int p = mod){ return power(a, p-2, p);}

inline int div(int a, int b, int p = mod) {
    return mul(a, Fermat(b, p), p);
}

#define N 400005
#define int ll
// #define trace(...) 42

int fact[N], ifact[N];

void prep() {
    fact[0] = ifact[0] = 1;
    rep(i, 1, N) {
        fact[i] = mul(fact[i-1], i);
        // ifact[i] = inv(fact[i]);
    }
    ifact[N-1] = inv(fact[N-1]);
    repi(i, N-2, -1) ifact[i] = mul(i+1, ifact[i+1]);
}

int nCr(int n, int r) {
    if(r > n) return 0;
    int ans = fact[n];
    ans = mul(ans, ifact[n-r]);
    ans = mul(ans, ifact[r]);
    return ans;
}

int n;
string s;

int L[N], R[N];

int value(int n, int m) {
    return sub(nCr(n+m, n), 1);
}

main()
{
    #ifndef ONLINE_JUDGE
        freopen("/home/tarun/Desktop/input.txt", "r", stdin);
     // freopen("/home/tarun/Desktop/output.txt", "w", stdout);
    #endif
    sync;
    clock_t clk = clock();
    cerr << "I will return...\n";

    prep();
    cin >> s; n = s.size();
    rep(i, 0, n) {
        L[i] = s[i] == '(';
        if(i) L[i] += L[i-1];
    }

    repi(i, n-1, -1) {
        R[i] = s[i] == ')';
        if(i != n-1) R[i] += R[i+1];
    }

    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == '(') {
            ans = add(ans, sub(value(L[i], R[i]), value(L[i]-1, R[i])));
            // trace(i, value(L[i], R[i]));
        }
    }

    cout << ans << '\n';

    cerr << "...don't you ever hang your head.\n";
    cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / cps << '\n';
}

//Compile using:
//g++ -o filename.exe --std=c++11 filename.cpp
//Use -D CP for defining a macro CP in the local environment


//Link : https://codeforces.com/contest/1253

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200005

/*
#include <limits.h>
INT_MAX
LLONG_MAX
*/

char s[N];
int preOpen[N];
int preClose[N];
int fac[N];
#define mod 1000000007

int add(int x,int y) {
  return (x+y)%mod;
}

int mul(int x,int y) {
  return (ll)x*y%mod;
}

int mypow(int x,int c) {
  int ret = 1;
  while(c>0) {
    if(c&1) {
      ret = mul(ret,x);
    }
    c/=2;
    x = mul(x,x);
  }
  return ret;
}

int invFac[N];
int combi(int n,int r) {
  int ret = fac[n];
  ret = mul(ret, invFac[r]);
  ret = mul(ret, invFac[n-r]);
  return ret;
}

void solve() {
  scanf("%s ", s+1);
  int n = strlen(s+1);
  fac[0] = 1;
  invFac[0] = 1;
  for(int i=1;i<N;++i) {
    fac[i] = mul(fac[i-1],i);
    invFac[i] = mypow(fac[i],mod-2);
  }
  for(int i=1;i<=n;++i) {
    preOpen[i] = preOpen[i-1] + (s[i]=='(' ? 1 : 0);
  }
  for(int i=1;i<=n;++i) {
    preClose[i] = preClose[i-1] + (s[i]==')' ? 1 : 0);
  }
  int ret = 0;
  int numOpen = 0;
  for(int i=1;i<=n;++i) {
    if(s[i]=='(') {
      ++numOpen;
      ret = add(ret, combi(numOpen + preClose[n] - preClose[i]-1,numOpen));
    }
  }
  printf("%d\n", ret);
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


//Link : https://codeforces.com/contest/1253

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200005

/*
#include <limits.h>
INT_MAX
LLONG_MAX
*/

char s[N];
int preOpen[N];
int preClose[N];
int fac[N];
#define mod 1000000007

int add(int x,int y) {
  return (x+y)%mod;
}

int mul(int x,int y) {
  return (ll)x*y%mod;
}

int mypow(int x,int c) {
  int ret = 1;
  while(c>0) {
    if(c&1) {
      ret = mul(ret,x);
    }
    c/=2;
    x = mul(x,x);
  }
  return ret;
}

int invFac[N];
int combi(int n,int r) {
  int ret = fac[n];
  ret = mul(ret, invFac[r]);
  ret = mul(ret, invFac[n-r]);
  return ret;
}

int dnc(int l,int r) {
  if(l==r) {
    return 0;
  }
  int mid = (l+r)/2;
  int ret = add(dnc(l,mid),dnc(mid+1,r));
  int numOpen = preOpen[mid] - preOpen[l-1];
  int numClose = preClose[r] - preClose[mid];
  int mini = min(numOpen,numClose);
  for(int i=1;i<=mini;++i) {
    ret = add(ret, mul(combi(numOpen,i), combi(numClose,i)));
  }
  return ret;
}
void solve() {
  scanf("%s ", s+1);
  int n = strlen(s+1);
  fac[0] = 1;
  invFac[0] = 1;
  for(int i=1;i<N;++i) {
    fac[i] = mul(fac[i-1],i);
    invFac[i] = mypow(fac[i],mod-2);
  }
  for(int i=1;i<=n;++i) {
    preOpen[i] = preOpen[i-1] + (s[i]=='(' ? 1 : 0);
  }
  for(int i=1;i<=n;++i) {
    preClose[i] = preClose[i-1] + (s[i]==')' ? 1 : 0);
  }
  printf("%d\n", dnc(1,n));
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 200005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int f[MX],ni[MX],l[MX],r[MX],ans;
string s;
int C(int n,int m){ return f[n]*ni[m]%mo*ni[n-m]%mo;}
main(){
	IOS;
	f[0] = ni[0] = ni[1] =1;
	REP(i,1,MX) f[i] = f[i-1]*i%mo;
	REP(i,2,MX) ni[i] = ni[mo%i]*(mo-mo/i)%mo;
	REP(i,2,MX) ni[i] = ni[i]*ni[i-1]%mo;
	cin>>s;
	REP(i,1,sz(s)+1) l[i] = l[i-1]+(s[i-1]=='(');
	RREP(i,sz(s)+1,1) r[i] = r[i+1]+(s[i-1]==')');
	REP(i,1,sz(s)+1) if(s[i-1]=='(') ans = (ans+C(l[i]+r[i]-1,r[i]-1))%mo;
	cout<<ans;
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 200005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int f[MX],ni[MX],l[MX],r[MX],ans;
string s;
int C(int n,int m){ return f[n]*ni[m]%mo*ni[n-m]%mo;}
main(){
	IOS;
	f[0] = ni[0] = ni[1] =1;
	REP(i,1,MX) f[i] = f[i-1]*i%mo;
	REP(i,2,MX) ni[i] = ni[mo%i]*(mo-mo/i)%mo;
	REP(i,2,MX) ni[i] = ni[i]*ni[i-1]%mo;
	cin>>s;
	REP(i,1,sz(s)+1) l[i] = l[i-1]+(s[i-1]=='(');
	RREP(i,sz(s)+1,1) r[i] = r[i+1]+(s[i-1]==')');
	REP(i,1,sz(s)+1) if(s[i-1]=='(') ans = (ans+C(l[i]+r[i]-1,l[i]))%mo;
	cout<<ans;
}


/* Manish Pant - insider_pants, hello_my_friend */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define endl "\n"
#define pb push_back

typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const multiset<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.F << ' ' << v.S; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.F << " => " << i.S << ')' << ' '; return os; }

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const ll MOD = 1e9 + 7;
const int N = 4e5 + 5;
vector<ll> fact(N, 1), inv(N, 1);
vector<ll> cnt(N, 0);
vector<int> v;
int n;

ll power(ll x, ll y)
{
    ll ans = 1;
    while(y > 0)
    {
        if(y & 1) ans = (ans * x) % MOD;

        x = (x * x) % MOD;
        y >>= 1;
    }
    return ans;
}

void pre()
{
    n = v.size();
    for(int i = 2; i < N; i++)
    {
        fact[i] = (fact[i - 1] * i) % MOD;
        inv[i] = power(fact[i], MOD - 2);
    }

    ll t = 0;
    for(int i = n - 1; i >= 0; i--)
    {
        if(v[i] == 0) t++;
        cnt[i] = t;
    }
}

ll ncr(ll a, ll b)
{
    assert(a >= b);
    ll ans = fact[a];
    ans = (ans * inv[b]) % MOD;
    ans = (ans * inv[a - b]) % MOD;

    return ans;
}

void solve()
{
    pre();

    ll ans = 0;
    ll x = 0;
    for(int i = 0; i < n; i++)
    {
        if(v[i] == 0) continue;
        else x++;

        ll y = cnt[i];
        // we have x opening brackets in [0, i] and y closing bracket in (i, n - 1];

        ans = (ans + ncr(x + y - 1, y - 1)) % MOD;
    }

    cout << ans << endl;
}

int main()
{
    fast();
    string temp;
    cin >> temp;
    for(int i = 0; i < temp.length(); i++)
    {
        if(temp[i] == '(') v.pb(1);
        else v.pb(0);
    }
    solve();
}


/* Manish Pant - insider_pants, hello_my_friend */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define endl "\n"
#define pb push_back

typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const multiset<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.F << ' ' << v.S; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.F << " => " << i.S << ')' << ' '; return os; }

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const ll MOD = 1e9 + 7;
const int N = 4e5 + 5;
vector<ll> fact(N, 1), inv(N, 1);
vector<ll> cnt(N, 0);
vector<int> v;
int n;

ll power(ll x, ll y)
{
    ll ans = 1;
    while(y > 0)
    {
        if(y & 1) ans = (ans * x) % MOD;

        x = (x * x) % MOD;
        y >>= 1;
    }
    return ans;
}

void pre()
{
    n = v.size();
    for(int i = 2; i < N; i++)
    {
        fact[i] = (fact[i - 1] * i) % MOD;
        inv[i] = power(fact[i], MOD - 2);
    }

    ll t = 0;
    for(int i = n - 1; i >= 0; i--)
    {
        if(v[i] == 0) t++;
        cnt[i] = t;
    }
}

ll ncr(ll a, ll b)
{
    assert(a >= b);
    ll ans = fact[a];
    ans = (ans * inv[b]) % MOD;
    ans = (ans * inv[a - b]) % MOD;

    return ans;
}

void solve()
{
    pre();

    ll ans = 0;
    ll x = 0;
    for(int i = 0; i < n; i++)
    {
        if(v[i] == 0) continue;

        ll y = cnt[i];
        // we have x opening brackets in [0, i] and y closing bracket in (i, n - 1];

        for(ll i = 1; i <= min(x + 1, y); i++)
        {
            ll temp = (ncr(x, i - 1) * ncr(y, i)) % MOD;
            ans = (ans + temp) % MOD;
        }

        x++;
    }

    cout << ans << endl;
}

int main()
{
    fast();
    string temp;
    cin >> temp;
    for(int i = 0; i < temp.length(); i++)
    {
        if(temp[i] == '(') v.pb(1);
        else v.pb(0);
    }
    solve();
}


/* Manish Pant - insider_pants, hello_my_friend */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define endl "\n"
#define pb push_back

typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const multiset<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.F << ' ' << v.S; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.F << " => " << i.S << ')' << ' '; return os; }

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const ll MOD = 1e9 + 7;
const int N = 4e5 + 5;
vector<ll> fact(N, 1), inv(N, 1);
vector<ll> cnt(N, 0);
vector<int> v;
int n;

ll power(ll x, ll y)
{
    ll ans = 1;
    while(y > 0)
    {
        if(y & 1) ans = (ans * x) % MOD;

        x = (x * x) % MOD;
        y >>= 1;
    }
    return ans;
}

void pre()
{
    n = v.size();
    for(int i = 2; i < N; i++)
    {
        fact[i] = (fact[i - 1] * i) % MOD;
        inv[i] = power(fact[i], MOD - 2);
    }

    ll t = 0;
    for(int i = n - 1; i >= 0; i--)
    {
        if(v[i] == 0) t++;
        cnt[i] = t;
    }
}

ll ncr(ll a, ll b)
{
    assert(a >= b);
    ll ans = fact[a];
    ans = (ans * inv[b]) % MOD;
    ans = (ans * inv[a - b]) % MOD;

    return ans;
}

void solve()
{
    pre();

    ll ans = 0;
    ll x = 0;
    for(int i = 0; i < n; i++)
    {
        if(v[i] == 0) continue;
        else x++;

        ll y = cnt[i + 1];
        // we have x opening brackets in [0, i] and y closing bracket in (i, n - 1];

        ans = (ans + ncr(x + y - 1, y - 1)) % MOD;
    }

    cout << ans << endl;
}

int main()
{
    fast();
    string temp;
    cin >> temp;
    for(int i = 0; i < temp.length(); i++)
    {
        if(temp[i] == '(') v.pb(1);
        else v.pb(0);
    }
    solve();
}


/* Manish Pant - insider_pants, hello_my_friend */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define endl "\n"
#define pb push_back

typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const multiset<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.F << ' ' << v.S; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.F << " => " << i.S << ')' << ' '; return os; }

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const ll MOD = 1e9 + 7;
const int N = 4e5 + 5;
vector<ll> fact(N, 1), inv(N, 1);
vector<ll> cnt(N, 0);
vector<int> v;
int n;

ll power(ll x, ll y)
{
    ll ans = 1;
    while(y > 0)
    {
        if(y & 1) ans = (ans * x) % MOD;

        x = (x * x) % MOD;
        y >>= 1;
    }
    return ans;
}

void pre()
{
    n = v.size();
    for(int i = 2; i < N; i++)
    {
        fact[i] = (fact[i - 1] * i) % MOD;
        inv[i] = power(fact[i], MOD - 2);
    }

    for(int i = n - 1; i >= 0; i--)
    {
        if(v[i] == 0) cnt[i]++;
        cnt[i] += cnt[i + 1];
    }
}

ll ncr(ll a, ll b)
{
    if(b < 0) return 0;
    assert(a >= b);
    ll ans = fact[a];
    ans = (ans * inv[b]) % MOD;
    ans = (ans * inv[a - b]) % MOD;

    return ans;
}

void solve()
{
    pre();

    ll ans = 0;
    ll x = 0;
    for(int i = 0; i < n; i++)
    {
        if(v[i] == 0) continue;
        else x++;

        ll y = cnt[i + 1];
        // we have x opening brackets in [0, i] and y closing bracket in (i, n - 1];

        if(x < y)
        {
            ans = (ans + ncr(x + y - 1, x)) % MOD;
        }
        else
        {
            ans = (ans + ncr(x + y - 1, y - 1)) % MOD;
        }
    }

    cout << ans << endl;
}

int main()
{
    fast();
    string temp;
    cin >> temp;
    for(int i = 0; i < temp.length(); i++)
    {
        if(temp[i] == '(') v.pb(1);
        else if(temp[i] == ')') v.pb(0);
    }
    solve();
}


/* Manish Pant - insider_pants, hello_my_friend */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define endl "\n"
#define pb push_back

typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const multiset<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.F << ' ' << v.S; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.F << " => " << i.S << ')' << ' '; return os; }

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const ll MOD = 1e9 + 7;
const int N = 4e5 + 5;
vector<ll> fact(N, 1), inv(N, 1);
vector<ll> cnt(N, 0);
vector<int> v;
int n;

ll power(ll x, ll y)
{
    ll ans = 1;
    while(y > 0)
    {
        if(y & 1) ans = (ans * x) % MOD;

        x = (x * x) % MOD;
        y >>= 1;
    }
    return ans;
}

void pre()
{
    n = v.size();
    for(int i = 2; i < N; i++)
    {
        fact[i] = (fact[i - 1] * i) % MOD;
        inv[i] = power(fact[i], MOD - 2);
    }

    for(int i = n - 1; i >= 0; i--)
    {
        if(v[i] == 0) cnt[i]++;
        cnt[i] += cnt[i + 1];
    }
}

ll ncr(ll a, ll b)
{
    if(b < 0) return 0;
    assert(a >= b);
    ll ans = fact[a];
    ans = (ans * inv[b]) % MOD;
    ans = (ans * inv[a - b]) % MOD;

    return ans;
}

void solve()
{
    pre();

    ll ans = 0;
    ll x = 0;
    for(int i = 0; i < n; i++)
    {
        if(v[i] == 0) continue;
        else x++;

        ll y = cnt[i + 1];
        if(y == 0) break;
        // we have x opening brackets in [0, i] and y closing bracket in (i, n - 1];

        ans = (ans + ncr(x + y - 1, y - 1)) % MOD;
    }

    cout << ans << endl;
}

int main()
{
    fast();
    string temp;
    cin >> temp;
    for(int i = 0; i < temp.length(); i++)
    {
        if(temp[i] == '(') v.pb(1);
        else if(temp[i] == ')') v.pb(0);
    }
    solve();
}


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

#define y1 as214
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back
#define t top()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , n) for(int i = 0 ; i < n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define ll long long
#define oo 1e17
#define int long long

const int N = 1e6 + 5;
int n , cnt , mod = 1e9 + 7;
int fact[N];
char f[N];

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

int sub(int a , int b)
{
    return ((a - b) % mod + mod) % mod;
}

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

int powmod(int a , int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1)
            res = mul(res , a);
        a = mul(a , a);
        b >>= 1;
    }
    return res;
}

int C(int n , int k)
{
    return mul(fact[n] , powmod(mul(fact[k] , fact[n - k]) , mod - 2));
}

main()
{
    //freopen("785D.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> f;
    int n = strlen(f);
    fact[0] = 1;
    FOR(i , 1 , n)
        fact[i] = mul(fact[i - 1] , i);
    FORD(i , n , 1)
        f[i] = f[i - 1];
    FOR(i , 1 , n)
    {
        if(f[i] == ')')
            cnt++;
    }
    int x = 0;
    int res = 0;
    FOR(i , 1 , n)
    {
        if(f[i] == '(')
        {
            if(x != 0 && cnt != 0)
                res = add(res , sub(C(x + cnt , min(x , cnt) + 1) , 1));
            else
                res = add(res , cnt);
            x++;
        }
        else
            cnt--;
    }
    cout << res;
}


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

#define y1 as214
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back
#define t top()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , n) for(int i = 0 ; i < n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define ll long long
#define oo 1e17
#define int long long

const int N = 1e6 + 5;
int n , cnt , mod = 1e9 + 7;
int fact[N];
char f[N];

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

int sub(int a , int b)
{
    return ((a - b) % mod + mod) % mod;
}

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

int powmod(int a , int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1)
            res = mul(res , a);
        a = mul(a , a);
        b >>= 1;
    }
    return res;
}

int C(int n , int k)
{
    return mul(fact[n] , powmod(mul(fact[k] , fact[n - k]) , mod - 2));
}

main()
{
    //freopen("785D.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> f;
    int n = strlen(f);
    fact[0] = 1;
    FOR(i , 1 , n)
        fact[i] = mul(fact[i - 1] , i);
    FORD(i , n , 1)
        f[i] = f[i - 1];
    FOR(i , 1 , n)
    {
        if(f[i] == ')')
            cnt++;
    }
    int x = 0;
    int res = 0;
    FOR(i , 1 , n)
    {
        if(f[i] == '(')
        {
            if(x != 0 && cnt >= 2)
                res = add(res , C(x + cnt , x + 1));
            else
                res = add(res , cnt);
            x++;
        }
        else
            cnt--;
    }
    cout << res;
}


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

#define y1 as214
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back
#define t top()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , n) for(int i = 0 ; i < n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define ll long long
#define oo 1e17
#define int long long

const int N = 1e6 + 5;
int n , cnt , mod = 1e9 + 7;
int fact[N];
char f[N];

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

int sub(int a , int b)
{
    return ((a - b) % mod + mod) % mod;
}

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

int powmod(int a , int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1)
            res = mul(res , a);
        a = mul(a , a);
        b >>= 1;
    }
    return res;
}

int C(int n , int k)
{
    return mul(fact[n] , powmod(mul(fact[k] , fact[n - k]) , mod - 2));
}

main()
{
    //freopen("785D.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> f;
    int n = strlen(f);
    fact[0] = 1;
    FOR(i , 1 , n)
        fact[i] = mul(fact[i - 1] , i);
    FORD(i , n , 1)
        f[i] = f[i - 1];
    FOR(i , 1 , n)
    {
        if(f[i] == ')')
            cnt++;
    }
    int x = 0;
    int res = 0;
    FOR(i , 1 , n)
    {
        if(f[i] == '(')
        {
            res = add(res , C(x + cnt , x + 1));
            x++;
        }
        else
            cnt--;
    }
    cout << res;
}


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

#define y1 as214
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back
#define t top()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , n) for(int i = 0 ; i < n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define ll long long
#define oo 1e17
#define int long long

const int N = 1e6 + 5;
int n , cnt , mod = 1e9 + 7;
int fact[N];
char f[N];

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

int sub(int a , int b)
{
    return ((a - b) % mod + mod) % mod;
}

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

int powmod(int a , int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1)
            res = mul(res , a);
        a = mul(a , a);
        b >>= 1;
    }
    return res;
}

int C(int n , int k)
{
    return mul(fact[n] , powmod(mul(fact[k] , fact[n - k]) , mod - 2));
}

main()
{
    //freopen("785D.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> f;
    int n = strlen(f);
    fact[0] = 1;
    FOR(i , 1 , n)
        fact[i] = mul(fact[i - 1] , i);
    FORD(i , n , 1)
        f[i] = f[i - 1];
    FOR(i , 1 , n)
    {
        if(f[i] == ')')
            cnt++;
    }
    int x = 0;
    int res = 0;
    FOR(i , 1 , n)
    {
        if(f[i] == '(')
        {
            if(x != 0 && cnt >= 2)
                res = add(res , C(x + cnt , min(x , cnt) + 1));
            else
                res = add(res , cnt);
            x++;
        }
        else
            cnt--;
    }
    cout << res;
}


#include <bits/stdc++.h>

using namespace std;

// somethings maybe wrong in template, did not veryify everything pay attention.
// update template regularly
// < (template) >
// < (defines) >
#define ar array
#define ll long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define lbi(A,x)   (lower_bound(A.begin(),A.end(), x) - A.begin())
#define ubi(A,x)   (upper_bound(A.begin(), A.end(), x) - A.begin())
#define lbir(A,i,j,x)  (lower_bound(A.begin() + i , A.begin() + j , x) - A.begin())
#define ubir(A,i,j,x)  (upper_bound(A.begin() + i, A.begin() + j, x) - A.begin())
#define f_prec(prec)  cout << fixed << setprecision(prec) ;
#define vv(A, T, n1, n2, val) vector<vector<T>> A(n1, vector<T>(n2, val))
#define vvv(A, T, n1, n2, n3, val) vector<vector<vector<T>>> A(n1, vector<vector<T>>(n2, vector<T>(n3, val)))
#define vvvv(A, T, n1, n2, n3, n4, val) vector<vector<vector<vector<T>>>> A(n1, vector<vector<vector<T>>>(n2, vector<vector<T>>(n3, vector<T>(n4, val))))
// </ (defines)>
// <(debugging template) >
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename T>
string to_string(stack <T> st);
template <typename T>
string to_string(queue<T> q);
string to_string(char c){return string(1, c);}
string to_string(const string s){return '"' + s + '"';}
string to_string(const char* s){return to_string((string)s);}
string to_string(bool b){return (b ? "true" : "false");}
string to_string(vector<bool> v){bool first = true;string res = "{";for (int i = 0; i < static_cast<int>(v.size()); i++) {if (!first) {res += ", ";}first = false;res += to_string(v[i]);}res += "}";return res;}
// prints bitset just like a vector (not number)
template <size_t S>
string to_string(bitset<S> b){string res;res += '{';bool f = true;for (int i = 0; i < S; ++i) {if (!f) {res += ',';}f = false;res += char('0' + b[i]);}res += '}';return res;}
template <typename A>
string to_string(A v){bool first = true;string res = "{";for (const auto& x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename T >
string to_string(stack <T> st){bool first = true;string res = "{";while (!st.empty()) {if (!first) {res += ", ";}first = false;res += to_string(st.top());st.pop();}res += "}";return res;}
template <typename T>
string to_string(queue<T> q){bool first = true;string res = "{";while (!q.empty()) {if (!first) {res += ", ";}first = false;res += to_string(q.front());q.pop();}res += "}";return res;}
template <typename T>
string to_string(T pq, bool ispq){assert(ispq); bool first = true;string res = "{";while (!pq.empty()) {if (!first) {res += ", ";}first = false;res += to_string(pq.top());pq.pop();}res += "}";return res;}
// tuple deleted from template
void DBG(){cerr << " ]" << "\n";}
template <typename Head, typename... Tail>
void DBG(Head H, Tail... T){cerr << " " << to_string(H);if (sizeof...(T)) {cerr << ", ";}DBG(T...);}

#ifdef zxcv_1
#define dbg(...) cerr << "L(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 42
#endif
// <(/debugging template)>
// < (datastrucures) >
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename key, typename value, typename cmp = std::less<key>>
using omap = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// </ (datastructures) >
// < (loops) >
#define fr(i,a,b,d) for (int i = a; i < b; i += d)
#define rfr(i,b,a,d) for(int i= b; i>= a; i -= d)
#define frc(i,a,b,c,d) for(int i = a; (i< b) && c ; i += d)
#define rfrc(i,a,b,c,d) for(int i = b; (i>= a) && c ; i -= d)
// </ (loops) >
// < (reading) >
void read(char &x) {cin >> x;}
void read(int& x){cin >> x;}
void read(ll& x){cin >> x;}
void read(double& x){cin >> x;}
void read(string& s){cin >> s;}
// works only for simple pairs  <int,int>, <string,int> .....
template <typename T1, typename T2>
void read(pair<T1, T2>& p){cin >> p.first >> p.second;}
template <typename T>
void read(T& A){for (auto& x : A) {read(x);}}
template <typename T>
void assign_offset(T& A, int off = -1){for (auto& x : A) {x += off;}}
template <class H, class... T>
void read(H& h, T&... t){read(h);read(t...);}
// </ (reading) >
// < (writing) >
// where T must be simple
template <typename T>
void out (T &A, int offset = 0 ){for(auto &x : A){x += offset; cout <<  x <<" ";}cout <<"\n"; }
// </ (writing) >
// < (functions) >
#define fsttrue(lo_val,hi_val,valid,ansi) {ll lo = lo_val , hi = hi_val,  mid;while (lo <= hi) {mid = lo + (hi - lo) / 2;if (valid(mid)) {ansi = mid;hi = mid - 1;} else {lo = mid + 1;}}}
#define lsttrue(lo_val,hi_val,valid,ansi) {ll lo = lo_val , hi = hi_val,  mid;while (lo <= hi) {mid = lo + (hi - lo) / 2;if (valid(mid)) {ansi = mid;lo = mid + 1;} else {hi = mid - 1;}}}
#define ternint_hi(lo_val,hi_val,gv,ansi,ansv) {ll lo = lo_val, hi = hi_val, m1, m2;const int diffrange = 7;while (hi - lo > diffrange) {m1 = lo + (hi - lo) / 3;m2 = hi - (hi - lo) / 3;if (gv(m1) < gv(m2)) {    lo = m1;} else {    hi = m2;}}ansi = lo;ansv = gv(lo);for (int i = lo + 1; i <= hi; ++i) {if (a_max(ansv, gv(i))) {    ansi = i;}}}
#define ternint_lo(lo_val,hi_val,gv,ansi,ansv) {ll lo = lo_val, hi = hi_val, m1, m2;const int diffrange = 7;while (hi - lo > diffrange) {m1 = lo + (hi - lo) / 3;m2 = hi - (hi - lo) / 3;if (gv(m1) > gv(m2)) {    lo = m1;} else {    hi = m2;}}ansi = lo;ansv = gv(lo);for (int i = lo + 1; i <= hi; ++i) {if (a_min(ansv, gv(i))) {    ansi = i;}}}
#define terndouble_hi(lo_val,hi_val,gv,ansi,ansv) {double lo = lo_val, hi = hi_val, m1, m2;const double eps = 1e-9; while (hi - lo > eps) {m1 = lo + (hi - lo) / 3;m2 = hi - (hi - lo) / 3;if (gv(m1) < gv(m2)) {lo = m1;} else {hi = m2;}}double ansi = lo;double ansv = gv(lo);}
#define terndouble_lo(lo_val,hi_val,gv,ansi,ansv) {double lo = lo_val, hi = hi_val, m1, m2;const double eps = 1e-9; while (hi - lo > eps) {m1 = lo + (hi - lo) / 3;m2 = hi - (hi - lo) / 3;if (gv(m1) > gv(m2)) {lo = m1;} else {hi = m2;}}double ansi = lo;double ansv = gv(lo);}
// random in [l,r]
mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());ll rand_m(ll a, ll b){return uniform_int_distribution<ll>(a, b)(mt_rng);}
// assign min of (a,b) , if (a > b) return true and assigns a = b
template <typename T>
bool a_min(T& a, const T& b){return (b < a) ? (a = b), 1 : 0;}
// assign max of (a,b) ,if (a < b) return true and assigns a = b
template <typename T>
bool a_max(T& a, const T& b){return (b > a) ? (a = b), 1 : 0;}
// both m and n must be positive
ll ceil(ll m, ll n){return (m + n - 1) / n;}
// 0 based index
// getval , [i, j] sum using prefix
template<typename T>
ll gv(int i, int j, vector<T>& pre){if (i > j || (j < 0)) {return 0LL;}ll val = pre[j];if (i - 1 >= 0) {val -= pre[i - 1];}return val;}
// getprefixval , [0...i] sum
template <typename T>
ll gpv(int i, vector<T>& pre){return gv(0, i, pre);}
// getsuffixval, [i....n - 1] sum
template <typename T>
ll gsv(int i, vector<T>& suf){int n = sz(suf);if (i >= n) {return 0LL;}return suf[i];}
// assigns values to   prefix array with indices 0 to n-1
template<typename T>
void assign_pre(vector<T>& pre, vector<T>& A){int n = sz(A);for (int i = 0; i < n; ++i) {pre[i] = A[i];if (i) {pre[i] += pre[i - 1];}}}
// assigns values  suffix array with indices 0 to n-1
template<typename T>
void assign_suf(vector<T>& suf, vector<T>& A){int n = sz(A);for (int i = n - 1; i >= 0; --i) {suf[i] = A[i];if (i + 1 < n) {suf[i] += suf[i + 1];}}}
// finds no of values between [l,r]
template <typename T>
int sorted_range (const vector<T>& A , int l , int r){int n = A.size(); if (r < l){return 0 ;}return ubi(A,r) - ubi(A,l-1); }
// sorts and removes duplicates from vector
template <typename T>
void remove_dup(vector<T>& v){sort(all(v));v.erase(unique(all(v)), v.end());}
// returns no of 1's in binary representation
constexpr int ppcnt(int x){return __builtin_popcount(x);}
constexpr int ppcnt(ll x){return __builtin_popcountll(x);}
// returns floor(log2(x))
constexpr int f_lg(int x){return 31 - __builtin_clz(x);}
constexpr int f_lg(ll x){return 63 - __builtin_clzll(x);}
// </ (functions) >
// </ (template)>

#ifdef zxcv_1
auto start = std::chrono::system_clock::now();
#endif

// < (modify if needed) >
const ld PI = acos((ld)-1);
const ll inf = 2e18;
const ll ninf = -2e18;

const int M = 1e9 + 7;
// const int M =  998244353;

#define ret_g() cout << "Good" << "\n"; return;
#define ret_b() cout << "Bad" << "\n"; return;

// no need to set multiple_test_cases if code_jam flag is set
bool code_jam = 0;

bool multiple_test_cases =  0;

// </ (modify if needed) >

// (write main logic here)

const int N = 2e5 + 10;

const int invN = 1500;

ll ainv[invN];

ll fact[N];

int add(int x, int y)
{

    // assuming x and y values are valid [0 , M-1]
    /*

        x %= M ;
        y %= M ;
        if (x < 0) {
            x += M;
        }
        if (y < 0) {
            y += M;
        }

    */
    x += y;
    if (x >= M)
        return x - M;
    return x;
}

int sub(int x, int y)
{

    // assuming x and y values are valid [0 , M-1]
    /*

        x %= M ;
        y %= M ;
        if (x < 0) {
            x += M;
        }
        if (y < 0) {
            y += M;
        }

    */
    x -= y;
    if (x < 0)
        return x + M;
    return x;
}

int mul(int x, int y)
{
    // assuming x and y values are valid [0 , M-1]
    /*

        x %= M ;
        y %= M ;
        if (x < 0) {
            x += M;
        }
        if (y < 0) {
            y += M;
        }

    */
    return ((ll)x * y) % M;
}

void preprocess(){

    ainv[1] = 1 ;

    for(int i = 2 ; i < invN; ++i){
        ainv[i] = M - M/i * ainv[M % i] %M;
    }

    fact[0] = 1 ;

    for(int i = 1 ; i< N;++i){
        fact[i] = mul(fact[i-1],i);
    }

}

void euclid (ll a, ll b , ll &x , ll &y){

    if(a == 1){

        x = 1 ;
        y = 0 ;
        return ;
    }

    ll x1 , y1 ;
    euclid(b % a , a , x1 , y1);

    x = y1 - (b/a) * x1;

    y = x1;

}

ll einv (ll b){

    int a= b % M;

    if (__gcd(a, M) != 1){
        return -1;
    }

    ll x, y ;

    euclid(a ,M , x,  y);

    x = (x % M + M) % M ;
    return x ;
}

ll bpow(ll a, ll b)
{

    ll res = 1;

    while (b > 0) {

        if (b & 1) {
            res = mul(res, a);
        }

        a = mul(a, a);
        b >>= 1;
    }

    return res;
}

ll binv(ll x){
    return bpow(x , M - 2);
}

ll divide (ll x, ll y){
    x %= M ;
    y %= M ;

    // choose any inverse method   here
    return mul(x,  einv(y));
}

int C(int n , int k){

    if (n  < k || n < 0 || k < 0){
        return 0;
    }

    return divide(fact[n] , mul(fact[k] , fact[n-k]));
}

void solve(){

    string s;
    cin >> s;

    int n =  sz(s);

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

    for(int i = 0; i <  n ; ++i){
        if (s[i] == '('){
            op[i] = 1 ;
        }
        else{
            cl[i] = 1 ;
        }
    }

    vector<int> op_pre(n), cl_suf(n);

    assign_pre(op_pre, op) ;  assign_suf(cl_suf, cl);

    int ans =0 ;

    for(int i = 0 ; i < n ; ++i){

        if (s[i] == ')'){
            continue;

        }

        int x =  gpv(i - 1 , op_pre);
        int y =  gsv (i + 1 , cl_suf);

        ans = add(ans, C(x+ y  , y  - 1));

    }

    cout << ans <<"\n";

}

// main function
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    preprocess();

    int T = 1 ;

    if (code_jam){
        multiple_test_cases =  true;
    }

    if(multiple_test_cases){
        cin >> T;
    }

    for (int t = 1; t <= T; ++t) {
        if(t == 1){
            #ifdef zxcv_1
                start = std::chrono::system_clock::now();
            #endif
        }
        if(code_jam)
            cout << "Case #" << t << ": ";
        solve();
    }

    #ifdef zxcv_1
        auto end = std::chrono::system_clock::now();
        std::chrono::duration<double> elapsed_seconds = end - start;
        std::cerr << "Elapsed time: " << elapsed_seconds.count() << "s\n";
    #endif

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

// somethings maybe wrong in template, did not veryify everything pay attention.
// update template regularly
// < (template) >
// < (defines) >
#define ar array
#define ll long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define lbi(A,x)   (lower_bound(A.begin(),A.end(), x) - A.begin())
#define ubi(A,x)   (upper_bound(A.begin(), A.end(), x) - A.begin())
#define lbir(A,i,j,x)  (lower_bound(A.begin() + i , A.begin() + j , x) - A.begin())
#define ubir(A,i,j,x)  (upper_bound(A.begin() + i, A.begin() + j, x) - A.begin())
#define f_prec(prec)  cout << fixed << setprecision(prec) ;
#define vv(A, T, n1, n2, val) vector<vector<T>> A(n1, vector<T>(n2, val))
#define vvv(A, T, n1, n2, n3, val) vector<vector<vector<T>>> A(n1, vector<vector<T>>(n2, vector<T>(n3, val)))
#define vvvv(A, T, n1, n2, n3, n4, val) vector<vector<vector<vector<T>>>> A(n1, vector<vector<vector<T>>>(n2, vector<vector<T>>(n3, vector<T>(n4, val))))
// </ (defines)>
// <(debugging template) >
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename T>
string to_string(stack <T> st);
template <typename T>
string to_string(queue<T> q);
string to_string(char c){return string(1, c);}
string to_string(const string s){return '"' + s + '"';}
string to_string(const char* s){return to_string((string)s);}
string to_string(bool b){return (b ? "true" : "false");}
string to_string(vector<bool> v){bool first = true;string res = "{";for (int i = 0; i < static_cast<int>(v.size()); i++) {if (!first) {res += ", ";}first = false;res += to_string(v[i]);}res += "}";return res;}
// prints bitset just like a vector (not number)
template <size_t S>
string to_string(bitset<S> b){string res;res += '{';bool f = true;for (int i = 0; i < S; ++i) {if (!f) {res += ',';}f = false;res += char('0' + b[i]);}res += '}';return res;}
template <typename A>
string to_string(A v){bool first = true;string res = "{";for (const auto& x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename T >
string to_string(stack <T> st){bool first = true;string res = "{";while (!st.empty()) {if (!first) {res += ", ";}first = false;res += to_string(st.top());st.pop();}res += "}";return res;}
template <typename T>
string to_string(queue<T> q){bool first = true;string res = "{";while (!q.empty()) {if (!first) {res += ", ";}first = false;res += to_string(q.front());q.pop();}res += "}";return res;}
template <typename T>
string to_string(T pq, bool ispq){assert(ispq); bool first = true;string res = "{";while (!pq.empty()) {if (!first) {res += ", ";}first = false;res += to_string(pq.top());pq.pop();}res += "}";return res;}
// tuple deleted from template
void DBG(){cerr << " ]" << "\n";}
template <typename Head, typename... Tail>
void DBG(Head H, Tail... T){cerr << " " << to_string(H);if (sizeof...(T)) {cerr << ", ";}DBG(T...);}

#ifdef zxcv_1
#define dbg(...) cerr << "L(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 42
#endif
// <(/debugging template)>
// < (datastrucures) >
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename key, typename value, typename cmp = std::less<key>>
using omap = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// </ (datastructures) >
// < (loops) >
#define fr(i,a,b,d) for (int i = a; i < b; i += d)
#define rfr(i,b,a,d) for(int i= b; i>= a; i -= d)
#define frc(i,a,b,c,d) for(int i = a; (i< b) && c ; i += d)
#define rfrc(i,a,b,c,d) for(int i = b; (i>= a) && c ; i -= d)
// </ (loops) >
// < (reading) >
void read(char &x) {cin >> x;}
void read(int& x){cin >> x;}
void read(ll& x){cin >> x;}
void read(double& x){cin >> x;}
void read(string& s){cin >> s;}
// works only for simple pairs  <int,int>, <string,int> .....
template <typename T1, typename T2>
void read(pair<T1, T2>& p){cin >> p.first >> p.second;}
template <typename T>
void read(T& A){for (auto& x : A) {read(x);}}
template <typename T>
void assign_offset(T& A, int off = -1){for (auto& x : A) {x += off;}}
template <class H, class... T>
void read(H& h, T&... t){read(h);read(t...);}
// </ (reading) >
// < (writing) >
// where T must be simple
template <typename T>
void out (T &A, int offset = 0 ){for(auto &x : A){x += offset; cout <<  x <<" ";}cout <<"\n"; }
// </ (writing) >
// < (functions) >
#define fsttrue(lo_val,hi_val,valid,ansi) {ll lo = lo_val , hi = hi_val,  mid;while (lo <= hi) {mid = lo + (hi - lo) / 2;if (valid(mid)) {ansi = mid;hi = mid - 1;} else {lo = mid + 1;}}}
#define lsttrue(lo_val,hi_val,valid,ansi) {ll lo = lo_val , hi = hi_val,  mid;while (lo <= hi) {mid = lo + (hi - lo) / 2;if (valid(mid)) {ansi = mid;lo = mid + 1;} else {hi = mid - 1;}}}
#define ternint_hi(lo_val,hi_val,gv,ansi,ansv) {ll lo = lo_val, hi = hi_val, m1, m2;const int diffrange = 7;while (hi - lo > diffrange) {m1 = lo + (hi - lo) / 3;m2 = hi - (hi - lo) / 3;if (gv(m1) < gv(m2)) {    lo = m1;} else {    hi = m2;}}ansi = lo;ansv = gv(lo);for (int i = lo + 1; i <= hi; ++i) {if (a_max(ansv, gv(i))) {    ansi = i;}}}
#define ternint_lo(lo_val,hi_val,gv,ansi,ansv) {ll lo = lo_val, hi = hi_val, m1, m2;const int diffrange = 7;while (hi - lo > diffrange) {m1 = lo + (hi - lo) / 3;m2 = hi - (hi - lo) / 3;if (gv(m1) > gv(m2)) {    lo = m1;} else {    hi = m2;}}ansi = lo;ansv = gv(lo);for (int i = lo + 1; i <= hi; ++i) {if (a_min(ansv, gv(i))) {    ansi = i;}}}
#define terndouble_hi(lo_val,hi_val,gv,ansi,ansv) {double lo = lo_val, hi = hi_val, m1, m2;const double eps = 1e-9; while (hi - lo > eps) {m1 = lo + (hi - lo) / 3;m2 = hi - (hi - lo) / 3;if (gv(m1) < gv(m2)) {lo = m1;} else {hi = m2;}}double ansi = lo;double ansv = gv(lo);}
#define terndouble_lo(lo_val,hi_val,gv,ansi,ansv) {double lo = lo_val, hi = hi_val, m1, m2;const double eps = 1e-9; while (hi - lo > eps) {m1 = lo + (hi - lo) / 3;m2 = hi - (hi - lo) / 3;if (gv(m1) > gv(m2)) {lo = m1;} else {hi = m2;}}double ansi = lo;double ansv = gv(lo);}
// random in [l,r]
mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());ll rand_m(ll a, ll b){return uniform_int_distribution<ll>(a, b)(mt_rng);}
// assign min of (a,b) , if (a > b) return true and assigns a = b
template <typename T>
bool a_min(T& a, const T& b){return (b < a) ? (a = b), 1 : 0;}
// assign max of (a,b) ,if (a < b) return true and assigns a = b
template <typename T>
bool a_max(T& a, const T& b){return (b > a) ? (a = b), 1 : 0;}
// both m and n must be positive
ll ceil(ll m, ll n){return (m + n - 1) / n;}
// 0 based index
// getval , [i, j] sum using prefix
template<typename T>
ll gv(int i, int j, vector<T>& pre){if (i > j || (j < 0)) {return 0LL;}ll val = pre[j];if (i - 1 >= 0) {val -= pre[i - 1];}return val;}
// getprefixval , [0...i] sum
template <typename T>
ll gpv(int i, vector<T>& pre){return gv(0, i, pre);}
// getsuffixval, [i....n - 1] sum
template <typename T>
ll gsv(int i, vector<T>& suf){int n = sz(suf);if (i >= n) {return 0LL;}return suf[i];}
// assigns values to   prefix array with indices 0 to n-1
template<typename T>
void assign_pre(vector<T>& pre, vector<T>& A){int n = sz(A);for (int i = 0; i < n; ++i) {pre[i] = A[i];if (i) {pre[i] += pre[i - 1];}}}
// assigns values  suffix array with indices 0 to n-1
template<typename T>
void assign_suf(vector<T>& suf, vector<T>& A){int n = sz(A);for (int i = n - 1; i >= 0; --i) {suf[i] = A[i];if (i + 1 < n) {suf[i] += suf[i + 1];}}}
// finds no of values between [l,r]
template <typename T>
int sorted_range (const vector<T>& A , int l , int r){int n = A.size(); if (r < l){return 0 ;}return ubi(A,r) - ubi(A,l-1); }
// sorts and removes duplicates from vector
template <typename T>
void remove_dup(vector<T>& v){sort(all(v));v.erase(unique(all(v)), v.end());}
// returns no of 1's in binary representation
constexpr int ppcnt(int x){return __builtin_popcount(x);}
constexpr int ppcnt(ll x){return __builtin_popcountll(x);}
// returns floor(log2(x))
constexpr int f_lg(int x){return 31 - __builtin_clz(x);}
constexpr int f_lg(ll x){return 63 - __builtin_clzll(x);}
// </ (functions) >
// </ (template)>

#ifdef zxcv_1
auto start = std::chrono::system_clock::now();
#endif

// < (modify if needed) >
const ld PI = acos((ld)-1);
const ll inf = 2e18;
const ll ninf = -2e18;

const int M = 1e9 + 7;
// const int M =  998244353;

#define ret_g() cout << "Good" << "\n"; return;
#define ret_b() cout << "Bad" << "\n"; return;

// no need to set multiple_test_cases if code_jam flag is set
bool code_jam = 0;

bool multiple_test_cases =  0;

// </ (modify if needed) >

// (write main logic here)

const int N = 2e5 + 10;

const int invN = 1500;

ll ainv[invN];

ll fact[N];

int add(int x, int y)
{

    // assuming x and y values are valid [0 , M-1]
    /*

        x %= M ;
        y %= M ;
        if (x < 0) {
            x += M;
        }
        if (y < 0) {
            y += M;
        }

    */
    x += y;
    if (x >= M)
        return x - M;
    return x;
}

int sub(int x, int y)
{

    // assuming x and y values are valid [0 , M-1]
    /*

        x %= M ;
        y %= M ;
        if (x < 0) {
            x += M;
        }
        if (y < 0) {
            y += M;
        }

    */
    x -= y;
    if (x < 0)
        return x + M;
    return x;
}

int mul(int x, int y)
{
    // assuming x and y values are valid [0 , M-1]
    /*

        x %= M ;
        y %= M ;
        if (x < 0) {
            x += M;
        }
        if (y < 0) {
            y += M;
        }

    */
    return ((ll)x * y) % M;
}

void preprocess(){

    ainv[1] = 1 ;

    for(int i = 2 ; i < invN; ++i){
        ainv[i] = M - M/i * ainv[M % i] %M;
    }

    fact[0] = 1 ;

    for(int i = 1 ; i< N;++i){
        fact[i] = mul(fact[i-1],i);
    }

}

void euclid (ll a, ll b , ll &x , ll &y){

    if(a == 1){

        x = 1 ;
        y = 0 ;
        return ;
    }

    ll x1 , y1 ;
    euclid(b % a , a , x1 , y1);

    x = y1 - (b/a) * x1;

    y = x1;

}

ll einv (ll b){

    int a= b % M;

    if (__gcd(a, M) != 1){
        return -1;
    }

    ll x, y ;

    euclid(a ,M , x,  y);

    x = (x % M + M) % M ;
    return x ;
}

ll bpow(ll a, ll b)
{

    ll res = 1;

    while (b > 0) {

        if (b & 1) {
            res = mul(res, a);
        }

        a = mul(a, a);
        b >>= 1;
    }

    return res;
}

ll binv(ll x){
    return bpow(x , M - 2);
}

ll divide (ll x, ll y){
    x %= M ;
    y %= M ;

    // choose any inverse method   here
    return mul(x,  einv(y));
}

int C(int n , int k){

    return divide(fact[n] , mul(fact[k] , fact[n-k]));
}

void solve(){

    string s;
    cin >> s;

    int n =  sz(s);

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

    for(int i = 0; i <  n ; ++i){
        if (s[i] == '('){
            op[i] = 1 ;
        }
        else{
            cl[i] = 1 ;
        }
    }

    vector<int> op_pre(n), cl_suf(n);

    assign_pre(op_pre, op) ;  assign_suf(cl_suf, cl);

    int ans =0 ;

    for(int i = 0 ; i < n ; ++i){

        if (s[i] == ')'){
            continue;

        }

        int x =  gpv(i - 1 , op_pre);
        int y =  gsv (i + 1 , cl_suf);

        ans = add(ans, C(x+ y , y - 1));

    }

    cout << ans <<"\n";

}

// main function
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    preprocess();

    int T = 1 ;

    if (code_jam){
        multiple_test_cases =  true;
    }

    if(multiple_test_cases){
        cin >> T;
    }

    for (int t = 1; t <= T; ++t) {
        if(t == 1){
            #ifdef zxcv_1
                start = std::chrono::system_clock::now();
            #endif
        }
        if(code_jam)
            cout << "Case #" << t << ": ";
        solve();
    }

    #ifdef zxcv_1
        auto end = std::chrono::system_clock::now();
        std::chrono::duration<double> elapsed_seconds = end - start;
        std::cerr << "Elapsed time: " << elapsed_seconds.count() << "s\n";
    #endif

    return 0;
}


//Love the little things
#include<bits/stdc++.h>
using namespace std;

const long long maxn = 2e5 + 420, P = 998244353, delta = 1e9 + 7;

long long fact[maxn], fact_inv[maxn];
long long pw(long long a, int b){
    if(!b)
        return 1;
    long long tmp = pw(a, b / 2);
    tmp = (tmp * tmp) % delta;
    if(b & 1){
        tmp *= a;
        tmp %= delta;
    }
    return tmp;
}
long long inv(long long A){
    return pw(A, delta - 2);
}

void calc_facts(){
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    for(int i = 2; i < maxn; i++){
        fact[i] = (fact[i - 1] * i) % delta;
        fact_inv[i] = inv(fact[i]);
    }
}

long long ch(long long a, long long b){
    return ( (fact[b] * ((fact_inv[a] * fact_inv[b - a]) % delta )) % delta);
}

void opt(){
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
}
int main(){
    opt();
    calc_facts();
    int n, a, b;
    a = b = 0;
    string s;

    cin >> s;
    n = s.size();
    for(auto c : s)
        b += (c == ')');

    long long ans = 0;
    for(int i = 0; i < n; i++){
        a += (s[i] == '(');
        b -= (s[i] == ')');
        if(s[i] == '(')
            ans += ch(a, a + b - 1);//, cout << ans << endl;
    }
    cout << ans << endl;
}


#include <cstdio>
#include <iostream>
using namespace std;
const int sz = 302;
int d[sz][sz], n, summa = 0;
int floid () {
	for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
		  for (int j = 1; j <= n; j++)
			  if (d[i][k] + d[k][j] < d[i][j])
				  d[i][j] = d[i][k] + d[k][j];
  int s = 0;
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			s += d[i][j];
	return s;
}
int main() {
	int summing[sz] = {0};
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			scanf("%d", &d[i][j]);
			summa += d[i][j];
		}
	summa /= 2;
	int r;
	scanf("%d", &r);
	for (int i = 1; i <= r; i++) {
		int a, b, c, e = summa;
		scanf("%d%d%d", &a, &b, &c);
		if (c < d[a][b]) {
			d[a][b] = c;
			d[b][a] = c;
			e = floid();
			summa = e;
		}
		summing[i] = e;
	}
	for (int i = 1; i <= r; i++)
		printf("%d ", summing[i]);
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
const int sz = 302;
int d[sz][sz], n, summa = 0;
int floid (int k) {
	bool yes = false;
  for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (d[i][k] + d[k][j] < d[i][j]) {
				d[i][j] = d[i][k] + d[k][j];
				yes = true;
			}
  int s = 0;
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			s += d[i][j];
	return s;
}
int main() {
	int summing[sz] = {0};
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			scanf("%d", &d[i][j]);
			summa += d[i][j];
		}

	int r;
	scanf("%d", &r);
	for (int i = 1; i <= r; i++) {
		int a, b, c, e = summa;
		scanf("%d%d%d", &a, &b, &c);
		if (c < d[a][b]) {
			d[a][b] = c;
			d[b][a] = c;
			e = min(floid(b), floid(a));
		}
		summing[i] = e;
	}
	for (int i = 1; i <= r; i++)
		printf("%d ", summing[i]);
	return 0;
}


// sliao
#include <assert.h>
#include <queue>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>

using namespace std;

int d[301][301];

int main() {

  int n; cin >> n;
  int s = 0;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++) {
      cin >> d[i][j];
      s += d[i][j];
    }

  int m; cin >> m;
  while(m--) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;

    for(int i = 0; i < n; i++) {
      int nd;
      nd = d[i][b] + c;
      if(nd < d[i][a]) {
        s -= d[i][a] - nd;
        d[i][a] = nd;
      }
      nd = c + d[b][i];
      if(nd < d[a][i]) {
        s -= d[a][i] - nd;
        d[a][i] = nd;
      }
      nd = d[i][a] + c;
      if(nd < d[i][b]) {
        s -= d[i][b] - nd;
        d[i][b] = nd;
      }
      nd = c + d[a][i];
      if(nd < d[b][i]) {
        s -= d[b][i] - nd;
        d[b][i] = nd;
      }
    }

    cout << s / 2 << ' ';

  }
  cout << endl;
}


// sliao
#include <queue>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>

using namespace std;

int d[300][300];

int main() {

  int n; cin >> n;
  int s = 0;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++) {
      cin >> d[i][j];
      s += d[i][j];
    }

  int m; cin >> m;
  while(m--) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;

    for(int i = 0; i < n; i++) {
      int nd;
      nd = d[i][b] + c;
      if(nd < d[i][a]) {
        s -= 2 * (d[i][a] - nd);
        d[i][a] = nd;
        d[a][i] = nd;
      }
      nd = d[i][a] + c;
      if(nd < d[i][b]) {
        s -= 2 * (d[i][b] - nd);
        d[i][b] = nd;
        d[b][i] = nd;
      }
    }

    cout << s / 2 << ' ';

  }
  cout << endl;
}


// sliao
#include <assert.h>
#include <queue>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
ll d[301][301];

int main() {

  int n; cin >> n;
  ll s = 0;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++) {
      cin >> d[i][j];
      s += d[i][j];
    }

  int m; cin >> m;
  while(m--) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;

    for(int i = 0; i < n; i++) {
      ll nd;
      nd = d[i][b] + c;
      if(nd < d[i][a]) {
        s -= d[i][a] - nd;
        d[i][a] = nd;
      }
      nd = c + d[b][i];
      if(nd < d[a][i]) {
        s -= d[a][i] - nd;
        d[a][i] = nd;
      }
      nd = d[i][a] + c;
      if(nd < d[i][b]) {
        s -= d[i][b] - nd;
        d[i][b] = nd;
      }
      nd = c + d[a][i];
      if(nd < d[b][i]) {
        s -= d[b][i] - nd;
        d[b][i] = nd;
      }
    }

    cout << s / 2 << ' ';

  }
  cout << endl;
}


// sliao
#include <assert.h>
#include <queue>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
ll d[301][301];

int main() {

  int n; cin >> n;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++)
      cin >> d[i][j];

  int m; cin >> m;
  while(m--) {

    int a, b, c; cin >> a >> b >> c;
    a--; b--;

    int s = 0;

    for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][a] + c + d[b][j]);
        d[i][j] = min(d[i][j], d[i][b] + c + d[a][j]);
        s += d[i][j];
      }

    cout << s / 2 << ' ';

  }
  cout << endl;
}


// sliao
#include <queue>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
ll d[300][300];

int main() {

  int n; cin >> n;
  ll s = 0;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++) {
      cin >> d[i][j];
      s += d[i][j];
    }

  int m; cin >> m;
  while(m--) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;

    for(int i = 0; i < n; i++) {
      ll nd;
      nd = d[i][b] + c;
      if(nd < d[i][a]) {
        s -= d[i][a] - nd;
        d[i][a] = nd;
      }
      if(nd < d[a][i]) {
        s -= d[a][i] - nd;
        d[a][i] = nd;
      }
      nd = d[i][a] + c;
      if(nd < d[i][b]) {
        s -= d[i][b] - nd;
        d[i][b] = nd;
      }
      if(nd < d[b][i]) {
        s -= d[b][i] - nd;
        d[b][i] = nd;
      }
    }

    cout << s / 2 << ' ';

  }
  cout << endl;
}


// sliao
#include <queue>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
ll d[300][300];

int main() {

  int n; cin >> n;
  ll s = 0;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++) {
      cin >> d[i][j];
      s += d[i][j];
    }

  int m; cin >> m;
  while(m--) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;

    for(int i = 0; i < n; i++) {
      ll nd;
      nd = d[i][b] + c;
      if(nd < d[i][a]) {
        s -= d[i][a] - nd;
        d[i][a] = nd;
      }
      nd = c + d[b][i];
      if(nd < d[a][i]) {
        s -= d[a][i] - nd;
        d[a][i] = nd;
      }
      nd = d[i][a] + c;
      if(nd < d[i][b]) {
        s -= d[i][b] - nd;
        d[i][b] = nd;
      }
      nd = c + d[a][i];
      if(nd < d[b][i]) {
        s -= d[b][i] - nd;
        d[b][i] = nd;
      }
    }

    //    cout << s / 2 << ' ';
    int sum = 0;
    for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++)
        sum += d[i][j];
    cout << sum / 2 << ' ';

  }
  cout << endl;
}


// sliao
#include <assert.h>
#include <queue>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
ll d[301][301];

int main() {

  int n; cin >> n;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++)
      cin >> d[i][j];

  int m; cin >> m;
  while(m--) {

    int a, b, c; cin >> a >> b >> c;
    a--; b--;

    ll s = 0;

    for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][a] + c + d[b][j]);
        d[i][j] = min(d[i][j], d[i][b] + c + d[a][j]);
        s += d[i][j];
      }

    cout << s / 2 << ' ';

  }
  cout << endl;
}


// sliao
#include <queue>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>

using namespace std;

int d[300][300];

int main() {

  int n; cin >> n;
  int s = 0;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++) {
      cin >> d[i][j];
      s += d[i][j];
    }

  int m; cin >> m;
  while(m--) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;

    for(int i = 0; i < n; i++) {
      int nd;
      nd = d[i][b] + c;
      if(nd < d[i][a]) {
        s -= d[i][a] - nd;
        d[i][a] = nd;
      }
      if(nd < d[a][i]) {
        s -= d[a][i] - nd;
        d[a][i] = nd;
      }
      nd = d[i][a] + c;
      if(nd < d[i][b]) {
        s -= d[i][b] - nd;
        d[i][b] = nd;
      }
      if(nd < d[b][i]) {
        s -= d[b][i] - nd;
        d[b][i] = nd;
      }
    }

    cout << s / 2 << ' ';

  }
  cout << endl;
}


// sliao
#include <queue>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
ll d[300][300];

int main() {

  int n; cin >> n;
  ll s = 0;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++) {
      cin >> d[i][j];
      s += d[i][j];
    }

  int m; cin >> m;
  while(m--) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;

    for(int i = 0; i < n; i++) {
      ll nd;
      nd = d[i][b] + c;
      if(nd < d[i][a]) {
        s -= d[i][a] - nd;
        d[i][a] = nd;
      }
      nd = c + d[b][i];
      if(nd < d[a][i]) {
        s -= d[a][i] - nd;
        d[a][i] = nd;
      }
      nd = d[i][a] + c;
      if(nd < d[i][b]) {
        s -= d[i][b] - nd;
        d[i][b] = nd;
      }
      nd = c + d[a][i];
      if(nd < d[b][i]) {
        s -= d[b][i] - nd;
        d[b][i] = nd;
      }
    }

    cout << s / 2 << ' ';

  }
  cout << endl;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
int d[300][300];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; }
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[b][a]; }
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];}
        }

    }

int sum(){
    int vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs+=d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%d",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        update(a-1,b-1,c);
        if (i!=0) printf(" ");
        printf("%d",sum());
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
long long d[1000][1000];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b];}
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[a][b]; d[a][i]=d[i][b]+d[a][b];}
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];d[j][i]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];d[j][i]=d[i][b]+d[b][j];}
        }

    }

long long sum(){
    long long vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs=vs+(long long)d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%lld",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        if (c<d[a-1][b-1]) update(a-1,b-1,c);
        if (i!=0) printf(" ");
        long long vs=0;
    for (int ii=0;ii<n;ii++)
    for (int j=0;j<n;j++) vs=vs+d[ii][j];
        printf("%lld",vs/2);
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
long long d[1000][1000];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b];}
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[a][b]; d[a][i]=d[i][b]+d[a][b];}
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];d[j][i]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];d[j][i]=d[i][b]+d[b][j];}
        }

    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%lld",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        if (c<d[a-1][b-1]) update(a-1,b-1,c);
        if (i!=0) printf(" ");
        long long vs=0;
    for (int ii=0;ii<n;ii++)
    for (int j=ii;j<n;j++) vs=vs+d[ii][j];
        printf("%lld",vs);
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
long long d[1000][1000];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b];}
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[a][b]; d[a][i]=d[i][b]+d[a][b];}
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];d[j][i]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];d[j][i]=d[i][b]+d[b][j];}
        }

    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%lld",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        if (c<d[a-1][b-1]) update(a-1,b-1,c);
        if (i!=0) printf(" ");
        long long vs=0;
    for (int ii=0;ii<n;ii++)
    for (int j=ii;j<n;j++) vs=vs+d[ii][j];
        cout<<vs;
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
int d[300][300];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b];}
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[b][a]; d[a][i]=d[i][b]+d[b][a];}
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];d[j][i]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];d[j][i]=d[i][b]+d[b][j];}
        }

    }

int sum(){
    int vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs+=d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%d",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        update(a-1,b-1,c);
        if (i!=0) printf(" ");
        printf("%d",sum());
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
long long d[1000][1000];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b];}
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[a][b]; d[a][i]=d[i][b]+d[a][b];}
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];d[j][i]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];d[j][i]=d[i][b]+d[b][j];}
        }

    }

long long sum(){
    long long vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs=vs+(long long)d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%lld",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        if (c<d[a-1][b-1]) update(a-1,b-1,c);
        if (i!=0) printf(" ");
        long long vs=0;
    for (int ii=0;ii<n;ii++)
    for (int j=0;j<n;j++) vs=vs+(long long)d[ii][j];
        printf("%lld",vs);
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
int d[300][300];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b];}
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[a][b]; d[a][i]=d[i][b]+d[a][b];}
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];d[j][i]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];d[j][i]=d[i][b]+d[b][j];}
        }

    }

long long sum(){
    long long vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs=vs+d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%d",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        update(a-1,b-1,c);
        if (i!=0) printf(" ");
        printf("%d",sum());
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
int d[300][300];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b];}
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[a][b]; d[a][i]=d[i][b]+d[a][b];}
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];d[j][i]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];d[j][i]=d[i][b]+d[b][j];}
        }

    }

long long sum(){
    long long vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs=vs+(long long)d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%d",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        if (c<d[a-1][b-1]) update(a-1,b-1,c);
        if (i!=0) printf(" ");
        printf("%lld",sum());
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
long long d[1000][1000];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b];}
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[a][b]; d[a][i]=d[i][b]+d[a][b];}
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];d[j][i]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];d[j][i]=d[i][b]+d[b][j];}
        }

    }

long long sum(){
    long long vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs=vs+(long long)d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%lld",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        if (c<d[a-1][b-1]) update(a-1,b-1,c);
        if (i!=0) printf(" ");
        long long vs=0;
    for (int ii=0;ii<n;ii++)
    for (int j=0;j<n;j++) vs=vs+(long long)d[ii][j];
        printf("%lld",vs/2);
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
long long d[1000][1000];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b];}
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[a][b]; d[a][i]=d[i][b]+d[a][b];}
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];d[j][i]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];d[j][i]=d[i][b]+d[b][j];}
        }

    }

long long sum(){
    long long vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs=vs+(long long)d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%d",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        if (c<d[a-1][b-1]) update(a-1,b-1,c);
        if (i!=0) printf(" ");
        printf("%lld",sum());
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
int d[300][300];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b];}
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[a][b]; d[a][i]=d[i][b]+d[a][b];}
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];d[j][i]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];d[j][i]=d[i][b]+d[b][j];}
        }

    }

long long sum(){
    long long vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs=vs+(long long)d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%d",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        update(a-1,b-1,c);
        if (i!=0) printf(" ");
        printf("%lld",sum());
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
int d[300][300];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b];}
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[a][b]; d[a][i]=d[i][b]+d[a][b];}
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];}
        }

    }

int sum(){
    int vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs+=d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%d",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        update(a-1,b-1,c);
        if (i!=0) printf(" ");
        printf("%d",sum());
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
int d[1000][1000];
int res;

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b]; }
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[b][a]; d[a][i]=d[i][b]+d[a][b]; }
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][b]+d[b][j]) {d[i][j]=d[i][a]+d[a][b]+d[b][j];}
        if (d[i][j]>d[i][b]+d[a][b]+d[a][j]) {d[i][j]=d[i][b]+d[a][b]+d[a][j];}
        }

    }

int sum(){
    int vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs+=d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%d",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        update(a-1,b-1,c);
        if (i!=0) printf(" ");
        printf("%d",sum());
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
int d[1000][1000];
int res;

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b]; }
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[b][a]; d[a][i]=d[i][b]+d[a][b]; }
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[j][a]) {d[i][j]=d[i][a]+d[j][a];}
        if (d[i][j]>d[i][b]+d[j][b]) {d[i][j]=d[i][b]+d[j][b];}
        }

    }

int sum(){
    int vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs+=d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%d",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        update(a-1,b-1,c);
        if (i!=0) printf(" ");
        printf("%d",sum());
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
long long d[1000][1000];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b];}
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[a][b]; d[a][i]=d[i][b]+d[a][b];}
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];d[j][i]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];d[j][i]=d[i][b]+d[b][j];}
        }

    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%lld",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        if (c<d[a-1][b-1]) update(a-1,b-1,c);
        if (i!=0) printf(" ");
        long long vs=0;
    for (int ii=0;ii<n;ii++)
    for (int j=ii;j<n;j++) vs=vs+d[ii][j];
        printf("%l64d",vs);
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
int d[1000][1000];

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; }
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[b][a]; }
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][j]) {d[i][j]=d[i][a]+d[a][j];}
        if (d[i][j]>d[i][b]+d[b][j]) {d[i][j]=d[i][b]+d[b][j];}
        }

    }

int sum(){
    int vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs+=d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%d",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        update(a-1,b-1,c);
        if (i!=0) printf(" ");
        printf("%d",sum());
        }
    printf("\n");
    return 0;
    }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
int n,k;
int d[1000][1000];
int res;

void update(int a,int b,int c){
     if (c>=d[a][b]) return;
    d[a][b]=c;
    d[b][a]=c;
    for (int i=0;i<n;i++){
        if (d[i][a]+d[a][b]<d[i][b]) {d[i][b]=d[i][a]+d[a][b]; d[b][i]=d[i][a]+d[a][b]; }
        if (d[i][b]+d[b][a]<d[i][a]) {d[i][a]=d[i][b]+d[b][a]; d[a][i]=d[i][b]+d[a][b]; }
        }
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    {
        if (d[i][j]>d[i][a]+d[a][b]+d[b][j]) {d[i][j]=d[i][a]+d[a][b]+d[b][j];}
        if (d[i][j]>d[i][b]+d[a][b]+d[a][j]) {d[i][j]=d[i][b]+d[a][b]+d[a][j];}
        }

    }

long long sum(){
    long long vs=0;
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) vs=vs+d[i][j];
    return vs/2;
    }

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++) scanf("%d",&d[i][j]);
    scanf("%d",&k);
    for (int i=0;i<k;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        update(a-1,b-1,c);
        if (i!=0) printf(" ");
        printf("%lld",sum());
        }
    printf("\n");
    return 0;
    }


#include<iostream>
using namespace std;
int main(){
	int dp[301][301];
	int n;
	cin>>n;
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			cin>>dp[i][j];
	int m,a,b,c;
	cin>>m;
	for(int i=0;i<m;++i){
		cin>>a>>b>>c;
		long long s=0;
		--a;
		--b;
		dp[a][b]=dp[b][a]=min(c,dp[a][b]);
			for(int i=0;i<n;++i)
				for(int j=0;j<n;++j){
					if(a==i )
						dp[j][i]=dp[i][j]=min(dp[i][j],dp[i][b]+dp[b][j]);
					if(b==j )
						dp[j][i]=dp[i][j]=min(dp[i][j],dp[i][a]+dp[a][j]);
				}
		for(int i=0;i<n;++i)
			for(int j=i+1;j<n;++j)
				s+=dp[i][j];
		cout<<s<<" ";
	}

}


#include<iostream>
using namespace std;
int main(){
    int dp[301][301];
    int f[301][301];
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
        for(int j=0;j<n;++j)
            cin>>dp[i][j];
            for(int k=0;k<n;++k)
        for(int i=0;i<n;++i)
            for(int j=0;j<n;++j)
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
    int m,a,b,c;
    cin>>m;
    for(int i=0;i<m;++i){
        cin>>a>>b>>c;
        long long s=0;
        --a;
        --b;
        dp[a][b]=dp[b][a]=min(c,dp[a][b]);
            for(int i=0;i<n;++i)
                for(int j=0;j<n;++j){
                    if(a!=i && a!=j)
                    dp[i][j]=min(dp[i][j],dp[i][a]+dp[a][j]);
                    if(b!=i && b!=j)
                    dp[i][j]=min(dp[i][j],dp[i][b]+dp[b][j]);
                }
        for(int i=0;i<n;++i)
            for(int j=i+1;j<n;++j)
                s+=dp[i][j];
        cout<<s<<" ";
    }

}


#include<iostream>
using namespace std;
int main(){
    int dp[301][301];
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
        for(int j=0;j<n;++j)
            cin>>dp[i][j];
    int m,a,b,c;
    cin>>m;
    for(int i=0;i<m;++i){
        cin>>a>>b>>c;
        long long s=0;
        --a;
        --b;
        dp[a][b]=dp[b][a]=min(c,dp[a][b]);
            for(int i=0;i<n;++i)
                for(int j=0;j<n;++j){
                    //if(a!=i && a!=j)
                    dp[i][j]=min(dp[i][j],dp[i][a]+dp[a][j]);
                    //if(b!=i && b!=j)
                    dp[i][j]=min(dp[i][j],dp[i][b]+dp[b][j]);
                }
        for(int i=0;i<n;++i)
            for(int j=i+1;j<n;++j)
                s+=dp[i][j];
        cout<<s<<" ";
    }

}