Under construction

Still being built. Things may change

Yet Another Convolution

Time limit4sMemory limit512 MB

Summary
Given arrays a and b of length n, compute for each k the maximum of |a_i - b_j| over all pairs (i, j) with gcd(i, j) equal to k.
Level

Hard9 of 10

Topics
Number theory, Math, Divide and conquer
Solved
No attempts yet

Statement

You are given an integer array a1,…,ana_1, \dots, a_n and an integer array b1,…,bnb_1, \dots, b_n of length nn. Compute the array c1,…,cnc_1, \dots, c_n defined as follows:

ck=max⁡gcd⁡(i,j)=k∣ai−bj∣c_k = \max_{\gcd(i,j)=k} |a_i - b_j|

Input

The first line contains a single integer nn (1≤n≤1051 \le n \le 10^5). The second line contains nn integers a1,…,ana_1, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9). The third line contains nn integers b1,…,bnb_1, \dots, b_n (1≤bi≤1091 \le b_i \le 10^9).

Output

Output nn integers c1,…,cnc_1, \dots, c_n.

Examples1

  1. Example 1

    Input
    8
    1 2 3 4 5 6 7 8
    8 7 6 5 4 3 2 1
    
    Expected output
    7 5 3 3 1 3 5 7