Module: Bor


Problem

6 /10


String Queries

Problem

There is a set of strings that is initially empty. There are three different operations that need to be handled on this set of rows:
  • 1 s: Add the given string to the set.
  • 2 k l: Find out if there are k strings (not necessarily distinct) in the set that have a common suffix of length l. This suffix does not have to be the largest.
  • 3 i: Remove the string from the set that was added in the i-th operation (if it has not already been removed).
Input:
The first line contains a single integer - the number of operations q (1 <= q <= 105) to be processed.
Next, each line contains a description of the request. First it is a number 1, 2 or 3, indicating the type of request. 
If this is a query of the first type, then the string s is given below, the total length of which does not exceed 105.
If this is a query of the second type, then two integers k and l are given (1 <= k, l <= 105).
If this is a request of the third type, then the number i is given (1 <= i <= the number of the current operation), where i is the number of the operation of the first type.

Output:
For each query of the second type, print the word "YES" on a separate line, if the necessary lines exist, and "NO" otherwise.

Example:
 
Input Output
9
1 aba
1 accba
2 2 2
2 2 3
1 aaaa
1 ababa
2 3 2
3 1
2 3 2
YES
NO
YES
NO