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

typedef long long ll;

const int N = 600;
const ll M = 1e9 + 7;

ll l[N + 1];
ll p[N + 1];

string s[N + 1];

int n;

ll wyn(string x){
    //cout << x << "\n";
    int n2 = x.length();
    l[0] = 1;
    int maxim = 0;
    ll odp = 0;
    for(int i = 0; i < n2; i++){
        if(x[i] == 'L'){
            //cout << "L\n";
            for(int j = min(maxim, N); j >= 0; j--){
                l[j + 1] = l[j];
                l[j] = 0;
                p[j + 1] = (p[j + 1] + l[j + 1]) % M; 
                /*if(x == "LLPP"){
                    cout << "l " << i << " " <<  j + 1 << ": " << l[j + 1] << "\n";
                    cout << "p " << i << " "<< j + 1<< ": " << p[j + 1] << "\n";
                }*/
            }
            maxim++;
        }
        else{
            for(int j = 0; j < min(maxim, N); j++){
                p[j] = p[j + 1];
                p[j + 1] = 0;
                l[j] = (l[j] + p[j]) % M;
                if(j == 0) odp = (odp + p[j]) % M;
                /*if(x == "LLPP") {
                    cout << "p " << i << " " << j << ": " << p[j] << "\n";
                    cout << "l " << i << " " << j << ": " << l[j] << "\n";
                }*/
            }
        }
    }

    for(int i = 0; i <= min(maxim, N); i++){
        l[i] = p[i] = 0;
    }

    return odp;
}

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

    cin >> n;

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

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            string nowy = s[i] + s[j];
            cout << wyn(nowy) << " ";
        }
        cout << "\n";
    }
}