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

#FT0000242. Lễ trưởng thành (Coming of Age Celebration)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Lễ trưởng thành (Coming of Age Celebration)

Coming of Age Celebration

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A planet has NN aliens, all currently minors. Alien ii owns AiA_i stones and will become an adult exactly ii years from now. No additional aliens will be born.

Whenever an alien becomes an adult, every alien who became an adult earlier and still has at least one stone gives exactly one stone to the newly grown adult. An adult with no stones gives nothing. These events occur in years 1,2,…,N1,2,\ldots,N.

Determine the number of stones owned by each alien after year NN.

Input

  • The first line contains the integer NN.
  • The second line contains exactly NN integers A1,A2,…,ANA_1,A_2,\ldots,A_N in alien index order.

Output

Print exactly NN space-separated integers B1,B2,…,BNB_1,B_2,\ldots,B_N, where BiB_i is the final number of stones held by alien ii.

Subtasks

  • Subtask 1 (20 points): 1≤N≤201\le N\le20; 0≤Ai≤5⋅1050\le A_i\le5\cdot10^5 for all 1≤i≤N1\le i\le N.

  • Subtask 2 (30 points): 1≤N≤20001\le N\le2000; 0≤Ai≤5⋅1050\le A_i\le5\cdot10^5 for all 1≤i≤N1\le i\le N.

  • Subtask 3 (50 points): 1≤N≤5⋅1051\le N\le5\cdot10^5; 0≤Ai≤5⋅1050\le A_i\le5\cdot10^5 for all 1≤i≤N1\le i\le N.

Examples

Input

4
5 0 9 3

Output

2 0 10 5

Explanation

Initially the stone counts are (5,0,9,3)(5,0,9,3). After year 11, no older adult can give a stone: (5,0,9,3)(5,0,9,3). In year 22, alien 11 gives one stone to alien 22: (4,1,9,3)(4,1,9,3). In year 33, aliens 11 and 22 give stones to alien 33: (3,0,11,3)(3,0,11,3). In year 44, aliens 11 and 33 give stones to alien 44 while alien 22 is empty, leaving (2,0,10,5)(2,0,10,5).