AB
InterviewTime limit2sMemory limit1024 MB
Maintain string sets A and B with add and delete, and count ways to write a query string as a prefix of an A element joined with a suffix of a B element.
Problem
Write a program that handles the following queries on sets , and a string .
add A: Adds to .delete A: Removes from .add B: Adds to .delete B: Removes from .find: Prints the number of ways to form by joining a prefix of an element of with a suffix of an element of . Two ways are different if the elements differ or if the prefixes (suffixes) differ. Empty prefixes (suffixes) are not considered.
Initially, and are empty. No query adds an element that already exists or removes an element that does not exist.
Input
The first line contains the number of queries .
Each of the next lines contains one query. Strings consist of lowercase English letters, and each has length between 1 and 1,000 inclusive.
There is at least one find query.
Output
Print the answer to each find query on its own line.