rrsum_28822
Andrii is good in Math, but not in Programming. He is asking you to solve following problem: Given an integer number N and two sets of integer A and B. Let set A contain all numbers from 1 to N and set B contain all numbers from N + 1 to 2N. Multiset C contains all sums a + b such that a belongs to A and b belongs to B. Note that multiset may contain several elements with the same values. For example, if N equals to three, then A = {1, 2, 3}, B = {4, 5, 6} and C = {5, 6, 6, 7, 7, 7, 8, 8, 9}. Andrii has M queries about multiset C. Every query is defined by a single integer q. Andrii wants to know the number of times q is contained in C. For example, number 6 is contained two times, 1 is not contained in C at all. 
Please, help Andrii to answer all the queries.
 

Input

The first line of the input contains two integers N and M. Each of the next M line contains one integer q, the query asked by Andrii.
 

Output
Output the answer for each query in separate lines as in example.
 

Constraints

1 ≤ N ≤ 10^9
1 ≤ M ≤ 10^5
1 ≤ q ≤ 3N

 

Example
Input:
3 5
6
2
9
7
5
Output:
2
0
1
3
1
n,q = map(int,raw_input().split())
half=(1+(n+1)+n+(2*n))/2
for i in range(0,q):
    inp = input()
    diff = abs(half-inp)
    if(inp<(1+(n+1)) or inp>(n+(2*n))):
        print "0"
    elif(inp==half):
        print(n)
    else:
        print(n-diff)
3 5
6
2
9
7
5 3 5
6
2
9
10
5 3 5
6
2
9
7
0 3 5
6
2
8
7
0 3 5
6
1
8
10
9 3 5
5
2
8
10
9 3 5
5
2
9
7
0 3 5
6
1
9
6
5 3 5
6
2
8
5
0 3 5
3
2
8
10
9 6 5
5
2
9
7
0 3 5
6
1
9
6
3 5 5
6
2
8
7
0 9 5
6
2
8
7
0 3 5
4
2
8
7
0 3 5
6
1
7
10
9 3 5
7
1
9
6
5 3 5
6
6
8
10
9 3 5
6
1
9
10
3 3 5
6
1
7
10
2 4 5
6
1
5
10
9 3 5
4
1
9
10
3 3 5
6
1
0
10
2 4 5
6
1
5
10
2 3 5
10
2
9
6
5 3 5
6
0
8
0
0 4 5
6
1
5
9
2 12 5
5
2
9
18
1 7 5
6
0
8
9
0 4 5
5
1
5
9
2 3 5
1
0
9
6
4 6 5
10
0
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