QOJ.ac

QOJ

時間限制: 5.0 s 記憶體限制: 32 MB 總分: 100

#17798. Hamming Dominance

统计

Please note the unconventional time and memory limits for this problem!

A binary string $S$ of length $n$ is initially all zeros. You are given $n$ operations. In each operation, you first flip one bit of $S$, then output the number of pairs of binary strings $(A, B)$ that satisfy the following two conditions:

  • Both $A$ and $B$ are cyclically isomorphic to $S$.
  • The Hamming weight of every prefix of $A$ is no less than the Hamming weight of the prefix of $B$ of the same length.

Two strings are said to be cyclically isomorphic if and only if one can be transformed into the other through a number of left cyclic shifts. A "left cyclic shift" means moving the first character of the string to the end. For example, $abc$ becomes $bca$ after one left cyclic shift; thus, they are cyclically isomorphic, but they are not cyclically isomorphic to $cba$.

The Hamming weight of a binary string is defined as the number of $1$s it contains.

Input

The input contains multiple test cases.

The first line contains an integer $T$ ($1 \le T \le 2000$), representing the number of test cases.

For each test case, the first line contains an integer $n$ ($1 \le n \le 2000$), representing the length of the binary string.

The next line contains $n$ integers, where the $i$-th integer represents the index of the bit flipped in the $i$-th operation (1-indexed).

It is guaranteed that $\sum n \le 2000$.

Output

Output $T$ lines, each containing $n$ integers, representing the number of pairs satisfying the conditions after each flip.

Examples

Input 1

2
5
1 2 3 4 1
3
2 1 1

Output 1

15 13 13 15 13
6 6 6

Note

In the second example, after the second operation, $S$ becomes $110$. There are 6 pairs $(A, B)$ that satisfy the conditions:

  • $A = 110, B \in \{110, 101, 011\}$
  • $A = 101, B \in \{101, 011\}$
  • $A = B = 011$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.