#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include using namespace std; typedef long long LL; const int maxn = 3000006; int n,c = 1,t[maxn][26]; int cnt[maxn]; void insert(char s1[]){ int u = 0,m = strlen(s1); for (int i = 0; i < m; i++){ int ch = s1[i] - 'a'; if (!t[u][ch] || !cnt[t[u][ch]]) t[u][ch] = c++; u = t[u][ch]; cnt[u]++; } } void del(char s1[]){ queue Q; int u = 0; int m = strlen(s1); for (int i = 0; i < m - 1 ; i++){ int ch = s1[i] - 'a'; if (!cnt[t[u][ch]]) t[u][ch] = 0; if (!t[u][ch]) return; u = t[u][ch]; Q.push(u); } int x = cnt[t[u][s1[m - 1] - 'a']]; t[u][s1[m-1] - 'a'] = 0; while (!Q.empty()){ u = Q.front(); Q.pop(); cnt[u]-=x; } } bool search(char s1[]){ int u = 0; int m = strlen(s1); for (int i = 0; i < m - 1; i++){ int ch = s1[i] - 'a'; if (cnt[t[u][ch]] == 0) t[u][ch] = 0; if (!t[u][ch]) return 0; u = t[u][ch]; } return cnt[t[u][s1[m - 1] - 'a']]; } int main(){ scanf("%d", &n); char s[100],s2[100]; for (int i = 0; i < n; i++){ scanf("%s%s", s, s2); if (strcmp(s, "insert") == 0){ insert(s2); } else if (strcmp(s, "delete") == 0){ del(s2); } else { if (search(s2)) printf("Yes\n"); else printf("No\n"); } } return 0; }