stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 2.683177346923905x):
#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));

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.831777808694491x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.100679168519606x):
#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;

}
// Slower C++ solution:
#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;

	}

}

// Faster C++ solution for the same problem (measured speedup: 1.1164956120366807x):
#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);

	}

}
// Slower C++ solution:
#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"); 

}


// Faster C++ solution for the same problem (measured speedup: 5.292958431827244x):
#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");

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.367758016799359x):
#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");

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.366914350721631x):
#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");

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.364899361937519x):
#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");

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.22147160156631x):
#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");

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 4.409002494599563x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 4.350970987751101x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 4.340758396350586x):
#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;

}