CF BUDDY
← Problems·

1147A · Hide and Seek

1500 · graphs

Problem: Alice and Bob are playing a game on a line with nn cells. There are nn cells labeled from 11 through nn. For each ii from 11 to n1n-1, cells ii and i+1i+1 are adjacent.

Alice initially has a token on some cell on the line, and Bob tries to guess where it is.

Bob guesses a sequence of line cell numbers x1,x2,,xkx_1, x_2, \ldots, x_k in order. In the ii-th question, Bob asks Alice if her token is currently on cell xix_i. That is, Alice can answer either "YES" or "NO" to each Bob's question.

At most one time in this process, before or after answering a question, Alice is allowed to move her token from her current cell to some adjacent cell. Alice acted in such a way that she was able to answer "NO" to all of Bob's questions.

Note that Alice can even move her token before answering the first question or after answering the last question. Alice can also choose to not move at all.

You are given nn and Bob's questions x1,,xkx_1, \ldots, x_k. You would like to count the number of scenarios that let Alice answer "NO" to all of Bob's questions.

Let (a,b)(a,b) denote a scenario where Alice starts at cell aa and ends at cell bb. Two scenarios (ai,bi)(a_i, b_i) and (aj,bj)(a_j, b_j) are different if aiaja_i \neq a_j or bibjb_i \neq b_j.

Input Format: The first line contains two integers nn and kk (1n,k1051 \leq n,k \leq 10^5) — the number of cells and the number of questions Bob asked.

The second line contains kk integers x1,x2,,xkx_1, x_2, \ldots, x_k (1xin1 \leq x_i \leq n) — Bob's questions.

Output Format: Print a single integer, the number of scenarios that let Alice answer "NO" to all of Bob's questions.

Note: The notation (i,j)(i,j) denotes a scenario where Alice starts at cell ii and ends at cell jj.

In the first example, the valid scenarios are (1,2),(2,1),(2,2),(2,3),(3,2),(3,3),(3,4),(4,3),(4,5)(1, 2), (2, 1), (2, 2), (2, 3), (3, 2), (3, 3), (3, 4), (4, 3), (4, 5). For example, (3,4)(3,4) is valid since Alice can start at cell 33, stay there for the first three questions, then move to cell 44 after the last question.

(4,5)(4,5) is valid since Alice can start at cell 44, stay there for the first question, the move to cell 55 for the next two questions. Note that (4,5)(4,5) is only counted once, even though there are different questions that Alice can choose to do the move, but remember, we only count each pair of starting and ending positions once.

In the second example, Alice has no valid scenarios.

In the last example, all (i,j)(i,j) where ij1|i-j| \leq 1 except for (42,42)(42, 42) are valid scenarios.

Sample Cases

Case 1

Input

5 3
5 1 4

Output

9

Case 2

Input

4 8
1 2 3 4 4 3 2 1

Output

0

Case 3

Input

100000 1
42

Output

299997

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback