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: Wrong Answer)

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int32_t; using i64 = int64_t; using f64 = double_t; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define stepup(a, b, s, i) for (i32 i = (a); i <= (b); i+=(s))
#define stepdown(a, b, s, i) for (i32 i = (a); i >= (b); i-=(s))
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define foreach(xs, x) for (auto &x : (xs))
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define maximum(xs) (*max_element(all(xs)))
#define minimum(xs) (*min_element(all(xs)))
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
const i64 MOD = 1000000007;

i32 n, a[100000], t[100000];

bool check(vec<i32> &v) {
    memset(t, 0, sizeof(t));
    bool ret = true;
    times(v.size(), i) {
        i32 b = v[i];
        times(n, j) {
            if (j > b)
                t[j] += j-b;
            else
                t[j] += n+j-b;
            if (t[j] > a[j])
                return false;
        }
        if (a[i] != t[i]) {
            ret = false;
            break;
        }
    }
    if (ret) return ret;
    times(n, i) {
        if (a[i] < n) 
            continue;
        v.append(i);
        if (check(v))
            return true;
        v.erase(--v.end());
    }
    return false;
}

i32 main()
{
    cin >> n;
    i32 mini = INT_MAX;
    i64 f = 0;
    times(n, i) {
        cin >> a[i];
        mini = min(mini, a[i]);
        f += i+1;
    }
    times(n, i) {
        a[i] -= (mini/f) * f;
    }
    vec<i32> v;
    cout << (check(v) ? "YES" : "NO") << endl;
    return 0;
}