Problem:
Score : 500 points

Problem Statement

There are N boxes arranged in a circle. The i-th box contains A_i stones.

Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the following operation:

Select one box. Let the box be the i-th box. Then, for each j from 1 through N, remove exactly j stones from the (i+j)-th box. Here, the (N+k)-th box is identified with the k-th box.

Note that the operation cannot be performed if there is a box that does not contain enough number of stones to be removed.

Constraints

1 ≦ N ≦ 10^5

1 ≦ A_i ≦ 10^9

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 … A_N

Output

If it is possible to remove all the stones from the boxes, print YES. Otherwise, print NO.

Sample Input 1

5
4 5 1 2 3

Sample Output 1

YES

All the stones can be removed in one operation by selecting the second box.

Sample Input 2

5
6 9 12 10 8

Sample Output 2

YES

Sample Input 3

4
1 2 3 1

Sample Output 3

NO

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1,Dbg&>::type operator<<(const C &x) {os<<x; return *this;}
template<class C> Dbg &dump(C b, C e) {
    for (struct{C i;int j;} i={(*this<<"\n[",b),0}; i.i!=e and i.j<26; i.i++, i.j++) *this<<", "+2*(i.i==b)<<*i.i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator<<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator<<(const pair<B, C> &x) {return *this<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 100005;
#define yes return cout << "YES\n", 0
#define no return cout << "NO\n", 0
#define YN(x) return cout << ((x) ? "YES\n" : "NO\n"), 0

int n, a[mxn];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    /*int o[] = {0, 1, 2, 3};
    for (int i = 0; i < 24; i++) {
        bug(o);
        int cnt[4] = {};
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                cnt[(o[j]+k)%4] += k+1;
            }bug(cnt);
            for (int k = 0; k < 4; k++) {
                int diff = cnt[(k+1)%4]-cnt[k];
                ASSERT((j+1-diff)%4, ==, 0, diff, j+1)
            }
        }
        for (int j = 4; j <= 8; j++) {
            int tmp = int(rand()%4);
            for (int k = 0; k < 4; k++) {
                cnt[(tmp+k)%4] += k+1;
            }bug(cnt);
            for (int k = 0; k < 4; k++) {
                int diff = cnt[(k+1)%4]-cnt[k];
                ASSERT((j+1-diff)%4, ==, 0, diff, j+1)
            }
        }
        next_permutation(begin(o), end(o));
    }*/

    ll sum = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i], sum += a[i];
    }
    ll sumOnce = n*ll(n+1)/2;
    if (sum%sumOnce) no;
    int cntOp = int(sum/sumOnce);
    for (int i = 1; i <= n; i++) {
        int diff = a[(i == n ? 1 : i+1)]-a[i];
        if (cntOp-diff<0 or (cntOp-diff)%n) no;
    }
    yes;
}