Under construction

Still being built. Things may change

Max or Min

Time limit1sMemory limit256 MB

Summary
Given numbers on a circle and min/max operations over a value and its two neighbors, find for each x the least minutes to make all values equal x, or -1.
Level

Hard8 of 10

Topics
Implementation, Greedy, Math, Simulation
Solved
No attempts yet

Problem

Kevin has nn integers a1,a2,…,ana_1, a_2, \ldots, a_n arranged in a circle. That is, aia_i and ai+1a_{i+1} (1≤i<n1 \le i < n) are neighbors, and a1a_1 and ana_n are neighbors as well. Therefore, each number has exactly two neighbors.

In one minute, Kevin can set aia_i to the minimum among the three numbers aia_i and its two neighbors. Alternatively, he can set aia_i to the maximum among the same three numbers. For example, if ai=5a_i = 5 and its two neighbors are 3 and 2, and Kevin performs the minimum operation, aia_i becomes 2. If he performs the maximum operation, however, aia_i stays 5.

For each xx from 1 to mm, find the minimum number of minutes needed to make all numbers equal xx, or determine that it is impossible.

Input

The first line contains two integers nn and mm (3≤n≤2⋅1053 \le n \le 2 \cdot 10^5, 1≤m≤2⋅1051 \le m \le 2 \cdot 10^5): the number of integers in the circle and the number of values you need answers for.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤m1 \le a_i \le m).

Output

Print mm integers. The ii-th integer is the minimum number of minutes needed to make all numbers equal ii, or −1-1 if it is impossible.

Hint

To make all numbers equal 2, Kevin needs at least 5 minutes. One possible sequence of operations:

  1. Apply the minimum operation to a6a_6. It becomes 2.
  2. Apply the maximum operation to a4a_4. It becomes 2.
  3. Apply the maximum operation to a3a_3. It becomes 5.
  4. Apply the minimum operation to a2a_2. It becomes 2.
  5. Apply the minimum operation to a3a_3. It becomes 2.

Examples1

  1. Example 1

    Input
    7 5
    2 5 1 1 2 3 2
    
    Expected output
    5 5 7 -1 6