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;
typedef long long ll;
//Autor: Michał Szeliga
#ifdef LOCAL
#define debug(...) __VA_ARGS__;
#else
#define debug(...) {}
#endif
const ll mod = 1e9+7;
ll predod[2][1502];
ll prewy = 0;
void preprocess(string s){
	ll i;
	ll n = s.size();
	for (i = 0; i < 602; i++) predod[0][i] = predod[1][i] = 0;
	predod[0][0] = predod[1][0] = 1;
	ll wy = 0;
	for (i = 0; i < n; i++){
		ll dp[n+1];
		for (ll j = 0; j < n+1; j++){
			dp[j] = 0;
			if (s[i] == 'L'){
				if (j) dp[j] = predod[0][j-1];
			}else{
				if (j != n) dp[j] = predod[1][j+1];
			}
		}	
		if (s[i] == 'L'){
			for (ll j = 0; j < n+1; j++){
				predod[0][j] = dp[j];
				predod[1][j] = (predod[1][j]+dp[j])%mod;
			}
		}else{
			for (ll j = 0; j < n+1; j++){
				predod[1][j] = dp[j];
				predod[0][j] = (predod[0][j]+dp[j])%mod;
			}
		}
		wy = (wy+dp[0])%mod;
	}
	prewy = wy;
}
ll solve(string s){
	ll i;
	ll n = s.size();
	ll dod[2][n+1];
	for (i = 0; i < n+1; i++){
		dod[0][i] = predod[0][i];
		dod[1][i] = predod[1][i];
	}
	ll wy = prewy;
	for (i = 0; i < n; i++){
		ll dp[n+1];
		for (ll j = 0; j < (n-i)+1; j++){
			dp[j] = 0;
			if (s[i] == 'L'){
				if (j) dp[j] = dod[0][j-1];
			}else{
				if (j != n) dp[j] = dod[1][j+1];
			}
		}	
		if (s[i] == 'L'){
			for (ll j = 0; j < (n-i)+1; j++){
				dod[0][j] = dp[j];
				dod[1][j] = (dod[1][j]+dp[j])%mod;
			}
		}else{
			for (ll j = 0; j < (n-i)+1; j++){
				dod[1][j] = dp[j];
				dod[0][j] = (dod[0][j]+dp[j])%mod;
			}
		}
		wy = (wy+dp[0])%mod;
	}
	return wy%mod;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll i;
	ll n;
	cin>>n;
	string tab[n];
	for (i = 0; i < n; i++) cin>>tab[i];
	for (i = 0; i < n; i++){
		preprocess(tab[i]);
		for (ll j = 0; j < n; j++){
			cout<<solve(tab[j])<<" ";
		}
		cout<<"\n";
	}
    return 0;
}