PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000150. Những sinh vật chất nhầy (Slimes)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những sinh vật chất nhầy (Slimes)

Slimes

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn slimes in a line, numbered from 11 to nn. Slime ii initially has size aia_i.

During each second, if possible, exactly one slime eats an adjacent slime. A slime may eat its neighbor only when it is strictly larger. The eater gains the eaten slime's size, the eaten slime disappears, and adjacency is updated in the remaining line. The process stops when no move is possible.

For each original slime, find the smallest number of seconds until it can be eaten in some valid sequence of moves. Each slime can be considered under a different sequence of moves. Print −1-1 if it cannot be eaten.

Input

  • The first line contains nn, the number of initial slimes.
  • The second line contains the sizes a1,…,ana_1,\ldots,a_n from left to right.

Output

Print nn integers: the minimum seconds before each original slime is eaten, or −1-1 when impossible.

Subtasks

  • Subtask 1 (20 points): 1≤n≤351\le n\le35; 1≤ai≤1001\le a_i\le100 for all ii.
  • Subtask 2 (30 points): 1≤n≤60001\le n\le6000; 1≤ai≤1061\le a_i\le10^6 for all ii.
  • Subtask 3 (50 points): 1≤n≤3⋅1051\le n\le3\cdot10^5; 1≤ai≤1091\le a_i\le10^9 for all ii.

Examples

Input

5
2 2 3 1 4

Output

2 1 2 1 3

Explanation

For the initial line [2,2,3,1,4][2,2,3,1,4]:

  • Slime 11 can be eaten in 22 seconds: slime 33 eats slime 22, then slime 11.
  • Slime 22 can be eaten by slime 33 in 11 second.
  • Slime 33 can be eaten in 22 seconds: slime 55 eats slime 44 and grows to size 55, then eats slime 33.
  • Slime 44 can be eaten by slime 55 immediately.
  • Slime 55 can be eaten in 33 seconds: slime 33 first eats slime 44 (growing to 44), next slime 22 (growing to 66), then slime 55. These choices illustrate why different targets may use different move sequences. The output is 2 1 2 1 3.