Suffix tree in line#5914

Suffix tree in line

1 second
256 megabytes
Easy

Given an initially empty string , you are given a sequence of operations. Each operation is one of the following two types:

  1. Add a character to the end of the string , increasing the length of by .

  2. Remove the first character from the string , decreasing the length of by .

After each operation, output the number of distinct substrings present in the string at that moment.

Input

The first line contains an integer (1 \leq q \leq 10^4) — the number of operations. The next lines describe the operations. A type 1 operation is given as "+ c", where is a lowercase letter of the Latin alphabet. A type 2 operation is given as "-".

Output

Print lines, each containing the number of distinct substrings in the string after performing the corresponding operation.

Examples

Example 1

Loading
Loading