/* -*- coding: utf-8 -*- * * 1994.cc: No.1994 Confusing Name - yukicoder */ #include #include #include #include using namespace std; /* constant */ const int MAX_N = 50000; const int MAX_L = 10; const int P = 4073; const int MOD = 1000000009; /* typedef */ typedef map mii; template struct MI { int v; MI(): v() {} MI(int _v): v(_v % MOD) {} MI(long long _v): v(_v % MOD) {} MI operator+(const MI m) const { return MI(v + m.v); } MI operator-(const MI m) const { return MI(v + MOD - m.v); } MI operator*(const MI m) const { return MI((long long)v * m.v); } MI &operator+=(const MI m) { return (*this = *this + m); } MI &operator-=(const MI m) { return (*this = *this - m); } MI &operator*=(const MI m) { return (*this = *this * m); } MI pow(int n) const { // a^n % MOD MI pm = 1, a = *this; while (n > 0) { if (n & 1) pm *= a; a *= a; n >>= 1; } return pm; } MI inv() const { return pow(MOD - 2); } MI operator/(const MI m) const { return *this * m.inv(); } MI &operator/=(const MI m) { return (*this = *this / m); } }; typedef MI mi; /* global variables */ mi pes[MAX_L + 1], invpes[MAX_L + 1], rhs[MAX_N]; char s[MAX_L + 4]; string ss[MAX_N]; mii lhs[MAX_L + 1][MAX_L]; int ls[MAX_N]; /* subroutines */ inline void prep_rhash(int n) { pes[0] = invpes[0] = 1; pes[1] = P; invpes[1] = pes[1].inv(); for (int i = 2; i <= n; i++) { pes[i] = pes[i - 1] * P; invpes[i] = invpes[i - 1] * invpes[1]; } } inline mi s2hash(const string &s) { mi h = 0; for (int k = 0; k < s.size(); k++) h += pes[k] * s[k]; return h; } /* main */ int main() { prep_rhash(MAX_L); int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s", s); ss[i] = string(s); rhs[i] = s2hash(ss[i]); ls[i] = ss[i].size(); for (int j = 0; j < ls[i]; j++) { mi h = rhs[i] - pes[j] * s[j]; lhs[ls[i]][j][h.v]++; } } for (int i = 0; i < n; i++) { int li = ls[i], cnt = 0; for (int j = 0; j < li; j++) { mi h = rhs[i] - pes[j] * ss[i][j]; cnt += lhs[li][j][h.v] - 1; } printf("%d\n", cnt); } return 0; }