#P10852. Restoring the Dream Sequence

    ID: 12895 Type: Default 1000ms 256MiB

Restoring the Dream Sequence

Restoring the Dream Sequence

Yue had a dream in which she obtained an integer sequence \(a_1, a_2, \ldots, a_n\) with \(n \ge 5\). After waking up, she forgot some elements in the sequence and only remembered \(m\) positions with their values. She wants to fill in the missing positions such that the restored sequence satisfies the following property:

For any four distinct indices \(x_1,x_2,x_3,x_4\) that satisfy \(x_2+x_3=x_1+x_4\), the sequence obeys
\[ a_{x_2}+a_{x_3}=a_{x_1}+a_{x_4} \]

A careful analysis shows that this property holds if and only if the sequence forms an arithmetic progression. In other words, there exist integers \(A\) and \(B\) such that for every \(1 \le i \le n\),
\[ a_i = A + B \cdot i \]

You are given the length of the sequence \(n\) and \(m\) remembered positions along with their values. Determine whether it is possible to restore the sequence so that it becomes an arithmetic progression, while matching the remembered values. If it is possible, print Yes, otherwise print No.

inputFormat

The first line contains two integers \(n\) and \(m\) (with \(n \ge 5\)).

Each of the next \(m\) lines contains two integers \(p\) and \(v\) indicating that the element at position \(p\) (1-indexed) has value \(v\). The remembered positions are all distinct.

outputFormat

Output a single line containing Yes if it is possible to restore the sequence as an arithmetic progression that matches the remembered positions, or No otherwise.

sample

5 2
2 5
4 9
Yes