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
#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
int n;
string s[607];
int high[1207][2];
int low[1207][2];
int res[2];

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

    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> s[i];
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 607; j++){
            high[j][0] = 0;
            high[j][1] = 0;
            low[j][0] = 0;
            low[j][1] = 0;
        }
        res[0] = 0;
        high[0][0] = 1;
        for(int k = 0; k < s[i].size(); k++){
                if(s[i][k] == 'L'){
                    for(int l = s[i].size(); l >= 0; l--){
                        high[l+1][0] = high[l][0];
                        low[l+1][0] += high[l+1][0];
                        low[l+1][0] %= mod;
                    }
                    high[0][0] = 0;
                } else{
                    res[0] += low[1][0];
                    res[0] %= mod;
                    for(int l = 0; l <= s[i].size(); l++){
                        low[l][0] = low[l+1][0];
                        high[l][0] += low[l][0];
                        high[l][0] %= mod;
                    }
                    low[0][0] = 0;
                }
            }

            // for(int ii = 0; ii <= s[i].size(); ii++)
            //     cout << high[ii][0] << ' ';
            // cout << '\n';
            // for(int ii = 0; ii <= s[i].size(); ii++)
            //     cout << low[ii][0] << ' ';
            // cout << '\n';
            // cout << "COPEOEPOEPOEP " << res[0] << '\n';

        for(int j = 1; j <= n; j++){
            for(int l = 0; l <= s[i].size() + s[j].size(); l++){
                high[l][1] = high[l][0];
                low[l][1] = low[l][0];
            }
            res[1] = res[0];
            for(int k = 0; k < s[j].size(); k++){
                if(s[j][k] == 'L'){
                    for(int l = s[i].size() + s[j].size(); l >= 0; l--){
                        high[l+1][1] = high[l][1];
                        low[l+1][1] += high[l+1][1];
                        low[l+1][1] %= mod;
                    }
                    high[0][1] = 0;
                } else{
                    res[1] += low[1][1];
                    res[1] %= mod;
                    for(int l = 0; l <= s[i].size() + s[j].size(); l++){
                        low[l][1] = low[l+1][1];
                        high[l][1] += low[l][1];
                        high[l][1] %= mod;
                    }
                    low[0][1] = 0;
                }

                // for(int ii = 0; ii <= s[i].size() + s[j].size(); ii++)
                //     cout << high[ii][1] << ' ';
                // cout << '\n';
                // for(int ii = 0; ii <= s[i].size() + s[j].size(); ii++)
                //     cout << low[ii][1] << ' ';
                // cout << '\n';
                // cout << "----------\n";
            }
            cout << res[1] << ' ';
        }
        cout << '\n';
    }

return 0;
}