Codeforces Round 542 [Alex Lopashev Thanks-Round] (Div. 1)
C
Morse Code
Codeforces
2400
原题
← BD →
翻译中…

In Morse code, an letter of English alphabet is represented as a string of some length from $1$ to $4$. Moreover, each Morse code representation of an English letter contains only dots and dashes. In this task, we will represent a dot with a "0" and a dash with a "1".

翻译中…

Because there are $2^1+2^2+2^3+2^4 = 30$ strings with length $1$ to $4$ containing only "0" and/or "1", not all of them correspond to one of the $26$ English letters. In particular, each string of "0" and/or "1" of length at most $4$ translates into a distinct English letter, except the following four strings that do not correspond to any English alphabet: "0011", "0101", "1110", and "1111".

翻译中…

You will work with a string $S$, which is initially empty. For $m$ times, either a dot or a dash will be appended to $S$, one at a time. Your task is to find and report, after each of these modifications to string $S$, the number of non-empty sequences of English letters that are represented with some substring of $S$ in Morse code.

翻译中…

Since the answers can be incredibly tremendous, print them modulo $10^9 + 7$.

翻译中…

Input

翻译中…

The first line contains an integer $m$ ($1 \leq m \leq 3\,000$) — the number of modifications to $S$.

翻译中…

Each of the next $m$ lines contains either a "0" (representing a dot) or a "1" (representing a dash), specifying which character should be appended to $S$.

翻译中…

Output

翻译中…

Print $m$ lines, the $i$-th of which being the answer after the $i$-th modification to $S$.

翻译中…

Note

翻译中…

Let us consider the first sample after all characters have been appended to $S$, so S is "111".

翻译中…

As you can see, "1", "11", and "111" all correspond to some distinct English letter. In fact, they are translated into a 'T', an 'M', and an 'O', respectively. All non-empty sequences of English letters that are represented with some substring of $S$ in Morse code, therefore, are as follows.

翻译中…
  1. "T" (translates into "1")
  2. "M" (translates into "11")
  3. "O" (translates into "111")
  4. "TT" (translates into "11")
  5. "TM" (translates into "111")
  6. "MT" (translates into "111")
  7. "TTT" (translates into "111")
翻译中…

Although unnecessary for this task, a conversion table from English alphabets into Morse code can be found here.

翻译中…

样例

Input #1
3
1
1
1
Output #1
1
3
7
InputCopy OutputCopy
Input #2
5
1
0
1
0
1
Output #2
1
4
10
22
43
InputCopy OutputCopy
Input #3
9
1
1
0
0
0
1
1
0
1
Output #3
1
3
10
24
51
109
213
421
833
InputCopy OutputCopy
题目信息
题号
1129C
时间限制
2 s
内存限制
256 MB
标签
二分
数据结构
动态规划
哈希
排序
后缀结构
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。