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 (Python):
import sys
input = sys.stdin.buffer.readline
N = int(input())
a = list(map(int, input().split()))
d = [0] * N
for i in range(1, N):
  d[i] = a[i] - a[i - 1]
d[0] = a[0] - a[-1]
if sum(a) % (N * (N + 1) // 2):
  print("NO")
  exit(0)
f = 0
m = sum(a) // (N * (N + 1) // 2)
c = 0
for i in range(N):
  if m - d[i] < 0 or (m - d[i]) % N:
    f = 0
    break
  c += (m - d[i]) // N
  if c == m:
    f = 1
  else: f = 0
if c == 0:
  r = m
if c > m:
  l = m
if f:
  print("YES")
else: print("NO")

Solution (Python):
def getlist():
	return list(map(int, input().split()))


N = int(input())
A = getlist()
S = sum(A)
if S % (N * (N + 1) // 2) != 0:
	print("NO")

else:
	judge = "YES"
	n = S // (N * (N + 1) // 2)
	for i in range(N):
		val = A[(i + 1) % N] - A[i]
		if val < n * (1 - N) or val > n or (val - n) % N != 0:
			judge = "NO"

	print(judge)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
if n == 1:
    print('YES')
    exit()
suma = sum(a)
if sum(a) % (n*(n+1)//2) > 0:
    print('NO')
    exit()
k = 2*suma//(n*(n+1))
diffs = [a[i+1] - a[i] - k for i in range(-1, n-1)]
if all([d<=0 and -d % n == 0 for d in diffs]):
    print('YES')
else:
    print('NO')

Solution (Python):
N = int(input())
nums = list(map(int, input().split(" ")))

acc = [j - i for i, j in zip(nums[0:N - 1], nums[1:N])]
acc.append(nums[0] - nums[-1])
s = sum(nums)

if N == 1:
    print("YES")

else:
    change = N * (N + 1) // 2 


    if s % change != 0: 
        print("NO")
        exit()

    change_kaisu = s // change 

    acc = list(map(lambda x: x - change_kaisu, acc))
    c = 0
    for temp in acc:
        if temp == 0:
            continue
        elif -temp % N == 0 and temp < 0:
            c += -temp // N
        else:
            print("NO")
            exit()
    if c == change_kaisu:
        print("YES")
    else:
        print("NO")

Solution (Python):
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    Sum = sum(A)
    NN = N*(N+1)//2
    if Sum%NN != 0:
        return False
    k = Sum//NN
    cnt = 0
    for i in range(N):
        a = A[i]-A[i-1]
        if (k-a)%N != 0:
            return False
        cnt += (k-a)//N 
        if cnt > k:
            return False
    if cnt != k:
        return False
    for i in range(N):
        if A[i]<k:
            return False
    return True
if solve():
    print('YES')
else:
    print('NO')

Solution (Python):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))


def solve(A):
    if N == 1:
        return True

    S = sum(A)
    if S % ((N + 1) * N // 2) != 0:
        return False
    
    K = S // ((N + 1) * N // 2)

    cnt = 0
    for i in range(N):
        j = (i + 1) % N
        d = A[j] - A[i]
        if (K - d) % N != 0:
            return False
        if (K - d) // N < 0:
            return False
        cnt += (K - d) // N
    return cnt == K


if solve(A):
    print('YES')
else:
    print('NO')

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

ok = 1
sum_A = sum(A)
M, mod = divmod(sum_A, (N * (N + 1)) // 2)
if mod != 0:
    ok = 0

diff = [0] * N
for i in range(N):
    diff[i] = A[i] - A[i - 1]
count = 0
for i in range(N):
    x, mod = divmod(diff[i] - (1 - N) * M, N)
    count += (M - x)
    if mod != 0 or x < 0 or x > M:
        ok = 0
if count != M:
    ok = 0

if ok:
    print('YES')
else:
    print('NO')

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n = I()
    a = LI()
    s = 0
    for i in a:
        s ^= (i%2)
    if s:
        print("NO")
    else:
        print("YES")
    return


def B():
    n = I()
    a = LI()
    m = n*(n+1)>>1
    s = sum(a)
    if s%m:
        print("NO")
        return
    k = s//m
    b = [k+a[i-1]-a[i] for i in range(n)]
    s = 0
    for i in b:
        if i%n or i < 0:
            print("NO")
            return
        s += i//n
    if s == k:
        print("YES")
    else:
        print("NO")
    return


def C():
    n = I()

    return


def D():
    n = I()

    return


def E():
    n = I()

    return


def F():
    n = I()

    return


if __name__ == "__main__":
    B()

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    A = list( map( int, input().split()))
    if sum(A)%(N*(N+1)//2) != 0:
        print("NO")
        return
    t = sum(A)//(N*(N+1)//2)
    d = [0]*N
    for i in range(N):
        d[i] = A[i] - A[i-1] - t
    for i in range(N):
        if d[i] > 0 or d[i]%N != 0:
            print("NO")
            return
    print("YES")
    
if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    A = list( map( int, input().split()))
    if sum(A)%(N*(N+1)//2) != 0:
        print("NO")
        return
    t = sum(A)//(N*(N+1)//2)
    d = [0]*N
    for i in range(N):
        d[i] = A[i] - A[i-1] - t
    for i in range(N):
        if d[i] > 0 or d[i]%N != 0:
            print("NO")
            return
    print("YES")
    
if __name__ == '__main__':
    main()

Solution (Python):
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N = int(input())
    A = list(map(int, input().split()))

    S = sum(A)

    if S % (N * (N + 1) // 2) != 0:
        print('NO')
        return

    K = S // (N * (N + 1) // 2)
    for diff in [A[i] - A[i - 1] for i in range(N)]:
        if K - diff < 0 or (K - diff) % N != 0:
            print('NO')
            return

    print('YES')


sol()

Solution (Python):
N,*A=map(int,open(0).read().split())
S=sum(A)
if S%(N*(N+1)//2):
	print('NO')
	exit()
M=S//(N*(N+1)//2)
for b in[A[i]-A[i-1]for i in range(N)]:
	if M-b<0 or (M-b)%N:
		print('NO')
		exit()
print('YES')

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *

N = int(input())
A = list(map(int, input().split()))
S, s = sum(A), (N+1)*N//2
if S % s:
    print('NO')
else:
    k = S//s
    B = [A[i+1]-A[i]-k for i in range(N-1)]+[A[0]-A[N-1]-k]
    for b in B:
        if b > 0 or b % N:
            print('NO')
            exit()
    print('YES')

Solution (Python):
import sys
input = sys.stdin.readline

import numpy as np






N = int(input())
A = np.array(input().split(), dtype=np.int64)

total_op = A.sum() // (N*(N+1)//2)

diff = np.empty_like(A)
diff[1:] = np.diff(A)
diff[0] = A[0] - A[-1]


op = (total_op - diff)//N

bl = True
bl &= (total_op * (N*(N+1)//2) == A.sum())
bl &= (N*op + diff == total_op).all()
bl &= (op >= 0).all()

answer = 'YES' if bl else 'NO'
print(answer)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
  n = int(input())
  alist = list(map(int, input().split()))
  asum = sum(alist)
  rm = (1 + n) * n // 2
  if asum % rm != 0:
    print('NO')
  else:
    k = asum // rm
    d = [a-pa-k for pa, a in zip(alist, alist[1:])]
    d.append(alist[0] - alist[-1] - k)
    nk = 0
    for _d in d:
      if _d % n != 0:
        break
      else:
        nk += abs(_d) // n
    else:
      if nk == k:
        print('YES')
      else:
        print('NO')
      sys.exit(0)
    print('NO')


if __name__ == '__main__':
  main()

Solution (Python):
n,*a=map(int,open(0).read().split());q,m=divmod(sum(a),n*-~n//2);print('YNEOS'[any((y-x-q)%n+m|(y-x>q)for x,y in zip(a,a[1:]))::2])

Solution (Python):
n,*a=map(int,open(0).read().split())
q,m=divmod(sum(a),n*-~n//2)
print('YNEOS'[any((y-x-q)%n+m or y-x>q for x,y in zip(a,a[1:]))::2])

Solution (Python):
n,*a=map(int,open(0).read().split())
b,m=sum(a),n*-~n//2
n-=1
c=b//m
f=b%m>0
for i,j in zip(*[iter([a[-1]]+a*2)]*2):
  j-=i
  if n:
    t=min(0,j//n)
    f|=c!=j+n*-t-t
print('YNEOS'[f::2])

Solution (Python):
n,*a=map(int,open(0).read().split())
b,m=sum(a),n*-~n//2
n-=1
c=b//m
f=b%m>0
for i,j in zip(*[iter([a[-1]]+a*2)]*2):
  j-=i
  if n:
    t=min(0,j//n)
    f|=c!=j+n*-t-t
print('YNEOS'[f::2])

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n = getN()
nums = getList()
if sum(nums) % ((n * (n+1)) // 2) != 0:
    print("NO")
    sys.exit()
n_operate = sum(nums) // ((n * (n+1)) // 2)

v_valid = n_operate
v_sign = n

for i, j in zip(nums, nums[1:] + [nums[0]]):
    diff = j - i
    if diff > v_valid:
        print("NO")
        sys.exit()
    if (v_valid - diff) % v_sign != 0:
        print("NO")
        sys.exit()
    n_operate -= (v_valid - diff) // v_sign
    
if n_operate == 0:
    print("YES")
else:
    print("NO")

Solution (Python):
import numpy as np
def main():
    N = int(input())
    A = np.array(list(map(int,input().split())))
    S = np.sum(A)
    s = N*(N+1)//2
    if S%s : print("NO");return
    k = S//s
    B = A - np.arange(1,N+1)*k
    D = B[1:]-B[:-1]
    if (np.all(D<=0)) and (np.all(D%N==0)):
        print("YES")
    else:
        print("NO")
    
main()

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))

S = ((N+1)*N)//2
sA = sum(A)
if sA%S!=0:
    print("NO")
else:
    C = sA//S
    count = 0    
    flag = False
    for i in range(N):
        if i == N-1:
            sub=A[0]-A[i]
        else:
            sub=A[i+1]-A[i]

        if (sub + C*(N-1))%N != 0:
            flag = True
            break
        cnt = C-(sub + C*(N-1))//N
        if cnt>C or cnt<0:
            flag = True
            break
        count += cnt
    if flag:
        print("NO")
    else:
        if C == count:
            print("YES")
        else:
            print("NO")

Solution (Python):
import sys
input = sys.stdin.readline

n=int(input())
A=[int(i) for i in input().split()]
if sum(A)%(n*(n+1)//2)!=0:
  print("NO")
else:
  k=sum(A)//(n*(n+1)//2)
  AA=[0]*n
  for i in range(n):
    if i==n-1:
      AA[i]=A[0]-A[-1]-k
    else:
      AA[i]=A[i+1]-A[i]-k
  ans="YES"
  for i in range(n):
    if AA[i]>0 or AA[i]%n!=0:
      ans="NO"
  print(ans)

Solution (Python):
def check(N, A):
    S = N * (1+N) // 2
    total = sum(A)
    if total % S != 0:
        return False
    cnt = total//S
    tmp = cnt
    for i in range(N):
        diff = A[i] - A[(i+1) % N]
        if (diff + cnt) % N != 0 or (diff + cnt) < 0:
            return False
        tmp -= (diff + cnt) // N
    return tmp == 0


def main():
    N = int(input())
    A = list(map(int, input().split()))
    if check(N, A):
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
if n==1:
  print('YES')
else:
  sum1=sum(arr)
  sum2=(n*(n+1))//2
  moves=sum1//sum2
  cnt=0
  if sum1%sum2!=0:
    print('NO')
  else:
    flag=True
    arr2=[]
    for i in range(n-1):
      tmp=arr[i]+moves
      if arr[i+1]==tmp:
        continue
      else:
        diff=tmp-arr[i+1]
        if diff%n!=0:
          flag=False
        else:
          arr2.append(n-i)
          cnt+=diff//n
          tmp=arr[i+1]-diff//n
          if tmp>n*(moves-diff//n):
            flag=False
    if flag==False:
      print('NO')
    else:
      if len(arr2)==moves:
        if arr[0]==sum(arr2):
          print('YES')
        else:
          print('NO')
      elif len(arr2)>moves:
        print('NO')
      else:
        if 1*(moves-len(arr2))<=arr[0]-sum(arr2)<=n*(moves-len(arr2)):
          print('YES')
        else:
          print('NO')

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
if sum(A)%(N*(N+1)//2)!=0:
    print('NO')
    exit()
ALL=sum(A)//(N*(N+1)//2)
X=[0]*N
if (A[N-1]-A[0]+ALL)%N!=0:
    print('NO')
    exit()
elif (A[N-1]-A[0]+ALL)//N<0:
    print('NO')
    exit()
for i in range(1,N):
    if (A[i-1]-A[i]+ALL)%N!=0:
        print('NO')
        exit()
    elif (A[i-1]-A[i]+ALL)//N<0:
        print('NO')
        exit()
print('YES')

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = n * (n+1) // 2
t = sum(a)
if t % s:
    print("NO")
    quit()
m = t // s
d = [a[(i+1)%n] - a[i] - m for i in range(n)]
k = 0
for x in d:
    if x > 0 or x % n:
        print("NO")
        quit()
    k += -x // n
print("YES" if k == m else "NO")

Solution (Python):
n = int(input())
a = [int(item) for item in input().split()]


asum = sum(a)
if asum % ((n + 1)*n // 2) != 0:
    print("NO")
    exit()
k = asum // ((n + 1)*n // 2)


a.append(a[0])
drop = 0
for i in range(n):
    diff = a[i] + k - a[i+1]
    if diff == 0:
        continue
    else:
        if diff % n != 0 or diff < 0:
            print("NO")
            exit()
        else:
            drop += diff // n
if drop != k:
    print("NO")
    exit()

print("YES")

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
ans=True
c=[]
t=sum(a)//((n*(n+1))//2)

if sum(a)%((n*(n+1))//2)!=0:
    ans=False
else:
    for i in range(n):
        if i==0:
            d=a[0]-a[-1]
        else:
            d=a[i]-a[i-1]
        if (t-d)%n!=0 or d-t>0:
            ans=False
            break
if n==1:
    ans=True
print('YES' if ans else 'NO')

Solution (Python):

n=int(input())
a=[int(i) for i in input().split()]
ans=True
c=[]

t=sum(a)//((n*(n+1))//2)

if sum(a)%((n*(n+1))//2)!=0:
    ans=False
else:
    for i in range(n):
        if i==0:
            d=a[0]-a[-1]
        else:
            d=a[i]-a[i-1]
        if (t-d)%n!=0 or d-t>0:
            ans=False
            break
        s=(t-d)//n
        c.append(s)
    
        
if n==1:
    ans=True
print('YES' if ans else 'NO')

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
N=((n)*(n+1))//2

if sum(A)%N!=0:
    print("NO")
    exit()
elif n==1:
    print("YES")
elif n==2:
    if sum(A)%3==0 and max(A)<=2*min(A):
        print("YES")
    else:
        print("NO")
else:
    T=(sum(A)//N)
    A+=[A[0]]
    cnt=0
    for i in range(1,len(A)):
        if (A[i]-A[i-1])==T:
            
            continue
        else:
            if A[i-1]>A[i]-T:
                B=((A[i-1]-A[i])//n)+1
                cnt+=B
                
                if (A[i]-A[i-1]+n*B)==T:
                    continue
                else:
                    print("NO")
                    exit()
            else:
                print("NO")
                exit()
    if T==cnt:
        print("YES")
    else:
        print("NO")

Solution (Python):
import sys
N=int(input())
A=[int(i) for i in input().split()]
if sum(A)%((N*(N+1))//2)!=0:
    print('NO')
    sys.exit()
k=sum(A)//((N*(N+1))//2)
B=[0]*N
for i in range(N):
    B[i]=A[i]-A[i-1]
for a in B:
    if a-k<=0 and (k-a)%N==0:
        continue
    print('NO')
    sys.exit()
print('YES')

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

s = sum(a)

if s%(n*(n+1)//2)!=0:
    print('NO')
    exit()

ss = s//(n*(n+1)//2)

b = [0 for i in range(n)]


for i in range(n):
    b[i-1] = (ss-a[i]+a[i-1])//n
    if b[i-1]<0:
        print('NO')
        exit()

c = [0 for i in range(n)]
for i in range(n):
    c[0]+=b[i]*(n-i)

for i in range(1,n):
    c[i] = c[i-1] + ss - b[i-1]*n

if a==c:
    print('YES')
else:
    print('NO')

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    N = int(input())
    A = list(map(int, input().split()))

    k = sum(A)//(N*(N+1)//2)
    if sum(A) % (N*(N+1)//2) != 0:
        return "NO"

    D = [0]*N
    for i in range(N-1):
        D[i] = A[i+1]-A[i]-k
    D[-1] = A[0]-A[-1]-k

    cnt = sum([v//N for v in D])
    if all(x <= 0 and -x % N == 0 for x in D)and -cnt == k:
        return "YES"
    else:
        return "NO"


print(solve())

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
sa = sum(a)
stone = n*(n+1)//2
if sa % stone:
    print("NO")
    exit()
a.append(a[0])
k = sa//stone
d = [a[i+1]-a[i] - k for i in range(n)]
for i in d:
    if i%n or i>0:
        print("NO")
        exit()
print("YES")

Solution (Python):
n = int(input())
alist = list(map(int, input().split()))
suma = sum(alist)

if suma % (n * (n+1) // 2) != 0:
  print('NO')
else:
  k = suma // (n * (n+1) // 2)
  da = []
  for preva, a in zip(alist, alist[1:]):
    da.append(a - preva - k)
  da.append(alist[0] - alist[-1] - k)
  nk = 0
  is_a = True
  for _da in da:
    if abs(_da) % n != 0:
      is_a = False
      break
    nk += abs(_da) // n
  if not is_a:
    print('NO')
  else:
    if nk != k:
      print('NO')
    else:
      print('YES')

Solution (Python):

N = int(input())
A = list(map(int, input().split()))

S = sum(A)


ans = (
    'YES' if (2 * S) % (N * (N + 1)) == 0 and all(
        k % N == 0 and k >= 0
        for k in (
            (2 * S) // (N * (N + 1)) - (A[i] - A[i - 1])
            for i in range(N)
        )
    ) else
    'NO'
)


print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

if sum(a) % (n*(n+1)//2) != 0:
    print('NO')
    exit()
else:
    k = sum(a)// (n*(n+1)//2)


for i in range(n-1):
    d = a[i+1] - a[i] - k

    if d > 0 or d % n != 0:
        print('NO')
        exit()

print('YES')

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

K = sum(A) / sum(range(1, N+1))
D = []
for i in range(-1,N-1):
    D.append(A[i+1] - A[i] - K )

for d in D:
    if not (d <= 0 and d % N == 0):
        print("NO")
        break
else:
    print("YES")

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

def solve():
    q = N * (N + 1) // 2
    if sum(A) % q:
        return False
    times = sum(A) // q
    cnt = 0
    for i, j in zip(A, A[1:] + [A[0]]):
        dif = times + i - j
        if dif % N or dif < 0:
            return False
        cnt += dif // N
    return times == cnt

print('YES' if solve() else 'NO')

Solution (Python):


def io_generator():
	return input()



def main(io):
	ret_ng='NO'
	ret_ok='YES'
	
	n=int(io())
	l= list(map(int, io().split()))
	
	v_one_act =n*(n+1)/2
	
	if sum(l)%v_one_act != 0:
		return ret_ng
		
	act_num=sum(l)//v_one_act	
	st_num=0
	
	for a,b in zip(l, l[1:]+l):
		diff = b - a
		if (act_num-diff)%(n)!=0:
			return ret_ng
		if (act_num-diff)<0:
			return ret_ng
		st= (act_num-diff)//(n)
		st_num+=st
	
	if act_num!=st_num:
		return ret_ng
		
	
		
	return ret_ok



if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
 
sum_a = sum(a)
len_a = len(a)
kaisu = sum_a // ( (1/2)*(len_a)*(len_a+1) )
 
if sum_a % ( (1/2)*(len_a)*(len_a+1) ) !=0:
  print("NO")
  exit()

ans_kaisu = 0
a.append(a[0])

for i in range(n):
  tmp = (kaisu - (a[i+1]-a[i])) // len_a
  if (kaisu - (a[i+1]-a[i])) % len_a !=0 or tmp < 0:
    print("NO")
    exit()
  ans_kaisu += tmp
  
if ans_kaisu ==kaisu:
  print("YES")
else:
  print("NO")

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
q,m=divmod(sum(a),n*(n+1)//2)
print('YNEOS'[any([(y-x-q)%n or y-x>q or m for x,y in zip(a[:-1],a[1:])])::2])

Solution (Python):


import sys


INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    A = LI()

    
    k, mod = divmod(sum(A), (n * (n + 1) // 2))
    if mod:
        return 'NO'

    A.append(A[0])
    diff = []
    for a1, a2 in zip(A[:-1], A[1:]):
        diff.append(a2 - a1)

    
    

    
    return 'YES' if not any([(d - k) % n or d > k for d in diff]) else 'NO'


print(main())

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
if sum(a) % ((1 + n) * n // 2):
    print("NO")
else:
    m = sum(a) // ((1 + n) * n // 2)
    d = [0] * n
    for i in range(n):
        d[i] = a[(i + 1) % n] - a[i] - m
    for i in d:
        if i % n or i > 0:
            print("NO")
            exit()
    if -sum(d) == n * m:
        print("YES")
    else:
        print("NO")

Solution (Python):
N = int(input())
A = list(map(int, input().split()))



Sum = sum(A)
if Sum % (N * (N + 1) // 2) != 0:
    print('NO')
    exit()



K = Sum // (N * (N + 1) // 2)

Diff = [A[i] - A[(i - 1)] for i in range(N)]

Diff = [d - K for d in Diff]

for d in Diff:
    if d < 0:
        if d % N != 0:
            print('NO')
            exit()
        else:
            K -= abs(d // N)

if K == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

if sum(a) % (n * (n+1) // 2) != 0:
    print("NO")
    exit()

k = sum(a) // (n * (n+1) // 2)
b = [0] * n
for i in range(n-1):
    b[i] = a[i+1] - a[i]
b[n-1] = a[0] - a[n-1]

for i in range(n):
    b[i] -= k

count = 0
for nb in b:
    if (-nb % n) != 0 or nb > 0:
        print("NO")
        exit()
    count += -nb // n

if count == k:
    print("YES")
else:
    print("NO")

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
ans='YES'
suma=sum(a)
i=suma/(n*(n+1)//2)
a2=[a[j]-a[j-1]-i for j in range(n)]
for i in a2:
    if i%n!=0 or i>0:ans='NO'
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

one2n = sum([i for i in range(1, n+1)])

ok = True

if sum(a) % one2n > 0:
    ok = False
    
if ok:
    b = a + [a[0]]
    end = 0
    kire = sum(a) // one2n
    for idx in range(n):
        dif = b[idx+1] - b[idx]
        if (kire-dif) % n > 0:
            ok = False
            break
        
        elif (kire-dif)//n < 0:
            ok = False
            break
        
        end += (kire-dif) // n
        
    if end != kire:
        ok = False
        
print("YES") if ok else print("NO")

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
suma = sum(A)
unit = N*(N+1)//2
if suma % unit:
    print('NO')
    exit()
ope = suma // unit

d = A[0]-A[-1]
for a,b in zip(A,A[1:]):
    if (b-a)%N != d%N:
        print('NO')
        exit()

AA = A + [A[0]]
k = 0
for a,b in zip(AA,AA[1:]):
    if b-a > ope:
        print('NO')
        exit()
    k += (ope - (b-a)) // N

print('YES' if k==ope else 'NO')

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
s=sum(A)
if s%((n*(n+1))//2):
    print('NO')
else:
    k=s//(n*(n+1)//2)
    D=[]
    for i in range(n-1):
        D.append(A[i+1]-A[i]-k)
    D.append(A[0]-A[n-1]-k)
    ans='YES'
    for i in range(n):
        if D[i]>0 or D[i]%n!=0:
            ans='NO'
    print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
s = sum(A)
K = s // (N * (N + 1) // 2)
if N == 1:
    print("YES")
    exit()
if s % (N * (N + 1) // 2) != 0:
    print("NO")
    exit()
d = [0] * (N - 1)
for i in range(N - 1):
    d[i] = A[i + 1] - A[i] - K

for i in range(N - 1):
    if d[i] > 0 or abs(d[i]) % N != 0:
        print("NO")
        exit()
print("YES")

Solution (Python):
n = int(input())
a = [int(m) for m in input().split()]
p = []
for i in range(n):
    if i == n - 1:
        p.append(a[0] - a[n - 1])
    else:
        p.append(a[i + 1] - a[i])

k = sum(a) / ((n * (n + 1)) // 2)
if int(k) != k:
    print("NO")
    exit()
m = []
for i in range(n):
    mi = (k - p[i]) / n
    if int(mi) != mi or mi < 0:
        print("NO")
        exit()
    else:
        m.append(mi)

if sum(m) == k:
    print("YES")
else:
    print("NO")

Solution (Python):
n = int(input())
lis = list(map(int,input().split()))
if sum(lis) % sum([i for i in range(1,n+1)]) != 0:
    print("NO")
    exit()
key = sum(lis) // sum([i for i in range(1,n+1)])
li = [-lis[i]+lis[i-1]+key for i in range(n)]
for num in li:
    if num < 0 or num % n != 0:
        print("NO")
        exit()
print("YES")

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

P = "possible"

Nsum = N *(N+1)//2
if sum(A) % Nsum == 0:
  K = sum(A) // Nsum
  for i in range(N):
    A[i] -= K * (i + 1)
  A0 = A[0]
  for i in range(N):
    A[i] -= A0
  B = [0] * N
  for i in range(1, N):
    if (A[i] - A[i-1])%N != 0:
      P = "impossible"
    else:
      B[i] = (A[i-1] - A[i]) // N
  B[0] = K - sum(B)
  for i in range(N):
    if B[i] < 0:
      P = "impossible"
  for i in range(1, N):
    A0 -= B[i] * (N-i)
  if A0 != 0:
    P = "impossible"
else:
  P = "impossible"
  
if P == "impossible":
  print("NO")
else:
  print("YES")

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]

RejectStones = N * (N+1) // 2
if sum(A) % RejectStones != 0: print("NO")
else:
    TotalOperation = sum(A) // RejectStones
    sumcheck = 0
    for i in range(N-1):
        if (TotalOperation - A[i+1] + A[i]) % N != 0 or TotalOperation < A[i+1] - A[i]:
            print("NO")
            break
        else:
            sumcheck += (TotalOperation - A[i+1] + A[i]) // N
    else:
        if (TotalOperation - A[0] + A[-1]) % N != 0 or TotalOperation < A[0] - A[-1]: print("NO")
        else: 
            sumcheck += (TotalOperation - A[0] + A[-1]) // N
            if sumcheck == TotalOperation: print("YES")
            else: print("NO")

Solution (Python):
n=int(input())
a=list(map(int,input().split()))

total = sum(a)
oneTri = n*(n+1)//2
if total%oneTri!=0:
    print("NO")
    exit()

trial = total//oneTri

cnt=0
for i in range(n):
    sa = a[i-1] + trial - a[i]
    if sa == 0:
        continue
    if sa % n != 0 or sa < 0:
        print("NO")
        exit()
    cnt += sa//n

if cnt != trial:
    print("NO")
else:
    print("YES")

Solution (Python):



"""
解説PDFの英語版に従い実装
"""

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
A = list(map(int, input().split()))

A_sum = sum(A)
removed_unit = N * (N + 1) // 2

if A_sum % removed_unit:
    print('NO')
else:
    k = A_sum / removed_unit
    for i in range(N):
        d = A[(i + 1) % N] - A[i]
        if k - d >= 0 and (k - d) % N == 0:
            pass
        else:
            print('NO')
            sys.exit(0)
    print('YES')

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

bl = True

amount = N * (N + 1) // 2  
q1, r1 = divmod(sum(a), amount)  
if r1 != 0:
    bl = False
else:
    d = [a[(i + 1) % N] - a[i] for i in range(N)]
    d = list(map(lambda x: x - q1, d))

    cnt = 0
    for dd in d:
        if dd > 0:
            bl = False
            break
        else:
            q2, r2 = divmod(-dd, N)
            if r2 > 0:
                bl = False
                break
            else:
                cnt += q2
    bl &= (cnt == q1)

print('YES' if bl else 'NO')

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
S=sum(a)
if S%(N*(N+1)//2)==0:
  k=S//(N*(N+1)//2)
else:
  print("NO")
  exit()
D=[]
a.append(a[0])
for i in range(N):
  D.append(a[i+1]-a[i]-k)

for d in D:
  if d>0 or d%N!=0:
    print("NO")
    exit()
    
print("YES")

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
if sum(a)%((1+n)*n//2):
  print("NO")
  exit()
kai = sum(a)//((1+n)*n//2)
b = []
b.append(a[0]-a[-1]-kai)
for i in range(n-1):
  b.append(a[i+1]-a[i]-kai)
for i in b:
  if i>0:
    print("NO")
    exit()
ss = 0
for i in b:
  if (-i)%n !=0:
    print("NO")
    exit()
  ss += (-i)//n
if ss == kai:
  print("YES")
else:
  print("NO")

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = sum(a)
    if s % ((n+1) * n // 2) != 0:
        print('NO')
        return
    s //= ((n+1) * n // 2)

    b = [a[(i+1)%n] - a[i] for i in range(n)]
    for i in range(n):
        b[i] -= s

    for i in range(n):
        if b[i] > 0 or b[i] % n != 0:
            print('NO')
            return
    print('YES')

main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

s = sum(a)
one = n * (n+1) // 2
if s % one:
    print('NO')
    exit()
times = s // one

cnt = 0
b = a[1:]+[a[0]]
for i,j in zip(a,b):
    dif = j - i
    if (times - dif) % n:
        print('NO')
        exit()
    if (times-dif) // n < 0:
        print('NO')
        exit()
    cnt += (times-dif) // n
if times != cnt:
    print('NO')
else:
    print('YES')

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
sa = sum(A)

unit = N*(N+1)//2
if sa%unit:
    print('NO')
    exit()

k = sa//unit
A.append(A[0])

for a,b in zip(A,A[1:]):
    if b-a-k > 0 or (b-a-k)%N != 0:
        print('NO')
        exit()
print('YES')

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

b = [] 
for i in range(1,n):
    b.append(a[i]-a[i-1])
b.append(a[0]-a[n-1])

w = n*(n+1)//2 


if sum(a)%w != 0:
    print('NO')
else:
    res = 0
    c = sum(a)//w 
    for i in range(n):
        b[i]-=c
    
    for i in range(n):
        if (-b[i]) % n == 0 and b[i] <= 0:
            res += (-b[i])//n
        else:
            res = c+1
            break
            
    if res == c:
        print('YES')
    else:

        print('NO')

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
import sys

N = int(input())
A = inpl()

sumA = sum(A)
k = (N*(N+1)//2)
if sumA % k != 0:
    print('NO')
    sys.exit()
k = sumA // k
B = []
for i in range(N-1):
    B.append(A[i+1]-A[i]-k)
B.append(A[0]-A[N-1]-k)
flag = 0
ans = 'NO'
for i in B:
    if i%N != 0:
        break
    if i//N > 0:
        break
    flag -= i//N
else:
    if flag == k:
        ans = 'YES'
print(ans)