C. Cereal Trees III
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Daniel has $$$n$$$ trees in his backyard, each numbered from $$$1$$$ to $$$n$$$, and he is currently in the tree numbered $$$1$$$. These trees are very special, and can grow cereal on them! When Daniel is hungry, he travels from tree to tree and eats cereal from the trees that he reaches. Furthermore, each tree has a different type of cereal on it, and he would like to eat as many different varieties of cereal as possible.

Unfortunately, traveling from tree to tree takes a lot of energy. Specifically, traveling from tree $$$a$$$ to tree $$$b$$$ takes $$$a | b$$$ energy, where $$$|$$$ denotes the bitwise OR operator. However, once he has traveled on a path from $$$a$$$ to $$$b$$$, it no longer takes energy for it to travel on that path.

Recently, the cereal trees have been taking a long time to regrow their cereal, meaning every day, there is exactly one cereal tree that has no cereal on it. Daniel is trying to plan his meals for the next $$$d$$$ days. On a day $$$i$$$, he knows that there will be no cereal on tree $$$t_i$$$, and therefore will decide to skip visiting that tree that day. It is guaranteed that tree $$$1$$$ is never skipped. Note that each day is independent of other days - an empty tree on day $$$1$$$ will not stay empty on day $$$2$$$, and paths traveled on day $$$1$$$ reset on day $$$2$$$.

Daniel is very lazy, so can you help him figure out the smallest amount of energy he can spend to reach all cereal-bearing trees for each of the next $$$d$$$ days?

Input

The first line of input contains $$$2$$$ integers $$$n$$$ ($$$2\le n \le 10^5$$$) and $$$d$$$ ($$$1\le d \le 10^5$$$). Then $$$d$$$ lines follow.

Each of these $$$d$$$ lines contains one integer $$$t_i$$$ ($$$2\le t_i \le n$$$).

Output

For each value of $$$t_i$$$ from the input, output onto separate lines the minimum amount of energy Daniel can spend to reach all cereal-bearing trees each day.

Example
Input
5 2
3 4
Output
13
11
Note

When tree $$$3$$$ has no cereal, Daniel can use paths $$$1-2$$$, $$$1-4$$$, and $$$5-4$$$, leading to a total energy of $$$3 + 5 + 5 = 13$$$.

When tree $$$4$$$ has no cereal, Daniel can use paths $$$1-2$$$, $$$2-3$$$, and $$$1-5$$$, leading to a total energy of $$$3 + 3 + 5 = 11$$$.

Problem Credits: Daniel Kim