#include using namespace std; #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define bit(n) (1LL<<(n)) #define sz(x) ((int)(x).size()) #define TEN(n) ((ll)(1e##n)) #define fst first #define snd second string DBG_DLM(int &i){return(i++==0?"":", ");} #define DBG_B(exp){int i=0;os<<"{";{exp;}os<<"}";return os;} templateostream&operator<<(ostream&os,vectorv); templateostream&operator<<(ostream&os,setv); templateostream&operator<<(ostream&os,queueq); templateostream&operator<<(ostream&os,priority_queueq); templateostream&operator<<(ostream&os,pairp); templateostream&operator<<(ostream&os,mapmp); templateostream&operator<<(ostream&os,unordered_mapmp); templatevoid DBG(ostream&os,TPL t){} templatevoid DBG(ostream&os,TPL t){os<<(I==0?"":", ")<(t);DBG(os,t);} templatevoid DBG(ostream&os,pairp,string delim){os<<"("<ostream&operator<<(ostream&os,tuplet){os<<"(";DBG<0,tuple,Ts...>(os,t);os<<")";return os;} templateostream&operator<<(ostream&os,pairp){DBG(os,p,", ");return os;} templateostream&operator<<(ostream&os,vectorv){DBG_B(forr(t,v){os<ostream&operator<<(ostream&os,sets){DBG_B(forr(t,s){os<ostream&operator<<(ostream&os,queueq){DBG_B(for(;q.size();q.pop()){os<ostream&operator<<(ostream&os,priority_queueq){DBG_B(for(;q.size();q.pop()){os<ostream&operator<<(ostream&os,mapm){DBG_B(forr(p,m){os<");});} templateostream&operator<<(ostream&os,unordered_mapm){DBG_B(forr(p,m){os<");});} #define DBG_OVERLOAD(_1,_2,_3,_4,_5,_6,macro_name,...)macro_name #define DBG_LINE(){char s[99];sprintf(s,"line:%3d | ",__LINE__);cerr<;using pll=pair;using pil=pair;using pli=pair; using vs=vector;using vvs=vector;using vvvs=vector; using vb=vector;using vvb=vector;using vvvb=vector; using vi=vector;using vvi=vector;using vvvi=vector; using vl=vector;using vvl=vector;using vvvl=vector; using vd=vector;using vvd=vector;using vvvd=vector; using vpii=vector;using vvpii=vector;using vvvpii=vector; templatebool amax(A&a,const B&b){return b>a?a=b,1:0;} templatebool amin(A&a,const B&b){return b>l;return l;} string rs(){string s;cin>>s;return s;} const int mod = 1e9+7; template struct Mint { int x; Mint() : x(0) {} Mint(int y) : x(y >= 0 ? y % MOD : MOD - (-y) % MOD) {} Mint(int64_t sll) : x(sll % MOD) { if (x < 0) x += MOD; } Mint &operator+=(const Mint &rhs){ if((x += rhs.x) >= MOD) x -= MOD; return *this; } Mint &operator-=(const Mint &rhs){ if((x += MOD - rhs.x) >= MOD) x -= MOD; return *this; } Mint &operator*=(const Mint &rhs){ x = 1LL*x*rhs.x % MOD; return *this; } Mint &operator/=(const Mint &rhs){ x = (1LL*x*rhs.inv().x) % MOD; return *this; } Mint operator-() const { return Mint(-x); } Mint operator+(const Mint &rhs) const { return Mint(*this) += rhs; } Mint operator-(const Mint &rhs) const { return Mint(*this) -= rhs; } Mint operator*(const Mint &rhs) const { return Mint(*this) *= rhs; } Mint operator/(const Mint &rhs) const { return Mint(*this) /= rhs; } bool operator<(const Mint &rhs) const { return x < rhs.x; } Mint inv() const { signed a = x, b = MOD, u = 1, v = 0, t; while(b){ t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return Mint(u); } Mint operator^(uint64_t t) const { Mint e = *this, res = 1; for(; t; e *= e, t>>=1) if (t & 1) res *= e; return res; } }; template ostream &operator<<(ostream &os, const Mint &rhs) { return os << rhs.x; } template istream &operator>>(istream &is, Mint &rhs) { int64_t s; is >> s; rhs = Mint(s); return is; }; using mint = Mint; using vm=vector;using vvm=vector;using vvvm=vector; const int SET_FACT_MAX =100; mint fact[SET_FACT_MAX]; mint revFact[SET_FACT_MAX]; void setFact() { const int N = SET_FACT_MAX; fact[0] = 1; for (int i = 1; i < N; i++) { fact[i] = fact[i - 1] * i; } revFact[N - 1] = fact[N - 1] ^ (mod - 2); for (int i = N - 2; i >= 0; i--) { revFact[i] = revFact[i + 1] * (i + 1); } } mint nPr(int n, int r) { return n >= r ? fact[n] * revFact[n - r] : 0; } mint nCr(int n, int r) { return nPr(n, r) * revFact[r]; } mint nHr(int n, int r) { return n == 0 && r == 0 ? 1 : nCr(n + r - 1, r); } struct RollingHash64 { const int base = 1e9+7; const int N; vector P, H; RollingHash64(const string & S) : N(S.size()), P(N+1, 1), H(N+1, 0) { for (int i = 0; i < N; i++) { int c = (int) (S[i] - ' '); H[i+1] = H[i] * base + c; P[i+1] = P[i] * base; } } int64_t hash() const { return hash(0, N); } int64_t hash(int r) const { return H[r]; } int64_t hash(int l, int r) const { return H[r] - H[l] * P[r - l]; } bool equals(int l1, int r1, int l2, int r2) const { if (l1 < 0 || l2 < 0) return false; if (r1 > N || r2 > N) return false; if (r1 - l1 != r2 - l2) return false; return hash(l1, r1) == hash(l2, r2); } bool equals(int p1, int p2, int len) const { return equals(p1, p1 + len, p2, p2 + len); } bool equals(int pos, const RollingHash64 &other) const { int r = pos + other.N; if (r >= N) return false; return hash(pos, r) == hash(0, other.N); } int lcp(int p1, int p2) const { int ok = 0; int ng = min(N - p1, N - p2) + 1; while (ng - ok > 1) { int mid = (ok + ng) / 2; (equals(p1, p1 + mid, p2, p2 + mid) ? ok : ng) = mid; } return ok; } }; void Main() { int n = ri(); setFact(); vs S(n); rep(i, n) S[i] = rs(); sort(all(S)); out(S); string s; vi P(n+1); rep(i, n) { P[i] = sz(s); s += S[i]; s += ('A' + i); } RollingHash64 rh(s); vm dp(bit(n)); rep(i, bit(n)) { rep(j, n) if ((bit(j) & i) == 0) { int ma = 0; rep(k, n) if (j != k && (bit(k) & i) == 0) { amax(ma, rh.lcp(P[j], P[k])); } int ij = i|bit(j); int bci = __builtin_popcount(i); dp[ij] += dp[i] + fact[bci] * (ma + 1); } } vm Z(22); rep(i, bit(n)) { int bc = __builtin_popcount(i); Z[bc] += dp[i]; } out(Z); rep(i, 1, n+1) { cout << Z[i] << "\n"; } } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }