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
#!/usr/bin/env python
import sys
from collections import defaultdict

def multiset(A, B):
    ret = []
    for a in A:
        for b in B:
            ret.append(a+b)
    ret.sort()
    return ret

def counts(A):
    ret = defaultdict(lambda: 0)
    for a in A:
        ret[a] += 1
    return sorted(ret.items())

#ranges:
#  N + 2 to 2N + 1: val - N - 1
#  2N + 2 to 3N:  N - (val - 2N - 1)

def solve(N, val):
    if val >= N + 2 and val <= 2 * N + 1:
        return val - N - 1
    elif val >= 2 * N + 2 and val <= 3 * N:
        return 3 * N + 1 - val
    else:
        return 0

if __name__ == '__main__':
    N, M = map(int, sys.stdin.readline().strip().split())
    for m in xrange(M):
        val = int(sys.stdin.readline().strip())
        print solve(N, val)