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
//Franciszek Witt
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(int i=(l);i<=(r);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) int(x.size())
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#ifdef DEBUG
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif
typedef long long ll;
const int mod = int(1e9) + 7;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    auto add = [&](int x, int y) {
        int r = x + y;
        if(r >= mod)
            r -= mod;
        return r;
    };

    auto murL = [&] (vector<int> &v) {
        int n = ssize(v);
        assert(n > 3);
        for(int i = n - 3; i >= 2; i -= 2)
            v[i] = add(v[i - 1], v[i - 2]);
        v[2] = add(v[2], v[n - 1]);
    };
    auto murP = [&] (vector<int> &v) {
        int n = ssize(v);
        assert(n > 3);
        for(int i = 1; i <= n - 4; i += 2)
            v[i] = add(v[i + 1], v[i + 2]);
    };

    auto mulL = [&] (vector<int> &v) {
        int n = ssize(v);
        assert(n > 3);
        v[0] = add(v[0], v[2]);
        v[n - 1] = add(v[n - 1], v[2]);
        for(int i = 1; i <= n - 4; i += 2)
            v[i] = add(v[i], v[i + 1]);
        for(int i = 2; i <= n - 5; i += 2)
            v[i] = v[i + 2];
    };

    auto mulR = [&] (vector<int> &v) {
        int n = ssize(v);
        assert(n > 3);
        v[n - 2] = add(v[n - 2], v[n - 4]);
        for(int i = n - 3; i >= 2; i -= 2)
            v[i] = add(v[i], v[i - 1]);
        for(int i = n - 4; i >= 3; i -= 2)
            v[i] = v[i - 2];
        v[1] = 0;        
    };

    auto bruter = [&] (string s) {
        int n = ssize(s);
        vector<int> dp(2 * (n + 1) + 1);
        dp.back() = 1;
        for(auto e : s) {
            if(e == 'L')
                murL(dp);
            else
                murP(dp);
        }
        return dp;
    };

    auto brutel = [&] (string s) {
        int n = ssize(s);
        vector<int> dp(2 * (n + 1) + 1);
        dp[0] = dp[1] = 1;
        reverse(s.begin(), s.end());
        for(auto e : s) {
            if(e == 'L')
                mulL(dp);
            else
                mulR(dp);
        }
        return dp;
    };

    auto comb = [&] (vector<int> &v0, vector<int> &v1) {
        debug(v0, v1);
        ll res = 0;
        int n = min(ssize(v0), ssize(v1)) - 1;
        REP(i, n)
            res = (res + ll(v0[i]) * v1[i]) % mod;
        res += ll(v0.back()) * v1.back();
        res %= mod;
        return res;
    };

/*
    int n;
    cin >> n;
    assert(n & 1);
    vector<int> v(n);
    for(auto &i : v)
        cin >> i;
    mulR(v);
    for(auto i : v)
        cout << i << " ";
    cout << endl;*/
    /*
    string s1, s2;
    cin >> s1 >> s2;
    auto r = bruter(s1), l = brutel(s2);
    debug(r);
    debug(l);
    cout << comb(r, l) << endl;;
    */
    int n;
    cin >> n;
    vector<vector<int>> vr(n), vl(n);
    vector<string> vs(n);
    for(auto &i : vs)
        cin >> i;
    REP(i, n) {
        vr[i] = bruter(vs[i]);
        vl[i] = brutel(vs[i]);
    }
    REP(i, n) {
        REP(j, n)
            cout << comb(vr[i], vl[j]) << " ";
        cout << endl;
    }
}