#K91027. Document Retrieval System

    ID: 37884 Type: Default 1000ms 256MiB

Document Retrieval System

Document Retrieval System

You are required to implement a document retrieval system that supports a set of operations. The system maintains a collection of documents and supports the following operations:

  1. add : Add a document to the system.
  2. remove : Remove the document from the system. If the document does not exist, do nothing.
  3. search : Print the number of documents that contain the specified as a substring.
  4. list: Print all documents in lexicographical order (sorted in ascending order) separated by a single space.

The system will process a series of commands provided from standard input (stdin) and output the results to standard output (stdout). For each command that produces an output (i.e. search and list), print the result on a new line.

Note: When a document is added, if it already exists, you may ignore it since the internal storage is a set.

inputFormat

The input begins with an integer n (1 ≤ n ≤ 10^5) denoting the number of commands. Each of the following n lines contains a command. A command is one of the following four types:

• add • remove • search • list

The or will be a non-empty string without spaces.

outputFormat

For each command of type 'search', output a line containing a single integer — the number of documents that contain the given keyword. For each command of type 'list', output a line containing all documents in lexicographical (alphabetical) order separated by a single space. Commands 'add' and 'remove' produce no output.## sample

6
add hello
add world
search hello
list
remove hello
list
1

hello world world

</p>