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 ≤ 109
- 1 ≤ M ≤ 105
- 1 ≤ q ≤ 3N

-----Example-----
Input:
3 5
6
2
9
7
5
Output:
2
0
1
3
1

Starter code:

Solutions:
# cook your dish here
import math;
from math import gcd,sqrt,floor,factorial,ceil
from bisect import bisect_left,bisect_right
import bisect;
import sys;
from sys import stdin,stdout
import os
sys.setrecursionlimit(pow(10,7))
import collections
from collections import defaultdict,Counter
from statistics import median
# input=stdin.readline
# print=stdout.write
from queue import Queue
inf = float("inf")
from operator import neg;
n,m=map(int,input().split())
for i in range(m):
    k=int(input())
    print(max(0,min(k-n-1,3*n+1-k)))


# cook your dish here
n,m = map(int,input().split())

for _ in range(m):
    q=int(input())
    
    if q-n-1 > n:
        print(3*n - q +1)
        
    elif q<n+2 or q>(3*n):
        print(0)
        
    else:
        print(q-n-1)

n,m = map(int,input().split())
for i in range(m):
    x=int(input())
    if (n+2)>x or x>(3*n):
        print(0)
    elif (2*n)+1==x:
        print(n)
    elif (2*n)+1>x:
        print(n-(((2*n)+1)-x))
    else:
        print(n-(x-((2*n)+1)))

# cook your dish here
n,m=map(int,input().split())
for i in range(m):
    x=int(input())
    a=0
    if (n+2)>x or x>(3*n):
        a=0
    elif (2*n)+1==x:
        a=n
    elif (2*n)+1>x:
       
        a=n-(((2*n)+1)-x)
    else:
        a=n-(x-((2*n)+1))
    print(a)

n,m=map(int,input().split())
a=[]
for i in range(m):
	x=int(input())
	if x<=n+1 or x>3*n:
		print(0)
	elif x<=(2*n)+1:
		print(x-n-1)
	else:
		print((3*n)+1-x)
		# cook your dish here


from collections import defaultdict 
def def_value(): 
    return 0
n,m=map(int,input().split())
for i in range(m):
	x=int(input())
	if x<=n+1 or x>3*n:
		print(0)
	elif x<=(2*n)+1:
		print(x%(n+1))
	else:
		print((3*n)+1-x)

ans = []

N,M = [int(i) for i in input().split()]

for i in range(M):
    q = int(input())
    if(q<=N):
        s = 0
    elif(q<=2*N):
        s = q-N-1
    else:
        s = N - (q-2*N-1)
    ans.append(s)

for i in ans:
    print(i)


# cook your dish here
n, m = map(int, input().split())
for i in range(m):
    q = int(input())
    if q < n + 2:
        print(0)
    else:
        s = 3 * n - q
        if s < n:
            print(s + 1)
        else:
            print(q - (2 + n) + 1)


n,m=map(int,input().split())
a=[]
for i in range(m):
	x=int(input())
	if x<=n+1 or x>3*n:
		print(0)
	elif x<=(2*n)+1:
		print(x%(n+1))
	else:
		print((3*n)+1-x)
		


n,m=map(int,input().split())
ma=n*2+1
for i in range(m):
    x=int(input())
    if(x>n+1):
        z=abs(ma-x)
        print(n-z)
    else:
        print(0)


# cook your dish here
n,m=map(int,input().split())
for i in range(m):
    
    q=int(input())
    if q<n+2 or q>3*n:
        print(0)
    else:
        print(n-(abs(q-((2*n)+1))))
    
    

from sys import stdin,stdout
def problem():
    n , m = [int(x) for x in stdin.readline().split()]
    for _ in range(m):
        q = int(stdin.readline());l = max(q-n,n+1);r = min(q -1 ,2*n)
        if r >= l:print(r- l + 1)
        else:print(0)
problem()

# cook your dish here
n,m=map(int,input().split())
for _ in range(m):
  q=int(input())
  if q<n+2 or q>2*n+n:
    print(0)
    continue
  else:
    low=n+2
    high=2*n+n
    count=1+min(abs(q-low),abs(q-high))
    print(count)  



# cook your dish here
n,m=map(int,input().split())
for i in range(m):
   x=int(input())
   if x<=n or x>3*n:
      print(0)
   elif x>n and x<=2*n:
      print(x-n-1)
   else:
      print(n-(x%(2*n))+1)


# cook your dish here
n,m=map(int,input().split())
for i in range(m):
    x=int(input())
    if x<=n or x>3*n:
        print(0)
    elif x>n and x<=2*n:
        print(x-n-1)
    else:
        print(n-(x%(2*n))+1)

# cook your dish here
# cook your dish here
n,m=map(int,input().split())
for i in range(m):
    x=int(input())
    if x<=n or x>3*n:
        print(0)
    elif x>n and x<=2*n:
        print(x-n-1)
    else:
        print(n-(x%(2*n))+1)
        
        
    

# cook your dish here
n,m=map(int,input().split())
for i in range(m):
    x=int(input())
    if x<=n or x>3*n:
        print(0)
    elif x>n and x<=2*n:
        print(x-n-1)
    else:
        print(n-(x%(2*n))+1)
        
        
    

# cook your dish here
n,m=map(int,input().split())
for i in range(m):
    x=int(input())
    if(x<=n or x>3*n):
        print(0)
    elif(x>n and x<=2*n):
        print(x-n-1)
    else:
        print(n-(x%(2*n))+1)

# cook your dish here
n,m=map(int,input().split())
for i in range(m):
    x=int(input())
    if(x<=n or x>3*n):
        print(0)
    elif(x>n and x<=2*n):
        print(x-n-1)
    else:
        print(n-(x%(2*n))+1)


# cook your dish here
n,m=map(int,input().split())
for i in range(m):
     q=int(input()) 
     if q>=n+2:
      if q<=2*n+1:
         print(q-n-1)
      else:
         print(3*n-q+1) 
     else:
         print("0")

# cook your dish here
n,m = list(map(int,input().split(" ")))
for i in range(m):
    q = int(input())
    if(q<n+2):
        print('0')
        continue
    else:
        print(n-abs(2*n +1 -q))

# cook your dish here
n,m=map(int,input().split())
for i in range(m):
     q=int(input()) 
     if q>=n+2:
      if q<=2*n+1:
         print(q-n-1)
      else:
         print(3*n-q+1) 
     else:
         print("0")

a,b=map(int,input().strip().split())
for j in range(b):
	n=int(input())
	if(n<=a+1 or n>3*a):print(0)
	
	else:
		mi=min(n-a-1,3*a-n+1)
		print(mi)

n,m = map(int,input().split())
for i in range(m):
    q = int(input())
    if q>n+1: print(q-n-1) if q<2*(n+1) else print(3*n-q+1)
    else: print('0')