#include using namespace std; struct Trie{ struct Node { std::array child; int sz; Node(void) :sz(0) { child.fill(-1); } const int& operator[](int k) const { return child[k]; } int& operator[](int k) { return child[k]; } }; int num; vector tree; Trie() : num(0) { tree.emplace_back(Node()); } void insert(const string &s){ int cur = 0; for(auto &&c:s){ if(tree[cur][c - 'a'] == -1){ tree[cur][c - 'a'] = ++num; tree.emplace_back(Node()); } cur = tree[cur][c - 'a']; } tree[cur].sz++; } bool search(string &s){ int cur = 0, d = 0; for(int i = 0; i < s.size(); i++){ if(tree[cur][s[i] - 'a'] == -1){ if(i + 1 == s.size())return false; swap(s[i], s[i + 1]); bool ans = true; for(int j = i; j < s.size(); j++){ cur = tree[cur][s[j] - 'a']; if(cur == -1){ ans = false; break; } } swap(s[i], s[i + 1]); return ans && tree[cur].sz ? true : false; } cur = tree[cur][s[i] - 'a']; } return tree[cur].sz ? true : false; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); int Q; cin >> Q; Trie trie; string s; while(Q--){ cin >> s; cout << (trie.search(s) ? "Yes" : "No") << '\n'; trie.insert(s); } }