Under construction

Still being built. Things may change

Bead Sort

Time limit2sMemory limit1024 MB

Summary
For each prefix of b, output the total bead travel distance of bead sort on that prefix, modulo 1000000007.
Level

Medium7 of 10

Topics
Segment tree, Sorting, Math
Solved
No attempts yet

Problem

Bead sort (also called gravity sort) sorts an array of positive integers by threading beads onto vertical rods and letting gravity pull them down. Implementing it on a computer has many difficulties, such as space complexity, but in a realistic physical model it is known to run in roughly O(n)O(\sqrt{n}) time. Bead sort proceeds exactly as follows.

  1. Let mm be the largest value in the sequence. Prepare mm rods and number them 1 to mm. Initially the rods lie flat.
  2. Divide each rod into nn cells, where the length of one cell equals the diameter of a bead. From this point on, write "the yy-th cell of the xx-th rod" as (x,y)(x,y).
  3. For each element aia_i of the sequence, thread a total of aia_i beads, from (1,i)(1,i) through (ai,i)(a_i,i).
  4. Stand all rods up perpendicular to the ground at the same time, with cell 1 at the top. Gravity pulls each bead toward the higher-numbered cells. Then count the beads in the ii-th cell from the top. These counts match the elements of the sorted array.

Bead sort therefore uses ∑_ia_i\displaystyle{\sum \_i{a\_i}} beads in total. For an array aa of positive integers, let f(a)f(a) be the total distance moved by all ∑_ia_i\displaystyle{\sum \_i{a\_i}} beads when bead sort is run on aa, measured in cells. Given an array bb of length nn, compute f(ai)f(a_i) for each ii from 1 to nn, where ai=[b1,b2,⋯bi]a_i=[b_1, b_2, \cdots b_i] is the prefix of length ii. Since the answer can be large, print it modulo 1 000 000 0071\,000\,000\,007.

Input

The first line contains the length of the array nn (1≤n≤2×1051 \le n \le 2 \times 10^5).

The second line contains the nn positive integers b1b_1 through bnb_n, separated by spaces. (0<bi≤1090 < b_i \le 10^9)

Output

Print nn lines. On the ii-th line, print the value of f(ai)f(a_i). Since the answer can be large, print it modulo 1 000 000 0071\,000\,000\,007.

Examples1

  1. Example 1

    Input
    5
    5 4 3 2 1
    
    Expected output
    0
    1
    4
    10
    20