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

using namespace std;

template <class T> inline bool chmax(T &a, T b) {

    if(a < b) {

        a = b;

        return 1;

    }

    return 0;

}

template <class T> inline bool chmin(T &a, T b) {

    if(a > b) {

        a = b;

        return 1;

    }

    return 0;

}

typedef long long int ll;



#define ALL(v) (v).begin(), (v).end()

#define RALL(v) (v).rbegin(), (v).rend()

#define endl "\n"

const double EPS = 1e-7;

const int INF = 1 << 30;

const ll LLINF = 1LL << 60;

const double PI = acos(-1);

const int MOD = 1000000007;

const int dx[4] = {1, 0, -1, 0};

const int dy[4] = {0, 1, 0, -1};



//-------------------------------------



using P = pair<int, int>;



int dp[3010][6020];



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n, t;

    cin >> n >> t;

    vector<P> ab(n);

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

        cin >> ab[i].first >> ab[i].second;

    }

    sort(ALL(ab));



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

        for(int j = 0; j < 6020; j++) {

            if(j < t) {

                chmax(dp[i + 1][j + ab[i].first], dp[i][j] + ab[i].second);

            }

            chmax(dp[i + 1][j], dp[i][j]);

        }

    }

    int ans = -INF;

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

        chmax(ans, dp[n][i]);

    }

    cout << ans << endl;

}

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

using namespace std;

template <class T> inline bool chmax(T &a, T b) {

    if(a < b) {

        a = b;

        return 1;

    }

    return 0;

}

template <class T> inline bool chmin(T &a, T b) {

    if(a > b) {

        a = b;

        return 1;

    }

    return 0;

}

typedef long long int ll;



#define ALL(v) (v).begin(), (v).end()

#define RALL(v) (v).rbegin(), (v).rend()

#define endl "\n"

const double EPS = 1e-7;

const int INF = 1 << 30;

const ll LLINF = 1LL << 60;

const double PI = acos(-1);

const int MOD = 1000000007;

const int dx[4] = {1, 0, -1, 0};

const int dy[4] = {0, 1, 0, -1};



//-------------------------------------



int dp[3010][3010][2];



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n, t;

    cin >> n >> t;

    vector<int> a(n), b(n);

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

        cin >> a[i] >> b[i];

    }



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

        for(int j = 0; j < t; j++) {

            for(int k = 0; k < 2; k++) {

                if(j - a[i] >= 0) {

                    chmax(dp[i + 1][j][k], dp[i][j - a[i]][k] + b[i]);

                }

                chmax(dp[i + 1][j][k], dp[i][j][k]);

                // 最後に食べるとき

                if(k == 0) {

                    chmax(dp[i + 1][j][1], dp[i][j][k] + b[i]);

                }

            }

        }

    }



    int ans = 0;

    for(int j = 0; j < t; j++) {

        for(int k = 0; k < 2; k++) {

            chmax(ans, dp[n][j][k]);

        }

    }

    cout << ans << endl;

}

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

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);i++)

#define rep(i,n) repd(i,0,n)

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

typedef long long ll;

const long long INF = 1LL << 60;

typedef pair<int, int> P;

int main()

{

    int N, T;

    cin >> N >> T;



    vector<P> AB(N);

    rep(i, N) {

        int A, B;

        cin >> A >> B;

        AB[i] = {A, B};

    }



    sort(all(AB));



    vector<vector<int>> dp(N + 1, vector<int>(7000, -1));

    dp[0][0] = 0;



    rep(i, N) {

        rep(j, 7000) {

            if (dp[i][j] != -1) {

                if (j < T) chmax(dp[i + 1][j + AB[i].first], dp[i][j] + AB[i].second);

                chmax(dp[i + 1][j], dp[i][j]);

            }

        }

    }



    int ans = 0;

    rep(i, dp[N].size()) {

        chmax(ans, dp[N][i]);

    }



    cout << ans << endl;

    return 0;

}

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

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);i++)

#define rep(i,n) repd(i,0,n)

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

typedef long long ll;

const long long INF = 1LL << 60;

typedef pair<int, int> P;

int main()

{

    int N, T;

    cin >> N >> T;

    vector<P> AB(N);

    rep(i, N) {

        int A, B;

        cin >> A >> B;

        AB[i] = {A, B};

    }



    sort(all(AB));



    vector<vector<ll>> dp(N + 1, vector<ll>(T + 1));



    rep(i, N) {

        rep(j, T) {

            chmax(dp[i + 1][j], dp[i][j]);

            chmax(dp[i + 1][min(T, j + AB[i].first)], dp[i][j] + AB[i].second);

        }

    }



    ll ans = 0;

    rep(i, N) {

        chmax(ans, dp[i + 1][T]);

    }

    cout << ans << endl;

    return 0;

}

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

#include <iostream>

#include <string>

#include <vector>

#include <sstream>

#include <map>

#include <set>

#include <queue>

#include <algorithm>

#include <cmath>

#include <cstring>

#include <typeinfo>

#include <numeric>

#include <functional>

#include <unordered_map>

#include <bitset>

#include <stack>

#include <assert.h>

#include <unordered_set>

#include <random>







using namespace std;

using ll = long long;

using ull = unsigned long long;



const ll INF = 1e18;

const ll MOD = 1e9 + 7;



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



































int main(){

    ll n, t;

    cin >> n >> t;

    vector<ll> a(n), b(n);

    REP(i, n){

        cin >> a[i] >> b[i];

    }

    

    vector<vector<ll>> dp1(n + 2, vector<ll>(6005));

    vector<vector<ll>> dp2(n + 2, vector<ll>(6005));

    REP(i, n){

        REP(j, t){

            dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][j]);

            dp1[i + 1][j + a[i]] = max(dp1[i + 1][j + a[i]], dp1[i][j] + b[i]);

        }

    }

    for(ll i = n - 1; i >= 0; i--){

        REP(j, t){

            dp2[i + 1][j] = max(dp2[i + 1][j], dp2[i + 2][j]);

            dp2[i + 1][j + a[i]] = max(dp2[i + 1][j + a[i]], dp2[i + 2][j] + b[i]);

        }

    }

    ll ans = 0;

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

        REP(j, t){

            ans = max(ans, dp1[i - 1][j] + dp2[i + 1][t - 1 - j] + b[i - 1]);

        }

    }

    cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <iostream>

#include <string>

#include <vector>

#include <sstream>

#include <map>

#include <set>

#include <queue>

#include <algorithm>

#include <cmath>

#include <cstring>

#include <typeinfo>

#include <numeric>

#include <functional>

#include <unordered_map>

#include <bitset>

#include <stack>

#include <assert.h>

#include <unordered_set>

#include <random>







using namespace std;

using ll = long long;

using ull = unsigned long long;



const ll INF = 1e18;

const ll MOD = 1e9 + 7;



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



































int main(){

    int n, t;

    scanf("%d %d", &n, &t);

    pair<int, int> v[3000];

    int max_a = 0;

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

        scanf("%d %d", &v[i].first, &v[i].second);

        max_a = max(max_a, v[i].first);

    }

    sort(v, v + n);

    int dp[6000] = {}, tmp[6000] = {};

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

        for(int j = 0; j < t; j++){

            tmp[j + v[i].first] = dp[j] + v[i].second;

        }

        for(int j = 0; j < t + max_a; j++){

            dp[j] = max(dp[j], tmp[j]);

        }

    }

    printf("%d\n", *max_element(dp, dp + t + max_a));

}

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

using namespace std;



const int N = (int)1e6;



pair<int,int> dat[N+5];

int dp[N+5];



int main() {

    int n,t; scanf("%d %d", &n, &t);



    for (int i=0; i<N+3; i++) dp[i] = -1;

    dp[0] = 0;

    int res = 0;

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

        int a,b; scanf("%d %d", &a, &b);

        dat[i] = make_pair(a,b);



        for (int j=t-1+a; j>=a; j--) {

            if (dp[j-a] != -1) {

                dp[j] = max(dp[j], dp[j-a] + b);

                res = max(res, dp[j]);

            }

        }

    }



    sort(dat+1, dat+1+n);



    for (int i=0; i<N+3; i++) dp[i] = -1;

    dp[0] = 0;

    int resa = 0;

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

        int a = dat[i].first;

        int b = dat[i].second;

        for (int j=t-1+a; j>=a; j--) {

            if (dp[j-a] != -1) {

                dp[j] = max(dp[j], dp[j-a] + b);

                resa = max(resa, dp[j]);

            }

        }

    }

    assert(resa >= res);



    printf("%d\n", resa);

    return 0;

}


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

using namespace std;



const int N = (int)1e6;



pair<int,int> dat[N+5];

int dp[N+5];



int main() {

    for (int i=0; i<N+3; i++) dp[i] = -1;

    dp[0] = 0;



    int n,t; scanf("%d %d", &n, &t);

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

        scanf("%d %d", &dat[i].first, &dat[i].second);

    }



    sort(dat+1, dat+1+n);



    int res = 0;

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

        int a = dat[i].first;

        int b = dat[i].second;



        for (int j=t-1+a; j>=a; j--) {

            if (dp[j-a] != -1) {

                dp[j] = max(dp[j], dp[j-a] + b);

                res = max(res, dp[j]);

            }

        }

    }



    printf("%d\n", res);

    return 0;

}


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

#define f first

#define s second 

#define mp make_pair

#define inf 1<<30

using namespace std;



int main()

{

  int N,M,L,a,b,c,d;

  int dis[101][101],th[101][101];

  int dp[101][101];



  while(1){

    cin>>N>>M>>L;

    if(N+M+L==0)break;

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

      for(int j=0;j<101;j++){

	dis[i][j]=th[i][j]=dp[i][j]=inf;

      }

    }

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

      cin>>a>>b>>c>>d;

      a--;b--;

      dis[a][b]=c;

      dis[b][a]=c;

      th[a][b]=d;

      th[b][a]=d;

    }

    int ans=inf;

    dp[0][L]=0;

    priority_queue<pair<int,pair<int,int> > > pq;

    pq.push(mp(0,mp(0,L)));

    while(!pq.empty()){

      pair<int,pair<int,int> > u=pq.top();

      pq.pop();

      u.f=(-1)*u.f;

      if(dp[u.s.f][u.s.s]<u.f)continue;

      if(u.s.f==N-1){

	ans=min(ans,u.f);

	continue;

      }

      

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

	if(dis[u.s.f][i]==inf)continue;

	int c=u.s.s-dis[u.s.f][i];

	if(0<=c){

	  if(u.f<dp[i][c]){

	    dp[i][c]=u.f;

	    pq.push(mp(u.f*(-1),mp(i,c)));

	  }

	}

	if(u.f+th[u.s.f][i]<dp[i][u.s.s]){

	  dp[i][u.s.s]=u.f+th[u.s.f][i];

	  pq.push(mp((u.f+th[u.s.f][i])*(-1),mp(i,u.s.s)));

	}

      }

    }

    cout<<ans<<endl;

  }

  return 0;

}

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

#define f first

#define s second 

#define mp make_pair

#define inf 1<<30

using namespace std;



vector<pair<int,pair<int,int> > > v[101];



int main()

{

  int N,M,L,a,b,c,d;

  int dp[101][101];



  while(1){

    cin>>N>>M>>L;

    if(N+M+L==0)break;

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

      for(int j=0;j<101;j++){

	dp[i][j]=inf;

      }

      v[i].clear();

    }

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

      cin>>a>>b>>c>>d;

      a--;b--;

      v[a].push_back(mp(b,mp(c,d)));

      v[b].push_back(mp(a,mp(c,d)));

    }



    int ans=inf;

    dp[0][L]=0;

    priority_queue<pair<int,pair<int,int> > > pq;

    pq.push(mp(0,mp(0,L)));

    while(!pq.empty()){

      pair<int,pair<int,int> > u=pq.top();

      pq.pop();

      int now=u.s.f,money=u.s.s,cost=(-1)*u.f;

      if(dp[now][money]<cost)continue;

      if(now==N-1){

	ans=cost;

	break;

      }

      

      for(int i=0;i<v[now].size();i++){

	int next=v[now][i].f,dis=v[now][i].s.f,e=v[now][i].s.s;

	int c=money-dis;

	if(0<=c){

	  if(cost<dp[next][c]){

	    dp[next][c]=cost;

	    pq.push(mp(cost*(-1),mp(next,c)));

	  }

	}

	if(cost+e<dp[next][money]){

	  dp[next][money]=cost+e;

	  pq.push(mp((cost+e)*(-1),mp(next,money)));

	}

      }

    }

    cout<<ans<<endl;

  }

  return 0;

}

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

#include<set>

using namespace std;

int D;

int c[26];

int S[365][26];

int t[365];

set<int>id[26];

main()

{

	cin>>D;

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

	{

		cin>>c[i];

		id[i].insert(-1);

	}

	for(int i=0;i<D;i++)for(int j=0;j<26;j++)cin>>S[i][j];

	int ans=0;

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

	{

		cin>>t[i];

		t[i]--;

		ans+=S[i][t[i]];

		id[t[i]].insert(i);

		for(int j=0;j<26;j++)ans-=c[j]*(i-*id[j].rbegin());

	}

	for(int i=0;i<26;i++)id[i].insert(D);

	int M;cin>>M;

	for(;M--;)

	{

		int d,q;cin>>d>>q;d--,q--;

		ans-=S[d][t[d]];

		ans+=S[d][q];

		set<int>::iterator it=id[t[d]].lower_bound(d);

		it=id[t[d]].erase(it);

		{

			int r=*it;

			int l=*--it;

			ans-=c[t[d]]*(r-d)*(d-l);

		}

		it=id[q].lower_bound(d);

		{

			int r=*it;

			int l=*--it;

			ans+=c[q]*(r-d)*(d-l);

		}

		it++;

		id[q].insert(it,d);

		t[d]=q;

		cout<<ans<<endl;

	}

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<set>

using namespace std;

int D;

int c[26];

int S[365][26];

int t[365];

set<int>id[26];

main()

{

	scanf("%d",&D);

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

	{

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

		id[i].insert(-1);

	}

	for(int i=0;i<D;i++)for(int j=0;j<26;j++)scanf("%d",&S[i][j]);

	int ans=0;

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

	{

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

		t[i]--;

		ans+=S[i][t[i]];

		id[t[i]].insert(i);

		for(int j=0;j<26;j++)ans-=c[j]*(i-*id[j].rbegin());

	}

	for(int i=0;i<26;i++)id[i].insert(D);

	int M;scanf("%d",&M);

	for(;M--;)

	{

		int d,q;scanf("%d%d",&d,&q);d--,q--;

		ans-=S[d][t[d]];

		ans+=S[d][q];

		set<int>::iterator it=id[t[d]].lower_bound(d);

		it=id[t[d]].erase(it);

		{

			int r=*it;

			int l=*--it;

			ans-=c[t[d]]*(r-d)*(d-l);

		}

		it=id[q].lower_bound(d);

		{

			int r=*it;

			int l=*--it;

			ans+=c[q]*(r-d)*(d-l);

		}

		it++;

		id[q].insert(it,d);

		t[d]=q;

		printf("%d\n",ans);

	}

}

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



using namespace std;



typedef long long int ll;

typedef string str;

typedef pair<ll,ll> pll;

typedef vector<ll> vll;



#define X first

#define Y second

#define PB push_back

#define For(i,a,b) for (int i=a;i<b;i++)

#define Ford(i,a,b) for (int i=a;i>=b;i--)

#define smax(a,b) a=max(a,b)

#define smin(a,b) a=min(a,b)

#define SZ(a) ((ll)a.size())

#define E(a) cout << #a << ' ' << a << '\n'





const ll M=5e5+5,LG=17,inf=1e18;



ll n;



ll a[M];



int main()

{

	cin >> n;

	if (n==1)

	{

		cout << "YES";

		return 0;

	}

	ll s=0;

	For(i,0,n)

	{

		cin >> a[i];

		s+=a[i];

	}

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

	if (s%t)

	{

		cout << "NO";

		return 0;

	}

	t=s/t;

	ll ss=t;

	a[n]=a[0];

	For(i,0,n)

	{

		ll x=a[i]-a[i+1]+t;

		if (x<0 || x%n)

		{

			cout << "NO";

			return 0;

		}

		ss-=x/n;

	}

	cout << (ss==0?"YES":"NO"); 

}


// Optimized solution to the same problem (faster):
#include<cstdio>

long long a[200001],b[200001];

int n;

long long sum=0;

int main(){

	scanf("%d",&n);

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

	long long p=(1ll*n*(n+1)/2);

	if(sum%p)return !puts("NO");

	long long k=sum/p;

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

	for(int i=0;i<n;i++)if(b[i]>0||(-b[i])%n) return !puts("NO");

	return !puts("YES");

}

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



#define fi first

#define se second

#define mp make_pair

#define pb push_back

#define fbo find_by_order

#define ook order_of_key

#define INF 1e9



typedef long long ll;

typedef pair<ll,ll> ii;

typedef vector<int> vi;

typedef vector < pair<int, int> > vii;

typedef long double ld;

typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;

typedef set<int>::iterator sit;

typedef map<int,int>::iterator mit;

typedef vector<int>::iterator vit;



ll x[100001], d[100001], n, t, q, cnt;



int main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cin >> n;

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

		cin >> x[i];

		t+=x[i];

	}

	if(t%(n*(n+1)/2)!=0){

		cout << "NO";

	}

	else{

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

		cnt=q;

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

			d[i] = x[(i+1)%n]-x[i];

		}

		bool pos = 1;

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

			if((q-d[i])%n!=0 || q-d[i]<0){

				pos=0;

			}

		}

		if(pos){

			cout<<"YES";

		}

		else{

			cout<<"NO";

		}

	}

	

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

long long a[200001],b[200001];

int n;

long long sum=0;

int main(){

	scanf("%d",&n);

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

	long long p=(1ll*n*(n+1)/2);

	if(sum%p)return !puts("NO");

	long long k=sum/p;

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

	for(int i=0;i<n;i++)if(b[i]>0||(-b[i])%n) return !puts("NO");

	return !puts("YES");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define _CRT_SECURE_NO_WARNINGS

#include <vector>

#include <iostream>

#include <string.h>

#include <string>

#include <algorithm>

using namespace std;



typedef double LD;

typedef long long LL;

typedef pair<int, int> PII;

#define MP make_pair

#define PB push_back

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)

#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)

#define REP(i, t) FOR(i,0,t)

#define ALL(a) a.begin(), a.end()

#define SZ(a) (int)((a).size())



const LL MOD = 1000000007;

const int INF = 1e9;

const int MAXN = 100007;

const LD EPS = 1e-7;



int n, A[MAXN];



bool possible()

{

	LL s = 0, c;

	REP(i, n) s += A[i];

	if ((2 * s) % (n * (n + 1LL))) return false;

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

	REP(i, n)

	{

		if (c + A[i] - A[i + 1] < 0) return false;

		if ((c + A[i] - A[i + 1]) % n) return false;

	}

	return true;

}



int main()

{

	ios_base::sync_with_stdio(0);

	//freopen("In.txt", "r", stdin);

	cin >> n;

	REP(i, n) cin >> A[i];

	A[n] = A[0];

	if (possible()) cout << "YES";

	else cout << "NO";

	//cout << endl; system("pause");

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

long long a[200001],b[200001];

int n;

long long sum=0;

int main(){

	scanf("%d",&n);

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

	long long p=(1ll*n*(n+1)/2);

	if(sum%p)return !puts("NO");

	long long k=sum/p;

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

	for(int i=0;i<n;i++)if(b[i]>0||(-b[i])%n) return !puts("NO");

	return !puts("YES");

}

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

#include <cmath>

#include <algorithm>

#include <cstdio>

#include <string>

#include <map>

#include <set>

#include <locale.h>

#include <vector>

#include <iomanip>

#include <cassert>

#include <list>

#include <unordered_map>

#include <cstring>



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

#define sz(x) (int)(x.size())

#define pb push_back



#define onlycin ios_base::sync_with_stdio(false); cin.tie(0)

#define mp make_pair

#define endl "\n"

#define rep(i,x,y) for(int i = x; i <= y; ++i)

#define repr(i,x,y) for(long long i = x; i >= y; --i)

#define y1 wearsdfasdf

#define fi first

#define se second



typedef long long ll;



const int N = (100000) + 322;

const int INF = (ll)(1e9) + 7;



using namespace std;



ll pr[N], a[N], n, pos[N], m, ans, b[N], c[N];



int main () {

  ios_base::sync_with_stdio(false);

  cin >> n;

  ll x = 0, y = n * (n + 1) / 2;

  rep(i, 1, n) {

    cin >> a[i];

    x += a[i];

  }

  if (x % y != 0)

    cout << "NO", exit (0);

  ll cnt = x / y;

  ll ans = 0;

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

  rep(i, 1, n) {

    if ((cnt - (a[i + 1] - a[i])) % n != 0 || (cnt - (a[i + 1] - a[i])) < 0) {

      cout << "NO";

      return 0;

    }

    ans += (cnt - (a[i + 1] - a[i])) / n;

  }

  if (ans != cnt) {

    cout << "NO";

    return 0;

  }

  cout << "YES";

  return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

long long a[200001],b[200001];

int n;

long long sum=0;

int main(){

	scanf("%d",&n);

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

	long long p=(1ll*n*(n+1)/2);

	if(sum%p)return !puts("NO");

	long long k=sum/p;

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

	for(int i=0;i<n;i++)if(b[i]>0||(-b[i])%n) return !puts("NO");

	return !puts("YES");

}

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

using namespace std;

inline int read(){

	int x=0,f=1;char ch=getchar();

	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}

	return x*f;

}

#define MN 100005

long long sum,n,a[MN];

int main(){

	n=read();register int i;

	for(i=1;i<=n;i++) a[i]=read(),sum+=a[i];

	if(sum%((n+n*n)/2)!=0){printf("NO\n");return 0;}

	long long nn=sum/((n+n*n)/2),mm=nn;

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

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

		if((nn-a[i+1]+a[i])%n!=0||(nn-a[i+1]+a[i])/n<0) {

			printf("NO\n");

			return 0;	

		}

		mm-=(nn-a[i+1]+a[i])/n;

	}

	if(mm!=0) {printf("NO\n");return 0;}

	printf("YES\n");

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

long long a[200001],b[200001];

int n;

long long sum=0;

int main(){

	scanf("%d",&n);

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

	long long p=(1ll*n*(n+1)/2);

	if(sum%p)return !puts("NO");

	long long k=sum/p;

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

	for(int i=0;i<n;i++)if(b[i]>0||(-b[i])%n) return !puts("NO");

	return !puts("YES");

}

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

using namespace std;

typedef long long LL;

const int maxn=1e5+10;

int n,a[maxn];

bool check()

{

	LL s=0;

	for (int i=1;i<=n;i++) s+=a[i];

	s*=2;

	if (s%((LL)n*(n+1))!=0) return 0;

	s/=n;s/=(n+1);

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

	{

		LL s1=a[i]-a[i+1]+s;

		if (s1<0||s1%n!=0) return 0;

	}

	LL s1=a[n]-a[1]+s;

	if (s1<0||s1%n!=0) return 0;

	return 1;

}

int main()

{

	cin>>n;

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

	if (check()) printf("YES");

	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: