Elephant Filimon decided to visit his panda-friend Cheng Shi from Chengdu, China. Cheng Shi loves bamboo and showed her collection of bamboo inscriptions. Each inscription is a string of lowercase Latin letters.
Cheng Shi's collection is a dynamic multiset of strings. Initially, it is empty.
The panda can perform operations of two types:
Elephant Filimon became curious about the minimum number of actions required after each operation to make all strings in the current multiset identical.
Allowed actions on one string from the collection:
The string to which all others are brought can be any (including empty) and does not have to be present in the multiset.
Note: The strings in the multiset are not actually changed. After each query, it is only necessary to compute the minimum number of actions required to make all strings identical. For subsequent operations, the multiset remains unchanged.
Help Cheng Shi quickly respond to Filimon's question after each change.
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 5 \cdot 10^5$$$) — the number of operations.
Each of the following $$$q$$$ lines describes one operation and has the form:
+ s or - s
where $$$s$$$ is a non-empty string consisting of lowercase Latin letters.
In all queries, $$$1 \le |s| \le 5 \cdot 10^5$$$. The total length of all strings in all operations does not exceed $$$5 \cdot 10^5$$$.
After each operation, output a single integer — the minimum number of actions required to make all strings in the current multiset identical.
If the multiset is empty after the operation, output $$$0$$$.
| Additional constraints | |||||
| Subgroup | Points | $$$q$$$ | $$$\sum |s_i|$$$ | Type of operations | Required subgroups |
| 1 | 10 | $$$q \le 100$$$ | $$$\sum |s_i| \le 1000$$$ | + and - | – |
| 2 | 10 | $$$q \le 1000$$$ | $$$\sum |s_i| \le 10^4$$$ | + and - | 1 |
| 3 | 15 | $$$q \le 50\,000$$$ | $$$\sum |s_i| \le 10^5$$$ | + and - | 1,2 |
| 4 | 10 | $$$q \le 5 \cdot 10^5$$$ | $$$\sum |s_i| \le 5 \cdot 10^5$$$, $$$|s_i| \le 10$$$ | + | – |
| 5 | 10 | $$$q \le 5 \cdot 10^5$$$ | $$$\sum |s_i| \le 5 \cdot 10^5$$$, $$$|s_i| \le 10$$$ | + and - | 4 |
| 6 | 20 | $$$q \le 5 \cdot 10^5$$$ | $$$\sum |s_i| \le 5 \cdot 10^5$$$ | + | 4 |
| 7 | 25 | – | – | + and - | 1–6 |
5+ abc+ ab+ a- ab+ b
0 1 2 2 4
| Name |
|---|


