#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef pair PII; typedef vector VI; typedef vector VPII; typedef pair PLL; typedef pair PIL; typedef pair PLI; typedef double DB; #define pb push_back #define mset(a, b) memset(a, b, sizeof a) #define all(x) (x).begin(), (x).end() #define bit(x) (1 << (x)) #define bitl(x) (1LL << (x)) #define sqr(x) ((x) * (x)) #define sz(x) ((int)(x.size())) #define cnti(x) (__builtin_popcount(x)) #define cntl(x) (__builtin_popcountll(x)) #define clzi(x) (__builtin_clz(x)) #define clzl(x) (__builtin_clzll(x)) #define ctzi(x) (__builtin_ctz(x)) #define ctzl(x) (__builtin_ctzll(x)) #define X first #define Y second #define Error(x) cout << #x << " = " << x << endl template inline void chkmax(T& x, U y) { if (x < y) x = y; } template inline void chkmin(T& x, U y) { if (y < x) x = y; } const int MN = 1000005; int sz; struct Node { int ch[26]; int val, I, sum; } t[MN]; inline void renew(int x) { t[x].val = t[x].sum = 0; t[x].I = 1; } inline void down(int x) { if (t[x].I == 1) { for (int i = 0; i < 26; i++) if (t[x].ch[i]) { renew(t[x].ch[i]); } t[x].I = 0; } } inline void up(int x) { t[x].sum = t[x].val; for (int i = 0; i < 26; i++) if (t[x].ch[i]) { t[x].sum += t[t[x].ch[i]].sum; } } int newNode() { return ++sz; } void Insert(int x, char *s) { if (*s == 0) { t[x].val++; t[x].sum++; return; } down(x); int id = *s - 'a'; if (t[x].ch[id] == 0) t[x].ch[id] = newNode(); Insert(t[x].ch[id], s + 1); up(x); } void Delete(int x, char *s) { if (*s == 0) { renew(x); return; } down(x); int id = *s - 'a'; if (t[x].ch[id] == 0) return; Delete(t[x].ch[id], s + 1); up(x); } int Search(int x, char *s) { if (*s == 0) { return t[x].sum; } down(x); int id = *s - 'a'; if (t[x].ch[id] == 0) return 0; return Search(t[x].ch[id], s + 1); } int main() { int root = newNode(), q; scanf("%d", &q); while (q--) { char type[20], str[100]; scanf("%s%s", type, str); if (type[0] == 'i') { Insert(root, str); } else if (type[0] == 's') { printf("%s\n", Search(root, str) ? "Yes" : "No"); } else { Delete(root, str); } } return 0; }