Under construction

Still being built. Things may change

Preparing for War

Time limit2sMemory limit256 MB

Summary
Given group sizes in strict order, place all soldiers in a rectangle X by Y so that adjacent different-group pairs are at most k, and find the maximum Y for each k from 0 to N-1.
Level

Hard8 of 10

Topics
Math, Greedy, Number theory, Implementation
Solved
No attempts yet

Problem

The kingdom of Polymath is preparing for war to conquer its neighbor Scienceboard. You have been asked to design the battle formation for the war, and you are now studying formations.

Given the terrain of the war zone, the most efficient formation appears to be a rectangular one. That is, a rectangle with XX rows and YY columns filled by exactly XYXY soldiers. If the number of soldiers does not divide evenly and some are left over or missing, such a formation cannot be made.

Since the Polymath civilization has long subjugated many small neighboring countries with its strong military, its army contains soldiers from NN different ethnic groups. In particular, the number of soldiers from the ii-th ethnic group participating in this war is exactly AiA_i.

Because rank depends on ethnic group, the positions of the soldiers cannot be assigned arbitrarily. In particular, when i<ji<j, a soldier from the ii-th ethnic group must always stand in front of a soldier from the jj-th ethnic group. Here, a soldier at row aa, column bb standing in front of a soldier at row a′a', column b′b' means that one of the following two conditions holds.

  • a<a′a<a'
  • a=a′a=a' and b<b′b<b'

However, this arrangement has a slight problem: if soldiers from different ethnic groups are adjacent side by side, a fight will break out. Here, a soldier at row aa, column bb and a soldier at row a′a', column b′b' being adjacent side by side means that a=a′a=a' and ∣b−b′∣=1|b-b'|=1.

When you report this problem, the army officers of the kingdom decide to use peace stones to prevent fights. Using the power of a peace stone can prevent a fight even when soldiers from different ethnic groups are adjacent, but one stone can prevent only one fight. That is, if you have kk peace stones, fights will not break out only when the number of adjacent pairs of soldiers from different ethnic groups is at most kk.

The army officers believe that the wider the formation is, that is, the larger YY is, the stronger the army is. Therefore, you must find a formation satisfying the above conditions with the largest possible value of YY. However, information about the peace stones is a state secret, so you do not know exactly how many peace stones there are. Thus, you decide to find the maximum possible value of YY for every integer kk with 0≤k≤N−10 \le k \le N-1.

Input

The first line gives the number of ethnic groups NN.

The next line gives the number of soldiers in each ethnic group, A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N.

Output

On the first line, print the maximum possible value of YY for every integer kk with 0≤k≤N−10 \le k \le N-1, separated by spaces.

Constraints

  • 1≤N≤1031 \le N \le 10^3
  • 1≤Ai≤1061 \le A_i \le 10^6
  • M≤106M \le 10^6 (where M=A1+A2+⋯+ANM=A_1+A_2+\cdots+A_N)

Examples2

  1. Example 1

    Input
    5
    3 1 2 1 1
    
    Expected output
    1 1 2 4 8
    
  2. Example 2

    Input
    4
    6 2 14 14
    
    Expected output
    2 2 6 36