Kingdom of Crisis

TarifEzaz Criterion 2021 Round 9
Limits 1s, 512 MB

In a kingdom far away, $N$ 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 $N$ 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 $N$ $(1 \leq N \leq 10^5)$, the size of the population of the kingdom. The following $N$ lines will have one integer $x_i$ ($1\leq x_i \leq 10^9$) , where $x_i$ 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 $1$. Thus, $1$ and $N$ are adjacent to each other.


Output one line, Yes if it's possible to distribute the amount equally and No otherwise.



Since all of the citizens have equal amount, they already fulfill king's requirements.


Login to submit.


85% Solution Ratio
aomine23Earliest, Feb '21
habib036Fastest, 0.0s
ABID_JAWADLightest, 131 kB
Jewel.SamaCShortest, 83B
Toph uses cookies. By continuing you agree to our Cookie Policy.