#include #include #include #include #include using namespace std; constexpr int mod = 1e9 + 7; struct modint { int n; modint(int n = 0) : n(n) {} }; modint operator+(modint a, modint b) { return modint((a.n += b.n) >= mod ? a.n - mod : a.n); } modint operator-(modint a, modint b) { return modint((a.n -= b.n) < 0 ? a.n + mod : a.n); } modint operator*(modint a, modint b) { return modint(1LL * a.n * b.n % mod); } modint &operator+=(modint &a, modint b) { return a = a + b; } modint &operator-=(modint &a, modint b) { return a = a - b; } modint &operator*=(modint &a, modint b) { return a = a * b; } constexpr int N = 2e5 + 10; modint fact[N]; modint ifact[N]; modint inv[N]; modint P(int n, int r) { if (n < 0 || r < 0 || n < r) return 0; return fact[n] * ifact[n - r]; } modint C(int n, int r) { if (n < 0 || r < 0 || n < r) return 0; return fact[n] * ifact[r] * ifact[n - r]; } int main() { fact[0] = 1; for (int i = 1; i <= N; i++) { fact[i] = i * fact[i - 1]; } inv[1] = 1; for (int i = 2; i <= N; i++) { inv[i] = inv[mod % i] * (mod - mod / i); } ifact[0] = 1; for (int i = 1; i <= N; i++) { ifact[i] = inv[i] * ifact[i - 1]; } int n; cin >> n; vector s(n); for (int i = 0; i < n; i++) { cin >> s[i]; } sort(s.begin(), s.end()); vector h(n - 1); for (int i = 0; i + 1 < n; i++) { int k = 0; while (k < s[i].size() && k < s[i + 1].size() && s[i][k] == s[i + 1][k]) k++; h[i] = k; } vector ans(n + 2); for (int i = 0; i < n; i++) { vector lcp(n); int k = s[i].size(); for (int j = i + 1; j < n; j++) { k = min(k, h[j - 1]); lcp[j] = k; } k = s[i].size(); for (int j = i - 1; j >= 0; j--) { k = min(k, h[j]); lcp[j] = k; } map mp; for (int j = 0; j < n; j++) { if (i != j) mp[-lcp[j]]++; } int c = 0; for (auto kv : mp) { for (int j = 1; j <= n; j++) { int x = c; int y = c + kv.second; ans[j] += (kv.first - 1) * P(j - 1, y) * P(n - 1 - y, j - 1 - y); ans[j] -= (kv.first - 1) * P(j - 1, x) * P(n - 1 - x, j - 1 - x); } c += kv.second; // ans[c] += -kv.first * fact[c - 1] * fact[n - c]; } } for (int i = 1; i <= n; i++) { ans[i] += ans[i - 1] * (n - i + 1); if (i == n) ans[i] += fact[n]; cout << ans[i].n << endl; } }