SUBARRAY OR

Given an array of integers A of size N.

Value of a subarray is defined as BITWISE OR of all elements in it.

Return the sum of Value of all subarrays of A % 10^9 + 7.



Input Format

The first argument given is the integer array A.

Output Format

Return the sum of Value of all subarrays of A % 10^9 + 7.

Constraints

1 <= N <= 10^5
1 <= A[i] <= 10^8

For Example

Input 1:
    A = [1, 2, 3, 4, 5]
Output 1:
    71
Explaination 1:
    Value( [ 1 ] ) =	1
    Value( [ 1,2 ] ) =	3
    Value( [ 1,2,3 ] ) =	3
    Value( [ 1,2,3,4 ] ) =	7
    Value( [ 1,2,3,4,5 ] ) =	7
    Value( [ 2 ] ) =	2
    Value( [ 2,3 ] ) =	3
    Value( [ 2,3,4 ] ) =	7
    Value( [ 2,3,4,5 ] ) =	7
    Value( [ 3 ] ) =	3
    Value( [ 3,4 ] ) =	7
    Value( [ 3,4,5 ] ) =	7
    Value( [ 4 ] ) =	4
    Value( [ 4,5 ] ) =	5
    Value( [ 5 ] ) =	5
    Sum of all these values = 71

Input 2:
    A = [7, 8, 9, 10]
Output 2:
    110
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving SUBARRAY OR on Interview Code Editor
Sign Up
to access hints and editorial solutions for SUBARRAY OR

Discussion


Loading...
Click here to start solving coding interview questions