This page is still under construction.

Parts of this page are still being built. What you see may change.

AND and OR

Time limit1sMemory limit1024 MB

Summary
Given N numbers, repeatedly replace any two by two non-negative integers with the same bitwise AND and OR, and minimize the product modulo 1e9+7.
Level

Medium7 of 10

Topics
Bit manipulation, Greedy, Math, Sorting
Solved
No attempts yet

Problem

You are given NN numbers. You may perform the following operation any number of times.

  • Choose two numbers and replace them with two non-negative integers whose bitwise AND and bitwise OR both equal those of the two chosen numbers.

After performing operations, you want to minimize the product of the numbers. Find the minimized product of the NN numbers. Since the product can be very large, output its remainder modulo 109+710^{9} + 7 instead.

See the Hint section for an explanation of bitwise AND and bitwise OR.

Input

The first line contains an integer NN between 22 and 300 000300\,000.

The second line contains NN positive integers separated by spaces. Each integer is less than 2302^{30}.

Output

Print the remainder of the minimized product modulo 109+710^{9} + 7 on the first line.

Note that you are not minimizing the remainder of the product modulo 109+7\mathbf{10}^{\mathbf{9}} + \mathbf{7}.

Hint

A bitwise operation applies the operation to each bit position.

For example, suppose we bitwise AND 2828 and 8787. First, write 2828 and 8787 in binary so the bits are clear.

0001 1100=28=28
0101 0111=87=87

Take the bit at each position in order, apply AND, and write the result below. For AND, the result is 1 only when both bits are 1; otherwise it is 0.

0001 1100=28=28
AND0101 0111=87=87
0001 0100=20=20

Bitwise OR works the same way. For OR, the result is 0 only when both bits are 0; otherwise it is 1.

0001 1100=28=28
OR0101 0111=87=87
0101 1111=95=95

Examples1

  1. Example 1

    Input
    3
    3 6 10
    
    Expected output
    60