In a kingdom far away, people live in a circle of harmony. Literally, they have constructed a circular area and built their houses towards the periphery of it. For simplicity, we can assume that the kingdom is a circle and the houses are points on the circle's periphery.
Due to this scenario, a person living in that kingdom, can only interact with the two other neighbors who are adjacent to that person. When a person needs to make some money transaction, he can only do so with either the person on his right or with the person on his left.
Photo Credit: Hedning
Now, there is a huge economic crisis going on in the kingdom and the king has decided to equally divide the wealth across all the citizens. But the circular city only allows direct transaction between neighbors. Not just that, the king also ordered that a person can make at most one transaction with one of his neighbors.
So here's the deal, given the wealth of individuals and their relative positions, can you decide whether it would be possible to divide the money equally among all the people?
The first line of the input will contain an integer , the size of the population of the kingdom. The following lines will have one integer () , where is the wealth of the i'th person. Since all the people of this kingdom are living in a circle, we have picked a position at some point of the circle and called it . Thus, and are adjacent to each other.
Output one line, Yes if it's possible to distribute the amount equally and No otherwise.
3 1 1 1
Since all of the citizens have equal amount, they already fulfill king's requirements.
Login to submit
Since the kingdom is circular, we start from a person who has the highest money and move all the day...