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
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define TRAV(x, v) for(auto &x: v)
#define PB push_back
#define SZ(x) ((int)x.size())
#define X first
#define Y second

using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;

constexpr int mod = 1e9 + 7;

int licz(string s) {
    int MAXB = SZ(s) / 2 + 1;
    vector<int> lastL(MAXB), lastR(MAXB);
    vector<int> ans(MAXB);
    ans[0] = 1;
    FOR(j, 0, SZ(s)) {
        vector<int> newAns = ans;
        if(s[j] == 'L') {
            FOR(i, 1, MAXB) newAns[i] = (1ll * newAns[i] + ans[i - 1] - lastL[i - 1] + mod) % mod;
            lastL = ans;
        }
        else {
            FOR(i, 0, MAXB - 1) newAns[i] = (1ll * newAns[i] + ans[i + 1] - lastR[i + 1] + mod) % mod;
            lastR = ans;
        }
        ans = newAns;
    }
    return ans[0] - 1;
}

void solve() {
    int n;
    cin >> n;
    vector<string> s(n);
    TRAV(x, s) cin >> x;
    FOR(i, 0, n) FOR(j, 0, n) cout << licz(s[i] + s[j]) << " \n"[j + 1 == n];
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // int tt; cin >> tt;
    // FOR(te, 0, tt) {
    //     // cout << "Case #" << te + 1 << ": ";
    //     solve();
    // }
    solve();
    return 0;
}