#P1881. Folding the Rope

    ID: 15164 Type: Default 1000ms 256MiB

Folding the Rope

Folding the Rope

FJ has a rope of length \(L\) (\(1 \le L \le 10{,}000\)) with \(N\) knots (\(1 \le N \le 100\)), including the two endpoints. He wants to fold the rope so that the knots on the shorter side perfectly coincide with knots on the longer side. When the rope is folded at a crease \(f\) (with \(0 < f < L\)), the procedure is as follows:

  • If \(f \le \frac{L}{2}\), the left segment \([0, f]\) is reflected about \(f\). Thus, for every knot at position \(x \le f\), its reflection is at \(2f - x\) and must be a knot on the right segment \([f, L]\).
  • If \(f > \frac{L}{2}\), the right segment \([f, L]\) is reflected about \(f\). Hence, for every knot at position \(x \ge f\), its reflection at \(2f - x\) must exist among the knots in the left segment \([0, f]\).

Note that valid crease positions \(f\) will always be a multiple of \(0.5\) (since all knot positions are integers). Your task is to determine how many crease positions \(f\) yield a perfect alignment of knots.

inputFormat

The first line contains two integers \(L\) and \(N\): the length of the rope and the number of knots.

The second line contains \(N\) integers in increasing order, representing the positions of the knots along the rope.

outputFormat

Output a single integer: the number of valid crease (fold) positions \(f\) that allow perfect alignment of knots.

sample

10 4
0 2 8 10
1