#pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } unsigned M; void Add(unsigned &t, unsigned f) { t += f; t = (t >= M) ? (t - M) : t; } void Sub(unsigned &t, unsigned f) { t -= f; t = (t >= M) ? (t + M) : t; } int N, K; int A[110]; int S, T; unsigned dp[47][50'010]; unsigned ans[100'010]; int main() { for (; ~scanf("%d%u%d", &N, &M, &K); ) { for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); } sort(A, A + N); const bool rev = chmin(K, N - K); S = 0; for (int i = 0; i < N; ++i) { S += A[i]; } T = S / 2; #define S do_not_use_S // <= K #ifdef LOCAL memset(dp, 0, sizeof(dp)); #endif dp[0][0] = 1 % M; for (int i = 0; i < N; ++i) { for (int k = min(i, K - 1); k >= 0; --k) { for (int x = 0; x + A[i] <= T; ++x) { Add(dp[k + 1][x + A[i]], dp[k][x]); } } } for (int x = 0; x <= T; ++x) { ans[x] = dp[K][x]; } // >= N - K memset(dp, 0, sizeof(dp)); dp[0][0] = 1 % M; for (int i = 0; i < K + 1; ++i) { for (int k = i; k >= 0; --k) { for (int x = 0; x + A[i] <= T; ++x) { Add(dp[k + 1][x + A[i]], dp[k][x]); } } } for (int i = K + 1; i < N; ++i) { // discard k + (N - i) = N - K - 1 const int k0 = (i - K - 1) % (K + 2); memset(dp[k0], 0, (T + 1) * sizeof(dp[0][0])); for (int k = k0 - 1; k >= 0; --k) { for (int x = 0; x + A[i] <= T; ++x) { Add(dp[k + 1][x + A[i]], dp[k][x]); } } if (k0 != K + 1) { for (int x = 0; x + A[i] <= T; ++x) { Add(dp[0][x + A[i]], dp[K + 1][x]); } } for (int k = K; k > k0; --k) { for (int x = 0; x + A[i] <= T; ++x) { Add(dp[k + 1][x + A[i]], dp[k][x]); } } } #undef S for (int x = 0; x <= T; ++x) { ans[S - x] = dp[(N - K) % (K + 2)][x]; } if (rev) { reverse(ans, ans + (S + 1)); } for (int x = 1; x <= S; ++x) { if (x > 1) printf(" "); printf("%u", ans[x]); } puts(""); } return 0; }