#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 998244353;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

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

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

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

ll modpower(ll x, ll y) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else if (y % 2 == 0) {
        ll p = modpower(x, y / 2);
        return p * p % mod;
    } else {
        ll p = modpower (x, y / 2);
        return (p * p) % mod * (x % mod) % mod;
    }
}

ll dp[310][90010];
ll dpb[310][90010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll a[N];
    ll sum = 0;
    REP(i, 0, N) {
        cin >> a[i];
        sum += a[i];
    }
    dp[0][0] = 1;
    dpb[0][0] = 1;
    REP(i, 0, N) {
        REP(j, 0, 90000) {
            dp[i + 1][j] = modadd(dp[i + 1][j], multiply(dp[i][j], 2));
            dpb[i + 1][j] = modadd(dpb[i + 1][j], dpb[i][j]);
            if (j + a[i] <= 90000) {
                dp[i + 1][j + a[i]] = modadd(dp[i + 1][j + a[i]], dp[i][j]);
                dpb[i + 1][j + a[i]] = modadd(dpb[i + 1][j + a[i]], dpb[i][j]);
            }
        }
    }
    ll dis = 0;
    ll disa = 0;
    REP(i, (sum + 1) / 2, sum) {
        dis = modadd(dis, dp[N][i]);
    }
    dis = multiply(dis, 3);
    if (sum % 2 == 0) {
        disa = dpb[N][sum / 2];
    }
    disa = multiply(disa, 3);
    ll base = modadd(modpower(3, N), -3);
    ll ans = modadd(base, - modadd(dis, - disa));
    cout << ans << endl;
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MOD = 1000000007;

int main(){
    const int maxSize = 100001;
    vector<long long> inv(maxSize);
    vector<long long> fact(maxSize);
    vector<long long> factInv(maxSize);
    for(int i=0;i<2;i++) inv[i] = fact[i] = factInv[i] = 1;
    for(int i=2;i<maxSize;i++){
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
        fact[i] = fact[i-1] * i % MOD;
        factInv[i] = factInv[i-1] * inv[i] % MOD;
    }
    int N, X; cin >> N >> X;
    vector<int> S(N);
    for(auto& t : S) cin >> t;
    sort(S.begin(), S.end());
    vector<int> sum(100001, 0);
    for(auto& t : S) sum[t] = 1;
    for(int i=1;i<=100001;i++) sum[i] += sum[i-1];
    vector dp(X+1, vector(N+1, 0LL));
    dp[X][N-sum[X]] = 1;
    for(int i=X;i>=S[0];i--){
        for(int j=N;j>=0;j--){
            if(!dp[i][j]) continue;
            if(j > 0){
                dp[i][j-1] += dp[i][j] * j;
                dp[i][j-1] %= MOD;
            }
            for(int k=0;k<sum[i];k++){
                int dst = i%S[k];
                int add = sum[i] - sum[dst] - 1;
                dp[dst][j+add] += dp[i][j];
                dp[dst][j+add] %= MOD;
            }
        }
    }
    long long res = 0;
    for(int i=1;i<S[0];i++){
        for(int j=0;j<=N;j++){
            res += dp[i][j] * fact[j] % MOD * i % MOD;
            res %= MOD;
        }
    }
    cout << res << endl;
}