Under construction

Still being built. Things may change

Merging Cells

Time limit2sMemory limit1024 MB

Summary
Given N cells in a row with sizes, adjacent cells merge at random until one remains, and the task is to find the probability each original label ends as the winner modulo 1e9+7.
Level

Hard8 of 10

Topics
Dynamic programming, Divide and conquer, Probability
Solved
No attempts yet

Problem

Bessie is playing an online game with a row of cells. Each cell has a label and a size. Cells keep eating their neighbors until only one winner remains.

There are NN cells (2≤N≤50002\le N\le 5000) in a row, labeled 11 to NN from left to right. The initial sizes are s1,s2,…,sNs_1, s_2, \dots, s_N (1≤si≤1051\le s_i\le 10^5).

While more than one cell remains, a pair of adjacent cells is picked uniformly at random and merged into one new cell. Suppose a cell with label aa and current size cac_a merges with a cell with label bb and current size cbc_b. The new cell has size ca+cbc_a+c_b. Its label is the label of the larger cell. If the sizes are equal, the larger label wins. Formally,

resulting label={aca>cbbca<cbmax⁡(a,b)ca=cb\text{resulting label} = \begin{cases} a & c_a > c_b \\ b & c_a < c_b \\ \max(a,b) & c_a = c_b \end{cases}

For each label ii from 11 to NN, find the probability that the final cell has label ii. The probability can be written as aibi\frac{a_i}{b_i} with bi≢0(mod109+7)b_i\not\equiv 0 \pmod{10^9+7}. Print aibi−1 mod (109+7)a_i b_i^{-1} \bmod (10^9+7).

Input

The first line contains NN.

The next line contains s1,s2,…,sNs_1, s_2, \dots, s_N.

Output

For each label ii from 11 to NN, print on its own line the probability that the final cell has label ii, modulo 109+710^9+7.

Examples2

  1. Example 1

    Input
    3
    1 1 1
    
    Expected output
    0
    500000004
    500000004
    
  2. Example 2

    Input
    4
    3 1 1 1
    
    Expected output
    666666672
    0
    166666668
    166666668