#include #include #include using namespace std; struct node { node *next[26]; bool flag; int sum[26]; }; node* H; node* init() { node* tmp = new node; for(int i = 0;i < 26;i ++) { tmp ->sum[i] = 0; tmp ->next[i] = NULL; } tmp ->flag = false; return tmp; } void del(node* tmp) { for(int i = 0;i < 26;i ++) { if(tmp ->next[i] != NULL) del(tmp ->next[i]); } free(tmp); } void fun(node *tmp) { //puts("1"); for(int i = 0;i < 26;i ++) { tmp ->sum[i] = 0; if(tmp ->next[i] != NULL) fun(tmp ->next[i]); tmp ->next[i] = NULL; } } void Delete(char *s) { node* tmp = H; int len = strlen(s); int sum = 0; for(int i = 0;i < len;i ++) { int k = s[i] - 'a'; if(tmp ->next[k] == NULL) return ; sum = tmp ->sum[k]; tmp = tmp ->next[k]; } fun(tmp); tmp =H; //puts("2"); for(int i = 0;i < len;i ++) { int k = s[i] - 'a'; tmp ->sum[k] -= sum; //puts("a"); tmp =tmp ->next[k]; //puts("b"); } tmp = H; //puts("4"); for(int i = 0;i < len;i ++) { int k = s[i] - 'a'; node* p =tmp; tmp =tmp ->next[k]; if(p ->sum[k] == 0) p = NULL; } //puts("3"); } bool Search(char *s) { node* tmp = H; int len = strlen(s); for(int i = 0;i < len;i ++) { int k = s[i] - 'a'; if(tmp ->next[k] == NULL||tmp ->sum[k] <= 0) return false; tmp = tmp ->next[k]; } return true; } void Insert(char *s) { node* tmp = H; int len = strlen(s); for(int i = 0;i < len;i ++) { int k = s[i] - 'a'; if(tmp ->next[k] == NULL) tmp ->next[k] = init(); tmp ->sum[k]++; tmp = tmp ->next[k]; } tmp ->flag = true; } int main() { int N; char ss[14000],s[100000]; while(~scanf("%d", &N)) { H = init(); while(N--) { scanf("%s %s",ss,s); if(ss[0] == 's') { bool flag = Search(s); //puts("1"); if(flag) puts("Yes"); else puts("No"); }else if(ss[0] == 'i') { Insert(s); }else{ Delete(s); } } del(H); } return 0; }