{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eOnce there was a rooted tree. The tree contained $$$n$$$ nodes, which were numbered $$$1, \\dots, n$$$. The node numbered $$$1$$$ was the root of the tree. Besides, every node $$$i$$$ was assigned a number $$$a_i$$$. Your were surprised to find that there were several pairs of nodes $$$(i, j)$$$ satisfying $$$$$$a_i \\oplus a_j \u003d a_{\\operatorname{lca}(i, j)},$$$$$$ where $$$\\oplus$$$ denotes the bitwise XOR operation, and $$$\\operatorname{lca}(i, j)$$$ is the lowest common ancestor of $$$i$$$ and $$$j$$$, or formally, the lowest (i.e. deepest) node that has both $$$i$$$ and $$$j$$$ as descendants.\u003c/p\u003e\u003cp\u003eUnfortunately, you cannot remember all such pairs, and only remember the sum of $$$i \\oplus j$$$ for all different pairs of nodes $$$(i, j)$$$ satisfying the above property. Note that $$$(i, j)$$$ and $$$(j, i)$$$ are considered the same here. In other words, you will only be able to recall $$$$$$\\sum\\limits_{i\u003d1}^n\\sum\\limits_{j\u003di+1}^n [a_i \\oplus a_j \u003d a_{\\operatorname{lca}(i, j)}] (i \\oplus j).$$$$$$\u003c/p\u003e\u003cp\u003eYou are assumed to calculate it now in order to memorize it better in the future.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains a single integer $$$n$$$ ($$$2 \\leq n \\leq 10^5$$$).\u003c/p\u003e\u003cp\u003eThe second line contains $$$n$$$ integers, $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 10^6$$$).\u003c/p\u003e\u003cp\u003eEach of the next $$$n - 1$$$ lines contains $$$2$$$ integers $$$u$$$ and $$$v$$$ ($$$1 \\leq u, v \\leq n, u \\neq v$$$), indicating that there is an edge between $$$u$$$ and $$$v$$$. It is guaranteed that these edges form a tree.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint what you will memorize in the future.\u003c/p\u003e"}},{"title":"Examples","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e6\n4 2 1 6 6 5\n1 2\n2 3\n1 4\n4 5\n4 6\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e18\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}