QueryreuQ

Maintain a string under append and pop-back operations, and after each operation print the number of palindromic substrings it contains.

Medium5StringDynamic programmingImplementationTwo pointersInterviewNo attempts yetTime limit1sMemory limit1024 MB

Problem

A string is a palindrome when reading it backwards gives the same string. For example "a", "aa", "appa" and "queryreuq" are all palindromes.

You start with an empty string SS and process two kinds of operations.

  1. Append one lowercase letter to the end of SS.
  2. Delete the last character of SS.

After each operation, count the palindromic substrings of the current string. For a string SS and integers ii, jj with 1ijS1 \le i \le j \le |S|, let S[i,j]S[i, j] be the substring of SS that runs from its ii-th character to its jj-th character. Count the pairs (i,j)(i, j) for which S[i,j]S[i, j] is a palindrome, and print that count.

Input

The input has two lines.

The first line has the number of queries QQ.

The second line has the queries as a single string of length QQ. Its ii-th character KiK_i describes the ii-th query.

KiK_i is either '-' or a lowercase English letter ('a', 'b', ..., 'z'). The quotation marks are not part of the input.

If KiK_i is '-', delete the last character of SS. If KiK_i is a lowercase letter, append KiK_i to the end of SS.

The length of SS after every query is guaranteed to be at least 1.

Output

Print QQ integers on one line, separated by a single space. The ii-th integer is the answer after the ii-th query.

Constraints

  • 1Q10,0001 \le Q \le 10{,}000