Day 6 - Bob and Random Expression

0

0 votes
Medium, Exception handling, Recruit, Combinatorics, Probability and Statistics, Data Structures, Ready, Mathematics, Approved, Probability
Problem

Bob was given N integers by his teacher. He was supposed to make a expression out of them without changing the order of integers. So he decided to use 2 types of operators: "|"(also known as Bitwise Or ) and "+". He decided to put exactly one operator between every consecutive integers. Thus he would use N1 operators to form a valid mathematical expression from the N integers. But as Bob is feeling very sleepy, he might use any of the 2 operators with equal probability at any of the valid places.

His teacher was perplexed by this random behavior and wondered what is the Expected value of the Random Expression thus created by her student. Note that Bitwise OR has higher precedence than addition operator.

Input Format

The first line consists of an integer, N.
Next line follows with N integers.

Output Format

Print PQ1mod 109+7, where PQ is the expected value of expression expressed as an irreducible fraction.

Input Constraints

1N106
0all integers109

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

The different ways are:
1+2+3=6
1+2|3=4
1|2+3=6
1|2|3=3
All these ways have probability = 14
So the Expected value = 6×14+4×14+6×14+3×14=194750000010 mod 109+7.

Editor Image

?