#P6393. Perfect Chestnut Pairing

    ID: 19609 Type: Default 1000ms 256MiB

Perfect Chestnut Pairing

Perfect Chestnut Pairing

You have n chestnuts arranged in a row and numbered from \(1\) to \(n\). Each chestnut \(i\) has a sweetness value \(a_i\) and a saltiness value \(b_i\).

Tiyi defines a perfect pairing between two chestnuts \((i, j)\) (with \(i < j\)) if and only if \(j\) is the smallest index satisfying the following equation:

\[ b_j\Bigl(a_j - a_i - b_i\Bigr) = b_i^2 \]

In other words, for a fixed \(i\), the perfect pairing \(j\) is defined as the smallest \(j\) (where \(i < j \le n\)) for which the above equation holds. It is guaranteed that if such an index exists then it is unique.

If no such chestnut \(j\) exists for chestnut \(i\), output \(-1\) for that \(i\).

Your task is to find the perfect pairing for each chestnut \(i\).

inputFormat

The first line contains an integer \(n\) (the number of chestnuts).

The second line contains \(n\) space-separated integers \(a_1, a_2, \ldots, a_n\) representing the sweetness values.

The third line contains \(n\) space-separated integers \(b_1, b_2, \ldots, b_n\) representing the saltiness values.

outputFormat

Output \(n\) space-separated integers. The \(i\)-th integer is the index \(j\) (\(i < j \le n\)) that forms a perfect pairing with chestnut \(i\) according to the equation \[ b_j(a_j - a_i - b_i) = b_i^2, \] if such a chestnut exists; otherwise, output \(-1\) for that \(i\).

sample

3
3 5 10
1 2 3
-1 -1 -1