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


#include <iostream>
#define int long long
#define mod 1000000007
using namespace std;
int inv[500005],jcinv[500005],jc[500005];
inline int C(int x,int y)
{
	if(x<y||y<0) return 0;
	return jc[x]*jcinv[y]%mod*jcinv[x-y]%mod;
}
inline int cal(int x,int y)
{
	return C(x+y-1,x);
	int rtn=0;
	for(int i=1;i<=min(x,y);i++)
		rtn+=C(x-1,i-1)*C(y,i)%mod,rtn%=mod;
	return rtn;
}
int qzh[500005],hzh[500005];
signed main(int argc, char** argv) {
	inv[1]=jcinv[0]=jc[0]=jcinv[1]=jc[1]=1;
	for(int i=2;i<=500000;i++)
	{
		jc[i]=jc[i-1]*i%mod;
		inv[i]=(mod-mod/i)*inv[mod%i]%mod;
		jcinv[i]=jcinv[i-1]*inv[i]%mod;
	}
	string a;
	cin >> a;
	for(int i=0;i<a.size();i++)
	{
		qzh[i]=a[i]=='(';
		if(i) qzh[i]+=qzh[i-1];
		hzh[i]=a[i]==')';
	}
	for(int i=a.size()-1;i>=0;i--) hzh[i]+=hzh[i+1];
	int ans=0;
	for(int i=0;i<a.size();i++) if(a[i]=='(') ans+=cal(qzh[i],hzh[i]),ans%=mod;
	cout << ans;
/*	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cout << cal(i,j) << " " << C(i+j-1,i) << "\n";
		}
		cout << "\n";
	}*/
	return 0;
}


#include <iostream>
#define int long long
#define mod 1000000007
using namespace std;
int inv[500005],jcinv[500005],jc[500005];
inline int C(int x,int y)
{
	if(x<y||y<0) return 0;
	return jc[x]*jcinv[y]%mod*jcinv[x-y]%mod;
}
inline int cal(int x,int y)
{
	return C(i+j-1,i);
	int rtn=0;
	for(int i=1;i<=min(x,y);i++)
		rtn+=C(x-1,i-1)*C(y,i)%mod,rtn%=mod;
	return rtn;
}
int qzh[500005],hzh[500005];
signed main(int argc, char** argv) {
	inv[1]=jcinv[0]=jc[0]=jcinv[1]=jc[1]=1;
	for(int i=2;i<=500000;i++)
	{
		jc[i]=jc[i-1]*i%mod;
		inv[i]=(mod-mod/i)*inv[mod%i]%mod;
		jcinv[i]=jcinv[i-1]*inv[i]%mod;
	}
	string a;
	cin >> a;
	for(int i=0;i<a.size();i++)
	{
		qzh[i]=a[i]=='(';
		if(i) qzh[i]+=qzh[i-1];
		hzh[i]=a[i]==')';
	}
	for(int i=a.size()-1;i>=0;i--) hzh[i]+=hzh[i+1];
	int ans=0;
	for(int i=0;i<a.size();i++) if(a[i]=='(') ans+=cal(qzh[i],hzh[i]),ans%=mod;
	cout << ans;
/*	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cout << cal(i,j) << " " << C(i+j-1,i) << "\n";
		}
		cout << "\n";
	}*/
	return 0;
}


// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

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

// int n;

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll m, n;

	cin >> n >> m;

	if(n <= m) {
		cout << n << endl;
	} else {
		ll d = m + 1;
		n -= m;
		while(n > 0) {
			n += m;
			n -= d;
			d++;
		}
		cout << d - 1 << endl;
	}

	return 0;
}


// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

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

// int n;

ll fact[400009], inv_fact[400009], inv[400009];

ll ncr(ll n, ll r) {
	return (fact[n] * inv_fact[r] % mod * inv_fact[n-r] % mod) % mod;
}

void init() {
	fact[0] = inv_fact[0] = 1ll;
	inv[1] = 1ll;
	for(ll i = 2; i <= 400000; i++)
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;

	for(ll i = 1; i <= 400000; i++) {
		fact[i] = fact[i - 1] * i % mod;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % mod;
	}
}

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	init();
	string x;
	cin >> x;

	// for(int i = 0; i < 10; i++)
	// 	cout << fact[i] << " " << inv_fact[i] << endl;

	int n = x.length();

	ll o = 0, c = 0;

	for(int i = 0; i < n; i++) {
		if(x[i] == '(') o++;
		else c++;
	}

	ll uo = 0, uc = c;

	ll ans = 0;

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

		if(x[i] == '(') {
			uo ++;
			ans += ncr(uo + uc - 1, uc - 1) % mod;
		} else uc --;
	}

	cout << ans % mod << endl;

	return 0;
}


// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

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

// int n;

ll fact[400009], inv_fact[400009], inv[400009];

ll ncr(ll n, ll r) {
	return (fact[n] * inv_fact[r] % mod * inv_fact[n-r] % mod) % mod;
}

void init() {
	fact[0] = inv_fact[0] = 1ll;
	inv[1] = 1ll;
	for(ll i = 2; i <= 400000; i++)
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;

	for(ll i = 1; i <= 400000; i++) {
		fact[i] = fact[i - 1] * i % mod;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % mod;
	}
}

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	init();
	string x;
	cin >> x;

	// for(int i = 0; i < 10; i++)
	// 	cout << fact[i] << " " << inv_fact[i] << endl;

	int n = x.length();

	ll o = 0, c = 0;

	for(int i = 0; i < n; i++) {
		if(x[i] == '(') o++;
		else c++;
	}

	ll uo = 0, uc = c;

	ll ans = 0;

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

		if(x[i] == '(') {
			uo ++;
			ans += ncr(uo + uc - 1, uc - 1) % mod;
		} else uc --;
	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const uint64_t MOD = 1e9+7;

struct ModInt
{
	//int x;
	uint64_t x;
	ModInt() : x(0) { }
	ModInt(uint64_t u) : x(u) { if (x >= MOD || x < 0) { x %= MOD; if (x < 0) x += MOD; } }
	//ModInt(uint64_t u) : x(u) { }
	ModInt(const ModInt &m) : x(m.x) { }
	ModInt& operator=(const ModInt &m) { x = m.x; return *this; }
	friend bool operator==(const ModInt& a, const ModInt& b) { return a.x == b.x; }
	friend bool operator!=(const ModInt& a, const ModInt& b) { return a.x != b.x; }
	friend bool operator<(const ModInt& a, const ModInt& b) { return a.x < b.x; }

	ModInt& operator+=(const ModInt& m) { x += m.x; while (x >= MOD) x -= MOD; return *this; }
	ModInt& operator-=(const ModInt& m) { x -= m.x; while (x < 0) x += MOD; return *this; }
	ModInt& operator*=(const ModInt& m) { x = (1ll*x*m.x)%MOD; return *this; }

	friend ModInt operator-(const ModInt &a) { ModInt res(a); if (res.x) res.x = MOD-res.x; return res; }
	friend ModInt operator+(const ModInt& a, const ModInt &b) { return ModInt(a) += ModInt(b); }
	friend ModInt operator-(const ModInt& a, const ModInt &b) { return ModInt(a) -= ModInt(b); }
	friend ModInt operator*(const ModInt& a, const ModInt &b) { return ModInt(a) *= ModInt(b); }
	ModInt f2() { return ModInt(x) += ModInt(x); }

	static uint64_t fp(uint64_t u, uint64_t k) {
		uint64_t res = 1;
		while (k > 0) {
			if (k & 1)
				res = (res*u) % MOD;
			u = (u*u) % MOD;
			k /= 2;
		}
		return res;
	}
	ModInt fastpow(uint64_t k) { return ModInt(fp(x, k)); }
	ModInt inv() { return ModInt(fp(x, MOD-2)); }
	static ModInt sign(uint64_t k) { return ((k & 1) ? ModInt(MOD-1) : ModInt(1)); }
	friend ostream& operator << (ostream& out, const ModInt& a) { return out << a.x; }
};

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

	uint64_t closingRight = 0;
	uint64_t openingRight = 0;
	for(int c=0;c<s.size();c++) {
		if(s[c] == ')') closingRight++;
		else openingRight++;
	}

	uint64_t openingLeft = 0;
	uint64_t closingLeft = 0;
	vector<ModInt> facts(400010);
	vector<ModInt> factsInverse(400010);
	ModInt m(1);
	for(uint64_t c=0;c<facts.size();c++) {
		if(c != 0) m = m*ModInt(c);
		facts[c] = m;
		factsInverse[c] = m.inv();
	}
	ModInt res(0);
	for(int c=0;c<s.size();c++){
		if(s[c] == ')') {closingRight--;closingLeft++;}
		if(s[c] == '(') {
			openingRight--;
			openingLeft++;
			res = res+ facts[openingLeft+closingRight-1]*factsInverse[openingLeft]*factsInverse[openingLeft+closingRight-1-openingLeft];
		}
	}
	cout<<res;
}


#include <bits/stdc++.h>

using namespace std;

const int64_t MOD = 1e9+7;

struct ModInt
{
	//int x;
	int64_t x;
	ModInt() : x(0) { }
	ModInt(int64_t u) : x(u) { if (x >= MOD || x < 0) { x %= MOD; if (x < 0) x += MOD; } }
	//ModInt(int64_t u) : x(u) { }
	ModInt(const ModInt &m) : x(m.x) { }
	ModInt& operator=(const ModInt &m) { x = m.x; return *this; }
	friend bool operator==(const ModInt& a, const ModInt& b) { return a.x == b.x; }
	friend bool operator!=(const ModInt& a, const ModInt& b) { return a.x != b.x; }
	friend bool operator<(const ModInt& a, const ModInt& b) { return a.x < b.x; }

	ModInt& operator+=(const ModInt& m) { x += m.x; while (x >= MOD) x -= MOD; return *this; }
	ModInt& operator-=(const ModInt& m) { x -= m.x; while (x < 0) x += MOD; return *this; }
	ModInt& operator*=(const ModInt& m) { x = (1ll*x*m.x)%MOD; return *this; }

	friend ModInt operator-(const ModInt &a) { ModInt res(a); if (res.x) res.x = MOD-res.x; return res; }
	friend ModInt operator+(const ModInt& a, const ModInt &b) { return ModInt(a) += ModInt(b); }
	friend ModInt operator-(const ModInt& a, const ModInt &b) { return ModInt(a) -= ModInt(b); }
	friend ModInt operator*(const ModInt& a, const ModInt &b) { return ModInt(a) *= ModInt(b); }
	ModInt f2() { return ModInt(x) += ModInt(x); }

	static int64_t fp(int64_t u, int64_t k) {
		int64_t res = 1;
		while (k > 0) {
			if (k & 1)
				res = (res*u) % MOD;
			u = (u*u) % MOD;
			k /= 2;
		}
		return res;
	}
	ModInt fastpow(int64_t k) { return ModInt(fp(x, k)); }
	ModInt inv() { return ModInt(fp(x, MOD-2)); }
	static ModInt sign(int64_t k) { return ((k & 1) ? ModInt(MOD-1) : ModInt(1)); }
	friend ostream& operator << (ostream& out, const ModInt& a) { return out << a.x; }
};

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

	int64_t closingRight = 0;
	int64_t openingRight = 0;
	for(int c=0;c<s.size();c++) {
		if(s[c] == ')') closingRight++;
		else openingRight++;
	}

	int64_t openingLeft = 0;
	int64_t closingLeft = 0;
	vector<ModInt> facts(400010);
	vector<ModInt> factsInverse(400010);
	ModInt m(1);
	for(int64_t c=0;c<facts.size();c++) {
		if(c != 0) m = m*ModInt(c);
		facts[c] = m;
		factsInverse[c] = m.inv();
	}
	ModInt res(0);
	for(int c=0;c<s.size();c++){
		if(s[c] == ')') {closingRight--;closingLeft++;}
		if(s[c] == '(') {
			openingRight--;
			openingLeft++;
			res = res+ facts[openingLeft+closingRight-1]*factsInverse[openingLeft]*factsInverse[openingLeft+closingRight-1-openingLeft];
		}
	}
	cout<<res;
}


#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1e9+7;

struct ModInt
{
	//int x;
	long long x;
	ModInt() : x(0) { }
	ModInt(long long u) : x(u) { if (x >= MOD || x < 0) { x %= MOD; if (x < 0) x += MOD; } }
	//ModInt(long long u) : x(u) { }
	ModInt(const ModInt &m) : x(m.x) { }
	ModInt& operator=(const ModInt &m) { x = m.x; return *this; }
	friend bool operator==(const ModInt& a, const ModInt& b) { return a.x == b.x; }
	friend bool operator!=(const ModInt& a, const ModInt& b) { return a.x != b.x; }
	friend bool operator<(const ModInt& a, const ModInt& b) { return a.x < b.x; }

	ModInt& operator+=(const ModInt& m) { x += m.x; while (x >= MOD) x -= MOD; return *this; }
	ModInt& operator-=(const ModInt& m) { x -= m.x; while (x < 0) x += MOD; return *this; }
	ModInt& operator*=(const ModInt& m) { x = (1ll*x*m.x)%MOD; return *this; }

	friend ModInt operator-(const ModInt &a) { ModInt res(a); if (res.x) res.x = MOD-res.x; return res; }
	friend ModInt operator+(const ModInt& a, const ModInt &b) { return ModInt(a) += ModInt(b); }
	friend ModInt operator-(const ModInt& a, const ModInt &b) { return ModInt(a) -= ModInt(b); }
	friend ModInt operator*(const ModInt& a, const ModInt &b) { return ModInt(a) *= ModInt(b); }
	ModInt f2() { return ModInt(x) += ModInt(x); }

	static long long fp(long long u, long long k) {
		long long res = 1;
		while (k > 0) {
			if (k & 1)
				res = (res*u) % MOD;
			u = (u*u) % MOD;
			k /= 2;
		}
		return res;
	}
	ModInt fastpow(long long k) { return ModInt(fp(x, k)); }
	ModInt inv() { return ModInt(fp(x, MOD-2)); }
	static ModInt sign(long long k) { return ((k & 1) ? ModInt(MOD-1) : ModInt(1)); }
	friend ostream& operator << (ostream& out, const ModInt& a) { return out << a.x; }
};

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

	long long int closingRight = 0;
	long long int openingRight = 0;
	for(int c=0;c<s.size();c++) {
		if(s[c] == ')') closingRight++;
		else openingRight++;
	}

	long long int openingLeft = 0;
	long long int closingLeft = 0;
	vector<ModInt> facts(400010);
	vector<ModInt> factsInverse(400010);
	ModInt m(1);
	for(long long int c=0;c<facts.size();c++) {
		if(c != 0) m = m*ModInt(c);
		facts[c] = m;
		factsInverse[c] = m.inv();
	}
	ModInt res(0);
	for(int c=0;c<s.size();c++){
		if(s[c] == ')') {closingRight--;closingLeft++;}
		if(s[c] == '(') {
			openingRight--;
			openingLeft++;
			res = res+ facts[openingLeft+closingRight-1]*factsInverse[openingLeft]*factsInverse[openingLeft+closingRight-1-openingLeft];
		}
	}
	cout<<res;
}


#include <bits/stdc++.h>

using namespace std;

const uint64_t MOD = 1e9+7;

struct ModInt
{
	//int x;
	uint64_t x;
	ModInt() : x(0) { }
	ModInt(uint64_t u) : x(u) { if (x >= MOD || x < 0) { x %= MOD; if (x < 0) x += MOD; } }
	//ModInt(uint64_t u) : x(u) { }
	ModInt(const ModInt &m) : x(m.x) { }
	ModInt& operator=(const ModInt &m) { x = m.x; return *this; }
	friend bool operator==(const ModInt& a, const ModInt& b) { return a.x == b.x; }
	friend bool operator!=(const ModInt& a, const ModInt& b) { return a.x != b.x; }
	friend bool operator<(const ModInt& a, const ModInt& b) { return a.x < b.x; }

	ModInt& operator+=(const ModInt& m) { x += m.x; while (x >= MOD) x -= MOD; return *this; }
	ModInt& operator-=(const ModInt& m) { x -= m.x; while (x < 0) x += MOD; return *this; }
	ModInt& operator*=(const ModInt& m) { x = (1ll*x*m.x)%MOD; return *this; }

	friend ModInt operator-(const ModInt &a) { ModInt res(a); if (res.x) res.x = MOD-res.x; return res; }
	friend ModInt operator+(const ModInt& a, const ModInt &b) { return ModInt(a) += ModInt(b); }
	friend ModInt operator-(const ModInt& a, const ModInt &b) { return ModInt(a) -= ModInt(b); }
	friend ModInt operator*(const ModInt& a, const ModInt &b) { return ModInt(a) *= ModInt(b); }
	ModInt f2() { return ModInt(x) += ModInt(x); }

	static uint64_t fp(uint64_t u, uint64_t k) {
		uint64_t res = 1;
		while (k > 0) {
			if (k & 1)
				res = (res*u) % MOD;
			u = (u*u) % MOD;
			k /= 2;
		}
		return res;
	}
	ModInt fastpow(uint64_t k) { return ModInt(fp(x, k)); }
	ModInt inv() { return ModInt(fp(x, MOD-2)); }
	static ModInt sign(uint64_t k) { return ((k & 1) ? ModInt(MOD-1) : ModInt(1)); }
	friend ostream& operator << (ostream& out, const ModInt& a) { return out << a.x; }
};

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

	uint64_t closingRight = 0;
	uint64_t openingRight = 0;
	for(int c=0;c<s.size();c++) {
		if(s[c] == ')') closingRight++;
		else openingRight++;
	}

	uint64_t openingLeft = 0;
	uint64_t closingLeft = 0;
	vector<ModInt> facts(400010);
	vector<ModInt> factsInverse(400010);
	ModInt m(1);
	uint64_t lim = 400010;
	for(uint64_t c=0;c<lim;c++) {
		if(c != 0) m = m*ModInt(c);
		facts[c] = m;
		factsInverse[c] = m.inv();
	}
	ModInt res(0);
	for(int c=0;c<s.size();c++){
		if(s[c] == ')') {closingRight--;closingLeft++;}
		if(s[c] == '(') {
			openingRight--;
			openingLeft++;
			if(closingRight > 0){
			res = res+ facts[openingLeft+closingRight-1]*factsInverse[openingLeft]*factsInverse[openingLeft+closingRight-1-openingLeft];
			}
		}
	}
	cout<<res;
}


#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1e9+7;

struct ModInt
{
	//int x;
	long long x;
	ModInt() : x(0) { }
	ModInt(long long u) : x(u) { if (x >= MOD || x < 0) { x %= MOD; if (x < 0) x += MOD; } }
	//ModInt(long long u) : x(u) { }
	ModInt(const ModInt &m) : x(m.x) { }
	ModInt& operator=(const ModInt &m) { x = m.x; return *this; }
	friend bool operator==(const ModInt& a, const ModInt& b) { return a.x == b.x; }
	friend bool operator!=(const ModInt& a, const ModInt& b) { return a.x != b.x; }
	friend bool operator<(const ModInt& a, const ModInt& b) { return a.x < b.x; }

	ModInt& operator+=(const ModInt& m) { x += m.x; if (x >= MOD) x -= MOD; return *this; }
	ModInt& operator-=(const ModInt& m) { x -= m.x; if (x < 0) x += MOD; return *this; }
	ModInt& operator*=(const ModInt& m) { x = (1ll*x*m.x)%MOD; return *this; }

	friend ModInt operator-(const ModInt &a) { ModInt res(a); if (res.x) res.x = MOD-res.x; return res; }
	friend ModInt operator+(const ModInt& a, const ModInt &b) { return ModInt(a) += ModInt(b); }
	friend ModInt operator-(const ModInt& a, const ModInt &b) { return ModInt(a) -= ModInt(b); }
	friend ModInt operator*(const ModInt& a, const ModInt &b) { return ModInt(a) *= ModInt(b); }
	ModInt f2() { return ModInt(x) += ModInt(x); }

	static long long fp(long long u, long long k) {
		long long res = 1;
		while (k > 0) {
			if (k & 1)
				res = (res*u) % MOD;
			u = (u*u) % MOD;
			k /= 2;
		}
		return res;
	}
	ModInt fastpow(long long k) { return ModInt(fp(x, k)); }
	ModInt inv() { return ModInt(fp(x, MOD-2)); }
	static ModInt sign(long long k) { return ((k & 1) ? ModInt(MOD-1) : ModInt(1)); }
	friend ostream& operator << (ostream& out, const ModInt& a) { return out << a.x; }
};

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

	long long int closingRight = 0;
	long long int openingRight = 0;
	for(int c=0;c<s.size();c++) {
		if(s[c] == ')') closingRight++;
		else openingRight++;
	}

	long long int openingLeft = 0;
	long long int closingLeft = 0;
	vector<ModInt> facts(400010);
	vector<ModInt> factsInverse(400010);
	ModInt m(1);
	for(long long int c=0;c<facts.size();c++) {
		if(c != 0) m = m*ModInt(c);
		facts[c] = m;
		factsInverse[c] = m.inv();
	}
	ModInt res(0);
	for(int c=0;c<s.size();c++){
		if(s[c] == ')') {closingRight--;closingLeft++;}
		if(s[c] == '(') {
			openingRight--;
			openingLeft++;
			res = res+ facts[openingLeft+closingRight-1]*factsInverse[openingLeft]*factsInverse[openingLeft+closingRight-1-openingLeft];
		}
	}
	cout<<res;
}


#include <bits/stdc++.h>

using namespace std;

const uint64_t MOD = 1e9+7;

struct ModInt
{
	//int x;
	uint64_t x;
	ModInt() : x(0) { }
	ModInt(uint64_t u) : x(u) { if (x >= MOD || x < 0) { x %= MOD; if (x < 0) x += MOD; } }
	//ModInt(uint64_t u) : x(u) { }
	ModInt(const ModInt &m) : x(m.x) { }
	ModInt& operator=(const ModInt &m) { x = m.x; return *this; }
	friend bool operator==(const ModInt& a, const ModInt& b) { return a.x == b.x; }
	friend bool operator!=(const ModInt& a, const ModInt& b) { return a.x != b.x; }
	friend bool operator<(const ModInt& a, const ModInt& b) { return a.x < b.x; }

	ModInt& operator+=(const ModInt& m) { x += m.x; while (x >= MOD) x -= MOD; return *this; }
	ModInt& operator-=(const ModInt& m) { x -= m.x; while (x < 0) x += MOD; return *this; }
	ModInt& operator*=(const ModInt& m) { x = (1ll*x*m.x)%MOD; return *this; }

	friend ModInt operator-(const ModInt &a) { ModInt res(a); if (res.x) res.x = MOD-res.x; return res; }
	friend ModInt operator+(const ModInt& a, const ModInt &b) { return ModInt(a) += ModInt(b); }
	friend ModInt operator-(const ModInt& a, const ModInt &b) { return ModInt(a) -= ModInt(b); }
	friend ModInt operator*(const ModInt& a, const ModInt &b) { return ModInt(a) *= ModInt(b); }
	ModInt f2() { return ModInt(x) += ModInt(x); }

	static uint64_t fp(uint64_t u, uint64_t k) {
		uint64_t res = 1;
		while (k > 0) {
			if (k & 1)
				res = (res*u) % MOD;
			u = (u*u) % MOD;
			k /= 2;
		}
		return res;
	}
	ModInt fastpow(uint64_t k) { return ModInt(fp(x, k)); }
	ModInt inv() { return ModInt(fp(x, MOD-2)); }
	static ModInt sign(uint64_t k) { return ((k & 1) ? ModInt(MOD-1) : ModInt(1)); }
	friend ostream& operator << (ostream& out, const ModInt& a) { return out << a.x; }
};

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

	uint64_t closingRight = 0;
	uint64_t openingRight = 0;
	for(int c=0;c<s.size();c++) {
		if(s[c] == ')') closingRight++;
		else openingRight++;
	}

	uint64_t openingLeft = 0;
	uint64_t closingLeft = 0;
	vector<ModInt> facts(400010);
	vector<ModInt> factsInverse(400010);
	ModInt m(1);
	uint64_t lim = 400010;
	for(uint64_t c=0;c<lim;c++) {
		if(c != 0) m = m*ModInt(c);
		facts[c] = m;
		factsInverse[c] = m.inv();
	}
	ModInt res(0);
	for(int c=0;c<s.size();c++){
		if(s[c] == ')') {closingRight--;closingLeft++;}
		if(s[c] == '(') {
			openingRight--;
			openingLeft++;
			res = res+ facts[openingLeft+closingRight-1]*factsInverse[openingLeft]*factsInverse[openingLeft+closingRight-1-openingLeft];
		}
	}
	cout<<res;
}


#include<bits/stdc++.h>

using namespace std;

#include <ext/rope>
using namespace __gnu_cxx;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define int long long

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef map<string, int> MAPS;
typedef map<char, int> MAPC;
typedef map<int, int> MAPI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef set<char> SETC;
typedef complex<double> POINT;
typedef tree<int, int, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> MAP_T;
typedef trie<string, null_type, trie_string_access_traits<>,
        pat_trie_tag, trie_prefix_search_node_update> TRIE;

#define add push_back
#define rem pop_back
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define SZ(x) int((x).size())
#define F first
#define S second
#define NEW(x, y, z) x y; x::iterator z;

void INPUT(int *a, int size)  { for(int i = 0; i < size; ++i) cin >> a[i]; }
void OUTPUT(int *a, int size) { for(int i = 0; i < size; ++i) cout << a[i] << " "; cout << endl;}

#define REPI(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define REP(i, a, b)  for(int i = a; i <  b; i++)
#define REPN(i, a, b) for(int i = a; i <= b; i++)
#define REPV(i, b, a) for(int i = b; i >= a; i--)

const double EPS = 1e-9;
const double PI = acos(-1.);
const int MOD = 1e9 + 7;
const int MAXN = 500001;
int INF = __INT64_MAX__;
int MAX = -1e16;
int MIN = 1e16;
string YN[] = {"NO", "YES"};

#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))

template<typename T1, typename T2> T2 max(T1 a, T2 b) { T2 res = a > b ? a : b; return res; }
template<typename T1, typename T2> T2 min(T1 a, T2 b) { T2 res = a < b ? a : b; return res; }

int POW (int a, int n)
{
        int res = 1;
        while (n) {
                if (n & 1)
                        res *= a;
                a *= a;
                n >>= 1;
        }
        return res;
}

string to_string(int n)
{
        stringstream ss;
        string s;
        ss << n;
        ss >> s;
        return s;
}

string to_binary(int n)
{
        string s;
        while(n) {
                s += (n & 1) + '0';
                n >>= 1;
        }
        reverse(ALL(s));
        return s;
}

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

inline int addMOD(int a, int b, int m = MOD)
{
        return (a + b) % m;
}

inline int mulMOD(int a, int b, int m = MOD)
{
        return (a * b) % m;
}

inline int divMOD(int a, int b, int m = MOD)
{
        int x, y;
        int g = GCD_E(b, m, x, y);
        x = (x % m + m) % m;
        return mulMOD(a, x, m);
}

int px[] = { 1, 1, -1, -1 };
int py[] = { -1, 1, -1, 1};
int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
int fx[] = {-2, -2, -1, -1,  1,  1,  2,  2};
int fy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

int n, m, k, cnt, res;
int A[MAXN], B[MAXN], fact[1 << 20];
inline void precalcFactorials()
{
        fact[0] = 1;
        for (int i = 1; i < (1 << 20); i++)
                fact[i] = mulMOD(fact[i - 1], i);
}
inline int C(int k, int n)
{
        return divMOD(fact[n], mulMOD(fact[n - k], fact[k]));
}

string s, t;

int func(int k)
{
        return k * (k + 1) / 2 / m - n - m;
}
void solution()
{
        cin >> s;
        precalcFactorials();
        n = s.size();
        vector<int> O(n), P(n);
        O[0] = (s[0] == '(') ? 1 : 0;
        for (int i = 1; i < n; i++)
                O[i] = O[i - 1] + ((s[i] == '(') ? 1 : 0);
        P[n - 1] = (s[n - 1] == ')') ? 1 : 0;
        for (int i = n - 2; i >= 0; i--)
                P[i] = P[i + 1] + ((s[i] == ')') ? 1 : 0);
        for (int i = 0; i < n; i++) {
                if (s[i] != '(' || P[i] == 0)
                        continue;
                int add = C(O[i], O[i] + P[i] - 1);
                res = addMOD(res, add);
        }
        cout << res << endl;
}

__INT16_C() main()
{
        //ifstream fin("input.in");
        //ofstream fout("output.out");

        ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

        int t = 1;
        // cin >> t;

        while(t--) solution();
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e6+5;
const int MOD=1e9+7;

int fact[N], invfact[N];

int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

int modinv(int k)
{
	return pow(k, MOD-2, MOD);
}

void precompute()
{
	fact[0]=fact[1]=1;
	for(int i=2;i<N;i++)
	{
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}
	invfact[N-1]=modinv(fact[N-1]);
	for(int i=N-2;i>=0;i--)
	{
		invfact[i]=invfact[i+1]*(i+1);
		invfact[i]%=MOD;
	}
}

int nCr(int x, int y)
{
	int num=fact[x];
	num*=invfact[y];
	num%=MOD;
	num*=invfact[x-y];
	num%=MOD;
	return num;
}

int32_t main()
{
	IOS;
	precompute();
	string s;
	cin>>s;
	int open=0, close=0;
	int n=s.size();
	for(auto it:s)
		close+=(it==')');
	int ans=0;
	for(auto it:s)
	{
		if(it==')')
			close--;
		else
		{
			open++;
			ans+=(nCr(open+close-1, open));
			ans%=MOD;
		}
	}
	cout<<ans;
	return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

const int N=1e6+5;
const int MOD=1e9+7;

int fact[N], invfact[N];

int modinv(int k)
{
    return pow(k, MOD-2, MOD);
}

void precompute()
{
    fact[0]=fact[1]=1;
    for(int i=2;i<N;i++)
    {
        fact[i]=fact[i-1]*i;
        fact[i]%=MOD;
    }
    invfact[N-1]=modinv(fact[N-1]);
    for(int i=N-2;i>=0;i--)
    {
        invfact[i]=invfact[i+1]*(i+1);
        invfact[i]%=MOD;
    }
}

int nCr(int x, int y)
{
	int num=fact[x];
	num*=invfact[y];
	num%=MOD;
	num*=invfact[x-y];
	num%=MOD;
	return num;
}

int32_t main()
{
	IOS;
	precompute();
	string s;
	cin>>s;
	int open=0, close=0;
	int n=s.size();
	for(auto it:s)
		close+=(it==')');
	int ans=0;
	for(auto it:s)
	{
		if(it==')')
			close--;
		else
		{
			open++;
			ans+=(nCr(open+close-1, open));
			ans%=MOD;
		}
	}
	cout<<ans;
	return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

const int N=1e6+5;
const int MOD=1e9+7;

int fact[N], invfact[N];

int modinv(int k)
{
    return pow(k, MOD-2, MOD);
}

void precompute()
{
    fact[0]=fact[1]=1;
    for(int i=2;i<N;i++)
    {
        fact[i]=fact[i-1]*i;
        fact[i]%=MOD;
    }
    invfact[N-1]=modinv(fact[N-1]);
    for(int i=N-2;i>=0;i--)
    {
        invfact[i]=invfact[i+1]*(i+1);
        invfact[i]%=MOD;
    }
}

int nCr(int x, int y)
{
	int num=fact[x];
	num*=invfact[y];
	num%=MOD;
	num*=invfact[x-y];
	num%=MOD;
	return num;
}

int32_t main()
{
	IOS;
	precompute();
	string s;
	cin>>s;
	int open=0, close=0;
	int n=s.size();
	for(auto it:s)
		close+=(it==')');
	int ans=0;
	for(auto it:s)
	{
		if(it==')')
			close--;
		else
		{
			ans+=(nCr(open+close, open+1));
			open++;
			ans%=MOD;
		}
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll mod=1000000007;

ll fpow(ll b,ll e)
{
    ll res=1;
    while(e)
    {
        if(e&1) res=(res*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n=s.size();
    s="$"+s;
    vector<ll> f(n+1,1);
    for(ll i=1;i<=n;i++) f[i]=(f[i-1]*i)%mod;
    vector<ll> finv(n+1,1);
    finv[n]=fpow(f[n],mod-2);
    for(ll i=n-1;i>=0;i--) finv[i]=(finv[i+1]*(i+1))%mod;
    auto c=[&](int a,int b)->ll
    {
        ll res=f[a];
        res=(res*finv[b])%mod;
        res=(res*finv[a-b])%mod;
        return res;
    };
    int b=0;
    for(int i=1;i<=n;i++) b+=(s[i]==')');
    int a=0;
    ll res=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='(')
        {
            a++;
            res=(res+c(a+b-1,a))%mod;
        }
        else b--;
    }
    cout << res << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll mod=1000000007;

ll fpow(ll b,ll e)
{
    ll res=1;
    while(e)
    {
        if(e&1) res=(res*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n=s.size();
    s="$"+s;
    vector<ll> f(n+1,1);
    for(ll i=1;i<=n;i++) f[i]=(f[i-1]*i)%mod;
    vector<ll> finv(n+1,1);
    finv[n]=fpow(f[n],mod-2);
    for(ll i=n-1;i>=0;i--) finv[i]=(finv[i+1]*(i+1))%mod;
    auto c=[&](int a,int b)->ll
    {
        ll res=f[a];
        res=(res*finv[b])%mod;
        res=(res*finv[a-b])%mod;
        return res;
    };
    int b=0;
    for(int i=1;i<=n;i++) b+=(s[i]==')');
    int a=0;
    ll res=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='(')
        {
            a++;
            if(b>0) res=(res+c(a+b-1,a))%mod;
        }
        else b--;
    }
    cout << res << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll mod=1000000007;

ll fpow(ll b,ll e)
{
    ll res=1;
    while(e)
    {
        if(e&1) res=(res*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n=s.size();
    s="$"+s;
    vector<ll> f(n+1,1);
    for(ll i=1;i<=n;i++) f[i]=(f[i-1]*i)%mod;
    vector<ll> finv(n+1,1);
    finv[n]=fpow(f[n],mod-2);
    for(ll i=n-1;i>=0;i--) finv[i]=(finv[i+1]*(i+1))%mod;
    int b=0;
    for(int i=1;i<=n;i++) b+=(s[i]==')');
    int a=0;
    ll res=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='(')
        {
            ll now=(b*f[a+b])%mod;
            now=(now*fpow(a+1,mod-2))%mod;
            now=(now*finv[a])%mod;
            now=(now*finv[b])%mod;
            res=(res+now)%mod;
            a++;
        }
        else b--;
    }
    cout << res << "\n";
    return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wsign-compare"
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#define io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
#define setio(x)
#else
#define setio(x) freopen((x+".in").c_str(),"r",stdin); freopen((x+".out").c_str(),"w",stdout)
#endif
const int MN = 2e5+3, BASE = 31, LOG = 20, MOD = 1e9+7;
int pw[MN], fac[MN], invfac[MN], rgt[MN], dfac[MN]; char s[MN];
int madd (int a, int b) {
	a += b;
	return a >= MOD ? a - MOD : a;
}
int inv (int base) {
	int res = 1, exp = MOD-2;
	while (exp) {
		if (exp&1) res = res*1LL*base%MOD;
		base = base*1LL*base%MOD;
		exp>>=1;
	}
	return res;
}
int choose (int n, int k) {
	return fac[n]*1LL*invfac[k]%MOD*invfac[n-k]%MOD;
}
int main() {
	scanf ("%s",s+1);
	int n = strlen(s+1), cnt = 0, ans = 0;
	pw[0] = fac[0] = invfac[0] = 1;
	for (int i = 1; i <= n; i++) pw[i] = madd(pw[i-1],pw[i-1]), fac[i]=fac[i-1]*1LL*i%MOD, invfac[i]=inv(fac[i]);
	for (int i = 1; i <= n; i+=2) dfac[i] = (i==1?1:dfac[i-2])*1LL*i%MOD;
	for (int i = n; i >= 1; i--) rgt[i] = rgt[i+1] + (s[i] == ')');
	for (int i = 1; i <= n; i++) if (s[i] == '('){
		int c1 = ++cnt, c2 = rgt[i];
		ans += choose(c1+c2-1,c1);
	}
	printf ("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wsign-compare"
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#define io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
#define setio(x)
#else
#define setio(x) freopen((x+".in").c_str(),"r",stdin); freopen((x+".out").c_str(),"w",stdout)
#endif
const int MN = 2e5+3, BASE = 31, LOG = 20, MOD = 1e9+7;
int pw[MN], fac[MN], invfac[MN], rgt[MN], dfac[MN]; char s[MN];
int madd (int a, int b) {
	a += b;
	return a >= MOD ? a - MOD : a;
}
int inv (int base) {
	int res = 1, exp = MOD-2;
	while (exp) {
		if (exp&1) res = res*1LL*base%MOD;
		base = base*1LL*base%MOD;
		exp>>=1;
	}
	return res;
}
int choose (int n, int k) {
	return fac[n]*1LL*invfac[k]%MOD*invfac[n-k]%MOD;
}
int main() {
	scanf ("%s",s+1);
	int n = strlen(s+1), cnt = 0, ans = 0;
	pw[0] = fac[0] = invfac[0] = 1;
	for (int i = 1; i <= n; i++) pw[i] = madd(pw[i-1],pw[i-1]), fac[i]=fac[i-1]*1LL*i%MOD, invfac[i]=inv(fac[i]);
	for (int i = 1; i <= n; i+=2) dfac[i] = (i==1?1:dfac[i-2])*1LL*i%MOD;
	for (int i = n; i >= 1; i--) rgt[i] = rgt[i+1] + (s[i] == ')');
	for (int i = 1; i <= n; i++) if (s[i] == '('){
		int c1 = ++cnt, c2 = rgt[i];
		ans += choose(c1+c2-1,c1);
		ans %= MOD;
	}
	printf ("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Mod = 1e9+7;
const int maxn = 2e5+100;
ll jie[maxn],ni[maxn];
string s;
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;
assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll c(ll n,ll m){
	return jie[n]%Mod*ni[n-m]%Mod*ni[m]%Mod;
}
int main()
{
	jie[0]=ni[0]=1;
	for(int i=1;i<=maxn-100;i++){
		jie[i]=jie[i-1]*i;
		ni[i] = powmod(jie[i],Mod-2,Mod);
	}
	cin>>s;
	ll l=0,r=0,ans=0;
	for(int i=0;i<s.length();i++){
		if(s[i]==')') r++;
	}
	for(int i=0;i<s.length();i++){
		if(s[i]==')') r--;
		else {
			l++;
			ans = (ans+c(l+r-1,l))%Mod;
		}
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Mod = 1e9+7;
const int maxn = 2e5+100;
ll jie[maxn],ni[maxn];
string s;
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;
assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll c(ll n,ll m){
	return jie[n]%Mod*ni[n-m]%Mod*ni[m]%Mod;
}
int main()
{
	jie[0]=ni[0]=1;
	for(int i=1;i<=maxn-100;i++){
		jie[i]=jie[i-1]*i%mod;
		ni[i] = powmod(jie[i],Mod-2,Mod);
	}
	cin>>s;
	ll l=0,r=0,ans=0;
	for(int i=0;i<s.length();i++){
		if(s[i]==')') r++;
	}
	for(int i=0;i<s.length();i++){
		if(s[i]==')') r--;
		else {
			l++;
			ans = (ans+c(l+r-1,l))%Mod;
		}
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Mod = 1e9+7;
const int maxn = 2e5+100;
ll jie[maxn],ni[maxn];
string s;
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;
assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll c(ll n,ll m){
	return jie[n]%Mod*ni[n-m]%Mod*ni[m]%Mod;
}
int main()
{
	jie[0]=ni[0]=1;
	for(int i=1;i<=maxn-100;i++){
		jie[i]=jie[i-1]*i%Mod;
		ni[i] = powmod(jie[i],Mod-2,Mod);
	}
	cin>>s;
	ll l=0,r=0,ans=0;
	for(int i=0;i<s.length();i++){
		if(s[i]==')') r++;
	}
	for(int i=0;i<s.length();i++){
		if(s[i]==')') r--;
		else {
			l++;
			ans = (ans+c(l+r-1,l))%Mod;
		}
	}
	cout<<ans<<endl;
}


/*#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll fac[100005];
int main(){
	fac[0]=1;
	for(int i=1;i<=100000;i++)
		fac[i]=fac[i-1]*i%mod;
	int T;
	scanf("%d",&T);
	while(T--){
		int n,m;
		scanf("%d%d",&n,&m);
		ll res=1,ans=1;
		int x;
		for(int i=0;i<n;i++){
			scanf("%d",&x);
			res=res*fac[x]%mod;
		}
		for(int i=0;i<m;i++){
			scanf("%d",&x);
			ans=ans*fac[x]%mod;
		}
		if(ans==res)
			puts("equal");
		else puts("unequal");
	}
} */
/*#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int c[maxn],d[maxn];
int prime[maxn],num[maxn],pre[maxn];
int main(){
	memset(prime,0,sizeof(prime));
	prime[1]=prime[0]=1;
	num[1]=num[0]=1;
	int cnt=0;
	for(int i=2;i<=100000;i++){
		if(!prime[i]){
			pre[++cnt]=i;
			num[i]=i;
		}
		for(int j=1;i*pre[j]<=100000;j++){
			num[i*pre[j]]=pre[j];
			prime[i*pre[j]]=pre[j];
			if(i%pre[j]==0)
				break;
		}
	}
	int T;
	scanf("%d",&T);
	while(T--){
		for(int i=0;i<=100001;i++)
			c[i]=d[i]=0;
		int n,m;
		scanf("%d%d",&n,&m);
		int x;
		for(int i=0;i<n;i++){
			scanf("%d",&x);
			c[x]++;
		}
		for(int i=0;i<m;i++){
			scanf("%d",&x);
			d[x]++;
		}
		for(int i=100000;i>=2;i--){
			c[i]=c[i]+c[i+1];
			d[i]=d[i]+d[i+1];
		}
		for(int i=100000;i>=2;i--){
			int t=c[i];
			c[i]=0;
			c[i/num[i]]+=t;
			c[num[i]]+=t;
			t=d[i];
			d[i]=0;
			d[i/num[i]]+=t;
			d[num[i]]+=t;
		}
		int f=0;
		for(int i=2;i<=100000;i++){
			if(c[i]!=d[i]){
				f=1;
				break;
			}
		}
		if(f==0)
			puts("equal");
		else puts("unequal");
	}
}*/
/*#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll a[3][100005];
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int n,m;
		int x,y;
		memset(a,0,sizeof(a));
		scanf("%d%d",&n,&m);
		for(int i=0;i<m;i++){
			scanf("%d%d",&x,&y);
			a[x-1][y]++;
		}
		ll b=0,c=0,d=0;
		ll c1=0,d1=0,d2=0,ans;
		for(int i=1;i<=n;i++){
			b=(b+a[0][i])%mod;
			c1=(c1+a[1][i])%mod;
			c=(c+c1)%mod;
			d1=(d1+a[2][i])%mod;
			d=(d+2*d2+d1);
			d2=(d2+d1);
			ans=(b+c+d)%mod;
			printf("%lld ",ans);
		}
		printf("\n");
	}
}*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll inv(ll b){return b==1?1:(mod-mod/b)*inv(mod%b)%mod;}//�˷���Ԫ
ll jc[200100];
ll c(ll m,ll n){
	if(m<n)
		return 0;
	return jc[m]*inv(jc[n])%mod*inv(jc[m-n])%mod;
}
int main(){
	jc[0]=1;
	for(int i=1;i<=200000;i++)
		jc[i]=jc[i-1]*i%mod;
	int sr=0,l=0,r;
	ll ans=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]==')')
			sr++;
	r=sr;
	for(int i=0;i<s.size();i++){
		if(s[i]=='('){
			l++;
			ans=(ans+c(l+r-1,l))%mod;
		}
		else r--;
	}
	printf("%lld\n",ans);
}


/*#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll fac[100005];
int main(){
	fac[0]=1;
	for(int i=1;i<=100000;i++)
		fac[i]=fac[i-1]*i%mod;
	int T;
	scanf("%d",&T);
	while(T--){
		int n,m;
		scanf("%d%d",&n,&m);
		ll res=1,ans=1;
		int x;
		for(int i=0;i<n;i++){
			scanf("%d",&x);
			res=res*fac[x]%mod;
		}
		for(int i=0;i<m;i++){
			scanf("%d",&x);
			ans=ans*fac[x]%mod;
		}
		if(ans==res)
			puts("equal");
		else puts("unequal");
	}
} */
/*#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int c[maxn],d[maxn];
int prime[maxn],num[maxn],pre[maxn];
int main(){
	memset(prime,0,sizeof(prime));
	prime[1]=prime[0]=1;
	num[1]=num[0]=1;
	int cnt=0;
	for(int i=2;i<=100000;i++){
		if(!prime[i]){
			pre[++cnt]=i;
			num[i]=i;
		}
		for(int j=1;i*pre[j]<=100000;j++){
			num[i*pre[j]]=pre[j];
			prime[i*pre[j]]=pre[j];
			if(i%pre[j]==0)
				break;
		}
	}
	int T;
	scanf("%d",&T);
	while(T--){
		for(int i=0;i<=100001;i++)
			c[i]=d[i]=0;
		int n,m;
		scanf("%d%d",&n,&m);
		int x;
		for(int i=0;i<n;i++){
			scanf("%d",&x);
			c[x]++;
		}
		for(int i=0;i<m;i++){
			scanf("%d",&x);
			d[x]++;
		}
		for(int i=100000;i>=2;i--){
			c[i]=c[i]+c[i+1];
			d[i]=d[i]+d[i+1];
		}
		for(int i=100000;i>=2;i--){
			int t=c[i];
			c[i]=0;
			c[i/num[i]]+=t;
			c[num[i]]+=t;
			t=d[i];
			d[i]=0;
			d[i/num[i]]+=t;
			d[num[i]]+=t;
		}
		int f=0;
		for(int i=2;i<=100000;i++){
			if(c[i]!=d[i]){
				f=1;
				break;
			}
		}
		if(f==0)
			puts("equal");
		else puts("unequal");
	}
}*/
/*#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll a[3][100005];
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int n,m;
		int x,y;
		memset(a,0,sizeof(a));
		scanf("%d%d",&n,&m);
		for(int i=0;i<m;i++){
			scanf("%d%d",&x,&y);
			a[x-1][y]++;
		}
		ll b=0,c=0,d=0;
		ll c1=0,d1=0,d2=0,ans;
		for(int i=1;i<=n;i++){
			b=(b+a[0][i])%mod;
			c1=(c1+a[1][i])%mod;
			c=(c+c1)%mod;
			d1=(d1+a[2][i])%mod;
			d=(d+2*d2+d1);
			d2=(d2+d1);
			ans=(b+c+d)%mod;
			printf("%lld ",ans);
		}
		printf("\n");
	}
}*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll inv(ll b){return b==1?1:(mod-mod/b)*inv(mod%b)%mod;}//�˷���Ԫ
ll jc[200100];
ll c(ll m,ll n){
	return jc[m]*inv(jc[m-n])%mod*inv(jc[n])%mod;
}
int main(){
	jc[0]=1;
	for(int i=1;i<=200000;i++)
		jc[i]=jc[i-1]*i%mod;
	int sr=0,l=0,r;
	ll ans=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]==')')
			sr++;
	r=sr;
	for(int i=0;i<s.size();i++){
		if(s[i]=='('){
			l++;
			ans=(ans+c(l+r-1,l))%mod;
		}
		else r--;
	}
	printf("%lld\n",ans);
}


/*#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll fac[100005];
int main(){
	fac[0]=1;
	for(int i=1;i<=100000;i++)
		fac[i]=fac[i-1]*i%mod;
	int T;
	scanf("%d",&T);
	while(T--){
		int n,m;
		scanf("%d%d",&n,&m);
		ll res=1,ans=1;
		int x;
		for(int i=0;i<n;i++){
			scanf("%d",&x);
			res=res*fac[x]%mod;
		}
		for(int i=0;i<m;i++){
			scanf("%d",&x);
			ans=ans*fac[x]%mod;
		}
		if(ans==res)
			puts("equal");
		else puts("unequal");
	}
} */
/*#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int c[maxn],d[maxn];
int prime[maxn],num[maxn],pre[maxn];
int main(){
	memset(prime,0,sizeof(prime));
	prime[1]=prime[0]=1;
	num[1]=num[0]=1;
	int cnt=0;
	for(int i=2;i<=100000;i++){
		if(!prime[i]){
			pre[++cnt]=i;
			num[i]=i;
		}
		for(int j=1;i*pre[j]<=100000;j++){
			num[i*pre[j]]=pre[j];
			prime[i*pre[j]]=pre[j];
			if(i%pre[j]==0)
				break;
		}
	}
	int T;
	scanf("%d",&T);
	while(T--){
		for(int i=0;i<=100001;i++)
			c[i]=d[i]=0;
		int n,m;
		scanf("%d%d",&n,&m);
		int x;
		for(int i=0;i<n;i++){
			scanf("%d",&x);
			c[x]++;
		}
		for(int i=0;i<m;i++){
			scanf("%d",&x);
			d[x]++;
		}
		for(int i=100000;i>=2;i--){
			c[i]=c[i]+c[i+1];
			d[i]=d[i]+d[i+1];
		}
		for(int i=100000;i>=2;i--){
			int t=c[i];
			c[i]=0;
			c[i/num[i]]+=t;
			c[num[i]]+=t;
			t=d[i];
			d[i]=0;
			d[i/num[i]]+=t;
			d[num[i]]+=t;
		}
		int f=0;
		for(int i=2;i<=100000;i++){
			if(c[i]!=d[i]){
				f=1;
				break;
			}
		}
		if(f==0)
			puts("equal");
		else puts("unequal");
	}
}*/
/*#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll a[3][100005];
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int n,m;
		int x,y;
		memset(a,0,sizeof(a));
		scanf("%d%d",&n,&m);
		for(int i=0;i<m;i++){
			scanf("%d%d",&x,&y);
			a[x-1][y]++;
		}
		ll b=0,c=0,d=0;
		ll c1=0,d1=0,d2=0,ans;
		for(int i=1;i<=n;i++){
			b=(b+a[0][i])%mod;
			c1=(c1+a[1][i])%mod;
			c=(c+c1)%mod;
			d1=(d1+a[2][i])%mod;
			d=(d+2*d2+d1);
			d2=(d2+d1);
			ans=(b+c+d)%mod;
			printf("%lld ",ans);
		}
		printf("\n");
	}
}*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll inv(ll b){return b==1?1:(mod-mod/b)*inv(mod%b)%mod;}//�˷���Ԫ
ll jc[200005];
ll c(ll m,ll n){
	return jc[m]*inv(jc[m-n])%mod*inv(jc[n])%mod;
}
int main(){
	jc[0]=1;
	for(int i=1;i<=200000;i++)
		jc[i]=jc[i-1]*i%mod;
	int sr=0,l=0,r;
	ll ans=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]==')')
			sr++;
	r=sr;
	for(int i=0;i<s.size();i++){
		if(s[i]=='('){
			l++;
			ans=(ans+c(l+r-1,l))%mod;
		}
		else r--;
	}
	printf("%lld\n",ans);
}


/*#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll fac[100005];
int main(){
	fac[0]=1;
	for(int i=1;i<=100000;i++)
		fac[i]=fac[i-1]*i%mod;
	int T;
	scanf("%d",&T);
	while(T--){
		int n,m;
		scanf("%d%d",&n,&m);
		ll res=1,ans=1;
		int x;
		for(int i=0;i<n;i++){
			scanf("%d",&x);
			res=res*fac[x]%mod;
		}
		for(int i=0;i<m;i++){
			scanf("%d",&x);
			ans=ans*fac[x]%mod;
		}
		if(ans==res)
			puts("equal");
		else puts("unequal");
	}
} */
/*#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int c[maxn],d[maxn];
int prime[maxn],num[maxn],pre[maxn];
int main(){
	memset(prime,0,sizeof(prime));
	prime[1]=prime[0]=1;
	num[1]=num[0]=1;
	int cnt=0;
	for(int i=2;i<=100000;i++){
		if(!prime[i]){
			pre[++cnt]=i;
			num[i]=i;
		}
		for(int j=1;i*pre[j]<=100000;j++){
			num[i*pre[j]]=pre[j];
			prime[i*pre[j]]=pre[j];
			if(i%pre[j]==0)
				break;
		}
	}
	int T;
	scanf("%d",&T);
	while(T--){
		for(int i=0;i<=100001;i++)
			c[i]=d[i]=0;
		int n,m;
		scanf("%d%d",&n,&m);
		int x;
		for(int i=0;i<n;i++){
			scanf("%d",&x);
			c[x]++;
		}
		for(int i=0;i<m;i++){
			scanf("%d",&x);
			d[x]++;
		}
		for(int i=100000;i>=2;i--){
			c[i]=c[i]+c[i+1];
			d[i]=d[i]+d[i+1];
		}
		for(int i=100000;i>=2;i--){
			int t=c[i];
			c[i]=0;
			c[i/num[i]]+=t;
			c[num[i]]+=t;
			t=d[i];
			d[i]=0;
			d[i/num[i]]+=t;
			d[num[i]]+=t;
		}
		int f=0;
		for(int i=2;i<=100000;i++){
			if(c[i]!=d[i]){
				f=1;
				break;
			}
		}
		if(f==0)
			puts("equal");
		else puts("unequal");
	}
}*/
/*#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll a[3][100005];
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int n,m;
		int x,y;
		memset(a,0,sizeof(a));
		scanf("%d%d",&n,&m);
		for(int i=0;i<m;i++){
			scanf("%d%d",&x,&y);
			a[x-1][y]++;
		}
		ll b=0,c=0,d=0;
		ll c1=0,d1=0,d2=0,ans;
		for(int i=1;i<=n;i++){
			b=(b+a[0][i])%mod;
			c1=(c1+a[1][i])%mod;
			c=(c+c1)%mod;
			d1=(d1+a[2][i])%mod;
			d=(d+2*d2+d1);
			d2=(d2+d1);
			ans=(b+c+d)%mod;
			printf("%lld ",ans);
		}
		printf("\n");
	}
}*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll inv(ll b){return b==1?1:(mod-mod/b)*inv(mod%b)%mod;}//�˷���Ԫ
ll jc[200100];
ll c(ll m,ll n){
	return jc[m]*inv(jc[n])%mod*inv(jc[m-n])%mod;
}
int main(){
	jc[0]=1;
	for(int i=1;i<=200000;i++)
		jc[i]=jc[i-1]*i%mod;
	int sr=0,l=0,r;
	ll ans=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]==')')
			sr++;
	r=sr;
	for(int i=0;i<s.size();i++){
		if(s[i]=='('){
			l++;
			ans=(ans+c(l+r-1,l))%mod;
		}
		else r--;
	}
	printf("%lld\n",ans);
}


//IF YOU GIVE UP,THEN YOU DON'T DESERVE IT

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI 3.14159265358979323846264
#define isz(x) (int)x.size()
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define typ int
#define ordered_set tree<typ, null_type, less<typ>, rb_tree_tag, tree_order_statistics_node_update>
//*s.find_by_order(x) --> value at position x(0-indexed)
//s.order_of_key(x)   --> number of elements less than x
#define eps 1e-9
#define int long long
#define mod (long long)(1000000007)

int fact[200005];int suf[200005];

ll power(ll x, unsigned ll y, unsigned ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;
    return (y%2 == 0)? p : (x * p) % m;
}

ll imod(ll a)
{ ll m=mod;
    return power(a, m-2, m);
}

int find(int n,int r)
{
   int num = fact[n];
   int den = (fact[n-r]*fact[r])%mod;
   return (num*imod(den))%mod;
}

int solve(int x,int y)
{ if(y==0)return 0;
  return find(x+y-1,x);
}

int32_t main()
{  fact[0] = 1;
   for(int i=1;i<200005;i++)
    fact[i] = (fact[i-1]*i)%mod;

  string str;
  cin>>str;

  int n = str.size();

  for(int i=0;i<=n;i++)suf[i] = 0;

  for(int i=n-1;i>=0;i--)
  { suf[i] = suf[i+1];
    if(str[i]==')')
      suf[i]++;
  }
  int c = 0,ans = 0;
  for(int i=0;i<n;i++)
  {
    if(str[i]=='(')
    {
      c++;
    //  cout<<c<<" "<<suf[i]<<" "<<solve(c,suf[i])<<endl;
      ans = (ans + solve(c,suf[i]))%mod;
    }

  }
  cout<<ans;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
using namespace std;
const ll N = 200042;
const ll m = 1e9 + 7;
ll add(ll x, ll y) {
  x += y;
  while(x >= m) x -= m;
  while(x < 0) x += m;
  return x;
}
ll mul(ll x, ll y) {
  return (x * 1ll * y) % m;
}
ll binpow(ll x, ll y) {
  ll z = 1;
  while(y) {
    if(y & 1) z = mul(z, x);
    x = mul(x, x);
    y >>= 1;
  }
  return z;
}
ll inv(ll x) {
  return binpow(x, m - 2);
}
ll divide(ll x, ll y) {
  return mul(x, inv(y));
}
ll fact[N];
void precalc() {
  fact[0] = 1;
  for(ll i = 1; i < N; i++) fact[i] = mul(fact[i - 1], i);
}
ll C(ll n, ll k) {
  return divide(fact[n], mul(fact[k], fact[n - k]));
}
ll A(ll n, ll m) {
  return divide(fact[n], fact[n - m]);
}
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  precalc();

  string s;

  cin >> s;

  ll suff[200042] = {0}, ans = 0;

  for(ll i = s.size() - 1; i >= 0; i--) suff[i] = suff[i + 1] + (s[i] == ')');

  ll cur = 0;

  for(ll i = 0; i < s.size() - 1; i++) {
    if(s[i] == '(') ans = add(ans, C(++cur + suff[i] - 1, cur));
    ans %= m;
  }

  cout << ans % m;

  return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
using namespace std;
const ll N = 200042;
const ll m = 1e9 + 7;
ll add(ll x, ll y) {
  x += y;
  while(x >= m) x -= m;
  while(x < 0) x += m;
  return x;
}
ll mul(ll x, ll y) {
  return (x * 1ll * y) % m;
}
ll binpow(ll x, ll y) {
  ll z = 1;
  while(y) {
    if(y & 1) z = mul(z, x);
    x = mul(x, x);
    y >>= 1;
  }
  return z;
}
ll inv(ll x) {
  return binpow(x, m - 2);
}
ll divide(ll x, ll y) {
  return mul(x, inv(y));
}
ll fact[N];
void precalc() {
  fact[0] = 1;
  for(ll i = 1; i < N; i++) fact[i] = mul(fact[i - 1], i);
}
ll C(ll n, ll k) {
  return divide(fact[n], mul(fact[k], fact[n - k]));
}
ll A(ll n, ll m) {
  return divide(fact[n], fact[n - m]);
}
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  precalc();

  string s;

  cin >> s;

  ll suff[200042] = {0}, ans = 0;

  for(ll i = s.size() - 1; i >= 0; i--) suff[i] = suff[i + 1] + (s[i] == ')');

  ll cur = 0;

  for(ll i = 0; i < s.size() - 1; i++) {
    if(s[i] == '(') {
      cur++;
      if(cur > 0 && suff[i + 1] > 0) {
        if(suff[i + 1] >= cur) {
          ans += C(suff[i + 1], cur);
        }
        for(ll j = 1; j < min(suff[i + 1] + 1, cur); j++) {
          ans += mul(C(cur, j) - C(cur - 1, j), C(suff[i + 1], j));
          ans %= m;
        }
      }
    }
    ans %= m;
  }

  cout << ans % m;

  return 0;
}


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

const int maxn = 1e6 + 10;
const int MOD = 998244353;

int n;
int a[maxn], f[maxn];

void add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; if (x < 0) x += MOD; }
int mul(int x, int y) { return 1ll * x * y % MOD; }

int main() {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	cin >> n;
	f[0] = 1;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		f[i] = (f[i - 1] + f[i - 1]) % MOD;
	}
	int answer = 0, cur = a[1] * f[n - 1];
	for (int i = 1; i <= n; ++i) {
		add(answer, cur);
		if (i == n) continue;
		add(cur, -mul(f[n - i - 1], a[i]));
		add(cur, mul(f[n - i - 1], a[i + 1]));
	}
	cout << answer << "\n";
	return 0;
}


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

const int maxn = 1e6 + 10;
const int MOD = 998244353;

int n;
int a[maxn], f[maxn];

void add(int &x, int y) { x += y; if (x > MOD) x -= MOD; if (x < 0) x += MOD; }
int mul(int x, int y) { return 1ll * x * y % MOD; }

int main() {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	cin >> n;
	f[0] = 1;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		f[i] = (f[i - 1] + f[i - 1]) % MOD;
	}
	int answer = 0, cur = a[1] * f[n - 1];
	for (int i = 1; i <= n; ++i) {
		add(answer, cur);
		if (i == n) continue;
		add(cur, -mul(f[n - i - 1], a[i]));
		add(cur, mul(f[n - i - 1], a[i + 1]));
	}
	cout << answer << "\n";
	return 0;
}


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

const int maxn = 1e6 + 10;
const int MOD = 998244353;

int n;
int a[maxn], f[maxn];

void add(int &x, int y) { x += y; if (x < 0) x += MOD; }
int mul(int x, int y) { return 1ll * x * y % MOD; }

int main() {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	cin >> n;
	f[0] = 1;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		f[i] = (f[i - 1] + f[i - 1]) % MOD;
	}
	int answer = 0, cur = a[1] * f[n - 1];
	for (int i = 1; i <= n; ++i) {
		add(answer, cur);
		if (i == n) continue;
		add(cur, -mul(f[n - i - 1], a[i]));
		add(cur, mul(f[n - i - 1], a[i + 1]));
	}
	cout << answer << "\n";
	return 0;
}


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

const int maxn = 1e6 + 10;
const int MOD = 998244353;

int n;
int a[maxn], f[maxn];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	cin >> n;
	f[0] = 1;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		f[i] = f[i - 1] * 2 % MOD;
	}
	int answer = 0, cur = a[1] * f[n - 1];
	for (int i = 1; i <= n; ++i) {
		answer = (answer + cur) % MOD;
		if (i == n) continue;
		cur = (cur - 1ll * f[n - i - 1] * a[i] % MOD + 1ll * MOD * MOD) % MOD;
		cur = (cur + 1ll * f[n - i - 1] * (a[i + 1]) % MOD) % MOD;
	}
	cout << answer << "\n";
	return 0;
}


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

const int maxn = 1e6 + 10;
const int MOD = 998244353;

int n;
int a[maxn], f[maxn];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	cin >> n;
	f[0] = 1;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		f[i] = f[i - 1] * 2 % MOD;
	}
	int answer = 0, cur = a[1] * f[n - 1];
	for (int i = 1; i <= n; ++i) {
		answer = (answer + cur) % MOD;
		if (i == n) continue;
		cur = (cur - 1ll * f[n - i - 1] * a[i] % MOD + MOD) % MOD;
		cur = (cur + 1ll * f[n - i - 1] * (a[i + 1]) % MOD) % MOD;
	}
	cout << answer << "\n";
	return 0;
}


#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
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...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 998244353;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

void add(int& x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}

int main() {
  int n;
  cin >> n;
  // n = 1e6;
  vector<int> ip2(n + 1, 1);
  int inv2 = (MOD + 1) / 2;
  for (int i = 1; i <= n; ++i) ip2[i] = 1LL * ip2[i - 1] * inv2 % MOD;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  vector<int> dp(n + 1);
  dp[1] = a[1];
  for (int i = 2; i <= n; ++i) {
    dp[i] = dp[i - 1] + 1LL * a[i] * ip2[i - 1] % MOD;
    if (dp[i] >= MOD) dp[i] -= MOD;
    dp[i] -= a[i - 1] * ip2[i - 1] % MOD;
    if (dp[i] < 0) dp[i] += MOD;
  }
  int ret = 0;
  for (int i = 1; i <= n; ++i) add(ret, dp[i]);
  for (int i = 1; i < n; ++i) ret = ret * 2 % MOD;
  cout << ret << '\n';
  return 0;
}


#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
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...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 998244353;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

void add(int& x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}

int main() {
  int n;
  cin >> n;
  // n = 1e6;
  vector<int> ip2(n + 1, 1);
  int inv2 = (MOD + 1) / 2;
  for (int i = 1; i <= n; ++i) ip2[i] = 1LL * ip2[i - 1] * inv2 % MOD;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  vector<int> dp(n + 1);
  dp[1] = a[1];
  for (int i = 2; i <= n; ++i) {
    dp[i] = dp[i - 1] + a[i] * ip2[i - 1] % MOD;
    if (dp[i] >= MOD) dp[i] -= MOD;
    dp[i] -= a[i - 1] * ip2[i - 1] % MOD;
    if (dp[i] < 0) dp[i] += MOD;
  }
  int ret = 0;
  for (int i = 1; i <= n; ++i) add(ret, dp[i]);
  for (int i = 1; i < n; ++i) ret = ret * 2 % MOD;
  cout << ret << '\n';
  return 0;
}


#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
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...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 998244353;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

void add(int& x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}

int main() {
  int n;
  cin >> n;
  // n = 1e6;
  vector<int> ip2(n + 1, 1);
  int inv2 = (MOD + 1) / 2;
  for (int i = 1; i <= n; ++i) ip2[i] = 1LL * ip2[i - 1] * inv2 % MOD;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  vector<int> dp(n + 1);
  dp[1] = a[1];
  for (int i = 2; i <= n; ++i) {
    dp[i] = dp[i - 1] + 1LL * a[i] * ip2[i - 1] % MOD;
    if (dp[i] >= MOD) dp[i] -= MOD;
    dp[i] -= 1LL * a[i - 1] * ip2[i - 1] % MOD;
    if (dp[i] < 0) dp[i] += MOD;
  }
  int ret = 0;
  for (int i = 1; i <= n; ++i) add(ret, dp[i]);
  for (int i = 1; i < n; ++i) ret = ret * 2 % MOD;
  cout << ret << '\n';
  return 0;
}


#include<bits/stdc++.h>
//#define int long long
#define mod 998244353
using namespace std;
int n;
int a[3];
int f[3];
int b[3];
signed main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int res = (i-1)%2, cnt = i%2;
		cin >> a[cnt];
		if(i == 1) {
			f[cnt] = a[cnt]; continue;
			f[cnt] %= mod;
		}
		else if(i == 2)
		{
			f[cnt] = 3*a[1]+a[0]; f[cnt] %= mod;
			b[0] = a[1]+a[0]; b[0] %= mod;
			continue;
		}
		b[cnt] = 2*b[res]+(a[cnt]-a[res]); b[cnt] %= mod;
		f[cnt] = 2*f[res]+b[cnt]; f[cnt] %= mod;
	}
	cout << f[n%2]%mod << endl;
}


#include<iostream>
#define int long long
#define mod 998244353ll
inline void input(int &_x)
{
    _x = 0;
    int _tmp = 1; char _tc = getchar();
    while((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
    if(_tc == '-') _tc = getchar(), _tmp = -1;
    while(_tc >= '0' && _tc <= '9') _x = _x*10+(_tc-48), _tc = getchar();
    _x *= _tmp;
}
inline void output(int _x)
{
	if(_x == 0)
	{
		putchar('0');
		return;
	}
	if(_x < 0)
	{
		putchar('-');
		_x = -_x;
	}
    char _buff[20]; int _f = 0;
    while(_x > 0)
    {
        _buff[_f++] = _x%10+'0';
        _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
        putchar(_buff[_f]);
    putchar('\n');
}
using namespace std;
int n;
int a[3];
int f[3];
int b[3];
signed main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int res = (i-1)%2ll, cnt = i%2ll;
		input(a[cnt]);
		if(i == 1) {
			f[cnt] = a[cnt]; continue;
		}
		else if(i == 2)
		{
			f[cnt] = 3ll*a[1]+a[0];
			b[0] = a[1]+a[0];
			continue;
		}
		b[cnt] = 2ll*b[res]+(a[cnt]-a[res]); b[cnt] %= mod;
		f[cnt] = 2ll*f[res]+b[cnt]; f[cnt] %= mod;
	}
	output(f[n%2]%mod);
}


#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
using namespace std;
int n;
int a[3];
int f[3];
int b[3];
signed main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int res = (i-1)%2ll, cnt = i%2ll;
		cin >> a[cnt];
		if(i == 1) {
			f[cnt] = a[cnt]; continue;
		}
		else if(i == 2)
		{
			f[cnt] = 3ll*a[1]+a[0];
			b[0] = a[1]+a[0];
			continue;
		}
		b[cnt] = 2ll*b[res]+(a[cnt]-a[res]); b[cnt] %= mod;
		f[cnt] = 2ll*f[res]+b[cnt]; f[cnt] %= mod;
	}
	cout << f[n%2]%mod << endl;
}


#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

const int mod = 998244353;

int powmod(int a, int p) {
    if (p == 0) return 1;
    if (p == 1) return a;
    int k = powmod(a, p / 2);
    if (p & 1) return (((k * k) % mod) * a) % mod;
    return (k * k) % mod;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = 0;
    for (int d = 1; d < n; d++) { // i - j
        ans += ((n - d) * ((powmod(2, n - 1 - d) * a[d - 1]) % mod)) % mod;
        ans %= mod;
    }
    for (int i = 0; i < n; i++) {
        ans += (powmod(2, n - i - 1) * a[i]) % mod;
        ans %= mod;
    }
    cout << ans;
}
/*

*/


#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

const int mod = 998244353;

int powmod(int a, int p) {
    if (p == 0) return 1;
    if (p == 1) return a;
    int k = powmod(a, p / 2);
    if (p & 1) return (((k * k) % mod) * a) % mod;
    return (k * k) % mod;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            ans += (powmod(2, n - 1 - (i - j)) * a[i - j - 1]) % mod;
            ans %= mod;
        }
        ans += powmod(2, n - i - 1) * a[i];
        ans %= mod;
        dbg(ans)
    }
    cout << ans;
}
/*

*/


#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

const int mod = 998244353;

int powmod(int a, int p) {
    if (p == 0) return 1;
    if (p == 1) return a;
    int k = powmod(a, p / 2);
    if (p & 1) return (((k * k) % mod) * a) % mod;
    return (k * k) % mod;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = 0;
    for (int d = 1; d < n; d++) { // i - j
        ans += ((n - d) * (powmod(2, n - 1 - d) * a[d - 1]) % mod) % mod;
        ans %= mod;
    }
    for (int i = 0; i < n; i++) {
        ans += powmod(2, n - i - 1) * a[i];
        ans %= mod;
    }
    cout << ans;
}
/*

*/


/*
Author: Dung Tuan Le
University of Rochester
*/

#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define FOR(i, l, r) for (int i=l; i<=r; i++)
#define REP(i, r, l) for (int i=r; i>=l; i--)
#define sz(x) int(x.size())
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
ll max(ll a, ll b) { return (a>=b)?a:b; }
ll min(ll a, ll b) { return (a<=b)?a:b; }

const ll mod = 998244353;
#define maxn 1000000 + 10
ll pw[maxn], a[maxn];

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

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

int main() {
	fio;
  ll n;
  cin >> n;
  pw[0] = 1;
  FOR(i, 1, n) {
    cin >> a[i];
    pw[i] = (pw[i - 1] * 2) % mod;
  }
  if (n == 1) return cout << a[1], 0;
  ll res = 0;
  FOR(i, 1, n - 1) {
    res = add(res, mul(add(pw[n - i], mul(pw[n - i - 1], n - i)), a[i]));
  }
  res = add(res, a[n]);
  cout << res;
	return 0;
}


/*
Author: Dung Tuan Le
University of Rochester
*/

#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define FOR(i, l, r) for (int i=l; i<=r; i++)
#define REP(i, r, l) for (int i=r; i>=l; i--)
#define sz(x) int(x.size())
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
ll max(ll a, ll b) { return (a>=b)?a:b; }
ll min(ll a, ll b) { return (a<=b)?a:b; }

const ll mod = 998244353;
#define maxn 1000000 + 10
ll pw[maxn], a[maxn];
int main() {
	fio;
  ll n;
  cin >> n;
  pw[0] = 1;
  FOR(i, 1, n) {
    cin >> a[i];
    pw[i] = (pw[i - 1] * 2) % mod;
  }
  ll res = 0;
  FOR(i, 1, n) {
    res = (res + (pw[n - i] + pw[n - i - 1] * (n - i)) * a[i]) % mod;
  }
  cout << res;
	return 0;
}


/*
Author: Dung Tuan Le
University of Rochester
*/

#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define FOR(i, l, r) for (int i=l; i<=r; i++)
#define REP(i, r, l) for (int i=r; i>=l; i--)
#define sz(x) int(x.size())

using namespace std;

typedef long long ll;
const ll mod = 998244353;
#define maxn 1000000 + 10
ll pw[maxn], a[maxn];

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

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

int main() {
	fio;
  ll n;
  cin >> n;
  pw[0] = 1;
  FOR(i, 1, n) {
    cin >> a[i];
    pw[i] = (pw[i - 1] * 2) % mod;
  }
  if (n == 1) return cout << a[1], 0;
  ll res = 0;
  FOR(i, 1, n - 1) {
    res = add(res, mul(add(pw[n - i], mul(pw[n - i - 1], n - i)), a[i]));
  }
  res = add(res, a[n]);
  cout << res;
	return 0;
}


/*
Author: Dung Tuan Le
University of Rochester
*/

#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define FOR(i, l, r) for (int i=l; i<=r; i++)
#define REP(i, r, l) for (int i=r; i>=l; i--)
#define sz(x) int(x.size())
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
ll max(ll a, ll b) { return (a>=b)?a:b; }
ll min(ll a, ll b) { return (a<=b)?a:b; }

const ll mod = 998244353;
#define maxn 1000000 + 10
ll pw[maxn], a[maxn];
int main() {
	fio;
  ll n;
  cin >> n;
  pw[0] = 1;
  FOR(i, 1, n) {
    cin >> a[i];
    pw[i] = (pw[i - 1] * 2) % mod;
  }
  if (n == 1) return cout << a[1], 0;
  ll res = 0;
  FOR(i, 1, n - 1) {
    res = (res + (pw[n - i] + pw[n - i - 1] * (n - i)) * a[i]) % mod;
  }
  res = (res + a[n]) % mod;
  cout << res;
	return 0;
}


//看到expect以为是概率，结果根概率啥关系都没有
//之后又想用dp，但是数据太大了
//最后才发现这好像是一道考虑贡献也不知道用了啥算法的题。。。。。

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<cstring>
#include<string>
#include<algorithm>

using namespace std;

typedef long long ll;

const ll maxn=1e6+5;

const ll mod=998244353;

ll two[maxn];

int a[maxn];

void init(int n)
{
	two[0]=1;
	for(int i=1;i<n;i++)
	{
		two[i]=two[i-1]*2%mod;
	}
}

// a[i]的贡献： a[i]*(2^（n-i）+(n-i)*(2^(n-i-1))

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	init(n);
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		ans=(ans+a[i]*(two[n-i]+(n-i)*two[n-i-1]%mod)%mod)%mod;
	}
	printf("%lld",ans);
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

#define MOD 998244353

int a[1000000];

int main() {
	int n;
	scanf("%d", &n);
	LL add = 1;
	LL mul = 1;
	LL ans = 0;
	REP(i, n) scanf("%d", &a[i]);
	REP(i, n) {
		ans = (ans + a[n - 1 - i] * mul) % MOD;
		mul = (2 * mul + add) % MOD;
		add = (2 * add) % MOD;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <math.h>
#include <iomanip>
using namespace std;
#define forr(i,a,b,c) for(int i=a;i<b;i+=c)
#define forrb(i,a,b,c) for(int i=a;i>b;i-=c)
#define fori(i,n) forr(i,0,n,1)
#define forib(i,n) forrb(i,n-1,-1,1)
#define forn(i,n) forr(i,1,n,1)
#define fornb(i,n) forrb(i,n-1,0,1)
#define fort(i,m,n) forr(i,m,n,1)
#define fortb(i,m,n) forrb(i,n-1,m-1,1)
#define forin(i,arr) fori(i,arr.size())
#define forinb(i,arr) forib(i,arr.size())
#define into(i) cin >> i;
#define def(i) int i; into(i)
#define deft(t,i) t i; into(i)
#define defn def(n)
#define defp def(p)
#define defm def(m)
#define defk def(k)
#define defa def(a)
#define defb def(b)
#define defc def(c)
#define defd def(d)
#define vec(a) vector<a>
#define co cout <<
#define out(a) cout << a <<' ';
#define el << endl;
#define outv(arr,n) fori(i,n){out(arr[i])} co "" el
#define cas(p) co "Case #" << p+1 <<": ";
#define ex return 0;
#define qii queue<int>
#define sti stack<int>
#define dei deque<int>
#define con continue;
#define br break;
#define maxi 1000000013
#define mod %998244353;
#define wne(arr) while(!arr.empty())
#define all(arr) arr.begin(),arr.end()
#define _230 1073741824
typedef vector<int> veci;
typedef long long lol;
typedef vector<lol> vecl;
#define table(name,n,m) vector<veci> name(n,veci (m));
#define tablel(name,n,m) vector<vecl> name(n,vecl (m));
typedef pair<int, int> point;
typedef pair<point, point> poin;
lol gcd(lol a, lol b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a%b);
}

lol tri(lol n) {
	return (n*(n + 1)) / 2;
}
int main() {
	ios::sync_with_stdio(false);
	defn
	lol ans = 0;
	lol cur = 1;
	lol pow = 1;
	veci a(n);
	fori(i, n) {
		into(a[i])
	}
	forib(i, n) {
		ans=(ans+cur*a[i])mod
		cur=(2*cur+pow)mod
		pow=(2*pow)mod
	}
	co ans el
		ex
}


#include <iostream>
#include <vector>

#define MOD 998244353

using namespace std;

int main() {

	int n;
	cin >> n;

	vector <int> v(n + 1);
	for (int i = 1; i <= n; ++i)
		cin >> v[i];

	long long ans = v[n], bin = 1, k = 3;
	for (int i = n - 1; i > 0; --i)
	{
		ans += (((v[i] * bin) % MOD) * k);
		ans %= MOD;
		bin = (bin * 2) % MOD;
		++k;
	}

	cout << ans;
}


#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <bitset>

using namespace std;

typedef long long LL;
typedef pair<int, int> pair_ii;
typedef pair<long long, long long> pair_LL;
typedef pair<string, string> pair_ss;

#define fori(i, s, n) for (int i = s; i < n; ++i)
#define forir(i, f)   for (int i = f - 1; i >= 0; --i)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz size()

namespace mod {

LL const modul = 998244353;

LL sum(LL x, LL y) {
	return (x + y) % modul;
}

LL sub(LL x, LL y) {
	if (x > y) {
		return (x - y) % modul;
	}
	else {
		return (modul + x - y) % modul;
	}
}

LL mpl(LL x, LL y) {
	return (x * y) % modul;
}

LL bin_pow(LL x, LL e) {
	LL ans = 1;
	while (e) {
		if (e & 1) {
			ans = mod::mpl(ans, x);
		}
		x = mod::mpl(x, x);
		e >>= 1;
	}
	return ans;
}

LL rev(LL x) {
	LL ans = bin_pow(x, modul - 2);
	return ans;
}

LL div(LL x, LL y) {
	assert(y != 0);
	LL ans = x;
	ans = mod::mpl(ans, mod::rev(y));
	return ans;
}

}

void set_precise(int n) {
	cout << fixed;
	cout << setprecision(n);
}

int const N = 1000003;

LL two[N];

void pre() {
	two[0] = 1;
	fori(i, 1, N) {
		two[i] = mod::mpl(two[i - 1], 2);
	}
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
#endif
	pre();
	int n;
	cin >> n;
	LL ans = 0;
	fori(i, 1, n + 1) {
		LL a_i;
		cin >> a_i;
		LL cur = 0;
		if (i < n) {
			cur = two[n - i - 1];
			cur = mod::mpl(cur, n - i);
			cur = mod::sum(cur, two[n - i]);
		}
		else {
			cur = 1;
		}
		cur = mod::mpl(cur, a_i);
		ans = mod::sum(ans, cur);
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <vector>

using namespace std;

const int mod = 998244353;

int main() {
	int n, d, ans;
	scanf("%d", &n);
	vector<int> a(n), p2(n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &a[i]);
	p2[0] = 1;
	for (int i = 1; i < n; ++i)
		p2[i] = (p2[i - 1] * 2) % mod;
	ans = d = (a[0] * 1ll * p2[n - 1]) % mod;
	for (int i = 1; i < n; ++i) {
		d = (d - (a[i - 1] * 1ll * p2[n - 1 - i]) % mod + mod) % mod;
		d = (d + a[i] * 1ll * p2[n - 1 - i]) % mod;
		ans = (ans + d) % mod;
	}
	printf("%d", ans);
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <queue>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <float.h>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<unsigned> vu;
typedef vector<ll> vl;
typedef vector<pi> vp;
typedef vector<pl> vpl;
typedef vector<string> vs;
typedef set<int> si;
typedef map<int, int> mi;
typedef vector<int>::iterator vii;

int n;
vi a;

const int MOD = 998244353;

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

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

int main(int argc, char* argv[])
{
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	a.resize(n);

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

	int res = 0;
	int p2 = 1;

	// a(n) = (n+2)*2^(n-1)
	for (int i = n - 1, j = 2; i >= 0; --i, ++j)
	{
		int curr;
		if (j == 2)
		{
			curr = 1;
		}
		else
		{
			curr = mul(p2, j);
		}
		curr = mul(curr, a[i]);
		res = add(res, curr);
		if (j == 2)
			p2 = 1;
		else
			p2 = mul(p2, 2);
	}

	cout << res << endl;

	return 0;
}


#include<iostream>

using namespace std;
#define modd 998244353
//#define
typedef long long ll;
//a是底数，b是指数，mode是取模数，sum是记录取模的结果
long long Mode(long long a, long long b, long long mode)
{
	if (b <0)return 0;
	long long sum = 1;
	while (b) {
		if (b & 1) {
			sum = (sum * a) % mode;
			b--;
		}
		b /= 2;
		a = a * a % mode;
	}
	return sum;
}
ll n;
ll a[1000005];

int main() {
	while (cin >> n) {
		for (int i = 1; i <= n; i++)cin >> a[i];
		ll ans = 0;
		ll temp1 = 0; ll temp2 = 0;
		for (int i = 1; i <= n; i++) {
			temp1 = Mode(2, n - i, modd);
			temp2 = Mode(2, n - i - 1, modd);
			//cout << "temp1 " << temp1 << " temp2 " << temp2 << endl;
			temp1 += (temp2*(n - i)) % modd;
			ans += (temp1*a[i]) % modd;
			//cout << "ans: " << ans << endl;
		}
		cout << ans << endl;
	}
	return 0;
}


#include<iostream>

using namespace std;
#define modd 998244353
//#define
typedef long long ll;
//a是底数，b是指数，mode是取模数，sum是记录取模的结果
long long Mode(long long a, long long b, long long mode)
{
	if (b <0)return 0;
	long long sum = 1;
	while (b) {
		if (b & 1) {
			sum = (sum * a) % mode;
			b--;
		}
		b /= 2;
		a = a * a % mode;
	}
	return sum;
}
ll n;
ll a[1000005];

int main() {
	while (cin >> n) {
		for (int i = 1; i <= n; i++)scanf_s("%I64d",&a[i]);
			//cin >> a[i];
		ll ans = 0;
		ll temp1 = 0; ll temp2 = 0;
		for (int i = 1; i <= n; i++) {
			temp1 = Mode(2, n - i, modd);
			//temp2 = temp1 / 2;  //不能改,..  他们是不一样的-.-
			temp2 = Mode(2, n - i - 1, modd);
			//cout << "temp1 " << temp1 << " temp2 " << temp2 << endl;
			temp1 += (temp2*(n - i)) % modd;
			ans = (ans+(temp1*a[i]) % modd)%modd;
			//cout << "ans: " << ans << endl;

		}
		cout << ans << endl;
	}
	return 0;
}


#include<iostream>

using namespace std;
#define modd 998244353
//#define
typedef long long ll;
//a是底数，b是指数，mode是取模数，sum是记录取模的结果
long long Mode(long long a, long long b, long long mode)
{
	if (b <0)return 0;
	long long sum = 1;
	while (b) {
		if (b & 1) {
			sum = (sum * a) % mode;
			b--;
		}
		b /= 2;
		a = a * a % mode;
	}
	return sum;
}
ll n;
ll a[1000005];

int main() {
	while (cin >> n) {
		for (int i = 1; i <= n; i++)scanf_s("%I64d",&a[i]);
			//cin >> a[i];
		ll ans = 0;
		ll temp1 = 0; ll temp2 = 0;
		for (int i = 1; i <= n; i++) {
			temp1 = Mode(2, n - i, modd);
			temp2 = temp1 / 2;  //不能改,..  他们是不一样的-.-
			//temp2 = Mode(2, n - i - 1, modd);
			//cout << "temp1 " << temp1 << " temp2 " << temp2 << endl;
			temp1 += (temp2*(n - i)) % modd;
			ans = (ans+(temp1*a[i]) % modd)%modd;
			//cout << "ans: " << ans << endl;

		}
		cout << ans << endl;
	}
	return 0;
}


#include<iostream>

using namespace std;
#define modd 998244353
//#define
typedef long long ll;
//a是底数，b是指数，mode是取模数，sum是记录取模的结果
long long Mode(long long a, long long b, long long mode)
{
	if (b <0)return 0;
	long long sum = 1;
	while (b) {
		if (b & 1) {
			sum = (sum * a) % mode;
			b--;
		}
		b /= 2;
		a = a * a % mode;
	}
	return sum;
}
ll n;
ll a[1000005];

int main() {
	while (cin >> n) {
		for (int i = 1; i <= n; i++)cin >> a[i];
		ll ans = 0;
		ll temp1 = 0; ll temp2 = 0;
		for (int i = 1; i <= n; i++) {
			temp1 = Mode(2, n - i, modd);
			temp2 = Mode(2, n - i - 1, modd);
			//cout << "temp1 " << temp1 << " temp2 " << temp2 << endl;
			temp1 += (temp2*(n - i)) % modd;
			ans = (ans+(temp1*a[i]) % modd)%modd;
			//cout << "ans: " << ans << endl;

		}
		cout << ans << endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
#define maxn 1000000
#define mod 998244353
int a[maxn+5];
long long  sum[maxn+5];
int main()
{
	int n;
	long long ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sum[0]=1;
	for(int i=1;i<=n;i++)
	{
		sum[i]=(sum[i-1]*2)%mod;
	}
	for(int i=1;i<=n;i++)
	{
		ans+=((sum[n-i]+sum[n-i-1]*(n-i)%mod)*a[i])%mod;
        ans%=mod;
	}
	printf("%I64d\n",ans%mod);
	return 0;

}


#include<iostream>
#include<cstdio>
using namespace std;
#define maxn 1000000
#define mod 998244353
int a[maxn+5];
int sum[maxn+5];
int main()
{
	int n;
	int ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sum[0]=1;
	for(int i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]*2%mod;
	}
	for(int i=1;i<=n;i++)
	{
		ans+=(sum[n-i]+sum[n-i-1]*(n-i)%mod)*a[i]%mod;
	}
	printf("%d\n",ans);
	return 0;

}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <iostream>
#include <utility>
#include <cmath>
#include <stack>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <tuple>

#define mod 998244353

using namespace std;

typedef long long ll;
typedef pair <int, int > ii;
typedef pair <ll, ll > pll;
typedef pair <ll, pll > ppll;
typedef map <string, int> si;

ll a[1000013], dp[1000013];

int main()
{
	ll n, ans = 0;
	cin >> n;
	dp[0] = 1;
	for (int i = 1; i <= n; i++)
		dp[i] = ((dp[i - 1] * 2) % mod + mod) % mod;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		ans = (ans + (a[i] * ( dp [n -i] + (dp[n - i - 1] * (n - i))% mod) % mod) % mod)% mod;
	}
	cout << ans;
	return 0;
}


#include <iostream>
#include <string.h>
#include <limits.h>

using namespace std;

static char _buf[1 << 16];
int _pos = 1;
int _cap = 1;

inline char nextChar()
{
	if (_cap == 0) return 0;
	if (_pos == _cap)
	{
		_cap = (int)fread(_buf, 1, 1 << 16, stdin);
		if (_cap == 0) return 0;
		_pos = 0;
	}
	return _buf[_pos++];
}

template <class T> T nextInt()
{
	char c = nextChar();
	while (isspace(c)) c = nextChar();
	int sign = 1;
	if (c == '-')
	{
		sign = -1;
		c = nextChar();
	}
	T res = 0;
	while (isdigit(c))
	{
		res = res * 10 + c - '0';
		c = nextChar();
	}
	return res * sign;
}

const long long m = 998244353;

inline long long Pow(long long a, long long b)
{
	long long res = 1;
	while (b)
	{
		if (b & 1) res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}

long long a[1000000];
long long p2[1000001];

int main()
{
	/*
		1 : 2 ^ n : 1
		2 : 2 ^ (n - 1) : 2, 2 ^ (n - 1) : 1
		3 : 2 ^ (n - 2) : 3, 2 ^ (n - 2) : 2, 2 ^ (n - 1) : 1
		4 : 2 ^ (n - 3) : 4, 2 ^ (n - 3) : 3, 2 ^ (n - 2) : 2, 2 ^ (n - 1) : 1
	*/

	int n = nextInt<int>();
	for (int i = 0; i < n; i++)
		a[i] = nextInt<int>();

	p2[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		p2[i] = p2[i - 1] + p2[i - 1];
		if (p2[i] >= m) p2[i] -= m;
	}

	long long res = 0;
	for (int i = 0; i < n; i++)
		res = (res + a[i] * p2[n - i]) % m;

	for (int i = 0; i < n; i++)
	{
		long long p = (a[i] * p2[n - i - 1]) % m;
		p = (p * (n - i - 1)) % m;
		res = res + p;
		if (res >= m) res -= m;
	}
	res = (res * Pow(2, m - 2)) % m;
	cout << res << endl;

	return 0;
}


#include <iostream>
#include <string.h>
#include <limits.h>

using namespace std;

static char _buf[1 << 16];
int _pos = 1;
int _cap = 1;

inline char nextChar()
{
	if (_cap == 0) return 0;
	if (_pos == _cap)
	{
		_cap = (int)fread(_buf, 1, 1 << 16, stdin);
		if (_cap == 0) return 0;
		_pos = 0;
	}
	return _buf[_pos++];
}

template <class T> T nextInt()
{
	char c = nextChar();
	while (isspace(c)) c = nextChar();
	int sign = 1;
	if (c == '-')
	{
		sign = -1;
		c = nextChar();
	}
	T res = 0;
	while (isdigit(c))
	{
		res = res * 10 + c - '0';
		c = nextChar();
	}
	return res * sign;
}

const long long m = 998244353;

inline long long Pow(long long a, long long b)
{
	long long res = 1;
	while (b)
	{
		if (b & 1) res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}

long long a[100000];

int main()
{
	/*
		1 : 2 ^ n : 1
		2 : 2 ^ (n - 1) : 2, 2 ^ (n - 1) : 1
		3 : 2 ^ (n - 2) : 3, 2 ^ (n - 2) : 2, 2 ^ (n - 1) : 1
		4 : 2 ^ (n - 3) : 4, 2 ^ (n - 3) : 3, 2 ^ (n - 2) : 2, 2 ^ (n - 1) : 1
	*/

	int n = nextInt<int>();
	for (int i = 0; i < n; i++)
		a[i] = nextInt<int>();

	long long res = 0;
	for (int i = 0; i < n; i++)
		res = (res + a[i] * Pow(2, n - i)) % m;

	for (int i = 0; i < n; i++)
	{
		long long p = (a[i] * Pow(2, n - i - 1)) % m;
		p = (p * (n - i - 1)) % m;
		res = res + p;
		if (res >= m) res -= m;
	}
	res = (res * Pow(2, m - 2)) % m;
	cout << res << endl;

	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
#define maxn 1000000
#define mod 998244353
long long a[maxn+5];
long long  sum[maxn+5];
int main()
{
	int n;
	long long ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d",&a[i]);
	}
	sum[0]=1;
	for(int i=1;i<=n;i++)
	{
		sum[i]=(sum[i-1]*2)%mod;
	}
	for(int i=1;i<=n;i++)
	{
		ans+=((sum[n-i]+sum[n-i-1]*(n-i)%mod)*a[i])%mod;
        ans%=mod;
	}
	printf("%I64d\n",ans%mod);
	return 0;

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const long long mod=998244353;
long long sum=0;
int a[1000005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        sum+=a[i]*(n-i+2)*pow(2.0,double(n-i-1));
    }
    cout<<sum%mod<<endl;
    return 0;
}


#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
const int modo=998244353;
int a[1000005];
int power2[1000005];
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n;
    scanf("%d",&n);
    int i;
    for (i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    power2[0]=1;
    for (i=1;i<=n;i++)
    {
        power2[i]=power2[i-1]*2%modo;
    }
    int ans=0;
    for (i=1;i<=n;i++)
    {
        ans=(ans+(long long)power2[n-i]*a[i-1])%modo;
        if (i!=n)
        {
            ans=(ans+(long long)(n-i)*power2[n-i-1]%modo*a[i-1])%modo;
        }
    }
    printf("%d\n",ans);
    return 0;
}


a = int(input())
b = list(map(int,input().split()))
c = b[0]
d = b[0]
for i in range(1,a):
    c = 2*c + d + b[i]
    d = 2*d + b[i]
print(c)


a = int(input())
b = list(map(int,input().split()))
def totDist(k):
    if k == 1:
        #print('for k: 1 i: 0 remaining dist: 0')
        return b[0]
    else:
        c = 0
        for i in range(1,k):
            d = totDist(k-i)
            e = sum(b[:i])
            c += e*(2**(k-i-1))+d
            #print('for k: '+str(k)+' i: '+str(i)+ ' covered distance: '+str(e)+' remaining dist: ' + str(d))
        c += sum(b[:k])
        return c
print(totDist(a)%998244353)


#!/usr/bin/env python
"""
This file is part of https://github.com/Cheran-Senthil/PyRival.

Copyright 2018 Cheran Senthilkumar all rights reserved,
Cheran Senthilkumar <hello@cheran.io>
Permission to use, modify, and distribute this software is given under the
terms of the MIT License.

"""
from __future__ import division, print_function

import cmath
import itertools
import math
import operator as op
# import random
import sys
from atexit import register
from bisect import bisect_left, bisect_right
# from collections import Counter, MutableSequence, defaultdict, deque
# from copy import deepcopy
# from decimal import Decimal
# from difflib import SequenceMatcher
# from fractions import Fraction
# from heapq import heappop, heappush

if sys.version_info[0] < 3:
    # from cPickle import dumps
    from io import BytesIO as stream
    # from Queue import PriorityQueue, Queue
else:
    # from functools import reduce
    from io import StringIO as stream
    from math import gcd
    # from pickle import dumps
    # from queue import PriorityQueue, Queue

if sys.version_info[0] < 3:
    class dict(dict):
        """dict() -> new empty dictionary"""
        def items(self):
            """D.items() -> a set-like object providing a view on D's items"""
            return dict.iteritems(self)

        def keys(self):
            """D.keys() -> a set-like object providing a view on D's keys"""
            return dict.iterkeys(self)

        def values(self):
            """D.values() -> an object providing a view on D's values"""
            return dict.itervalues(self)

    def gcd(x, y):
        """greatest common divisor of x and y"""
        while y:
            x, y = y, x % y
        return x

    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

def sync_with_stdio(sync=True):
    """Set whether the standard Python streams are allowed to buffer their I/O.

    Args:
        sync (bool, optional): The new synchronization setting.

    """
    global input, flush

    if sync:
        flush = sys.stdout.flush
    else:
        sys.stdin = stream(sys.stdin.read())
        input = lambda: sys.stdin.readline().rstrip('\r\n')

        sys.stdout = stream()
        register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

def main():
    n = int(input())
    a = list(map(int, input().split(' ')))

if __name__ == '__main__':
    sync_with_stdio(False)
    main()