QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#311. Strongbox

Statistics

Byteasar is a famous safe-cracker, who renounced his criminal activity and got into testing and certifying anti-burglary devices. He has just received a new kind of strongbox for tests: a combinatorial safe. A combinatorial safe is something different from a combination safe, even though it is opened with a rotary dial. The dial can be set in $n$ different positions, numbered from $0$ to $n-1$. Setting the dial in some of these positions opens the safe, while in others it does not. And here is the combinatorial property, from which the name comes from: if $x$ and $y$ are opening positions, then so is $(x+y)\bmod n$ too; note that is holds for $x=y$ as well.

Byteasar tried $k$ different positions of the dial: $m_{1},m_{2},…,m_{k}$. The positions $m_{1},m_{2},…,m_{k-1}$ did not open the safe, only the last position $m_{k}$ did. Byteasar is already tired from checking these $k$ positions and has thus absolutely no intention of trying the remaining ones. He would like to know however, based on what he already knows about the positions he tried, what is the maximum possible number of positions that open the safe. Help him by writing an appropriate program!

Input Format

The first line of the standard input gives two integers $n$ and $k$, separated by a single space, $1 ≤ k ≤ 250,000$, $k ≤ n ≤ 10^{14}$. The second line holds $k$ different integers, also separated by single spaces, $m_{1},m_{2},…,m_{k}$, $0 ≤ m_{i} < n$. You can assume that the input data correspond to a certain combinatorial safe that complies with the description above.

In tests worth approximately $70\%$ of the points it holds that $k ≤ 1,000$. In some of those tests, worth approximately 20% of the points, the following conditions hold in addition: $n ≤ 10^{8}$ and $k ≤ 100$.

Output Format

Your program should print out to the first and only line of the standard output a single integer: the maximum number of the dial's positions that can open the safe.

Example

Input

42 5
28 31 10 38 24

Output

14
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.