#K75267. Tree Planting Rules Verification
Tree Planting Rules Verification
Tree Planting Rules Verification
You are given the positions where residents plant their trees. The residents are expected to follow a specific rule: no two trees can be planted in consecutive positions. In other words, for any two adjacent trees in the planting order, the absolute difference between their positions should not be equal to 1.
If the rule is followed, output YES
; otherwise, output NO
.
For example:
- Input: 3 and positions: 2 4 6 → Output: YES
- Input: 4 and positions: 3 5 7 6 → Output: NO
Note: The positions are given in the order in which the trees are planted. You only need to check adjacent pairs in this order.
inputFormat
The input consists of two lines:
- The first line contains an integer n (1 ≤ n ≤ 105), representing the number of residents (or trees planted).
- The second line contains n space-separated integers indicating the positions where the trees are planted, in the order of planting.
outputFormat
Output a single line containing YES
if the tree planting rules are followed, otherwise output NO
.
3
2 4 6
YES