XOR
Given a tree where each vertex has an associated value , the distance between two vertices is defined as the XOR of all vertex values along the path connecting them. Your task is to calculate the sum of distances for all pairs of vertices such that .
Input Format
The first line contains a single integer , representing the number of vertices in the tree.
The second line contains integers , which are the values associated with each vertex.
Each of the following lines contains two integers and , indicating an edge between vertices and .
Output Format
Output a single integer, which is the sum of distances between all pairs of vertices with .
Examples
Note
For example, consider the following calculations for a given tree:
The distance from vertex 1 to 1 is 1.
The distance from vertex 1 to 2 is 3.
The distance from vertex 1 to 3 is 0.
The distance from vertex 2 to 2 is 2.
The distance from vertex 2 to 3 is 1.
The distance from vertex 3 to 3 is 3.
The total sum of these distances is .