🏡 index : github.com/captn3m0/codechef.git

---
category_name: easy
problem_code: RRSUM
problem_name: 'Sum Queries'
languages_supported:
    - ADA
    - ASM
    - BASH
    - BF
    - C
    - 'C99 strict'
    - CAML
    - CLOJ
    - CLPS
    - 'CPP 4.3.2'
    - 'CPP 4.9.2'
    - CPP14
    - CS2
    - D
    - ERL
    - FORT
    - FS
    - GO
    - HASK
    - ICK
    - ICON
    - JAVA
    - JS
    - 'LISP clisp'
    - 'LISP sbcl'
    - LUA
    - NEM
    - NICE
    - NODEJS
    - 'PAS fpc'
    - 'PAS gpc'
    - PERL
    - PERL6
    - PHP
    - PIKE
    - PRLG
    - PYTH
    - 'PYTH 3.4'
    - RUBY
    - SCALA
    - 'SCM guile'
    - 'SCM qobi'
    - ST
    - TCL
    - TEXT
    - WSPC
max_timelimit: '1'
source_sizelimit: '50000'
problem_author: Rubanenko
problem_tester: shiplu
date_added: 11-07-2014
tags:
    - Rubanenko
    - cook48
    - simple
editorial_url: 'http://discuss.codechef.com/problems/RRSUM'
time:
    view_start_date: 1405884600
    submit_start_date: 1405884600
    visible_start_date: 1405884600
    end_date: 1735669800
    current: 1493558183
layout: problem
---
All submissions for this problem are available.###  Read problems statements in [Mandarin Chinese](http://www.codechef.com/download/translated/COOK48/mandarin2/RRSUM.pdf) and [Russian](http://www.codechef.com/download/translated/COOK48/russian/RRSUM.pdf) as well.

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

<pre><b>Input:</b>
3 5
6
2
9
7
5
<b>Output:</b>
2
0
1
3
1
</pre>