Under construction

Still being built. Things may change

Fence

Time limit3sMemory limit1024 MB

Summary
For each height b from 1 to M, compute the total length of the odd-numbered fence pieces when every plank is cut into pieces of length b.
Level

Medium6 of 10

Topics
Math, Prefix sum, Implementation
Solved
No attempts yet

Problem

Bajtazar is widely believed to be the greatest scrooge in the borough. One can find many examples to support this claim, and the least important one is that his estate has no fence at all. However, he recently found nn old planks in his basement, so he decided to build at least a fragment of a fence.

He stacked the planks one over another so that their lengths, from the top, are a1,…,ana_1, \ldots, a_n. He took the first plank, cut off a piece of length bb, and nailed it as the leftmost piece of the fence. He then cut another piece of length bb and nailed it next to the previous one. He kept doing this until what was left in his hand was a piece of length cc (1≤c≤b1 \leq c \leq b). He nailed that short piece to the fence too, since it would be a pity to waste such a good plank. Then he took the second plank from the stack and repeated the whole procedure, and so on for every plank.

When the job was done, he decided the short pieces were a poor idea. He painted the whole fence white, but then he noticed that painting every other plank, starting from the leftmost one, uses about half as much paint and still looks coherent. So he painted only every second plank, starting from the leftmost one. (He could have started from the second one, after all.)

That night he wondered whether a different height bb would have needed less paint. For every possible height b=1,…,Mb = 1, \ldots, M, where MM is the largest aia_i, compute the total length of planks he would have painted white.

Input

The first line contains the number of test cases zz (1≤z≤51 \leq z \leq 5).

The first line of each test case contains the number of planks nn (1≤n≤1 000 0001 \leq n \leq 1\,000\,000). The next nn integers are the plank lengths a1,…,ana_1, \ldots, a_n (1≤ai≤1 000 0001 \leq a_i \leq 1\,000\,000, ∑i=1nai≤1 000 000\sum_{i=1}^n a_i \leq 1\,000\,000).

Output

For each test case, output MM lines, where MM is the largest aia_i in that test case. On line ii, output fif_i, the total length of planks Bajtazar would have painted white if he had chosen the fence height b=ib = i.

Hint

For height b=4b = 4, the fence pieces are 4 4 2 4 3 2 4 4. He would paint pieces with total length 4+2+3+4=134 + 2 + 3 + 4 = 13, so the answer on line 4 is 13.

For height b=5b = 5, the fence pieces are 5 5 5 2 2 5 3. He would paint pieces with total length 5+5+2+3=155 + 5 + 2 + 3 = 15, so the answer on line 5 is 15.

Examples1

  1. Example 1

    Input
    1
    4
    10 7 2 8
    
    Expected output
    14
    13
    15
    13
    15
    16
    21
    23
    24
    12