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

#define MAX_N 607
#define MOD 1000000007

int n;
vector<string> driblings;

int count_fantastics(string dribling) {
    int sum_fantastics = 0;
    int count_L[2 * MAX_N][MAX_N] = { 0 }; // length, leftisty
    int count_P[2 * MAX_N][MAX_N] = { 0 }; // length, leftisty
    int count[2 * MAX_N][MAX_N] = { 0 }; // length, leftisty
    count[0][0] = 1;

    for (auto letter : dribling) {
        for (int length = dribling.size(); length > 0; length--) {
            if (letter == 'P' && count[length - 1][1]) {
                count[length][0] = count[length - 1][1];
                count_P[length][0] = count[length - 1][1];
            }
            for (size_t leftisty = 1; leftisty <= dribling.size() / 2; leftisty++) {
                if (letter == 'L') {
                    count_L[length][leftisty] = count[length - 1][leftisty - 1];
                }
                if (letter == 'P') {
                    count_P[length][leftisty] = count[length - 1][leftisty + 1];
                }
                count[length][leftisty] =
                    (count_L[length][leftisty] + count_P[length][leftisty]) % MOD;
            }
        }
    }

    for (size_t length = 1; length <= dribling.size(); length++) {
        sum_fantastics = (sum_fantastics + count[length][0]) % MOD;
    }

    return sum_fantastics;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin >> n;

    for (int i = 0; i < n; i++) {
        string dribling;
        cin >> dribling;
        driblings.push_back(dribling);
    }

    for (auto first_dribling : driblings) {
        for (auto second_dribling : driblings) {
            cout << count_fantastics(first_dribling + second_dribling) << " ";
        }
        cout << "\n";
    }

    return 0;
}