ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

NEERC, Central subregion, Rybinsk, October 2001

About     Problems     Submit solution     Judge status     Standings
Contest is over

B. Cards

Time limit: 1.0 second
Memory limit: 64 MB
Each of the n cards has numbers written on the both sides of it. The first card has 0 and 1 on it, the second has 1 and 2, …, the n-th has (n − 1) and n. First-grade pupil Nick takes cards one by one in random order and reads the number on one of the sides. Nick is not very good with numbers, so it is possible that he makes a mistake. Your task is to find out if he was mistaken, i.e. if the given sequence of numbers is possible for some order of taking cards.


The first line contains integers n, the total number of cards, and m, the number of the cards that were taken (2 ≤ n ≤ 1000; 1 ≤ mn). In the second line m integers are listed (the sequence read by Nick). All these integers are from 0 to n.


Write “YES” if the given sequence of numbers is possible for some order of taking cards, “NO” otherwise.


5 4
2 0 1 2
Problem Source: Quarterfinal, Central region of Russia, Rybinsk, October 17-18 2001
To submit the solution for this problem go to the Problem set: 1134. Cards