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
#include <bits/stdc++.h>
#define int long long 
#define pii pair<int, int>
#define pb push_back 
#define fi first
#define sec second
#define cln cout<<"\n--------------------\n"
using namespace std;

constexpr int N = 1e6;
constexpr int MOD = 1e9+7;

string T[N];

bool sprawdz(const string & s) {
    int l = 0, p = 0;
    bool lw = false;
    for (int i=0; i<s.size(); ++i) {
        if (s[i] == 'L') l++;
        else p++;
        if (l<p) return false; 
    }
    return (l>0 && l==p);
}

int policz (string a, string b) {
    set <string> s;
    a += b;
    int res = 0;
    const int dl = a.size();
    for (int i=1; i<(1ll<<(dl+1)); ++i) {
        string tbp = "";
        for (int j=0; j<dl; ++j) {
            if ((1ll<<j) & i) tbp += a[j];
        }
        s.insert(tbp);
    }
    for (auto &tbp : s) 
        if (sprawdz(tbp)) {res++;}
    return res;
}


int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin>>n;
    for (int i=0; i<n; ++i) {
        cin>>T[i];
    }
    
    for (int i=0; i<n; ++i) {
        for (int j=0; j<n; ++j) {
            cout<<(policz(T[i], T[j]))<<' ';
        }
        cout<<'\n';
    }
    
    return 0;
}