Duty Roster
InterviewTime limit0.5sMemory limit1024 MB
Given N duty days with soldier numbers, decide whether the roster can be rearranged so no soldier is on duty on two consecutive days.
Problem
The battalion of company commander Mansik keeps a duty roster that lists the duty schedule for days. Each day has one soldier on duty, and the roster records that soldier's number. Soldiers need enough rest after a duty shift, so the same soldier is strictly forbidden from serving duty on two consecutive days.
To avoid breaking this rule, Mansik wants to improve the roster by swapping the duty order of soldiers as many times as he likes. Determine whether the roster can be improved so that no soldier serves duty on two consecutive days.
Input
The first line contains the number of days in the schedule.
The second line contains integers separated by spaces, where is the number of the soldier on duty on day .
Output
Print YES if the roster can be improved so that no soldier is on duty on two consecutive days. Otherwise, print NO.