This page is still under construction.

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

Waging War Peacefully

Time limit5sMemory limit256 MB

Summary
Given group sizes A1..AN, find the largest rectangle width Y that fits all soldiers in row-major order with at most k row-boundary conflicts, for every k from 0 to N-1.
Level

Hard9 of 10

Topics
Math, Number theory, Prefix sum, Greedy
Solved
No attempts yet

Problem

The Polymath civilization is known to have fought a large-scale war called the First Donga War around 8500 BC to subjugate its neighbor Scienceboard. You are studying the army tactics of the Polymath civilization at that time. Fortunately, you obtained some useful information from old documents.

According to their book of tactics, the army of the Polymath civilization was formed into a precise rectangular formation. That is, a rectangle with XX rows and YY columns is filled by exactly XYXY soldiers. Cases where the number of soldiers did not divide exactly, leaving some soldiers left over or short, were not allowed.

Since the Polymath civilization had originally subjugated many small neighboring countries with its strong military power, its army also contained NN different ethnic groups. In particular, records show that among the soldiers who took part in the First Donga War, exactly AiA_i soldiers were from the ii-th ethnic group.

The Polymath civilization discriminated against its citizens based on ethnic origin, and the army was affected by this as well. In particular, when i<ji<j, a soldier from the ii-th ethnic group always had to 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 had a slight problem: whenever soldiers from different ethnic groups were adjacent side by side, a fight always broke 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.

The army officers of the Polymath civilization used peace stones to prevent fights. Using the power of a peace stone prevents 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, then the number of pairs of adjacent soldiers from different ethnic groups must be at most kk for no fight to occur.

Through various records, you discovered that the officers of the Polymath civilization believed that the wider the formation was, that is, the larger YY was, the stronger the army was. Therefore, you conjecture that the formation used in the First Donga War was also a perfectly rectangular formation with the largest YY value among formations where no fight occurs. However, since you have not yet determined exactly how many peace stones the Polymath civilization had, you decided 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, output the maximum possible value of YY for each kk with 0≤k≤N−10 \le k \le N-1, separated by spaces.

Constraints

  • 1≤N≤1061 \le N \le 10^6
  • 1≤Ai≤10181 \le A_i \le 10^{18}
  • M≤1018M \le 10^{18} (where M=∑i=1NAiM = \sum_{i=1}^N A_i)

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