#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

const LL M = 1e9 + 7;

LL a[3005];

LL dp[3005][3005];
LL fix[3005];

// dp[k][r] 代表 k 節，剩餘 r

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	dp[1][0] = 1;
	int mk = 1;
	for (int i = 2; i <= n; i++) {
		for (int k = mk + 1; k >= 2; k--) {
			fix[k] += a[i];
			fix[k] %= k;
			// printf("k = %d, dp[k - 1][k - 2 - fix[k - 1]] = %d\n", k, dp[k - 1][k - 2 - fix[k - 1]]);
			if (dp[k - 1][(k - 1 - fix[k - 1]) % (k - 1)]) {
				dp[k][(a[i] + k - fix[k]) % k] += dp[k - 1][(k - 1 - fix[k - 1]) % (k - 1)];
				dp[k][(a[i] + k - fix[k]) % k] %= M;
				mk = max(mk, k);
			}
		}
		// printf("##################### i = %d\n", i);
		// for (int k = 1; k <= mk; k++) {
		// 	printf("k = %d, fix[k] = %lld\n", k, fix[k]);
		// 	for (int r = 0; r < k; r++) {
		// 		printf("dp[%d][%d] = %lld\n", k, r, dp[k][r]);
		// 	}
		// }
	}
	LL sum = 0;
	for (int k = 1; k <= n; k++) {
		sum += dp[k][(k - fix[k]) % k];
		sum %= M;
	}
	printf("%lld\n", sum);
}

#include<stdio.h>
const int MOD=998244353;
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=(c==45),c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x%10+48);}
static inline int MPow(int a,int b){return b?1l*MPow(1l*a*a%MOD,b>>1)*(b&1?a:1)%MOD:1;}
int main(void)
{
  int N=IN(),M=IN(),K=IN(),total=0,x=0;
  if(N==1||M==1){return OUT(MPow(K,N>M?N:M)),0;}
  while(++x<=K){total=(1l*total+1l*(1l*MPow(x,N)+MOD-MPow(x-1,N))%MOD*MPow(K-x+1,M)%MOD)%MOD;}
  return OUT(total),0;
}