/* -*- coding: utf-8 -*- * * 2102.cc: No.2102 [Cherry Alpha *] Conditional Reflection - yukicoder */ #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int MAX_L = 1000000; const int P = 4079; const int MOD = 1000000033; /* 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; struct Stat { int l, i; mi h; Stat() {} Stat(int _l, int _i, mi _h): l(_l), i(_i), h(_h) {} bool operator<(const Stat &s) const { return l < s.l || (l == s.l && h < s.h); } }; typedef set sst; /* global variables */ mi pes[MAX_L + 1], invpes[MAX_L + 1]; char s[MAX_L + 4]; string ss[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 s2h(const string &s) { mi h = 0; for (int k = 0; k < s.size(); k++) h += pes[k] * s[k]; return h; } inline mi replh(mi h, const string &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; } bool check(sst &gs, string &s, mi h) { sst::iterator sit = gs.find(Stat((int)s.size(), -1, h)); return (sit != gs.end() && ss[sit->i] == s); } /* main */ int main() { prep_rhash(MAX_L); int n; scanf("%d", &n); sst gs; for (int i = 0; i < n; i++) { scanf("%s", s); string si(s); ss[i] = si; int l = si.size(); mi hi = s2h(si); //printf("%d: %s = %d,%d\n", i, s, l, hi.v); if (check(gs, si, hi)) { puts("Yes"); continue; } bool ok = false; for (int j = 0; ! ok && j + 1 < l; j++) { mi hj = replh(hi, si, j, j + 1); swap(si[j], si[j + 1]); ok = check(gs, si, hj); swap(si[j], si[j + 1]); } gs.insert(Stat(l, i, hi)); if (ok) puts("Yes"); else puts("No"); } return 0; }