#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]; constexpr int L = 46; unsigned dp[L][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); int S = 0; for (int i = 0; i < N; ++i) { S += A[i]; } const int T = S / 2; int lbs[110], ubs[110]; // K for (int i = 0; i <= N; ++i) { lbs[i] = max(0, K - (N - i)); ubs[i] = min(i, K); } #ifdef LOCAL memset(dp, 0, sizeof(dp)); #endif dp[0][0] = 1 % M; for (int i = 0; i < N; ++i) { for (int k = ubs[i + 1] - 1; k >= lbs[i]; --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 if (K == N - K) { for (int x = 0; x <= T; ++x) { ans[S - x] = dp[K][x]; } } else { for (int i = 0; i <= N; ++i) { lbs[i] = max(0, (N - K) - (N - i)); ubs[i] = min(i, (N - K)); } memset(dp, 0, sizeof(dp)); dp[0][0] = 1 % M; for (int i = 0; i < N; ++i) { for (int k = ubs[i + 1] - 1; k >= lbs[i]; --k) { const int pos0 = k % L; const int pos1 = (k + 1) % L; for (int x = 0; x + A[i] <= T; ++x) { Add(dp[pos1][x + A[i]], dp[pos0][x]); } } for (int k = lbs[i]; k < lbs[i + 1]; ++k) if (k + L <= N - K) { const int pos = k % L; memset(dp[pos], 0, (T + 1) * sizeof(dp[0][0])); } } { const int pos = (N - K) % L; for (int x = 0; x <= T; ++x) { ans[S - x] = dp[pos][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; }