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):
N = int(input())
A = list(map(int, input().split()))

M = N * (N + 1) // 2
d, m = divmod(sum(A), M)

def no():
  print("NO")
  exit()

if m != 0:
  no()

cnt = 0
for i in range(N):
  t = A[i - 1] - A[i]
  t += d
  if t < 0:
    no()
  dd, mm = divmod(t, N)
  if mm != 0:
    no()
  cnt += dd

if cnt == d:
  print("YES")
else:
  no()

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

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

cnt = 0
for i in range(n):
    tmp = a[i]-a[i-1]-cyc
    if(tmp%n != 0):
        print('NO')
        exit()
    cnt += abs(tmp//n)

if(cnt == cyc):
    print('YES')
else:
    print('NO')

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
cum = sum(a)
d = n*(n+1)//2
if cum%d:
    print("NO")
    exit()
x = cum//d

a.append(a[0])
count = 0
for i in range(n):
    dif = a[i+1]-a[i]
    if (x-dif)%n or x-dif < 0:
        print("NO")
        exit()
    count += (x-dif)//n
if count == x:
    print("YES")
else:
    print("NO")

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

Solution (Python):
def main(n,a):
  sa=sum(a)
  tmp=(n*(n+1))//2
  if sa%tmp!=0:
    return 'NO'
  cnt=sa//tmp
  chk=0
  for i in range(n):
    t=a[i]-a[i-1]
    t-=cnt
    if t==0:continue
    if t%n!=0:return 'NO'
    chk+=abs(t)//n
  if cnt==chk:return 'YES'
  return 'NO'

n=int(input())
a=list(map(int,input().split()))
print(main(n,a))

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

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

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

k = s//(N*(N+1)//2)
B = [A[(i+1)%N]-A[i] for i in range(N)]
B = list(map(lambda x: x-k, B))
cnt = 0

for Bi in B:
    if Bi>0 or Bi%N!=0:
        print('NO')
        exit()
        
    cnt += (-Bi)//N

if cnt==k:
    print('YES')
else:
    print('NO')

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
import numpy as np
nwa=n*(n+1)//2
if sum(A)%nwa!=0 : print("NO");exit()
k= sum(A)//nwa 


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


D=[i-k for i in D]
for i in D:
    if i>0:print("NO");exit()
    if i==0:continue
    if abs(i)%n!=0: print("NO");exit()
else:
    print("YES")

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
x=(N+1)*N//2
a=0 if sum(A)%x else 1
d=sum(A)//x
y=0
for i in range(N):
    if (A[i]-A[i-1])%N!=d%N or A[i]-A[i-1]>d:
        a=0
    else:
        y-=(A[i]-A[i-1]-d)//N
print(['NO','YES'][a and y==d])

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))
    x = n * (n + 1) // 2
    y = sum(a)

    if y % x != 0:
        return print("NO")

    b = [0] * n
    c = y // x
    for i in range(n):
        b[i] = a[i] - a[(i + 1) % n] + c

    p = [0] * n
    for i in range(n):
        if b[i] % n != 0 or b[i] < 0:
            return print("NO")
        else:
            p[i] = b[i] // n

    if sum(p) == c:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    sa = sum(a)
    if sa%(n*(n+1)//2) != 0:
        print("NO")
        exit()
    t = sa//(n*(n+1)//2)
    d = [a[i]-a[i-1] for i in range(n)]
    at = 0
    for i in d:
        if (t-i)%n != 0 or (t-i)//n < 0:
            print("NO")
            exit()
        at += (t-i)//n
    if at == t:
        print("YES")
    else:
        print("NO")

    return

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))

'''
import random
N = 30
A = [0]*N
for i in range(1000):
    n = random.randint(1,N)
    for j in range(N):
        A[(n-1+j)%N] += j+1
        '''

M = N*(N+1)//2
sumA = sum(A)

if sumA % M != 0:
    print('NO')
    exit()

diff = [x-y for x,y in zip(A[1:] + [A[0]], A)]

all_cnt = 0
while min(diff) < 0:
    cnt = 0
    for i in range(N):
        if diff[i] < 0:
            t = -(diff[i]//(N-1))
            cnt += t
            diff[i] += t*N
    diff = [d-cnt for d in diff]
    all_cnt += cnt*M
    if all_cnt > sumA:
        print('NO')
        exit()

N2 = sumA - all_cnt
if N2 % (M*N) == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
import sys



from bisect import bisect_left, bisect_right





input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 1000000007

def solve():
    n = getN()
    nums = getList()

    bulk = n*(n+1)//2
    ope = sum(nums) // bulk
    if sum(nums) % bulk != 0:
        print("NO")
        return
    nums = nums + [nums[0]]

    tmp = 0
    for i, j in zip(nums, nums[1:]):
        if j - i > ope:
            print("NO")
            return
        else:
            expected = i + ope
            if (expected - j) % n != 0:
                print("NO")
                return
            tmp += (expected - j) // n
    
    if tmp == ope:
        print("YES")
    else:
        print("NO")


def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    
    solve()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
t = n * (n + 1) // 2
s = sum(a)
if s % t:
    print('NO')
else:
    c = s // t
    b = [0] * n
    for i in range(n):
        b[i] = a[i] - a[i - 1] - c
    for i in range(n):
        if b[i] % n or b[i] > 0:
            print('NO')
            break
    else:
        print('YES')

Solution (Python):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = np.array(read().split(), np.int64)

def main(N, A):
    k = N * (N + 1) // 2
    t = A.sum() // k
    if k * t != A.sum():
        return False
    B = np.empty_like(A)
    B[1:] = A[1:] - A[:-1]
    B[0] = A[0] - A[-1]
    B -= t
    if np.any(B % N != 0):
        return False
    B //= (-N)
    return np.all(B >= 0)

print('YES' if main(N, A) else 'NO')

Solution (Python):
import sys
import heapq

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()


N = ini()
A = inl()
assert len(A) == N


def solve():
    if N == 1:
        return True
    asum = sum(A)
    k = N * (N + 1) // 2
    if asum % k != 0:
        return False
    t = asum // k  

    B = [None] * N
    for i in range(N - 1):
        B[i] = A[i + 1] - A[i]
    B[N - 1] = A[0] - A[N - 1]
    if sum(B) != 0:
        return False
    bmax = max(B)
    B.sort()
    s = 0
    for b in B:
        if (bmax - b) % N != 0:
            return False
        s += (bmax - b) // N
    return s == t


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

Solution (Python):
n = int(input())

a = [int(_) for _ in input().split()]


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

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

d = [a[i]-a[i-1]-m for i in range(n)]


for D in d:
    if D % n == 0:
        m += D//n
    if D % n != 0 or D > 0:
        print("NO")
        exit()
if m == 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(0)

k = sum(A) // (N * (N+1) / 2)
judge = True
for i, a in enumerate(A):
  x = A[(i+1)%N] - a - k
  if x % N != 0 or x > 0:
    judge = False
print("YES" if judge else "NO")

Solution (Python):


def main():
    N = int(input())
    A = list(map(int,input().split()))
    get = N*(N+1)//2
    if sum(A)%get!=0:
        print('NO')
        return
    k = sum(A)//get
    for i in range(N):
        d = A[(i+1)%N]-A[i]-k
        if d>0 or d%N!=0:
            print('NO')
            return
    print('YES')

main()

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

unit = n*(n+1)//2
k, m = divmod(sum(a), unit)
if m:
    ans = "NO"
else:
    count = [None] * n 
    for i in range(n):
        diff = a[i] - a[i-1]
        x, m = divmod(k- diff, n)
        if x<0 or m:
            ans = "NO"
            break
        count[i-1] = x
    else:
        if sum(count)==k and sum(c*(n-i) for i,c in enumerate(count)):
            ans = "YES"
        else:
            ans = "NO"
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

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

    s = N*(N + 1)//2
    tot = sum(A)
    if tot%s == 0:
        cnt = tot//s
    else:
        print('NO')
        return
    
    A.append(A[0])
    x = 0
    for i in range(N):
        diff = A[i + 1] - A[i]
        if cnt - diff < 0:
            print('NO')
            return
        if (cnt - diff)%N == 0:
            x += (cnt - diff)//N
        else:
            print('NO')
            return
    print('YES' if x == cnt else 'NO')
if __name__ == '__main__':
    main()

Solution (Python):

N=int(input())
A=list(map(int,input().split()))
oneton=(N*(N+1))//2
flag=1
allsum=sum(A)
dif=[]
for i in range(N):
    dif.append(A[(i+1)%N]-A[i%N])


if allsum%oneton!=0:
    flag=0
else:
    opnum=allsum//oneton        
    l=[opnum]*N                 
    
    for i in range(N):
        if l[i]<dif[i]:         
            flag=0
            break
        else:                   
            diff=l[i]-dif[i]    
            useminus=diff//N    
            opnum=opnum-useminus
            l[i]=l[i]-(useminus*N)
    if opnum!=0:                    
        flag=0
    for i in range(N):              
        if l[i]!=dif[i]:
            flag=0
if flag==0:
    print("NO")
else:
    print("YES")

Solution (Python):

N=int(input())
A=list(map(int,input().split()))
oneton=(N*(N+1))//2
flag=1
allsum=sum(A)
dif=[]
for i in range(N):
    dif.append(A[(i+1)%N]-A[i%N])


if allsum%oneton!=0:
    flag=0
else:
    opnum=allsum//oneton        
    l=[opnum]*N                 
    
    for i in range(N):
        if l[i]<dif[i]:         
            flag=0
            break
        else:                   
            diff=l[i]-dif[i]    
            useminus=diff//N    
            opnum=opnum-useminus
            l[i]=l[i]-(useminus*N)
    if opnum!=0:                    
        flag=0
    for i in range(N):              
        if l[i]!=dif[i]:
            flag=0
if flag==0:
    print("NO")
else:
    print("YES")

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

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

    K = Asum // rem
    A.append(A[0])
    dif = [r - l for l, r in zip(A[:-1], A[1:])]
    for d in dif:
        if d > K:
            return False
        if (K - d) % N != 0:
            return False
    return True


if __name__ == "__main__":
    if main():
        print("YES")
    else:
        print("NO")

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

ok = True
S = sum(A)
T = (1+N) * N // 2
if S % T != 0:
    ok = False
else:
    t = S // T
    count = 0
    for i in range(N):
        a0, a1 = A[i-1], A[i]
        if -(a1 - a0 - t) < 0:
            ok = False
            break
        if -(a1 - a0 - t) % N != 0:
            ok = False
            break
        count += -(a1 - a0 - t) // N
YESNO = lambda tf: print('YES') if tf else print('NO')
YESNO(ok and S // T == count)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    B=[A[i]-A[i-1] for i in range(N)]
    
    K = sum(A)//(N*(N+1)//2)
    if(K*(N*(N+1)//2) != sum(A)):
        print("NO")
        return
    ans = True
    for b in B:
        b-=K
        
        if(b%N!=0 or b>0):
            ans = False
    if(ans):
        print("YES")
    else:
        print("NO")
if __name__ == '__main__':
    main()

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

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

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

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

k = S // (N*(N+1)//2)
d = [A[0] - A[-1] - k]
for i in range(N-1):
  d.append(A[i+1] - A[i] - k)

time = 0
for di in d:
  if di <= 0 and (-di) % N == 0:
    time += -di // N
  else:
    print('NO')
    quit()

if time == k:
  print('YES')
else:
  print('NO')

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

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

s=sum(A)
if s%(N*(N+1)//2)!=0:
    print("NO")
    exit()
else:
    count=s//(N*(N+1)//2)

data=[0 for i in range(0,N)]
for i in range(N):
    if (count-(A[i]-A[i-1]))%N!=0:
        print("NO")
        exit()
    else:
        data[i]=(count-(A[i]-A[i-1]))//N
        if data[i]<0:
            print("NO")
            exit()

check=0
for i in range(N):
    check+=data[i]*((N-i)%N+1)

if check==A[0]:
    print("YES")
else:
    print("NO")

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))






N = I()
A = LI()

red_once = (N+1)*N//2
s = sum(A)

if s%red_once != 0:
    print('NO')
else:
    num = s//red_once
    t = [0]*N
    for i in range(N):
        d,m = divmod(num-A[i]+A[i-1],N)
        if m != 0 or d < 0:
            print('NO')
            exit()
        else:
            t[i] = d
    if sum(t) == num:
        print('YES')
    else:
        print('NO')

Solution (Python):

n=int(input())
a=list(map(int, input().split()))
sa= sum(a)
if sa%(n*(n+1)//2):
    print("NO")
    exit()
k=sa//(n*(n+1)//2)
b=[a[i]-a[i-1] -k for i in range(n)]

for i in range(n):
    if b[i]%n or b[i]>0:
        print("NO")
        exit()
print("YES")

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print('YES')
	exit()
tot = 0
for i in range(n):
	tot += a[i]
 
if tot % (n*(n+1)//2) != 0:
	print('NO')
	exit()
times = tot//(n*(n+1)//2)
 
x = a[n-1]-a[0]+times
if (x < 0) |(x % n != 0):
	print('NO')
	exit()
for i in range(1,n):
	x = a[i-1]-a[i]+times
	
	if (x < 0) | (x % n != 0):
		print('NO')
		exit()
print('YES')

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    totalA = sum(A)
    if totalA % (N * (N + 1) // 2) != 0: print("NO")
    else:
        Op = totalA // (N * (N + 1) // 2)
        subA = [A[(i + 1) % N] - A[i] for i in range(N)]
        count = 0
        for i, a in enumerate(subA):
            if (Op - a) % N != 0 or a > Op:
                print("NO")
                break
            else: count += (Op - a) // N
        else: 
            if count == Op: print("YES")
            else: print("NO")
    
    return 0

if __name__ == "__main__":
    solve()

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

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

K = S // (N * (N + 1) // 2)
B = [r - l - K for r, l in zip(A[1:] + [A[0]], A)]

if not all(b <= 0 and b % N == 0 for b in B):
    print('NO')
    exit()

if K == -sum([b // N for b in B]):
    print('YES')
    exit()

print('NO')

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

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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
if sum(a) % (n * (n + 1) // 2) != 0:
    print("NO")
    exit()

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

l = 0
for i in range(n):
    j = (i + 1) % n
    m = a[i]-a[j]
    if (m + k) % n != 0 or (m + k) // n < 0:
        print("NO")
        exit()
    l += (m + k) // n
if k == l:
    print("YES")
else:
    print("NO")

Solution (Python):


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

Solution (Python):

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

if sum(A) % (N * (N + 1) // 2) == 0:
    
    k = sum(A) // (N * (N + 1) // 2)
else:
    print("NO")
    exit()

sub = []
for i in range(N):
    sub.append(A[i] - A[i-1] - k)

flag,cnt = True,0
for i in range(N):
    
    if sub[i] <= 0 and sub[i] % N == 0:
        cnt += abs(sub[i]) // N
    else:
        flag = False

if flag and k == cnt:
    print("YES")
else:
    print("NO")

Solution (Python):

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

if sum(A) % (N * (N + 1) // 2) == 0:
    
    k = sum(A) // (N * (N + 1) // 2)
else:
    print("NO")
    exit()

sub = []
for i in range(N):
    sub.append(A[i] - A[i-1] - k)

flag = True
cnt = 0
for i in range(N):
    if sub[i] < 0 and sub[i] % N == 0:
        cnt += abs(sub[i]) // N
    elif sub[i] != 0:
        flag = False

if flag and k == cnt:
    print("YES")
else:
    print("NO")

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

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

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

Solution (Python):
def solve(n, aaa):
    added_once = n * (n + 1) // 2
    total = sum(aaa)
    d, m = divmod(total, added_once)
    if m != 0:
        return False
    cnt = 0
    for a1, a2 in zip(aaa, aaa[1:] + aaa[:1]):
        k = d - (a2 - a1)
        kd, km = divmod(k, n)
        if kd < 0 or km != 0:
            return False
        cnt += kd
    assert cnt == d
    return True


n = int(input())
aaa = list(map(int, input().split()))
print('YES' if solve(n, aaa) else 'NO')

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

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

sum_N = N * (N + 1) // 2
sum_A = sum(A)

if sum_A % sum_N != 0:
    print("NO")
    exit()
else:
    k = sum_A // sum_N

B = []
for i in range(N):
    if i + 1 != N:
        B.append(A[i + 1] - A[i] - k)
    else:
        B.append(A[0] - A[i] - k)

cnt = 0
for b in B:
    if b % N == 0 and b <= 0:
        k += b // N 
    else:
        print("NO")
        exit()

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

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
k = sum(a) // (n*(n+1)//2)
if n*(n+1)*k // 2 != sum(a):
  print('NO'); exit(0)
b = [a[i] - a[i-1] - k for i in range(n)]
for x in b:
  if x > 0 or x%n: print('NO'); break
else:
  print('YES')

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

total = sum(A)
each = N*(N+1) // 2
if total % each != 0:
    NO()
    exit()

K = total // each


B = [0] * N
for i in range(N):
    j = (i+1) % N
    B[i] = A[j] - A[i]

B = [b-K for b in B]

if all(b % N == 0 and b <= 0 for b in B):
    YES()
else:
    NO()

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
B = []
for i in range(n):
    B.append(A[i] - A[i-1])

m = max(B)
no = 0

if m < 0:
    no = 1
elif m == 0:
    if A[0] % (n*(n+1)//2) > 0:
        no = 1
else:
    c = 0
    for i in range(n):
        if (m - B[i]) % n > 0:
            no = 1
        else:
            c += (m - B[i]) // n

    if c != m:
        no = 1
    if sum(A) != m * n*(n+1)//2:
        no = 1

if no==1:
    print("NO")
else:
    print("YES")

Solution (Python):
def main():
    n=int(input())
    a=list(map(int,input().split()))
    s=sum(a)
    if s%(n*(n+1)//2) != 0:
        return "NO"
    k=s//(n*(n+1)//2)
    for i in range(n-1):
        if (a[i]-a[i+1]+k)%n!=0 or a[i+1]-a[i]>k or a[i+1]-a[i]<k*(1-n):
            return "NO"
    if (a[-1]-a[0]+k)%n!=0:
        return "NO"
    return "YES"

print(main())

Solution (Python):
"""
基本の差はable

 1  2 3  4 5
 4  5 1  2 3
+2  3 4  5 1

 7 10 8 11 9
sa3 -2 3 -2 -2

一度も選ばれてない=3
選ばれてる = -2
一回で -5・・・？
一回選ばれると本来あった +1が消えて -4される →よって-5
"""

import sys

N = int(input())

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

M = N*(N+1)//2

if sum(A) % M != 0:
    print ("NO")
    sys.exit()

able = sum(A) // M



A.append(A[0])
now = 0

for i in range(N):

    

    if A[i+1] - A[i] == able:
        continue

    else:
        
        if ((A[i+1]-A[i])-able) % N != 0 or ((A[i+1]-A[i])-able) // N > 0:
            print ("NO")
            sys.exit()

        else:
            now += ((A[i+1]-A[i])-able) // (0-N)


if now == able:
    print ("YES")
else:
    print ("NO")

Solution (Python):
def examA():
    N = I()
    A = LI()
    ans = "YES"
    cur = 0
    for a in A:
        if a%2==1:
            cur +=1
    if cur%2==1:
        ans = "NO"
    print(ans)
    return

def examB():
    N = I()
    A = LI()
    ans = "YES"
    sumA = sum(A)
    oneA = (1+N)*N//2
    if sumA%oneA!=0:
        ans = "NO"
    ope = sumA//oneA
    
    cur = 0
    for i in range(N):
        now = ope - (A[i]-A[i-1])
        if now%N!=0 or now<0:

            ans = "NO"
            break
        cur += now//N
    if cur!=ope:
        ans = "NO"
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examB()

Solution (Python):
def solve():
    N, *A = map(int, open(0).read().split())

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

    t = sum(A) // K
    cnt = 0
    for a, b in zip(A, A[1:] + [A[0]]):
        d = t + a - b
        if d % N or d < 0:
            return False
        cnt += d // N

    return (t == cnt)

if solve():
    print("YES")
else:
    print("NO")

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    nn = (n*(n+1))//2
    sum_ = sum(a)
    a += [a[0]]
    cnt = sum_//nn
    if sum_ % nn != 0:
        print("NO")
        return 0
    ans = 0
    for i in range(n):
        p = a[i]-a[i+1]+cnt
        if p % n != 0 or p//n<0:
            print("NO")
            return 0
        ans += p//n
    if ans == cnt:
        print("YES")
    else:
        print("NO")


main()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    N=n*(n+1)//2

    if(sum(A)%N):
        print("NO")
        return

    k=sum(A)//N
    for i in range(n):
        q,r=divmod(k-(A[(i+1)%n]-A[i]),n)
        if(q<0 or r):
            print("NO")
            return

    print("YES")
resolve()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    N=n*(n+1)//2

    if(sum(A)%N):
        print("NO")
        return

    k=sum(A)//N
    C=[None]*n
    for i in range(n):
        if((k-(A[(i+1)%n]-A[i]))%n):
            print("NO")
            return
        C[i]=(k-(A[(i+1)%n]-A[i]))//n

    print("YES" if(sum(C)==k and all(0<=c<=k for c in C)) else "NO")
resolve()

Solution (Python):
n,*a=map(int,open(0).read().split())
d=[j-i for i,j in zip(a,a[1:]+[a[0]])]
M=max(d)
dd=[M-x for x in d]
if n==1:
	print("YES")
elif (n==2 and sum(a)%3) or any(x%n for x in dd) or sum(x//n for x in dd)!=M or sum(a)//M!=n*(n+1)//2:
	print("NO")
else:
	print("YES")

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

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

S = sum(A)
ok = True
if S % ((N+1)*N//2) != 0:
    ok = False
else:
    K = S // ((N+1)*N//2)
    c = 0
    for i in range(N):
        a = K-A[i]+A[i-1]
        if a % N != 0:
            ok = False
            break
        x = a // N
        if 0 <= x <= K:
            c += x
        else:
            ok = False
            break
    if c != K:
        ok = False

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

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

def solve() :
    s = sum(A)
    if s % (N * (N + 1) // 2) != 0 :
        return 'NO'
        
    a = s // (N * (N + 1) // 2)
    ret = 0
    for i in range(N) :
        d = A[i] - A[i-1]
        if (a - d) % N != 0 or (a - d) < 0 :
            return 'NO'
        ret += (a - d) // N
        
    if ret == a :
        return 'YES'
    else :
        return 'NO'
        
print(solve())

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