This page is still under construction.

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

Separator

Time limit1.2sMemory limit512 MB

Summary
Append values one at a time to a growing sequence and after each append report how many indices are separators, meaning every earlier element is smaller and every later element is larger.
Level

Hard8 of 10

Topics
Tree, Implementation, Binary search, Sorting
Solved
No attempts yet

Problem

Let A=(a1,a2,…)A = (a_1, a_2, \ldots) be a sequence of distinct integers. An index jj is called a separator if the following two conditions hold:

  • for all k<jk < j: ak<aja_k < a_j,
  • for all k>jk > j: ak>aja_k > a_j.

In other words, the array AA consists of three parts: all elements smaller than aja_j, then aja_j itself, and finally all elements greater than aja_j.

For instance, let A=(30,10,20,50,80,60,90)A = (30, 10, 20, 50, 80, 60, 90). The separators are the indices 4 and 7, corresponding to the values 50 and 90.

The sequence AA is initially empty. You are given a sequence a1,…,ana_1, \ldots, a_n of elements to append to AA, one after another. After appending each aia_i, output the current number sis_i of separators in the sequence you have.

The input format is selected so that you have to compute the answers online. Instead of the elements aia_i you should append to AA, you are given a sequence bib_i.

Process the input as follows:

The empty sequence AA contains s0=0s_0 = 0 separators.

For each ii from 1 to nn, inclusive:

  1. Calculate the value ai=(bi+si−1) mod 109a_i = (b_i + s_{i-1}) \bmod 10^9.
  2. Append aia_i to the sequence AA.
  3. Calculate sis_i: the number of separators in the current sequence AA.
  4. Output a line containing the value sis_i.

Input

The first line contains a single integer nn (1≤n≤1061 \le n \le 10^6): the number of queries to process.

Then, nn lines follow. The ii-th of these lines contains the integer bib_i (0≤bi≤109−10 \le b_i \le 10^9 - 1). The values bib_i are chosen in such a way that the values aia_i you'll compute will all be distinct.

Output

As described above, output nn lines with the values s1s_1 through sns_n.

Notes

The first example is described in the problem statement.

The second example is decoded as A=(0,1,2,3,4,5,6,7,8,9)A = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

Examples2

  1. Example 1

    Input
    7
    30
    9
    20
    50
    79
    58
    89
    
    Expected output
    1
    0
    0
    1
    2
    1
    2
    
  2. Example 2

    Input
    10
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    
    Expected output
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10