Under construction

Still being built. Things may change

Maximum Bitwise OR by Window Length

Time limit2sMemory limit512 MB

Summary
For each window length K from 1 to N, output the maximum bitwise OR over all K consecutive elements of the array.
Level

Hard8 of 10

Topics
Bit manipulation, Divide and conquer, Array, Segment tree
Solved
No attempts yet

Problem

You are given an array of NN nonnegative integers. For every integer KK between 11 and NN, find the largest value that the bitwise OR of KK consecutive elements of the array can take.

The bitwise OR of several nonnegative integers is the integer whose ii-th binary digit from the right is 00 exactly when the ii-th binary digit from the right of every one of those integers is 00.

Input

The first line contains the length of the array NN (1≤N≤5000001 \le N \le 500000).

Each of the next NN lines contains one element of the array, an integer xx (0≤x<2300 \le x < 2^{30}).

Output

Print NN lines. On the kk-th line, print the largest value that the bitwise OR of kk consecutive elements of the array can take.

Examples2

  1. Example 1

    Input
    8
    10
    7
    11
    4
    7
    6
    2
    16
    
    Expected output
    16
    18
    22
    23
    23
    31
    31
    31
    
  2. Example 2

    Input
    5
    1
    2
    4
    8
    16
    
    Expected output
    16
    24
    28
    30
    31