This page is still under construction.

Parts of this page are still being built. What you see may change.

Gifted Composer

Time limit4sMemory limit256 MB

Summary
After each prepend or append, count the lengths k for which the note sequence is a repetition of period k, with a partial final block allowed.
Level

Hard8 of 10

Topics
String matching, String
Solved
No attempts yet

Problem

Acesrc is a gifted composer. He likes writing tuneful and melodic songs. Every song he writes can be viewed as a sequence of musical notes, and each musical note represents the pitch and the duration of the sound. In this problem, we consider only the following seven primary pitches

do re mi fa sol la si

and the duration of each note is one unit time. Hence, there are only seven types of notes, and we may use the pitch name to represent a note.

Acesrc composes a song in the following way. Initially, the sequence of notes is empty. Every day, he inserts a new note at the beginning or at the end of the sequence, until the song is done.

Acesrc particularly likes songs with repetitions. For a song with nn musical notes, we say the song has a repetition of length kk (1≤k≤n)(1 \leq k \leq n), if the song can be partitioned into one or more identical sections with kk notes, optionally followed by an incomplete section, which is an initial part of a complete section. For example, do re do re do can be partitioned into do re | do re | do, so it has a repetition of length 2; similarly, do re mi do re mi has a repetition of length 3, and do re do re mi has a repetition of length 5.

Acesrc wants to know, after he adds a note each day, the number of different lengths of repetitions the song has. Can you help him?

Input

The first line contains a single integer nn (1≤n≤106)(1 \leq n \leq 10^6), the number of days Acesrc uses to compose the song. Each of the remaining nn lines contains a character cc (c∈{(c \in \{p, a})\}) and a string ss (s∈{(s \in \{do, re, mi, fa, sol, la, si})\}). On the iith day, p means Acesrc prepends ss to the sequence, and a means he appends ss to the end.

Output

Output nn lines. The iith line contains a single integer, the answer for the iith day.

Examples2

  1. Example 1

    Input
    5
    a do
    p re
    a re
    a do
    p do
    
    Expected output
    1
    1
    2
    2
    3
    
  2. Example 2

    Input
    5
    a re
    a do
    a re
    p do
    a mi
    
    Expected output
    1
    1
    2
    2
    1