spoj#SECTORS. Equalize the Sectors
Equalize the Sectors
Digo has a cylindrical box which is vertically partitioned into N contiguous sectors which are open from the top. Each Sectorial Compartment initially contains a fixed number of coins. Now Digo wants to fill each Sectorial Compartment with equal number of coins. But the problem is that, at a time he is only allowed to increment any two adjacent sectors with one coin each. Given an initial arrangement, you need to tell whether such equalization is possible or not.
Every sector i (for all (0 < i < N)) is adjacent to sector (i + 1) and sector N is adjacent to sector 1.
Input
In first line, the number of test cases T.
Each test case consists of a number N, followed by a line containing N space seperated integers where ith integer (Mi) denotes the number of coins in ith sectorial compartment of the box (initially), in clockwise order.
Output
For every test case output “YES” for possible and “NO” for which equalization is not possible (Without quotes).
Constraints
1 <= T <= 1000
3 <= N <= 100 (Number of Sectorial Compartments)
1 <= Mi <= 10^9 (Number of coins in each Sectorial Compartment)
Sample Input
2
3
1 2 3
4
1 2 1 2
Sample Output
YES
NO