1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> C;
typedef vector<double> vd;

#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const ll Mod = 1000LL * 1000LL * 1000LL + 7LL;
int D;
int K = 0;
const int N = 1000 * 1000 + 7;
vl wzo, dp;

void fft(vector<C>& a) {
    int n = sz(a), L = 31 - __builtin_clz(n);
    static vector<complex<long double>> R(2, 1);
    static vector<C> rt(2, 1);  // (^ 10% faster if double)
    for (static int k = 2; k < n; k *= 2) {
        R.resize(n); rt.resize(n);
        auto x = polar(1.0L, acos(-1.0L) / k);
        rep(i,k,2*k) rt[i] = R[i] = i&1 ? R[i/2] * x : R[i/2];
    }
    vi rev(n);
    rep(i,0,n) rev[i] = (rev[i / 2] | (i & 1) << L) / 2;
    rep(i,0,n) if (i < rev[i]) swap(a[i], a[rev[i]]);
    for (int k = 1; k < n; k *= 2)
        for (int i = 0; i < n; i += 2 * k) rep(j,0,k) {
            // C z = rt[j+k] * a[i+j+k]; // (25% faster if hand-rolled)  /// include-line
            auto x = (double *)&rt[j+k], y = (double *)&a[i+j+k];        /// exclude-line
            C z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]);           /// exclude-line
            a[i + j + k] = a[i + j] - z;
            a[i + j] += z;
        }
}

template<int M> vl convMod(const vl &a, const vl &b) {
    if (a.empty() || b.empty()) return {};
    vl res(sz(a) + sz(b) - 1);
    int B=32-__builtin_clz(sz(res)), n=1<<B, cut=int(sqrt(M));
    vector<C> L(n), R(n), outs(n), outl(n);
    rep(i,0,sz(a)) L[i] = C((int)a[i] / cut, (int)a[i] % cut);
    rep(i,0,sz(b)) R[i] = C((int)b[i] / cut, (int)b[i] % cut);
    fft(L), fft(R);
    rep(i,0,n) {
        int j = -i & (n - 1);
        outl[j] = (L[i] + conj(L[j])) * R[i] / (2.0 * n);
        outs[j] = (L[i] - conj(L[j])) * R[i] / (2.0 * n) / 1i;
    }
    fft(outl), fft(outs);
    rep(i,0,sz(res)) {
        ll av = ll(real(outl[i])+.5), cv = ll(imag(outs[i])+.5);
        ll bv = ll(imag(outl[i])+.5) + ll(real(outs[i])+.5);
        res[i] = ((av % M * cut + bv) % M * cut + cv) % M;
    }
    return res;
}

inline int W(string s, int m)
{
    int ans = 0, cur = (1<<(m - 1));
    bool xd = false;
    for(int i = 0; i < m; ++i)
    {
        if(i != 0 && s[i] != s[i - 1]) xd = true;
        if(xd) cur /= 2;
        if(s[i] == 'C')
            ans += cur;
        else
            ans -= cur;
    }
    return ans;
}

void Solve()
{
    int n, m, k, curv = 0;
    string s;
    cin >> n >> m >> k;
    for(int i = 1; i <= k; ++i)
    {
        cin >> s;
        curv += W(s, m);
    }
    //cout << curv << "\n";
    K = -curv;
    dp.pb(1LL);
    D = (1<<(m - 1)) * m;
    for(int j = 0; j <= 2 * D + 1; ++j) wzo.pb(0);
    for(int i = 0; i < (1<<m) / 2; ++i)
    {
        s.clear();
        for(int j = 0; j < m; ++j)
            if((1<<j)&i)
                s.pb('C');
            else
                s.pb('N');
        int cur = W(s, m);
        wzo[cur + D] = 1;
        wzo[-cur + D] = 1;
    }
    //cout << wzo[curv + D] << "\n";
    if(curv == 0)
        cout << 1 << " ";
    else
        cout << 0 << " ";
    for(int l = k + 1; l <= n; ++l)
    {
        while(__builtin_popcount((int)dp.size()) > 1 || dp.size() < wzo.size())
            dp.pb(0);
        while(wzo.size() < dp.size())
            wzo.pb(0);
        dp = convMod<Mod>(dp, wzo);
        K += D;
        while(dp.back() == 0) dp.pop_back();
        if(K >= 0 && K < (int)dp.size())
            cout << dp[K] << " ";
        else
            cout << 0 << " ";
    }
    cout << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //int t; cin >> t;
    //while(t--)
        Solve();

    return 0;
}