Under construction

Still being built. Things may change

Maxtrix

Time limit2sMemory limit1024 MB

Summary
Given arrays A and B, find for each k from 1 to N the maximum of A_i + B_j - i*j over all i at most k at most j.
Level

Medium7 of 10

Topics
Divide and conquer, Array, Math
Solved
No attempts yet

Problem

Two integer arrays A,BA, B of length NN are given. Define an N×NN \times N matrix CC as follows.

C_ij=A_i+B_j−ijC\_{ij} = A\_i + B\_j - ij

For every integer kk with 1≤k≤N1 \le k \le N, compute max⁡_1≤i≤k≤j≤NC_ij\max\_{1 \le i \le k \le j \le N} C\_{ij}.

Input

The first line contains the integer NN, the length of both arrays.

The second line contains A_1,A_2,⋯ ,A_NA\_1, A\_2, \cdots, A\_N, separated by spaces.

The third line contains B_1,B_2,⋯ ,B_NB\_1, B\_2, \cdots, B\_N, separated by spaces.

Output

Print NN lines with the answers.

Constraints

  • 1≤N≤250 0001 \le N \le 250\,000
  • The absolute value of every element of AA and BB is at most 101810^{18}.

Examples2

  1. Example 1

    Input
    4
    3 2 -2 6
    1 3 -3 0
    
    Expected output
    4
    4
    -1
    -1
    
  2. Example 2

    Input
    1
    1000000000000000000
    -1000000000000000000
    
    Expected output
    -1