stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <map>

#include <set>

#include <cmath>

#include <ctime>

#include <stack>

#include <queue>

#include <cstdio>

#include <cctype>

#include <bitset>

#include <string>

#include <vector>

#include <climits>

#include <cstring>

#include <iostream>

#include <iomanip>

#include <algorithm>

#include <functional>

#define fuck(x) cout<<"["<<x<<"]";

#define FIN freopen("input.txt","r",stdin);

#define FOUT freopen("output.txt","w+",stdout);

using namespace std;

typedef long long LL;

typedef pair<int, int> PII;



const int MX = 1e5 + 5;

const int INF = 0x3f3f3f3f;

const int mod = 1e9 + 7;



int n;

LL A[MX], B[MX], sum;



bool solve() {

    LL tot = (LL)(1 + n) * n / 2;

    if(sum % tot != 0) return 0;



    LL k = sum / tot, used = 0;

    for(int i = 1; i <= n; i++) {

        int last = i == 1 ? n : i - 1;

        B[i] = A[i] - A[last];



        if((k - B[i]) % n != 0 || (k - B[i]) < 0) {

            return 0;

        }

        used += (k - B[i]) / n;

    }

    return used == k;

}



int main() {

    // FIN;

    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {

        scanf("%lld", &A[i]);

        sum += A[i];

    }

    printf("%s\n", solve() ? "YES" : "NO");

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

    long long n,i,a,b,c,d,max,s=0,s1,m,p=1;

    scanf("%lld",&n);

    if(n==1){

        printf("YES\n");

        return 0;

    }

    scanf("%lld%lld",&a,&b);

    s+=a+b;

    d=(b-a)%n;

    max=b-a;

    for(i=2;i<n;i++){

        scanf("%lld",&c);

        if((c-b-d)%n!=0){

            p=0;

            break;

        }

        if(c-b>max) max=c-b;

        s+=c;

        b=c;

    }

    if((a-b-d)%n!=0) p=0;

    if(a-b>max) max=a-b;

    if(p){

        s1=n*(n+1)/2;

        if(s%s1!=0){

            p=0;

        }else{

            m=s/s1;

            if((m-d)%n!=0 || max>m) p=0;

        }

    }

    if(p) printf("YES\n"); else printf("NO\n");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <stdio.h>

#include <string.h>

#include <vector>

#include <string>

#include <cmath>

#include <ctime>

#include <queue>

#include <stack>

#include <set>

#include <iostream>

#include <map>

#include <algorithm>

const double PI = acos(-1.0);

const double EPS = 1e-9;

using namespace std;



const int maxn = 1e5 + 5;

const int INF = 0x3f3f3f3f;

#define LL long long



LL a[maxn], b[maxn];



int main()

{

	LL n;

	while (scanf("%lld", &n) != EOF)

	{

		LL sum = 0;

		for (int i = 0; i < n; i++)

		{

			scanf("%lld", &a[i]);

			sum += a[i];

		}

		for (int i = 0; i < n - 1; i++) b[i] = a[i + 1] - a[i];

		b[n - 1] = a[0] - a[n - 1];

		LL t = n*(n + 1) / 2;

		if (sum%t)

		{

			puts("NO");

			continue;

		}

		sum /= t;

		LL cnt = 0;

		bool ok = true;

		for (int i = 0; i < n; i++)

		{

			if ( (sum - b[i]) % n || sum - b[i] < 0)

			{

				ok = false;

				break;

			}

			cnt += (sum - b[i]) / n;

		}

		if (!ok)

		{

			puts("NO");

			continue;

		}

		if (cnt == sum)

			puts("YES");

		else

			puts("NO");

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

    long long n,i,a,b,c,d,max,s=0,s1,m,p=1;

    scanf("%lld",&n);

    if(n==1){

        printf("YES\n");

        return 0;

    }

    scanf("%lld%lld",&a,&b);

    s+=a+b;

    d=(b-a)%n;

    max=b-a;

    for(i=2;i<n;i++){

        scanf("%lld",&c);

        if((c-b-d)%n!=0){

            p=0;

            break;

        }

        if(c-b>max) max=c-b;

        s+=c;

        b=c;

    }

    if((a-b-d)%n!=0) p=0;

    if(a-b>max) max=a-b;

    if(p){

        s1=n*(n+1)/2;

        if(s%s1!=0){

            p=0;

        }else{

            m=s/s1;

            if((m-d)%n!=0 || max>m) p=0;

        }

    }

    if(p) printf("YES\n"); else printf("NO\n");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <vector>

#include <list>

#include <map>

#include <set>

#include "queue"

#include <deque>

#include <stack>

#include <numeric>

#include <bitset>

#include <algorithm>

#include <functional>

#include <numeric>

#include <utility>

#include <sstream>

#include <complex>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <ctime>

#include <cstring>

#include <climits>

#include <cassert>

#include <iostream>

#include "fstream"

using namespace std;

#define PI acos(-1)

#define MOD (ll)1000000007

#define pii pair<long long ,long long >

#define ll  long long int

#define loop(i,n) for(ll i=0;i<n;i++)

#define loop2(i,n) for(ll i = 1;i<=n;i+=1)

#define pb push_back

#define mp make_pair

#define EPS 1e-8

void display(vector<ll> v1){loop(i,v1.size()){cout<<v1[i]<<" ";}cout<<endl;}

ll dx[8] = {0,1,0,-1,1,1,-1,-1};

ll dy[8] = {1,0,-1,0,1,-1,1,-1};



//Jai Shree Krishna

//:) :) :( :( :( :( :( :( :) :( :)

//Purple Dreams ??? 

//Shit ;More Shit and Hell lot of Shit and Still Shit 



const int MAXN = (ll)1e5+1000;

ll A[MAXN];

ll B[MAXN];



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    ll n;

    cin>>n;

    ll sum = 0 ;

    loop(i,n)

    {

        cin>>A[i];

        sum+=A[i];

    }

    ll t  = (n*(n+1))/2;

    

    if(sum%t)

    {

        cout<<"NO"<<endl;

        return 0;

    }

    ll cnt = sum/t;

    loop(i,n)

    {

        B[i] = A[(i+1)%n]-A[i]-cnt;

    }

    bool flag = true;

    loop(i,n)

    {

        if(B[i]>0||(-B[i])%n)

        {

            flag = false;

        }

    }

    if(flag)

    {

        cout<<"YES";

    }

    else{

        cout<<"NO";

    }

    cout<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

    long long n,i,a,b,c,d,max,s=0,s1,m,p=1;

    scanf("%lld",&n);

    if(n==1){

        printf("YES\n");

        return 0;

    }

    scanf("%lld%lld",&a,&b);

    s+=a+b;

    d=(b-a)%n;

    max=b-a;

    for(i=2;i<n;i++){

        scanf("%lld",&c);

        if((c-b-d)%n!=0){

            p=0;

            break;

        }

        if(c-b>max) max=c-b;

        s+=c;

        b=c;

    }

    if((a-b-d)%n!=0) p=0;

    if(a-b>max) max=a-b;

    if(p){

        s1=n*(n+1)/2;

        if(s%s1!=0){

            p=0;

        }else{

            m=s/s1;

            if((m-d)%n!=0 || max>m) p=0;

        }

    }

    if(p) printf("YES\n"); else printf("NO\n");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

ll a[100005],dis[100005];

int main(){

	ll n,i;

	scanf("%lld",&n);

	ll sum=0;

	for(i=1;i<=n;i++)scanf("%lld",&a[i]),sum+=a[i];

	if(sum%(n*(n+1)/2)){

		printf("NO\n");

		return 0;

	}

	sum/=(n*(n+1))/2;

	dis[1]=a[1]-a[n];

	for(i=2;i<=n;i++)dis[i]=a[i]-a[i-1];

	ll cnt=0;

	for(i=1;i<=n;i++){

		if((sum-dis[i]<0)||(sum-dis[i])%n){

			printf("NO\n"); 

			return 0;

		}

		else cnt+=(sum-dis[i])/n;

	}

	if(cnt!=sum)printf("NO\n");

	else printf("YES\n");

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

    long long n,i,a,b,c,d,max,s=0,s1,m,p=1;

    scanf("%lld",&n);

    if(n==1){

        printf("YES\n");

        return 0;

    }

    scanf("%lld%lld",&a,&b);

    s+=a+b;

    d=(b-a)%n;

    max=b-a;

    for(i=2;i<n;i++){

        scanf("%lld",&c);

        if((c-b-d)%n!=0){

            p=0;

            break;

        }

        if(c-b>max) max=c-b;

        s+=c;

        b=c;

    }

    if((a-b-d)%n!=0) p=0;

    if(a-b>max) max=a-b;

    if(p){

        s1=n*(n+1)/2;

        if(s%s1!=0){

            p=0;

        }else{

            m=s/s1;

            if((m-d)%n!=0 || max>m) p=0;

        }

    }

    if(p) printf("YES\n"); else printf("NO\n");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int main()

{

	long long n,a[100005],dis[100005];

	long long sum=0;

	scanf("%lld",&n);

	for(int i=1;i<=n;i++)

	{

		scanf("%lld",&a[i]);

		sum+=a[i];

	}

	if(sum%(n*(n+1)/2))

	printf("NO\n");

	else

	{

		long long k=sum/((n*(n+1))/2);

		dis[1]=a[1]-a[n];

	    for(int i=2;i<=n;i++)

	    dis[i]=a[i]-a[i-1];

	    int flag=1;

	    long long cnt=0;

	    for(int i=1;i<=n;i++)

	    {

	    	if(k-dis[i]<0||(k-dis[i])%n)

	    	flag=0;

	    	else

	    	cnt+=(k-dis[i])/n;

		}

		if(cnt!=k)

		flag=0;

		if(flag)

		printf("YES\n");

		else

		printf("NO\n");

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

    long long n,i,a,b,c,d,max,s=0,s1,m,p=1;

    scanf("%lld",&n);

    if(n==1){

        printf("YES\n");

        return 0;

    }

    scanf("%lld%lld",&a,&b);

    s+=a+b;

    d=(b-a)%n;

    max=b-a;

    for(i=2;i<n;i++){

        scanf("%lld",&c);

        if((c-b-d)%n!=0){

            p=0;

            break;

        }

        if(c-b>max) max=c-b;

        s+=c;

        b=c;

    }

    if((a-b-d)%n!=0) p=0;

    if(a-b>max) max=a-b;

    if(p){

        s1=n*(n+1)/2;

        if(s%s1!=0){

            p=0;

        }else{

            m=s/s1;

            if((m-d)%n!=0 || max>m) p=0;

        }

    }

    if(p) printf("YES\n"); else printf("NO\n");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<stdio.h>

#include<cstring>

int main()

{

    long long n,a,judge,sum,k;

    long long s1[100010],dis[100010];

    while(scanf("%lld",&n)!=EOF)

    {

        sum=0;

        for(a=1; a<=n; a++)

        {

            scanf("%lld",&s1[a]);

            sum+=s1[a];

        }

        dis[1]=s1[1]-s1[n];

        for(a=2; a<=n; a++)

        {

            dis[a]=s1[a]-s1[a-1];

        }

        if(sum%((1+n)*n/2))

        {

            printf("NO\n");

        }

        else

        {

            judge=0;

            k=sum/((1+n)*n/2);

            sum=0;

            for(a=1; a<=n; a++)

            {

                if((k-dis[a])%n||k<dis[a])

                  {

                    judge=1;

                  }

                else

                    sum+=(k-dis[a])/n;

            }

            if(sum!=k)printf("NO\n");

            else

            {

                if(judge)printf("NO\n");

                else printf("YES\n");

            }

        }

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

    long long n,i,a,b,c,d,max,s=0,s1,m,p=1;

    scanf("%lld",&n);

    if(n==1){

        printf("YES\n");

        return 0;

    }

    scanf("%lld%lld",&a,&b);

    s+=a+b;

    d=(b-a)%n;

    max=b-a;

    for(i=2;i<n;i++){

        scanf("%lld",&c);

        if((c-b-d)%n!=0){

            p=0;

            break;

        }

        if(c-b>max) max=c-b;

        s+=c;

        b=c;

    }

    if((a-b-d)%n!=0) p=0;

    if(a-b>max) max=a-b;

    if(p){

        s1=n*(n+1)/2;

        if(s%s1!=0){

            p=0;

        }else{

            m=s/s1;

            if((m-d)%n!=0 || max>m) p=0;

        }

    }

    if(p) printf("YES\n"); else printf("NO\n");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>  

#include <cmath>  

#include <iostream>  

#include <algorithm>  

#include <cstring>  

#include <cctype>  

#include <stack>  

using namespace std;  

  

typedef long long ll;  

const int qq = 1e5 + 10;  

ll diff[qq];  

ll num[qq];  

ll n;  

  

int main(){  

    scanf("%lld", &n);  

    ll sum = 0;  

    for(int i = 0; i < n; ++i)   scanf("%lld", num + i), sum += num[i];  

    for(int i = 0; i < n - 1; ++i)  

        diff[i] = num[i + 1] - num[i];  

    diff[n - 1] = num[0] - num[n - 1];  

    ll k = (1 + n) * n / 2;  

    if(sum % k != 0){  

        printf("NO\n");  

        return 0;  

    }  

    k = sum / k;  

    for(int i = 0; i < n; ++i){  

        if(k == diff[i])    continue;  

        ll c = k - diff[i];  

        if(c < 0 || c % n != 0){  

            printf("NO\n");  

            return 0;  

        }  

    }  

    printf("YES\n");  

    return 0;  

}  




// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

    long long n,i,a,b,c,d,max,s=0,s1,m,p=1;

    scanf("%lld",&n);

    if(n==1){

        printf("YES\n");

        return 0;

    }

    scanf("%lld%lld",&a,&b);

    s+=a+b;

    d=(b-a)%n;

    max=b-a;

    for(i=2;i<n;i++){

        scanf("%lld",&c);

        if((c-b-d)%n!=0){

            p=0;

            break;

        }

        if(c-b>max) max=c-b;

        s+=c;

        b=c;

    }

    if((a-b-d)%n!=0) p=0;

    if(a-b>max) max=a-b;

    if(p){

        s1=n*(n+1)/2;

        if(s%s1!=0){

            p=0;

        }else{

            m=s/s1;

            if((m-d)%n!=0 || max>m) p=0;

        }

    }

    if(p) printf("YES\n"); else printf("NO\n");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define F first

#define ll long long 

#define S second

#define pb push_back

const int inf = 1000 * 1000 * 1000 + 1000;

const ll INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000;



const int N = 1000 * 100 + 1000;

int a[N], d[N], x[N];



int32_t main(){

	ios::sync_with_stdio(false);cin.tie(0);



	int n, k, sum = 0, step;

	cin >> n;

	step = n * (n + 1) / 2;

	for(int i = 0; i < n; i++)

		cin >> a[i], sum += a[i];



	if(sum % step != 0){

		cout << "NO\n";

		return 0;

	}



	k = sum / step;

	for(int i = 0; i < n - 1; i++)

		d[i] = a[i + 1] - a[i];

	d[n - 1] = a[0] - a[n - 1];



	sum = 0;

	for(int i = 0; i < n; i++){

		int cnt = k - d[i];

		if(cnt % n != 0 || cnt < 0){

			cout << "NO\n";

			return 0;

		}

		x[i] = cnt / n;

		sum += x[i];

	}

	if(sum != k)

		cout << "NO\n";

	else

		cout << "YES\n";

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

    long long n,i,a,b,c,d,max,s=0,s1,m,p=1;

    scanf("%lld",&n);

    if(n==1){

        printf("YES\n");

        return 0;

    }

    scanf("%lld%lld",&a,&b);

    s+=a+b;

    d=(b-a)%n;

    max=b-a;

    for(i=2;i<n;i++){

        scanf("%lld",&c);

        if((c-b-d)%n!=0){

            p=0;

            break;

        }

        if(c-b>max) max=c-b;

        s+=c;

        b=c;

    }

    if((a-b-d)%n!=0) p=0;

    if(a-b>max) max=a-b;

    if(p){

        s1=n*(n+1)/2;

        if(s%s1!=0){

            p=0;

        }else{

            m=s/s1;

            if((m-d)%n!=0 || max>m) p=0;

        }

    }

    if(p) printf("YES\n"); else printf("NO\n");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstring>

#include <cmath>

#include <algorithm>

#include <cstdio>

#include <fstream>

#include <map>

#include <vector>

//#include <unordered_map>

//#include <unordered_set>

#include <stack>

#include <set>

#include <queue>

#include <list>



using namespace std;

int k[100005];

int main()

{

    int n;

    long long su=0,z;

    scanf("%d",&n);

    for(int i=0;i<n;++i){scanf("%d",&k[i]);su+=k[i];}

    z=((long long)n+1)*n/2;

    if(su%z==0)

    {

        long long f=su/z;

        long long co=f;

        for(int i=1;i<n;++i)

        {

            if(k[i]-k[i-1]>f)

            {

                printf("NO");

                return 0;

            }

            else

            {

                long long tm=f-k[i]+k[i-1];

                if(tm%n==0)

                {

                    co-=tm/n;

                }

            }

        }

        if(k[0]-k[n-1]>f)

        {

            printf("NO");

            return 0;

        }

        else

        {

            long long tm=f-k[0]+k[n-1];

                if(tm%n==0)

                {

                    co-=tm/n;

                }

        }

        if(co==0) printf("YES");

        else printf("NO");

    }

    else

    {

        printf("NO");

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

    long long n,i,a,b,c,d,max,s=0,s1,m,p=1;

    scanf("%lld",&n);

    if(n==1){

        printf("YES\n");

        return 0;

    }

    scanf("%lld%lld",&a,&b);

    s+=a+b;

    d=(b-a)%n;

    max=b-a;

    for(i=2;i<n;i++){

        scanf("%lld",&c);

        if((c-b-d)%n!=0){

            p=0;

            break;

        }

        if(c-b>max) max=c-b;

        s+=c;

        b=c;

    }

    if((a-b-d)%n!=0) p=0;

    if(a-b>max) max=a-b;

    if(p){

        s1=n*(n+1)/2;

        if(s%s1!=0){

            p=0;

        }else{

            m=s/s1;

            if((m-d)%n!=0 || max>m) p=0;

        }

    }

    if(p) printf("YES\n"); else printf("NO\n");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cstring>

#include<vector>

#include<stack> 

#include<queue>

#include<cmath>

#include<map>

#include<set>

#define LL long long

#define N 100100

#define MOD 1000000007

#define FOR(i,l,r) for (int i = (l); i <= (r); i ++)

#define CLR(a,x) memset(a,x,sizeof(a))

#define INF 0x7fffffff

#define pb push_back

#define X first

#define Y second

using namespace std;

int a[N],d[N];

int main(){

	int n;

	scanf("%d",&n);

	LL sum = 0;

	FOR(i,1,n){

		scanf("%d",&a[i]);

		sum += (LL)a[i];

	}

	LL s = (LL)(1 + n) * n / 2;

	if (sum % s != 0) printf("NO\n");

	else{

		a[n + 1] = a[1];

		int flag = 1;

		FOR(i,1,n){

			d[i] = a[i] - a[i + 1];

			LL t = sum / s;

			if ((d[i] + t) % n != 0 || d[i] + t < 0){

			   flag = 0;

			   break;

			}

		}

		if (flag) printf("YES\n");

		else printf("NO\n");

	}

	

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

const int maxn = 100005;

#define ll long long

ll a[maxn];

ll dis[maxn];





int main()

{

	ll n,i;

	scanf("%lld",&n);

	ll sum = 0;

	for (i = 1; i <= n; ++i)

	{

		scanf("%lld",&a[i]);

		if(i >= 2)

			dis[i] = a[i] - a[i-1];

		sum += a[i];

	}

	dis[1] = a[1] - a[n];

	if( sum % (n*(n+1)/2) )

	{

		printf("NO\n");

		return 0;

	}

	else

	{

		sum /= (n*(n+1)/2);

		ll ans = 0;

		for (i = 1; i <= n; ++i)

		{

			if( (sum - dis[i] < 0) || ((sum - dis[i]) % n) )

			{

				printf("NO\n");

				return 0;

			}

			else

				ans += (sum - dis[i]) / n;

		}

		if(ans != sum)

			printf("NO\n");

		else

			printf("YES\n");

	}

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <map>

#include <set>

#include <cmath>

#include <queue>

#include <stack>

#include <vector>

#include <cstdio>

#include <string>

#include <cstring>

#include <climits>

#include <cstdlib>

#include <iostream>

#include <algorithm>

using namespace std;

#define Mem(a) memset(a,0,sizeof(a))

#define mem(a) memset(a,-1,sizeof(a))

#define For(i,l,r) for(int (i)=(int)(l);(i)<(int)(r);++(i))

#define FOR(i,l,r) for(int (i)=(int)(l);(i)<=(int)(r);++(i))

#define rof(i,l,r) for(int (i)=(int)(l);(i)>=(int)(r);--(i))

#define all(x) (x).begin(),(x).end()

#define mp make_pair

#define pb push_back

typedef pair<int,int> pii;

typedef vector<pii> vpii;

typedef vector<int> vi;

typedef unsigned long long llu;

typedef long long ll;

const int mxn=1e5+3;

const int inf=INT_MAX;

ll a[mxn],n;

int main(){

	scanf("%lld",&n);

	ll sum=0;

	For(i,0,n){

		scanf("%lld",&a[i]);

		sum+=a[i];

	}

	ll tot=n*(n+1)/2;

	ll cnt=sum/tot;

	if(cnt*tot!=sum){puts("NO");return 0;}

	a[n]=a[0];ll x=0;

	For(i,0,n){

		ll sum=cnt-a[i+1]+a[i];

		ll t=sum/n;

		if(t*n!=sum||t<0||t>cnt){puts("NO");return 0;}

		x+=t;

	}

	if(x!=cnt){puts("NO");return 0;}

	puts("YES");return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

const int maxn = 100005;

#define ll long long

ll a[maxn];

ll dis[maxn];





int main()

{

	ll n,i;

	scanf("%lld",&n);

	ll sum = 0;

	for (i = 1; i <= n; ++i)

	{

		scanf("%lld",&a[i]);

		if(i >= 2)

			dis[i] = a[i] - a[i-1];

		sum += a[i];

	}

	dis[1] = a[1] - a[n];

	if( sum % (n*(n+1)/2) )

	{

		printf("NO\n");

		return 0;

	}

	else

	{

		sum /= (n*(n+1)/2);

		ll ans = 0;

		for (i = 1; i <= n; ++i)

		{

			if( (sum - dis[i] < 0) || ((sum - dis[i]) % n) )

			{

				printf("NO\n");

				return 0;

			}

			else

				ans += (sum - dis[i]) / n;

		}

		if(ans != sum)

			printf("NO\n");

		else

			printf("YES\n");

	}

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <set>

#include <cstring>

#include <algorithm>

#include <queue>

#include <cstdio>

#include <map>

#include <math.h>

#define LL long long

using namespace std;

LL n;

int a[100005];

int main()

{

    scanf("%d",&n);

    LL sum=0;

    for(int i=0;i<n;i++)

    {

        scanf("%d",&a[i]);

        sum+=a[i];

    }

    LL nn=n*(n+1)/2;

    if(sum%nn!=0)

    {

        cout<<"NO"<<endl;

    }

    else

    {

        LL k=sum/nn;

        int temp=a[0]-a[n-1];

        for(int i=n-1;i>0;i--)

        {

            a[i]=a[i]-a[i-1];

        }

        a[0]=temp;

        for(int i=0;i<n;i++)

        if(k-a[i]<0||(k-a[i])%n)

        {

            cout<<"NO"<<endl;

            return 0;

        }

        cout<<"YES"<<endl;

    }

    return 0;



}


// Optimized solution to the same problem (faster):
#include <stdio.h>

const int maxn = 100005;

#define ll long long

ll a[maxn];

ll dis[maxn];





int main()

{

	ll n,i;

	scanf("%lld",&n);

	ll sum = 0;

	for (i = 1; i <= n; ++i)

	{

		scanf("%lld",&a[i]);

		if(i >= 2)

			dis[i] = a[i] - a[i-1];

		sum += a[i];

	}

	dis[1] = a[1] - a[n];

	if( sum % (n*(n+1)/2) )

	{

		printf("NO\n");

		return 0;

	}

	else

	{

		sum /= (n*(n+1)/2);

		ll ans = 0;

		for (i = 1; i <= n; ++i)

		{

			if( (sum - dis[i] < 0) || ((sum - dis[i]) % n) )

			{

				printf("NO\n");

				return 0;

			}

			else

				ans += (sum - dis[i]) / n;

		}

		if(ans != sum)

			printf("NO\n");

		else

			printf("YES\n");

	}

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

ll a[100005],dis[100005];

int main(){

	ll n,i;

	scanf("%lld",&n);

	ll sum=0;

	for(i=1;i<=n;i++)scanf("%lld",&a[i]),sum+=a[i];

	if(sum%(n*(n+1)/2)){

		printf("NO\n");

		return 0;

	}

	sum/=(n*(n+1))/2;

	dis[1]=a[1]-a[n];

	for(i=2;i<=n;i++)dis[i]=a[i]-a[i-1];

	ll cnt=0;

	for(i=1;i<=n;i++){

		if((sum-dis[i]<0)||(sum-dis[i])%n){

			printf("NO\n"); 

			return 0;

		}

		else cnt+=(sum-dis[i])/n;

	}

	if(cnt!=sum)printf("NO\n");

	else printf("YES\n");

	return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

const int maxn = 100005;

#define ll long long

ll a[maxn];

ll dis[maxn];





int main()

{

	ll n,i;

	scanf("%lld",&n);

	ll sum = 0;

	for (i = 1; i <= n; ++i)

	{

		scanf("%lld",&a[i]);

		if(i >= 2)

			dis[i] = a[i] - a[i-1];

		sum += a[i];

	}

	dis[1] = a[1] - a[n];

	if( sum % (n*(n+1)/2) )

	{

		printf("NO\n");

		return 0;

	}

	else

	{

		sum /= (n*(n+1)/2);

		ll ans = 0;

		for (i = 1; i <= n; ++i)

		{

			if( (sum - dis[i] < 0) || ((sum - dis[i]) % n) )

			{

				printf("NO\n");

				return 0;

			}

			else

				ans += (sum - dis[i]) / n;

		}

		if(ans != sum)

			printf("NO\n");

		else

			printf("YES\n");

	}

	return 0;

}


// Fastest known solution for this problem: