#P7333. [JRKSJ R1] JFCA

[JRKSJ R1] JFCA

Description

A cycle is given with nn points on it, where the distance between every pair of adjacent points is 11.

Each point has two attributes aia_i and bib_i. For point ii, define fif_i as the shortest distance along the cycle between ii and a point jj such that iji \ne j and ajbia_j \ge b_i. In particular, if there is no such jj, then fi=1f_i=-1.

Input Format

The input has 33 lines.
Line 11 contains one integer nn.
Line 22 contains nn integers, where the ii-th integer denotes aia_i, with the same meaning as above.
Line 33 contains nn integers, where the ii-th integer denotes bib_i, with the same meaning as above.

Output Format

Output one line with nn integers, where the ii-th integer denotes fif_i, with the same meaning as above.

3
1 2 3
3 2 1
1 1 1
5
5 4 3 5 6
7 6 5 4 3
-1 2 1 1 1
5
1 1 2 1 1
2 2 2 2 2
2 1 -1 1 2

Hint

Constraints

For 20%20\% of the testdata, 1n1031 \le n \le 10^3.
For 100%100\% of the testdata, 1n1051 \le n \le 10^5, 1ai,bi1091 \le a_i,b_i \le 10^9.

For test points 44 to 1111, we use bundled evaluation.

Explanation of Sample 1

For i=1i=1, a3=3=b1=3a_3=3= b_1=3. The distance between 11 and 33 is 11, so f1=1f_1=1.
For i=2i=2, a3=3>b2=2a_3=3> b_2=2. The distance between 22 and 33 is 11, so f2=1f_2=1.
For i=3i=3, a2=2>b3=1a_2=2> b_3=1. The distance between 22 and 33 is 11, so f3=1f_3=1.

Upd 2021.3.30\text{Upd 2021.3.30}: Added a set of hack testdata.

Translated by ChatGPT 5