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

using namespace std;

string s[660];
int counter[660][2][660];
int res[660];
int tmp[2][660];

int mod = 1000000007;


void up(int *tab) {
    for(int i = 605; i >= 0; i--) {
        tab[i + 1] = tab[i];
    }
    tab[0] = 0;
}

void down(int *tab) {
    for(int i = 0; i < 606; i++) {
        tab[i] = tab[i + 1];
    }
}

void add(int *tab1, int *tab2) {
    for(int i = 0; i < 606; i++) {
        tab1[i] += tab2[i];
        tab1[i] %= mod;
    }
}

void copy(int *tab1, int* tab2) {
    for(int i = 0; i < 606; i++) {
        tab1[i] = tab2[i];
    }
}

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

    int n;
    cin >> n;

    for(int i = 0; i < n; i++) {
        cin >> s[i];

        counter[i][0][0] = 1;
        for(int j = 0; j < s[i].length(); j++) {
            if(s[i][j] == 'L') {
                up(counter[i][0]);
                add(counter[i][1], counter[i][0]);
            } else {
                down(counter[i][1]);
                add(counter[i][0], counter[i][1]);
                res[i] += counter[i][1][0];
                res[i] %= mod;
                counter[i][1][0] = 0;
            }
        }
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            int local_res = res[i];
            copy(tmp[0], counter[i][0]);
            copy(tmp[1], counter[i][1]);

            for(int k = 0; k < s[j].length(); k++) {
                if(s[j][k] == 'L') {
                    up(tmp[0]);
                    add(tmp[1], tmp[0]);
                } else {
                    down(tmp[1]);
                    add(tmp[0], tmp[1]);
                    local_res += tmp[1][0];
                    local_res %= mod;
                    tmp[1][0] = 0;
                }
            }
            cout << local_res << " ";
        }
        cout << "\n";
    }
    return 0;
}