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

#FT0000044. Mảng nhỏ nhất (Minimum Array)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Mảng nhỏ nhất (Minimum Array)

Minimum Array

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given two arrays aa and bb, each of length nn, with all values in [0,n−1][0,n-1], you may rearrange the elements of bb arbitrarily. You cannot change aa or add or remove any occurrence from bb.

After rearranging bb, define

ci=(ai+bi) mod n,c_i=(a_i+b_i)\bmod n,

for 1≤i≤n1\le i\le n. Choose the rearrangement that makes the array cc lexicographically smallest: first minimize c1c_1, then among such choices minimize c2c_2, and so on. Output the optimal array cc, not the rearranged array bb.

Input

  • Line 1: integer nn, the common array length.
  • Line 2: nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.
  • Line 3: nn integers b1,b2,…,bnb_1,b_2,\ldots,b_n.

Output

Print the nn values of the optimal array cc on one line, separated by spaces.

Subtasks

Subtask 1 (20 points):

  • 1≤n≤201\le n\le 20; 0≤ai,bi≤n−10\le a_i,b_i\le n-1 for all 1≤i≤n1\le i\le n; repeated values are allowed.

Subtask 2 (30 points):

  • 1≤n≤20001\le n\le 2000; 0≤ai,bi≤n−10\le a_i,b_i\le n-1 for all 1≤i≤n1\le i\le n; repeated values are allowed.

Subtask 3 (50 points):

  • 1≤n≤2000001\le n\le 200000; 0≤ai,bi≤n−10\le a_i,b_i\le n-1 for all 1≤i≤n1\le i\le n; repeated values are allowed.

Examples

Examples 1

Input

3
1 2 0
2 1 2

Output

0 0 2

Explanation

For a1=1a_1=1, choose b1=2b_1=2 to make (1+2) mod 3=0(1+2)\bmod3=0. Of the remaining bb values 11 and 22, choose 11 for a2=2a_2=2 to obtain 00 instead of 11. The last value is 22, giving c=[0,0,2]c=[0,0,2].

Examples 2

Input

4
0 0 0 0
3 1 2 1

Output

1 1 2 3

Explanation

As every ai=0a_i=0, we have ci=bic_i=b_i. Sorting the available values of bb in increasing order yields the lexicographically smallest c=[1,1,2,3]c=[1,1,2,3].

Every element of bb must be used exactly once. As all ai=0a_i=0 and every bib_i is below 44, the modulo operation leaves the chosen value unchanged. The smallest available value for the first position is 11, then another 11, followed by 22 and 33.