#include #include char op[20]; char va[40]; struct { int n[27]; int cnt; bool lazy; }t[3000005]; int mem = 0; void inser(char *s) { int p = 0; t[p].cnt++; while (char c = *(s++)) { if (t[p].n[c-'a'] == 0) { t[p].n[c-'a'] = ++mem; memset(&t[mem], 0, sizeof(t[0])); } p = t[p].n[c-'a']; if (t[p].lazy) { for (int i = 0; i < 26; i++) { if (t[p].n[i] != 0) { t[t[p].n[i]].lazy = true; t[t[p].n[i]].cnt = 0; } } t[p].lazy = false; } t[p].cnt++; } } void delet(char *s) { char *tmp = s; int p = 0; while (char c = *(s++)) { if (t[p].lazy || t[p].cnt == 0) { return; } if (t[p].n[c-'a'] == 0) { return; } p = t[p].n[c-'a']; } s = tmp; int va = t[p].cnt; p = 0; while (char c = *(s++)) { t[p].cnt -= va; p = t[p].n[c-'a']; } t[p].cnt = 0; t[p].lazy = true; } bool searc(char *s) { int p = 0; while (char c = *(s++)) { if (t[p].lazy || t[p].cnt == 0) { return false; } if (t[p].n[c-'a'] == 0) { return false; } p = t[p].n[c-'a']; } return t[p].cnt > 0; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s %s", op, va); if (op[0] == 'i') { inser(va); } else if (op[0] == 's') { if (searc(va)) { puts("Yes"); } else { puts("No"); } } else { delet(va); } } } /* 10000 i h i hh i hhh i hhhh i hhhhh i hhhhhh d hhhh s hhhh s hhhhh i hhhha s hhhhh s hhhha s hhhhhh */