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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#include <bits/stdc++.h>
#define dbg(x) " [" << #x << ": " << (x) << "] "
using namespace std;
using ll = long long;
template<typename A, typename B>
ostream& operator<<(ostream& out, const pair<A,B>& p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& c) {
    out << "{";
    for(auto it = c.begin(); it != c.end(); it++) {
        if(it != c.begin()) out << ", ";
        out << *it;
    }
    return out << "}";
}

template<int MOD, int RT> struct mint {
    static const int mod = MOD;
    static constexpr mint rt() {
        return RT;
    }
    int v;
    explicit operator int() const {
        return v;
    }
    mint() : v(0) {}
    mint(ll _v) {
        v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
        if(v < 0) v += MOD;
    }
    bool operator==(const mint& o) const {
        return v == o.v;
    }
    friend bool operator!=(const mint& a, const mint& b) {
        return !(a == b);
    }
    friend bool operator<(const mint& a, const mint& b) {
        return a.v < b.v;
    }

    mint& operator+=(const mint& o) {
        if((v += o.v) >= MOD) v -= MOD;
        return *this;
    }
    mint& operator-=(const mint& o) {
        if((v -= o.v) < 0) v += MOD;
        return *this;
    }
    mint& operator*=(const mint& o) {
        v = int((ll)v * o.v % MOD);
        return *this;
    }
    mint& operator/=(const mint& o) {
        return (*this) *= inv(o);
    }
    friend mint pow(mint a, ll p) {
        mint ans = 1;
        assert(p >= 0);
        for(; p; p /= 2, a *= a) {
            if(p & 1) ans *= a;
        }
        return ans;
    }
    friend mint inv(const mint& a) {
        assert(a.v != 0);
        return pow(a, MOD - 2);
    }

    mint operator-() const { return mint(-v); }
    mint& operator++() { return *this += 1; }
    mint& operator--() { return *this -= 1; }
    friend mint operator+(mint a, const mint& b) { return a += b; }
    friend mint operator-(mint a, const mint& b) { return a -= b; }
    friend mint operator*(mint a, const mint& b) { return a *= b; }
    friend mint operator/(mint a, const mint& b) { return a /= b; }
};

template<class T>
void fft(vector<T>& a, bool invert = 0) {
    int n = a.size();
    assert((T::mod - 1) % n == 0);
    vector<T> b(n);
    for(int p = n / 2; p; p /= 2, swap(a, b)) {
        T w = pow(T::rt(), (T::mod-1) / n * p);
        T m = 1;
        for(int i = 0; i < n; i += p * 2, m *= w) {
            for(int j = 0; j < p; j++) {
                T u = a[i + j];
                T v = a[i + j + p] * m;
                b[i / 2 + j] = u + v;
                b[i / 2 + j + n / 2] = u - v;
            }
        }
    }
    if(invert) {
        reverse(a.begin() + 1, a.end());
        T z = inv(T(n));
        for(auto& t : a) t *= z;
    }
}

template<class T>
vector<T> conv(vector<T> a, vector<T> b) {
    if(!min(a.size(), b.size())) return {};
    int s = a.size() + b.size() - 1;
    int n = 1;
    while(n < s) n *= 2;
    a.resize(n);
    fft(a);
    b.resize(n);
    fft(b);
    for(int i = 0; i < n; i++) {
        a[i] *= b[i];
    }
    fft(a,1);
    a.resize(s);
    return a;
}

template<class M, class T>
vector<M> mulMod(const vector<T>& x, const vector<T>& y) {
    auto con = [](const vector<T>& v) {
        vector<M> w(v.size());
        for(int i = 0; i < v.size(); i++) {
            w[i] = (int)v[i];
        }
        return w;
    };
    return conv(con(x), con(y));
}

template<class T> vector<T> conv_general(const vector<T>& A, const vector<T>& B) {
    using m0 = mint<(119<<23)+1, 62>;
    auto c0 = mulMod<m0>(A, B);
    using m1 = mint<(5<<25)+1, 62>;
    auto c1 = mulMod<m1>(A, B);
    using m2 = mint<(7<<26)+1, 62>;
    auto c2 = mulMod<m2>(A, B);
    int n = c0.size();
    vector<T> res(n);
    m1 r01 = inv(m1(m0::mod));
    m2 r02 = inv(m2(m0::mod));
    m2 r12 = inv(m2(m1::mod));
    for(int i = 0; i < n; i++) {
        int a = c0[i].v;
        int b = ((c1[i] - a) * r01).v;
        int c = (((c2[i] - a) * r02 - b) * r12).v;
        res[i] = (T(c) * m1::mod + b) * m0::mod + a;
    }
    return res;
}

vector<vector<int>> num;
vector<vector<int>> u;
vector<int> pw2;

int surreal(int msk, int n) {
    if(u[n][msk]) return num[n][msk];
    if(n == 0) return 0;
    int l = -1e9;
    int r = 1e9;

    if(msk == 0) {
        num[n][msk] = n * pw2[n];
        u[n][msk] = 1;
        return num[n][msk];
    } else if(msk + 1 == pw2[n]) {
        num[n][msk] = -n * pw2[n];
        u[n][msk] = 1;
        return num[n][msk];
    }

    int pref = 0;
    for(int i = 0; i < n; i++) {
        int x = surreal(pref, i) * pw2[n - i];
        if(msk & (1 << i)) {
            r = min(r, x);
            pref += pw2[i];
        } else {
            l = max(l, x);
        }
    }

    num[n][msk] = l + (r - l) / 2;
    u[n][msk] = 1;
    return num[n][msk];
}

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

    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<int>> v(k, vector<int>(m));
    for(int i = 0; i < k; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < m; j++) {
            if(s[j] == 'C') v[i][j] = 1;
        }
    }

    pw2.resize(m + 1);
    pw2[0] = 1;
    for(int i = 1; i <= m; i++) {
        pw2[i] = 2 * pw2[i - 1];
    }
    num.resize(m + 1);
    u.resize(m + 1);
    for(int i = 0; i <= m; i++) {
        num[i].resize(1 << i);
        u[i].resize(1 << i);
    }

    ll sum = 0;
    for(int i = 0; i < k; i++) {
        int msk = 0;
        for(int j = 0; j < m; j++) {
            if(v[i][j]) msk += pw2[j];
        }
        sum += surreal(msk, m);
    }
    sum = -sum;

    int bound = m * pw2[m];
    vector<ll> cnt(2 * bound + 1);

    for(int msk = 0; msk < (1 << m); msk++) {
        int x = surreal(msk, m);
        cnt[x + bound]++;
    }

    const int mod = 1e9 + 7;

    vector<ll> res = {1};
    for(int rep = 0; rep <= n - k; rep++) {
        int i = bound * rep + sum;
        int x = 0;
        if(0 <= i && i < res.size()) x = res[i];
        if(rep) cout << " ";
        cout << x;
        if(rep < n - k) {
            res = conv_general(res, cnt);
            for(int i = 0; i < res.size(); i++) {
                res[i] %= mod;
            }
        }
    }
    cout << endl;

    return 0;
}