Byteman is a scientist who studies how crystals form from the atoms of different elements. He has designed a special process for growing crystals and derived a formula that describes which combinations of atoms make a valid crystal. He now wants to know how many different crystals his process can produce.
For non-negative integers x and y, let x⊕y denote their bitwise exclusive or (XOR). On single bits it is defined by 1⊕1=0⊕0=0 and 0⊕1=1⊕0=1.
There are n elements, numbered from 1 to n. For each element i there is an upper bound mi on the number of atoms of that element that a single crystal may contain. A crystal that uses ai atoms of element i (for i=1,…,n) can be formed if and only if:
The last condition simply states that every crystal must contain at least one atom. Two crystals are considered different if they differ in the number of atoms of at least one element.
Write a program that reads the number of elements and the per-element upper bounds, computes the number of different crystals that can be formed, and prints that number.
The first line contains the number of elements n (1≤n≤50). The second line contains n positive integers m1,…,mn separated by single spaces, where 1≤mi<232−1.
Print a single integer: the total number of different crystals that can be formed. This number is guaranteed to be smaller than 264.
For the input with n=3 and upper bounds 2 1 3, the answer is 5. Written as (a1,a2,a3), the five crystals are (0,1,1), (1,0,1), (1,1,0), (2,0,2), and (2,1,3).