#include #include #include #include #include #include #include #include #include #include #define CLR(a, b) memset(a, b, sizeof(a)) using namespace std; typedef long long LL; typedef pair pii; const int MAXN = 3 * 1e6 + 10; const int MOD = 9973; const int INF = 0x3f3f3f3f; int sum; struct Trie { int L, next[MAXN][30], root, word[MAXN], End[MAXN]; int newnode() { for(int i = 0; i <= 25; i++) next[L][i] = -1; word[L] = 0; End[L] = 0; L++; return L-1; } void init() { L = 0; root = newnode(); } void Insert(char *s) { int u = root; for(int i = 0; s[i]; i++) { int v = s[i] - 'a'; if(next[u][v] == -1) next[u][v] = newnode(); u = next[u][v]; word[u]++; } End[u]++; } void DFS(int u) { sum += End[u]; word[u] = 0; End[u] = 0; for(int i = 0; i <= 25; i++) { if(next[u][i] != -1) { DFS(next[u][i]); next[u][i] = -1; } } } void Delete(char *s) { int u = root; sum = 0; for(int i = 0; s[i]; i++) { int v = s[i] - 'a'; if(next[u][v] == -1) return ; u = next[u][v]; } DFS(u); u = root; for(int i = 0; s[i]; i++) { int v = s[i] - 'a'; u = next[u][v]; //cout << word[u] << endl; word[u] -= sum; } word[u] += sum; } bool Query(char *s) { int u = root; for(int i = 0; s[i]; i++) { int v = s[i] - 'a'; u = next[u][v]; //cout << word[u] << endl; if(word[u] == 0 || u == -1) return false; } return true; } }; Trie T; int main() { int n; while(scanf("%d", &n) != EOF) { char op[10], str[100]; T.init(); while(n--) { scanf("%s%s", op, str); if(op[0] == 'i') { T.Insert(str); } else if(op[0] == 'd') { T.Delete(str); } else { printf(T.Query(str) ? "Yes\n" : "No\n"); } } } return 0; }