Under construction

Still being built. Things may change

Falling Portals

Time limit2sMemory limit512 MB

Summary
Each world falls at speed i, and a cow can jump to another world when their portals align. Find each cow's earliest arrival time at its target world.
Level

Hard8 of 10

Topics
Simulation, Sorting, Union-find
Solved
No attempts yet

Problem

There are NN (2≤N≤2⋅1052\le N\le 2\cdot 10^5) worlds, each with a portal. Initially, world ii (for 1≤i≤N1 \leq i \leq N) is at xx-coordinate ii, and yy-coordinate AiA_i (1≤Ai≤1091\le A_i\le 10^9). There is also a cow on each world. At time 00, all yy-coordinates are distinct and the worlds start falling: world ii moves continuously in the negative-yy direction at a speed of ii units per second.

At any time when two worlds are at the same yy-coordinate (possibly a fractional time), the portals align, meaning that a cow on one of the worlds can choose to travel instantaneously to the other world.

For each ii, the cow on world ii wants to travel to world QiQ_i (Qi≠iQ_i\neq i). Determine how long her journey will take if she travels optimally.

Each answer is a fraction a/ba/b where aa and bb are positive, relatively prime integers, or −1-1 if the journey is impossible.

Input

The first line contains a single integer NN.

The next line contains NN space-separated integers A1,A2,…,ANA_1, A_2, \ldots, A_N.

The next line contains NN space-separated integers Q1,Q2,…,QNQ_1, Q_2, \ldots, Q_N.

Output

Print NN lines. The ii-th line contains the journey length for cow ii.

Hint

Consider the answer for the cow originally on world 2. At time 22 worlds 1 and 2 align, so the cow can travel to world 1. At time 72\frac{7}{2} worlds 1 and 3 align, so the cow can travel to world 3.

Examples1

  1. Example 1

    Input
    4
    3 5 10 2
    3 3 2 1
    
    Expected output
    7/2
    7/2
    5/1
    -1