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

#FT0000035. Khôi phục hoán vị (Restore Permutation)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Khôi phục hoán vị (Restore Permutation)

Restore Permutation

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A hidden permutation p1,p2,…,pnp_1,p_2,\ldots,p_n contains every integer from 11 through nn exactly once.

For each position ii, you are given sis_i, the sum of the values pjp_j at earlier positions with strictly smaller values: both j<ij<i and pj<pip_j<p_i must hold. If no earlier element is smaller, the sum is zero.

Recover the complete permutation from s1,s2,…,sns_1,s_2,\ldots,s_n. The input is guaranteed to describe exactly one valid permutation.

Input

  • Line 1: integer nn, the permutation length.
  • Line 2: nn integers s1,s2,…,sns_1,s_2,\ldots,s_n in position order.

Output

Print the nn permutation elements p1,p2,…,pnp_1,p_2,\ldots,p_n on one line, separated by spaces.

Subtasks

Subtask 1 (20 points):

  • 1≤n≤201\le n\le 20; 0≤si≤n(n−1)/20\le s_i\le n(n-1)/2 for all 1≤i≤n1\le i\le n; ss corresponds to a valid permutation of 1,2,…,n1,2,\ldots,n.

Subtask 2 (30 points):

  • 1≤n≤20001\le n\le 2000; 0≤si≤n(n−1)/20\le s_i\le n(n-1)/2 for all 1≤i≤n1\le i\le n; ss corresponds to a valid permutation of 1,2,…,n1,2,\ldots,n.

Subtask 3 (50 points):

  • 1≤n≤2000001\le n\le 200000; 0≤si≤n(n−1)/20\le s_i\le n(n-1)/2 for all 1≤i≤n1\le i\le n; ss corresponds to a valid permutation of 1,2,…,n1,2,\ldots,n.

Examples

Examples 1

Input

5
0 1 1 1 10

Output

1 4 3 2 5

Explanation

For [1,4,3,2,5][1,4,3,2,5], the first sum is 00. At positions 2,3,42,3,4, only the earlier value 11 is smaller, so each sum is 11. At position 55, all four earlier values are smaller and 1+4+3+2=101+4+3+2=10. This exactly reproduces the input.

Examples 2

Input

3
0 0 0

Output

3 2 1

Explanation

In the decreasing order [3,2,1][3,2,1], no earlier value is smaller than the current value, so all three sums are zero.

Because every permutation value is positive, any earlier smaller value would make the corresponding sum positive. Since all three sums are zero, the permutation must be strictly decreasing. With values 1, 2, and 3, the only possible order is 3,2,13,2,1.