/* Author haleyk10198 */
/* 作者: haleyk10198 */
/* CF handle: haleyk100198*/
#include <bits/stdc++.h>
#define MOD 1000000007
#define LINF (1LL<<60)
#define INF 2147483647
#define PI 3.1415926535897932384626433
#define ll long long
#define pii pair<int,int>
#define mp(x,y) make_pair((x),(y))
#define pb(x) push_back((x))
using namespace std;
string itos(int x){
stringstream ss;
ss << x;
return ss.str();
}
int res, n, d[55], dp[55][55], sum[55];
int pwr(int b, int e){
if(e == 0) return 1;
if(e == 1) return b;
return (1LL*pwr((1LL*b*b)%MOD, e/2)*pwr(b, e%2))%MOD;
}
void upd(int &tar, int val){
(tar += val) %= MOD;
}
int help(int l, int r, int deb1, int deb2){
if(deb1 < 0 || deb2 < 0) return 0;
if(l > r)
return deb1 == 0 && deb2 == 0;
int res = 0, deb = deb1+deb2;
vector<int> v1(4), v2(4);
v1[0] = 1, v1[1] = deb1, v1[2] = (deb1-1)*deb1/2, v1[3] = (deb1-2)*(deb1-1)*deb1/6;
v2[0] = 1, v2[1] = deb1, v2[2] = (deb2-1)*deb2/2, v2[3] = (deb2-2)*(deb2-1)*deb2/6;
for(int ret = d[l]; ret >= 0; ret--){
if(ret == d[l])
for(int j = 0; j <= ret; j++)
upd(res, (1LL*v1[j]*v2[ret-j]*help(l+1, r, deb1-j+(ret-j), deb2-(ret-j)))%MOD);
else if(ret == 0)
upd(res, help(l+1, r, deb1+(d[l] == 1), deb2+(d[l] == 2)));
else
upd(res, (1LL*deb1*help(l+1, r, deb1, deb2)+1LL*deb2*help(l+1, r, deb1+2, deb2-1))%MOD);
}
return res;
}
int dpf(int l, int r){
if(r == n-1) return 1;
if(r >= n) return 0;
if(dp[l][r] != -1) return dp[l][r];
dp[l][r] = 0;
for(int i = 1; i <= min(n-1-r, sum[r+1]-sum[l]); i++){
int val = help(l, r, i, 0);
if(val)
(dp[l][r] += (1LL*val*dpf(r+1, r+i))%MOD) %= MOD;
}
return dp[l][r];
}
int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin >> n;
for(int i = 0; i < 55; i++) for(int j = 0; j < 55; j++) dp[i][j]--;
for(int i = 0; i < n; i++)
cin >> d[i];
for(int i = 1; i < n; i++) d[i]--;
for(int i = 1; i <= n; i++) sum[i] = sum[i-1]+d[i-1];
cout << dpf(0, 0) << endl;
return 0;
}
LyogQXV0aG9yIGhhbGV5azEwMTk4ICovCi8qIOS9nOiAhTogIGhhbGV5azEwMTk4ICovCi8qIENGIGhhbmRsZTogaGFsZXlrMTAwMTk4Ki8KI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIE1PRCAxMDAwMDAwMDA3CiNkZWZpbmUgTElORiAoMUxMPDw2MCkKI2RlZmluZSBJTkYgMjE0NzQ4MzY0NwojZGVmaW5lIFBJIDMuMTQxNTkyNjUzNTg5NzkzMjM4NDYyNjQzMwojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIHBpaSBwYWlyPGludCxpbnQ+CiNkZWZpbmUgbXAoeCx5KSBtYWtlX3BhaXIoKHgpLCh5KSkKI2RlZmluZSBwYih4KSBwdXNoX2JhY2soKHgpKQoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cmluZyBpdG9zKGludCB4KXsKCXN0cmluZ3N0cmVhbSBzczsKCXNzIDw8IHg7CglyZXR1cm4gc3Muc3RyKCk7Cn0KCmludCByZXMsIG4sIGRbNTVdLCBkcFs1NV1bNTVdLCBzdW1bNTVdOwoKaW50IHB3cihpbnQgYiwgaW50IGUpewoJaWYoZSA9PSAwKSByZXR1cm4gMTsKCWlmKGUgPT0gMSkgcmV0dXJuIGI7CglyZXR1cm4gKDFMTCpwd3IoKDFMTCpiKmIpJU1PRCwgZS8yKSpwd3IoYiwgZSUyKSklTU9EOwp9Cgp2b2lkIHVwZChpbnQgJnRhciwgaW50IHZhbCl7CgkodGFyICs9IHZhbCkgJT0gTU9EOwp9CgppbnQgaGVscChpbnQgbCwgaW50IHIsIG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