#P1725D. Deducing Sortability

    ID: 842 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>binary searchbitmasksmath*2900

Deducing Sortability

Description

Let's say Pak Chanek has an array AA consisting of NN positive integers. Pak Chanek will do a number of operations. In each operation, Pak Chanek will do the following:

  1. Choose an index pp (1pN1 \leq p \leq N).
  2. Let cc be the number of operations that have been done on index pp before this operation.
  3. Decrease the value of ApA_p by 2c2^c.
  4. Multiply the value of ApA_p by 22.

After each operation, all elements of AA must be positive integers.

An array AA is said to be sortable if and only if Pak Chanek can do zero or more operations so that A1<A2<A3<A4<<ANA_1 < A_2 < A_3 < A_4 < \ldots < A_N.

Pak Chanek must find an array AA that is sortable with length NN such that A1+A2+A3+A4++ANA_1 + A_2 + A_3 + A_4 + \ldots + A_N is the minimum possible. If there are more than one possibilities, Pak Chanek must choose the array that is lexicographically minimum among them.

Pak Chanek must solve the following things:

  • Pak Chanek must print the value of A1+A2+A3+A4++ANA_1 + A_2 + A_3 + A_4 + \ldots + A_N for that array.
  • QQ questions will be given. For the ii-th question, an integer PiP_i is given. Pak Chanek must print the value of APiA_{P_i}.

Help Pak Chanek solve the problem.

Note: an array BB of size NN is said to be lexicographically smaller than an array CC that is also of size NN if and only if there exists an index ii such that Bi<CiB_i < C_i and for each j<ij < i, Bj=CjB_j = C_j.

The first line contains two integers NN and QQ (1N1091 \leq N \leq 10^9, 0Qmin(N,105)0 \leq Q \leq \min(N, 10^5)) — the required length of array AA and the number of questions.

The ii-th of the next QQ lines contains a single integer PiP_i (1P1<P2<<PQN1 \leq P_1 < P_2 < \ldots < P_Q \leq N) — the index asked in the ii-th question.

Print Q+1Q+1 lines. The 11-st line contains an integer representing A1+A2+A3+A4++ANA_1 + A_2 + A_3 + A_4 + \ldots + A_N. For each 1iQ1 \leq i \leq Q, the (i+1)(i+1)-th line contains an integer representing APiA_{P_i}.

Input

The first line contains two integers NN and QQ (1N1091 \leq N \leq 10^9, 0Qmin(N,105)0 \leq Q \leq \min(N, 10^5)) — the required length of array AA and the number of questions.

The ii-th of the next QQ lines contains a single integer PiP_i (1P1<P2<<PQN1 \leq P_1 < P_2 < \ldots < P_Q \leq N) — the index asked in the ii-th question.

Output

Print Q+1Q+1 lines. The 11-st line contains an integer representing A1+A2+A3+A4++ANA_1 + A_2 + A_3 + A_4 + \ldots + A_N. For each 1iQ1 \leq i \leq Q, the (i+1)(i+1)-th line contains an integer representing APiA_{P_i}.

Sample Input 1

6 3
1
4
5

Sample Output 1

17
1
3
4

Sample Input 2

1 0

Sample Output 2

1

Note

In the first example, the array AA obtained is [1,2,3,3,4,4][1, 2, 3, 3, 4, 4]. We can see that the array is sortable by doing the following operations:

  • Choose index 55, then A=[1,2,3,3,6,4]A = [1, 2, 3, 3, 6, 4].
  • Choose index 66, then A=[1,2,3,3,6,6]A = [1, 2, 3, 3, 6, 6].
  • Choose index 44, then A=[1,2,3,4,6,6]A = [1, 2, 3, 4, 6, 6].
  • Choose index 66, then A=[1,2,3,4,6,8]A = [1, 2, 3, 4, 6, 8].