There are people standing in a row, numbered from to . Each person belongs to either the red team or the blue team, and both teams are non-empty.
The distance between people and is .
Each person reports the distance to the nearest person belonging to the other team. Their reports form an array .
Determine whether it is possible to assign people to the two teams so that every report is correct.
The first line contains the number of people .
The second line contains their reports .
Print Yes if a valid assignment exists, and No otherwise.
You may print each letter in either uppercase or lowercase. For example, YES, Yes, and YeS are all accepted.
One valid team assignment is RBBBBR, where R denotes the red team and B denotes the blue team. The first and last people each have a rival at distance . The four people between them have nearest rivals at distances , respectively.
The first person's report forces the first two people to belong to different teams. The second person then has a rival at distance , contradicting their report of .
One valid team assignment is RRBRR. The middle person has an adjacent rival. For the other four people, the nearest rival is the middle person, at distances , respectively.