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
 96
 97
 98
 99
100
101
102
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef pair<int,long long> PIL;
const int mod = 1e9+7;

const int SZ = 604;

string arr[605];
long long dp[605][605];

void calc(string s){
    for(int i=0;i<SZ;i++) for(int j=0;j<SZ;j++) dp[i][j]=0;
    dp[0][0] = 1;
    int lastL = 0;
    int lastP = 0;
    for(int i=1;i<=s.size();i++){
        if(s[i-1] == 'L'){
            dp[i][0] = dp[i-1][0];
            for(int k=1;k<=i;k++){
                if(lastL > 0) dp[i][k] = (dp[i-1][k]+dp[i-1][k-1]-dp[lastL-1][k-1])%mod;
                else dp[i][k] = (dp[i-1][k]+dp[i-1][k-1])%mod;
            }
            lastL = i;
        }
        else{
            for(int k=0;k<i;k++){
                if(lastP > 0) dp[i][k] = (dp[i-1][k]+dp[i-1][k+1]-dp[lastP-1][k+1])%mod;
                else dp[i][k] = (dp[i-1][k]+dp[i-1][k+1])%mod;
            }
            lastP = i;
        }
    }
}

long long suf[605][3*SZ];
long long sufcpy[605][3*SZ];


long long V[3*SZ];
int mult(int ind){
    long long res = 0;
    for(int i=0;i<3*SZ;i++){
        res = (res+V[i]*suf[ind][i])%mod;
    }
    res--;
    while(res<0) res+=mod;
    return res;
}

int main(){
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }

    for(int i=1;i<=n;i++){
        suf[i][0] = 1;
        for(int pos=arr[i].size()-1;pos>=0;pos--){
            char x = arr[i][pos];
            if(x == 'L'){
                for(int j=0;j<SZ-1;j++) sufcpy[i][j] = (suf[i][j]+suf[i][j+1]+suf[i][j+SZ])%mod;
                sufcpy[i][SZ-1] = (suf[i][SZ-1]+suf[i][SZ-1+SZ])%mod;
                for(int j=0;j<SZ-1;j++) sufcpy[i][j+SZ] = -suf[i][j+1];
                for(int j=0;j<SZ;j++) sufcpy[i][j+2*SZ] = suf[i][j+2*SZ];
            }
            else{
                sufcpy[i][0] = (suf[i][0]+suf[i][2*SZ])%mod;
                for(int j=1;j<SZ;j++) sufcpy[i][j] = (suf[i][j]+suf[i][j-1]+suf[i][j+2*SZ])%mod;
                for(int j=1;j<SZ;j++) sufcpy[i][j+2*SZ] = -suf[i][j-1];
                for(int j=0;j<SZ;j++) sufcpy[i][j+SZ] = suf[i][j+SZ];
            }
            for(int j=0;j<3*SZ;j++) suf[i][j] = sufcpy[i][j];
        }
    }
    
    for(int i=1;i<=n;i++){
        calc(arr[i]);
        int len = arr[i].size();
        for(int j=0;j<3*SZ;j++) V[j] = 0;
        for(int j=0;j<SZ;j++) V[j] = dp[len][j];
        for(int pos=len-1;pos>=0;pos--){
            if(arr[i][pos] == 'L'){
                for(int j=0;j<SZ;j++) V[j+SZ] = dp[pos][j];
                break;
            }
        }
        for(int pos=len-1;pos>=0;pos--){
            if(arr[i][pos] == 'P'){
                for(int j=0;j<SZ;j++) V[j+2*SZ] = dp[pos][j];
                break;
            }
        }

        for(int j=1;j<=n;j++){
            cout<<mult(j)<<" ";
        }
        cout<<endl;
    }
}