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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// 2022-3-baj-drybling-bajtessiego.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>

constexpr int MAXN = 607;
constexpr long long MD = 1e9 + 7;

long long hmarr[MAXN][MAXN][2];
long long hm2t[MAXN][MAXN][2];
long long ress[MAXN];

inline long long cnthm(const std::string& s, long long (&hm)[MAXN][2]) {
	int mxv = 1;
	long long res = 0;
	hm[0][0] = 1;
	for (char c : s) {
		if (c == 'L') {
			for (int i = mxv; i >= 0; i--) {
				hm[i + 1][0] = hm[i][0];
				hm[i + 1][1] += hm[i][0];
				hm[i + 1][1] %= MD;
			}
			mxv++;
			res %= MD;
			hm[0][0] = 0;
		}
		else
		{
			res += hm[1][1];
			res %= MD;
			for (int i = 0; i <= mxv; i++) {
				hm[i][0] += hm[i + 1][1];
				hm[i][0] %= MD;
				hm[i][1] = hm[i + 1][1];
			}
		}
	}
	return res;
}

inline void cntrev(const std::string& s, long long (&hm)[MAXN][2]) {
	long long res = 1;
	int maxv = 1;
	for (int i = s.size() - 1; i >= 0; i--) {
		char c = s[i];
		if (c == 'L') {
			for (int i = 0; i < maxv; i++) {
				hm[i][0] = hm[i + 1][0] + hm[i + 1][1];
				hm[i][0] %= MD;
			}
		}
		else {
			maxv++;
			for (int i = maxv; i >= 1; i--) {
				hm[i][1] = hm[i - 1][0] + hm[i - 1][1];
				hm[i][1] %= MD;
			}
			hm[1][1]++;
			hm[1][1] %= MD;
		}
	}
}

std::string st[MAXN];

long long mlp(long long (&a)[MAXN][2], long long (&b)[MAXN][2]) {
	long long res = 0;
	for (int i = 0; i < MAXN; i++) {
		for (int j = 0; j < 2; j++) {
			res += a[i][j] * b[i][j];
			res %= MD;
		}
	}
	return res;
}

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

	int n;
	std::cin >> n;

	for (int i = 0; i < n; i++) {
		std::cin >> st[i];
		ress[i] = cnthm(st[i], hmarr[i]);
		cntrev(st[i], hm2t[i]);

		/*
		for (int j = 0; j < 1 + st[i].size(); j++) {
			std::cout << hmarr[i][j][0] << ' ' << hmarr[i][j][1] << '\n';
		}
		std::cout << "--\n";
		for (int j = 0; j < 1 + st[i].size(); j++) {
			std::cout << hm2t[i][j][0] << ' ' << hm2t[i][j][1] << '\n';
		}
		std::cout << "==\n";*/
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			/*
			for (int k = 0; k < MAXN; k++) {
				hm[k][0] = 0;
				hm[k][1] = 0;
			}
			hm[0][0] = 1;
			std::cout << cnthm(st[i] + st[j], 1) << ' ';*/
			std::cout << (mlp(hmarr[i], hm2t[j]) + ress[i]) % MD << ' ';
		}
		std::cout << '\n';
	}
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file