/* -*- coding: utf-8 -*- * * 2102.cc: No.2102 [Cherry Alpha *] Conditional Reflection - yukicoder */ #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int MAX_L = 1000000; const int P = 4073; const int MOD = 1000000009; /* typedef */ /* typedef */ 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); } bool operator==(const MI m) const { return v == m.v; } bool operator!=(const MI m) const { return v != m.v; } bool operator<(const MI m) const { return v < m.v; } 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; typedef pair pimi; typedef set spimi; /* global variables */ mi pes[MAX_L + 1], invpes[MAX_L + 1]; char s[MAX_L + 4]; /* 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 int s2rh(mi rh[], const char s[]) { int k = 0; for (; s[k]; k++) rh[k + 1] = rh[k] + pes[k] * s[k]; return k; } inline mi s2h(const char s[]) { mi h = 0; for (int k = 0; s[k]; k++) h += pes[k] * s[k]; return h; } inline mi rhash(mi rh[], int i, int j) { return (rh[j] - rh[i]) * invpes[i]; } inline mi replh(mi h, char s[], int i, int j) { h -= pes[i] * s[i] + pes[j] * s[j]; h += pes[i] * s[j] + pes[j] * s[i]; return h; } /* main */ int main() { prep_rhash(MAX_L); int n; scanf("%d", &n); spimi gs; for (int i = 0; i < n; i++) { scanf("%s", s); int l = strlen(s); mi hi = s2h(s); //printf("%d: %s = %d,%d\n", i, s, l, hi.v); if (gs.find(pimi(l, hi)) != gs.end()) { puts("Yes"); continue; } bool ok = false; for (int j = 0; ! ok && j + 1 < l; j++) { mi hj = replh(hi, s, j, j + 1); ok = (gs.find(pimi(l, hj)) != gs.end()); } gs.insert(pimi(l, hi)); if (ok) puts("Yes"); else puts("No"); } return 0; }