Read problems statements in Mandarin chinese, Russian and Vietnamese as well. 

Chef Dobby loves playing games, especially games related to numbers. So, today Bhuvan gave him a new game. The description of the game goes as follows : 

Consider an array A of N non-negative integers. You can do the following move any number of times, pick two numbers from the array (x, y), such that x ≥ y and convert them into (x - y, 2 * y). The aim of the game is to make the array contains exactly (N - 1) zeros. If Dobby achieves this, after any number of steps, he wins the game.

Bhuvan wants to know the odds to choose an initial array satisfying for every index i, the condition 0 ≤ A[i] ≤ B[i] where B is given in input and Dobby wins the game with such an array. So please help him counting the number of such arrays, since the answer can be very large, output the answer modulo 10^{9} + 7.

------ Input section ------ 

The first line contains N, denoting the number of elements in the array.

Next line contains N space separated integers, denoting the elements of the array.

------ Output section ------ 

Output the number of possible winning arrays modulo 10^{9} + 7.

------ Input constraints ------ 

2 ≤ N ≤ 50
0 ≤ B[i] ≤ 50, where B[i] denotes the i^{th} element of the array.

------ Sample Input ------ 

3
2 0 1

------ Sample Output ------ 

4

------ Explanation ------ 

The possible winning arrays are (1, 0, 0), (0, 0, 1), (2, 0, 0) and (1, 0, 1).

Let us consider why array (2, 0, 1) is losing. The only move is 2 pick the pair (2, 1). After applying the operation, we get the pair (1, 2). Thus, only the order of elements in the array change and we are in a situation of deadlock. Thus, Chef Dobby can't convert the array to contain 2 zeros.

Source: codechef | Difficulty: VERY_HARD
Tags: Number theory

Dynamic programming

Mathematics


Solutions:
def solve0(x):
	lr = (max(x) + 1) * len(x) + 1
	ret = [0] * lr
	ret[0] = 1
	for y in x:
		ret0 = [0] * lr
		for (i, z) in enumerate(ret):
			if z == 0:
				continue
			for j in range(i, i + y + 1):
				ret0[j] += z
		ret = ret0
	q = 0
	for i in range(100):
		j = 1 << i
		if j >= len(ret):
			break
		q += ret[j]
	return q

def solve(x):
	ret = 0
	for i in range(1, max(x) + 1):
		if i % 2 == 1:
			y = [z // i for z in x]
			ret += solve0(y)
	return ret
import sys
f = sys.stdin
t = int(f.readline())
x = list(map(int, f.readline().split()))
print(solve(x) % (10 ** 9 + 7))