This page is still under construction.

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

Fighting Routine

Time limit2sMemory limit512 MB

Summary
For every window length d from 1 to n, sum the number of distinct task types over all length-d windows of the given array.
Level

Medium7 of 10

Topics
Array, Prefix sum, Combinatorics, Math
Solved
No attempts yet

Problem

Fighting routine is an important part of improving employee productivity. Let us build a mathematical model of the diversity of task types an employee performs at a company.

Consider an employee working over nn consecutive working days. Every day the employee performs exactly one type of task; let the type of task performed on day ii be an integer aia_i.

To measure how routine the employee's work is, we use the following quantity. Fix an integer dd and consider all segments of dd consecutive working days. For each such segment, count the number of distinct task types the employee performed over those days, then sum these counts. Call the resulting value SdS_d, the dd-diversity. The higher the dd-diversity, the more distinct task types the employee performed. The variability profile of the employee is the array [S1,S2,…,Sn][S_1, S_2, \ldots, S_n].

Write a program that, given the sequence a1,a2,…,ana_1, a_2, \ldots, a_n of task types the employee performs, computes the variability profile of that employee.

Input

The first line contains a single integer nn, the number of consecutive working days to analyze (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n, the task types the employee performed (1≤ai≤1091 \le a_i \le 10^9).

Output

Print nn integers: S1,S2,…,SnS_1, S_2, \ldots, S_n.

Hint

Consider how the values SdS_d are computed in the first sample.

1-diversity: sum the number of distinct task types the employee performed over all segments consisting of one day.

DaysTask typesDistinct count
1 - 111
2 - 231
3 - 321
4 - 411
5 - 521

The 1-diversity value is S1=1+1+1+1+1=5S_1 = 1 + 1 + 1 + 1 + 1 = 5.

2-diversity: sum the number of distinct task types the employee performed over all segments consisting of two days.

DaysTask typesDistinct count
1 - 21, 32
2 - 33, 22
3 - 42, 12
4 - 51, 22

The 2-diversity value is S2=2+2+2+2=8S_2 = 2 + 2 + 2 + 2 = 8.

3-diversity: sum the number of distinct task types the employee performed over all segments consisting of three days.

DaysTask typesDistinct count
1 - 31, 3, 23
2 - 43, 2, 13
3 - 52, 1, 22

The 3-diversity value is S3=3+3+2=8S_3 = 3 + 3 + 2 = 8.

4-diversity: sum the number of distinct task types the employee performed over all segments consisting of four days.

DaysTask typesDistinct count
1 - 41, 3, 2, 13
2 - 53, 2, 1, 23

The 4-diversity value is S4=3+3=6S_4 = 3 + 3 = 6.

5-diversity: sum the number of distinct task types the employee performed over all segments consisting of five days.

DaysTask typesDistinct count
1 - 51, 3, 2, 1, 23

The 5-diversity value is S5=3S_5 = 3.

Examples2

  1. Example 1

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

    Input
    3
    10 10 10
    
    Expected output
    3 2 1