#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 998244353;

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

  LL N;
  cin >> N;
  vector<LL> a(N);

  LL sum = 0;

  REP(i,N){
    cin >> a[i];
    sum += a[i];
  }
  //bound
  sum = (sum - 1) / 2 + 1;

  vector<vector<LL>> v(a.size()+1, vector<LL>(100001, 0));
  v[0][0] = 1;

  REP(i,a.size()){
    REP(j,90001){
      v[i + 1][j] += v[i][j]*2;
      v[i + 1][j+a[i]] += v[i][j];
      v[i + 1][j] %= mod;
      v[i + 1][j + a[i]] %= mod;
    }
  }

  LL ans = 1;

  REP(i,a.size()){
    ans *= 3;
    ans %= mod;
  }

  FOR(i,sum,90001){
    ans -= v[a.size()][i] * 3;
    ans %= mod;
    ans += mod;
    ans %= mod;
  }

  vector<vector<LL>> vv(a.size()+1, vector<LL>(100001, 0));
  vv[0][0] = 1;

  REP(i,a.size()){
    REP(j,90001){
      vv[i + 1][j] += vv[i][j];
      vv[i + 1][j+a[i]] += vv[i][j];
      vv[i + 1][j] %= mod;
      vv[i + 1][j + a[i]] %= mod;
    }
  }

  FOR(i,sum,90001){
    ans += vv[a.size()][i] * 3 *2;
    ans %= mod;
    ans += mod;
    ans %= mod;
  }

  LL cnt = 3;

  REP(i,a.size()){
    cnt *= 2;
    cnt %= mod;
  }

  ans -= cnt;
  ans %= mod;
  ans += mod;
  ans %= mod;

  cout << ans << endl;
}

#include<bits/stdc++.h>
#define inv(x) power(x,Mod-2)
#define upd(a,b) a=add(a,b)
using namespace std;
typedef long long ll;
const int Mod=1e9+7;
int add(int a,const int b){a+=b;if(a>=Mod)a-=Mod;return a;}
int sub(int a,const int b){a-=b;if(a<0)a+=Mod;return a;}
int mul(const int a,const int b){return (ll)a*b%Mod;}
int power(int x,int cs)
{
	int ras=1;
	while(cs)
	{
		if(cs&1) ras=mul(ras,x);
		x=mul(x,x);cs>>=1;
	}
	return ras;
}
const int N=2020;
int n,K,tot,ans=0;
int dp[N][N],sum[N],zp[N*N],fp[N*N];
int C(int a,int b)
{
	if(a<0||b<0||a<b) return 0;
	return mul(zp[a],mul(fp[b],fp[a-b]));
}
int main()
{
	int i,j;
	scanf("%d%d",&n,&K);
	if(K==1)
	{
		puts("1");
		return 0;
	}
	tot=n*K;
	zp[0]=fp[0]=1;
	for(i=1;i<=tot;i++) zp[i]=mul(zp[i-1],i);
	fp[tot]=inv(zp[tot]);
	for(i=tot-1;i>=1;i--) fp[i]=mul(fp[i+1],i+1);
	dp[1][0]=1;
	for(i=2;i<=n;i++)
	{
		memset(sum,0,sizeof(sum));
		for(j=0;j<=i;j++)
		{
			if(j>0) sum[j]=sum[j-1];
			upd(sum[j],dp[i-1][j]);
		}
		for(j=0;j<i;j++)
		{
			upd(dp[i][j],mul(sum[j],C(i*(K-1)+j-1,K-2)));
		}
	}
	for(i=0;i<=n;i++) upd(ans,dp[n][i]);
	ans=mul(ans,zp[n]);
	printf("%d",ans);
	return 0;
}