#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define ll long long
#define ull unsigned long long
#define y1 orzkcz
using namespace std;

const int mo=1000000007;
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
int main(){
	int S=0,n,m,x;
	scanf("%d%d",&n,&m);
	For(i,1,n) scanf("%d",&x),m++,S+=x+1;
	int s1=1,s2=1;
	For(i,1,S){
		s1=1ll*s1*i%mo;
		s2=1ll*s2*(m+1-i)%mo;
	}
	cout<<1ll*s2*power(s1,mo-2)%mo<<endl;
}
//#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9+7; //998244353;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}
//using mint = atcoder::modint1000000007;

struct Segtree{
	typedef ll sgT;
	vector<sgT> seg;
	int nbn; sgT INF;
	void init(int n){
		for(nbn=1; nbn<n+2; nbn<<=1); INF=1LL<<61; // min:+inf,max:-inf,0 
		seg.assign(nbn*2, INF);
	}
	sgT comp(sgT l, sgT r){return min(l, r);}  //min<->max
	void update(int k,sgT x){
		k+=nbn-1; seg[k]=x;
		while(k>0){ k=(k-1)/2; seg[k]=comp(seg[k*2+1],seg[k*2+2]); }
	}
	sgT query2(int a,int b,int l,int r,int k){
		if(b<=l||r<=a) return INF;
		if(a<=l&&r<=b) return seg[k];
		return comp(query2(a,b,l,(l+r)/2,k*2+1), query2(a,b,(l+r)/2,r,k*2+2));
	}
	sgT query(int a,int b){ return query2(a,b,0,nbn,0); }
	sgT get(int a){return seg[nbn+a-1];}  // =query(a,a+1)

	int posLeft(sgT v, int l, int r ){//v以上の右端rで最左位置を求める
		int lo=l-1, hi=r;
		while(hi - lo >1){
			int md = (hi + lo) >> 1;
			if( query(md, r+1) == v ) hi = md; else lo = md; 
		}
		return hi;
	}
	int posRight(sgT v, int l, int r ){ //v以上の左端lで最右位置を求める
		int lo=l-1, hi=r;
		while(hi - lo >1){
			int md = (hi + lo) >> 1;
			if( query(l, md+1) == v ) lo = md; else hi = md; 
		}
		return lo;
	}
};
	


int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	map<int, int> mp;
	rep(i, n) mp[a[i]] = i;
	Segtree sg; sg.init(n);
	rep(i, n) sg.update(i, a[i]);
	ll ans =0;
	
	rep(i, n){
		ll cr = a[i];
		int ps1 = sg.posLeft(cr, 0, i);
		int ps2 = sg.posRight(cr, i, n);

		ans = max(ans, cr * (ps2+1-ps1));
	}
	cout <<ans <<"\n";
	return 0;
}