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
// Author: Kajetan Ramsza
#include "bits/stdc++.h"

using namespace std;

template<typename F, typename S> ostream& operator<<(ostream& os, const pair<F, S> &p) { return os<<"("<<p.first<<", "<<p.second<<")"; }
template<typename T> ostream &operator<<(ostream & os, const vector<T> &v) { os << "{"; typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "}"; }

void dbg_out() { cerr<<'\n'; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr<<' '<<H; dbg_out(T...); }

#ifdef DEBUG
#define dbg(...) cerr<<"(" << #__VA_ARGS__ <<"):", dbg_out(__VA_ARGS__)
#else
#define dbg(...) 
#endif

typedef long long ll;

const int maxn = 1207;
const ll mod = 1e9 + 7;

ll lastp[maxn];
ll lastl[maxn];
ll val[maxn];

ll backup[maxn][3];

void print(int maxi) {
    cout<<"val: ";
    for(int i=0;i<maxi;i++) {
        cout<<val[i]<<' ';
    }
    cout<<'\n';
}

void add(bool left, int maxi) {
    if(left) {
        dbg(maxi);
        for(int i=maxi-1;i>0;i--) {
            lastl[i] = val[i];
            val[i] = (val[i] + val[i-1] - lastl[i-1] + mod) % mod;
        }
        lastl[0] = val[0];
    } else {
        for(int i=0;i<maxi-1;i++) {
            lastp[i] = val[i];
            val[i] = (val[i] + val[i+1] - lastp[i+1] + mod) % mod;
        }
        lastp[maxi-1] = val[maxi-1]; 
    }    
}
vector<string> vec;

ll solve(int ind, int &maxi, int m) {
    // dbg(vec[ind1] + vec[ind2]);
    dbg(vec[ind]);
    int n = vec[ind].size();
    // vector<ll> res(n+1, 0);
    // lastp.assign(n+1,0);
    // lastl.assign(n+1,0);
    for(int i=0;i<n;i++) {
        // dbg(i, res,"  ");
        // dbg(lastl,"");
        // dbg(lastp,"");
        // dbg("------------");
        bool left = vec[ind][i] == 'L';
        maxi += left;
        add(left, min(maxi, (n+m-i) + 1)+1);
        dbg(maxi);
        // print(min(maxi, (n+m-i) + 1)+1);
    }
    return val[0] - 1;
}

void clear(int n) {
    fill(val, val + n, 0);
    fill(lastl, lastl + n, 0);
    fill(lastp, lastp + n, 0);
    val[0] = 1;
}

void backupres(int n) {
    for(int i=0;i<=n;i++) {
        backup[i][0] = val[i];
        backup[i][1] = lastl[i];
        backup[i][2] = lastp[i];
    }
}

void loadfrombackup(int n) {
    for(int i=0;i<=n;i++) {
        val[i] = backup[i][0];
        lastl[i] = backup[i][1];
        lastp[i] = backup[i][2];
    }
}

int n;

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

    cin>>n;
    vec.resize(n);
    for(int i=0;i<n;i++) {
        cin>>vec[i];
    }
    // const int limit = 30;
    for(int i=0;i<n;i++) {
        // if(i % limit == 0) 
            // cerr<<"i: "<<i<<'\n';
        int maxi = 0;
        clear(maxn);
        solve(i,maxi,maxn);
        backupres(vec[i].size());
        for(int j=0;j<n;j++) {
            // dbg(i, j);
            // cout<<solve(i, j)<<' ';
            
            int m = maxi;
            cout<<solve(j,m,vec[i].size())<<' ';
            loadfrombackup(vec[i].size());
            // cout<<solve(vec[i] + vec[j])<<' ';
        }
        cout<<'\n';
    } 
}