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

sumA = sum(As)
num = N * (N + 1) // 2
if sumA % num:
    print('NO')
else:
    M = sumA // num
    sumK = 0
    for i in range(N):
        k = (M - (As[i] - As[i - 1])) / N
        if k < 0:
            print('NO')
            break
        sumK += k
    else:
        if sumK == M:
            print('YES')
        else:
            print('NO')

Solution (Python):
import sys
n=input()
a=map(int, raw_input().split())
diff=[a[(i+1)%n]-a[i] for i in range(n)]
cnt=max(diff)
diff=[value-cnt for value in diff]
start=[]
for value in diff:
	if value%n:
		print "NO"
		exit()
	else:
		start.append(-value/n)
cnt=sum(start)
b=[0]
for i in range(n):
	b[0]+=start[i]*(n-i)
for i in range(n):
	b.append(b[-1]+cnt-start[i]*n)
assert b[0]==b[-1]
b=b[:-1]
for i in range(n):
	if (a[i]-b[i])%(n*(n+1)/2) or a[i]<b[i]:
		print "NO"
		exit()
print "YES"

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())

exist = True


if sum(a) % (n*(n+1)//2) != 0:
    exist = False

if exist:
    
    com = sum(a) // (n*(n+1)//2)
    
    
    diff = [a[i] - a[i-1] for i in range(n)]
    ed = []
    for diffi in diff:
        if (com-diffi) % n != 0:
            exist = False
            break
        else:
            ed.append((com-diffi) // n)
    
    if exist:
        if sum(ed) != com or any([edi < 0 for edi in ed]):
            exist = False
        
if exist:
    print("YES")
else:
    print("NO")

Solution (Python):
n=int(input())
lis=list(map(int,input().split()))
num=(n*(n+1))//2
ll=sum(lis)
if ll%num!=0:
  print("NO")
  exit()
ans=0
for i in range(n):
  if abs(lis[i]-lis[i-1]-ll//num)%n!=0:
    print("NO")
    exit()
  ans+=abs(lis[i]-lis[i-1]-ll//num)//n
if ans == ll//num:print("YES")
else:print("NO")

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

if n == 1:
    print('YES')
    exit()

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

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

temp = k - a[0] + a[n - 1]
if temp % n != 0 or temp < 0:
    print('NO')
    exit()

d = temp // n
for i in range(1, n):
    temp = k - a[i] + a[i - 1]
    if temp % n != 0 or temp < 0:
        print('NO')
        exit()
    d += temp // n

print('YES')

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
k = sum(A) / (n * (n + 1) // 2)
d = [a2 - a1 - k for a1, a2 in zip(A, A[1:] + A[0:1])]
for di in d:
    if di > 0 or di % n:
        print('NO')
        break
else:
    print('YES')

Solution (Python):
import sys
ai = lambda: list(map(int, input().split()))

n = int(input())
a = ai()
d = [a[i]-a[i-1] for i in range(n)]

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

s //= n*(n+1)//2
d = [i-s for i in d]

if all(i % n == 0 for i in d) and sum(-i//n for i in d if i < 0) == s:
    print('YES')
else:
    print('NO')

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

Solution (Python):
n=int(input())
*l,=map(int,input().split())
m=[0]*n
a=n*(n+1)//2
b=sum(l)

if b%a:
  print("NO")
else:
  k=b//a
  m=[l[(i+1)%n]-l[i]-k for i in range(n)]
  for i in range(n):
    if m[i]>0 or m[i]%n!=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) != 0:
	print("NO")
else:
	k = sum(a) // (n * (n + 1) // 2)
	ok = True
	for i in range(n - 1):
		if (a[i] + k) % n != a[i + 1] % n or a[i] + k < a[i + 1]:
			ok = False
			break
	if (a[-1] + k) % n != a[0] % n or a[-1] + k < a[0]:
		ok = False

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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    sa = sum(A)
    M = N*(N+1)//2
    if sa % M != 0:
        return 'NO'

    k = sa // M

    kk = k
    for i in range(N):
        b = A[(i+1) % N] - A[i]
        b -= k
        if b > 0:
            error_print('a')
            return 'NO'
        if b % N != 0:
            error_print('b')
            return 'NO'
        kk += b // N

    if kk != 0:
        error_print('c')
        return 'NO'

    return 'YES'


def main():
    N = read_int()
    A = read_int_n()
    
    
    
    print(slv(N, A))


if __name__ == '__main__':
    main()

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    sa = sum(A)
    M = N*(N+1)//2
    if sa % M != 0:
        return 'NO'

    k = sa // M

    kk = k
    for i in range(N):
        b = A[(i+1) % N] - A[i]
        b -= k
        if b > 0:
            error_print('a')
            return 'NO'
        if b % N != 0:
            error_print('b')
            return 'NO'
        kk += b // N

    if kk != 0:
        error_print('c')
        return 'NO'

    return 'YES'


def main():
    N = read_int()
    A = read_int_n()
    
    
    
    print(slv(N, A))


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
MIN,MAX = min(aa),max(aa)
SUM = sum(aa)
S = N*(N+1)//2

def main():
	if SUM%S != 0:
		return 'NO'
	else:
		k = SUM // S
		if MIN < k or k*N < MAX:
			return 'NO'
		tmp = 0
		for i in range(N):
			d = aa[i-1] - aa[i]
			d += k
			if d % N == 0:
				tmp += d//N
			else:
				return 'NO'
		if tmp == k:
			return 'YES'
		else:
			return 'NO'

print(main())

Solution (Python):
import sys

n = input()
v = map(int, raw_input().split(' '))
startHere = [0 for i in range(n)]

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

operations = sum(v) / ((n * (n + 1)) / 2)
operationsFound = 0

for i in range(n):
	diff = v[(i + 1) % n] - v[i]

	if (operations - diff) % n != 0 or operations - diff < 0:
		print "NO"
		sys.exit()
	else:
		operationsFound += (operations - diff) / n

if operationsFound == operations:
	print "YES"
else:
	print "NO"

Solution (Python):
import sys

n = input()
v = map(int, raw_input().split(' '))
startHere = [0 for i in range(n)]

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

operations = sum(v) / ((n * (n + 1)) / 2)

for i in range(n):
	diff = v[(i + 1) % n] - v[i]

	startHere[i] = (operations - diff) / n

contribution = 0
gathered = 0

for i in range(n):
	v[i] -= contribution
	gathered += startHere[i % n]
	contribution += gathered

for i in range(n):
	v[i] -= contribution
	gathered -= startHere[i % n]
	contribution -= startHere[i % n] * n
	contribution += gathered

if min(startHere) >= 0 and sum(startHere) == operations and min(v) == 0 and max(v) == 0:
	print "YES"
else:
	print "NO"

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

def solve(li,n):
  cnt=sum(li)
  s=((n+1)*n)//2
  if cnt % s !=0:
    print("NO")
    return
  
  cnt//=s
  
  ch=[cnt for x in range(n)]
  res=[]
  for i in range(n-1):
    res.append(li[i+1]-li[i])
  res.append(li[0]-li[-1])
  
  for i in range(n):
    if ch[i] != res[i]:
      if abs(ch[i]-res[i]) % n !=0:
        print("NO")
        return
      else:
        cnt-=abs(ch[i]-res[i])//n
  if cnt==0:
    print("YES")
    return
  else:
    print("NO")
    return

solve(A,N)

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

def solve(N, A):
    k = N * (N + 1) // 2
    s = sum(A)
    if s % k > 0:
        return False
    m = s // k
    
    rs = []
    for i in range(N):
        p = A[i - 1]
        q = A[i]
        delta = q - p
        y = m - delta
        
        if y % N > 0:
            return False
        x = y // N
        rs.append(x)
    
    R = 0
    for i in range(N):
        x = rs[i]
        l = (N - i) % N + 1
        R += l * x
    
    if R != A[0]:
        return False
    for i in range(1, N):
        R += m - rs[i]
        R -= rs[i] * (N - 1)
        
        if R != A[i]:
            return False
    return True

def solve(N, A):
    k = N * (N + 1) // 2
    s = sum(A)
    if s % k > 0:
        return False
    m = s // k
    for i in range(N):
        x = A[i - 1] - A[i] + m
        if x < 0 or (x % N) > 0:
            return False
    return True

if solve(N, A):
    print("YES")
else:
    print("NO")

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

Solution (Python):


import sys, math, copy

import numpy as np


HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    an = list(map(int, input().split()))
    assert len(an) == n
    d = np.sum(an)
    if d % (n * (n + 1) // 2) > 0:
        return False
    k = d // (n * (n + 1) // 2)

    diffs = np.roll(np.array(an), -1) - np.array(an)
    diffs -= k
    if np.all(diffs <= 0) and np.all(diffs % n == 0):
        return True
    else:
        return False

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

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

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

A_sum = sum(A)

if A_sum % S != 0:
	print("NO")
	exit(0)
T = A_sum // S

diff = [A[(i+1)%N] - A[i%N] for i in range(N)]
zure = 0
for i in range(N):
	d = diff[i]
	if T - d >= 0 and (T - d) % N == 0:
		zure += (T - d) // N

if zure == T:
	print("YES")
else:
	print("NO")

Solution (Python):

import sys

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

S = N*(N+1) // 2
SA = sum(A)

if SA % S != 0:
    print("NO")
    sys.exit(0)

K = SA // S


C = []
for i in range(N):
    
    b = A[i] - A[i-1] - K
    if (b > 0) or (-b % N != 0):
        print("NO")
        sys.exit(0)
    C.append(-b//N)

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")
else:
	x,flag,num = sum(a)//(n*(n+1)//2),True,0
	for i in range(n):
		if (a[i]-a[i-1]-x)%n!=0:
			flag = False
			break
		else: num+=abs((a[i]-a[i-1]-x)//n)
	if flag and num==x: print("YES")
	else: print("NO")

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

K = sum(A) / sum(range(1, N+1))
D = [A[i+1] - A[i] - K for i in range(-1, N-1)]
for d in D:
    if not (d <= 0 and d % N == 0):
        print("NO")
        break
else:
    print("YES")

Solution (Python):
N = int(input())
*A, = map(int, input().split())
C = sum(A)
if C % (N*(N+1)//2) == 0:
    k = C // (N*(N+1) // 2)
    B = [A[i-1] - A[i] + k for i in range(N)]
    ok = 1
    for b in B:
        if b < 0 or b % N > 0:
            ok = 0
            break
    if ok:
        print('YES')
        exit(0)
print('NO')

Solution (Python):
N = int(input())
src = list(map(int,input().split()))
S = sum(src)
M = N*(N+1)//2

if S%M:
    print('NO')
    exit()

K = S//M
mem = [src[i+1] - src[i] - K for i in range(N-1)]
mem.append(src[0] - src[N-1] - K)

print('YES' if all(map(lambda x:x<=0 and x%N==0, mem)) else 'NO')

Solution (Python):

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

    one = n*(n+1)/2

    if sum(a) % one != 0:
        print("NO")
        return
    else:
        nop = sum(a) / one

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

    count = 0

    for i in range(n):
        if d[i] != 0:
            if d[i] % n != 0 or d[i] > 0:
                print("NO")
                return
            count = count + (-1*d[i]) / n
            d[i] = 0
            if count > nop:
                print("NO")
                return

    if sum(d) == 0 and count == nop:
        print("YES")
    else:
        print("NO")

solve()

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

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


d=[A[i+1]-A[i]-k for i in range(N-1)]
d.append(A[0]-A[N-1]-k)
for i in range(N):
        if d[i]>0 or d[i]%N!=0:
                ans=False
if ans:
        print("YES")
else:
        print("NO")

Solution (Python):


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

k = sum(A) / sum(range(1, N + 1))
D = [(A[(i + 1) % N] - A[i]) - k for i in range(N)]

cnt = sum(list(filter(lambda x: x < 0 and x % N == 0, D)))
print('YES' if (cnt == -k * N) else 'NO')

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


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


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
N=int(input())
A=list(map(int,input().split()))
total=0
for i in range(N):
  total+=A[i]
if total*2/((N+1)*N)%1!=0:
  print("NO")
  sys.exit()
times=int(total*2/((N+1)*N))
if (times-A[0]+A[N-1])/N%1!=0 or times-A[0]+A[N-1]<0:
  print("NO")
  sys.exit()
B=(times-A[0]+A[N-1])/N
for i in range(N-1):
  B+=(times-A[i+1]+A[i])/N
  if (times-A[i+1]+A[i])/N%1!=0 or times-A[i+1]+A[i]<0:
    print("NO")
    sys.exit()
if B==times:
  print("YES")
else:
  print("NO")

Solution (Python):
import sys

n = int(input())
a = [int(x) for x in input().strip().split()]

total = sum(a)
nn = n * (n + 1) / 2
if total % nn != 0 :
  print('NO')
else:
  m = total / nn
  l = 0
  flg = True
  for i in range(n):
    j = i - 1
    if i == 0:
      j = n - 1
    if a[j] + m - a[i] < 0 or (a[j] + m - a[i]) % n != 0:
      flg = False
      break
    l += (a[j] + m - a[i]) / n

  if flg == True:
    print('YES')
  else:
    print('NO')

Solution (Python):
'''
B - Boxes
時間制限 : 2sec / メモリ制限 : 256MB

配点 : 500 点

問題文
http://agc010.contest.atcoder.jp/tasks/agc010_b
問題文
N 個の箱が円環状に並んでおり、i 番目の箱には Ai 個の石が入っています。

以下の操作を繰り返して、全ての石を取り除くことができるか判定してください。

箱を一か所選ぶ。それを i 番目としたとき、1 から N の各 j に対して、i+j 番目の箱から石をちょうど j 個取り除く。
ただし、N+k 番目と表される箱は k 番目の箱と同一視するものとする。
各操作において、取り除きたい個数の石がない箱があるときは、その操作を行えないことに注意してください。

制約
1≦N≦105
1≦Ai≦109
'''
import numpy as np
import sys
import time

def gel(N,s):
	a=np.arange(1,N+1)
	return a[[(i-s) % N for i in range(N)]]

def dx(arr):
	n=arr.size
	b=[(s+1)%n for s in range(n)]
	return arr[b]-arr
	
N=int(input())
b=np.fromstring(input(),dtype=int,sep=' ')

U=int((N+1)*N/2)
m=b.sum()//U
r=b.sum()%U

if r!=0 or b.min()<m:
	print('NO')
else:
	k=(dx(b)-m)%N
	if k.min()==0 and k.max()==0:
		print('YES')
	else:
		print('NO')

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

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

print("YES")

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
if sum(A) % (N * (N + 1) // 2) != 0:
    print("NO")
    quit()
res = sum(A) // (N * (N + 1) // 2)
cnt = 0
for i in range(N):
    d = A[i] - A[(i+1)%N]
    if d + res < 0 or (d + res) % N != 0:
        print("NO")
        quit()
    cnt += (d + res) // N
print("YES" if cnt == res else "NO")

Solution (Python):



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

def solve(A):
    n = sum(A) // (N*(N+1)//2)
    if sum(A) % (N*(N+1)//2) != 0:
        return 'NO'

    count = 0

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

        if diff == n:
            continue

        if -1 * (diff - n) % N != 0:
            return 'NO'
        c = -(diff-n)//N
        if c < 0:
            return 'NO'

        count += c

    if count == n:
        return 'YES'
    return 'NO'

print(solve(A))

Solution (Python):
n = int(input())
a = list(map(int, list(input().split(" "))))
dif = [0] * n
itr = sum(a)/sum(list(range(n+1)))

if itr != int(itr):
	print("NO")
	exit()
 
count = 0
for i in range(n-1):
	dif[i] = a[i+1]-a[i]
	temp = (itr - dif[i])/n
	if temp < 0 or temp != int(temp):
		print("NO")
		exit()
	count += temp

if count > itr:
	print("NO")
	exit()

print("YES")

Solution (Python):

N = int(input())
A = [int(n) for n in input().split()]
stones = sum(A)
step = stones / int(N*(1+N)/2)

if step % 1 != 0:
    print("NO")
else:
    D = [(A[(n+1)%N] - A[n%N]) - step for n in range(N)]
    if all(d%N == 0 and d <= 0 for d in D):
        print("YES") 
    else:
        print("NO")

Solution (Python):
N = int(raw_input())
a = map(int, raw_input().strip().split())

identity = sum(xrange(1, N+1))
sum_a = sum(a)
if sum_a % identity:
    print 'NO'
else:
    lv = sum_a / identity
    if a[0]-a[-1] > lv:
        print "NO"
    else:
        for i in xrange(len(a)-1):
            d = a[i+1]-a[i]
            if d > lv or (d-lv) % N:
                print 'NO'
                break
        else:
            print 'YES'

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

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


def solve():
    n = (N + 1) * N // 2
    if S % n != 0:
        return False
    c = S // n
    cc = 0
    for i in range(N):
        j = (i + 1) % N
        delta = A[j] - A[i]
        if (c - delta) % N != 0:
            return False
        ci = (c - delta) // N
        if ci < 0:
            return False
        cc += ci
    assert(c == cc)


    return True

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

Solution (Python):
n = int(raw_input())
arr = map(int, raw_input().split())

tri = n * (n + 1) / 2
s = sum(arr)

if s % tri != 0:
    print "NO"
else:
    num = s / tri
    diff = map(lambda i: arr[(i + 1) % n] - arr[i], range(n))
    diff = map(lambda x: x - num, diff)
    poss = all(map(lambda x: x <= 0 and x % n == 0, diff))
    poss = poss and sum(diff) == -n * num
    print "YES" if poss else "NO"

Solution (Python):
from operator import sub

N = int(input())
data = list(map(int, input().split()))
step = N * (N+1) // 2
total = sum(data)

if total % step:
  print("NO")
else:
  K = total // step
  
  datar = [data[i % N] for i in range(-1, N)] 
  delta = list(map(sub, datar[1:], datar))
  
  
  
  if any(map(lambda x:(K-x) % N, delta)):
    print("NO")
  elif any(map(lambda x: K-x < 0, delta)): 
    print("NO")
  else:    
    ops = list(map(lambda x:(K-x) // N, delta))
    if sum(ops) == K:
      for i, v in enumerate(data[0:1]):
        vv = sum([ops[(i-k) % N] * (k+1) for k in range(N)])
        if v != vv:        
          print("NO")
          break
      else:    
        print("YES")
    else:
      print("NO")

Solution (Python):
def s(n,a):
    N=n*(n+1)/2
    sa=sum(a)
    if sa%N!=0:
        return False
    if sa<N:
        return False
    sn=sa/N
    da=[]
    for i in xrange(n-1):
        da.append(a[i+1]-a[i])
    da.append(a[0]-a[n-1])
    if max(da)>sn:
        return False
    if sum(da)!=0:
        return False
    for di in da:
        if (sn-di)%n!=0:
            return False
    return True
    
n = int(raw_input())
a = [int(i) for i in raw_input().split(" ")]
if s(n,a):
    print "YES"
else:
    print "NO"

Solution (Python):
def solve(ar):
  n = len(ar)
  if sum(ar) % (n * (n+1) // 2) != 0:
    return False
  l = sum(ar) // (n * (n+1) // 2)
  ar2 = []
  for i in range(n-1):
    if i == 0:
      ar2.append(ar[0])
    else:
      ar2.append(ar[i] - ar[i-1] - l)

  b = [0]
  for i in range(1, n-1):
    if ar2[i] % n != 0:
      return False
    bi = - ar2[i] // n
    if bi < 0:
      return False
    b.append(bi)

  a = ar[0]
  a2 = l
  for i in range(1, n-1):
    a -= b[i] * (n-i+1)
    a2 -= b[i]

  bn = a - a2
  b0 = a2 - bn
  if bn < 0 or b0 < 0:
    return False

  return True

n = int(input())
ar = [int(x) for x in input().split()]
if solve(ar):
  print("YES")
else:
  print("NO")

Solution (Python):
def main():
    N = int(input())
    A = [int(a) for a in input().rstrip().split()]
    sum_A = sum(A)
    sum_N = (N + 1) * N // 2
    if sum_A % sum_N:
        print('NO')
        return

    ope_num = sum_A // sum_N
    diffs = [r - l - ope_num for l, r in zip(A[:-1], A[1:])] + [A[0] - A[-1] - ope_num]
    if all([d % N == 0 and d <= 0 for d in diffs]):
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()

Solution (Python):
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    K, r = divmod(sum(A), N * (N+1) // 2)

    if r != 0:
        print('NO')
        return None

    dif = [A[(i + 1) % N] - A[i] for i in range(N)]

    for i in range(N):
        if dif[i] > K or (K - dif[i]) % N != 0:
            print('NO')
            return None

    print('YES')


if __name__ == '__main__':
    solve()

Solution (Python):
import numpy as np
import sys

n = int(next(sys.stdin))
a = np.array(list(map(int, next(sys.stdin).split())))
j = np.arange(n) + 1

if np.any(a.sum() % j.sum() > 0):
    print('NO')
    exit()

s = a.sum() // j.sum()
k = s - (a[1:] - a[:-1])
if np.all(k >= 0) and np.all(k % n == 0):
    print('YES')
else:
    print('NO')

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

tn = N*(N+1)//2
ta = sum(A)


if ta % tn != 0:
  print('NO')
  exit()

num = ta // tn

count = 0
seq = [0]*N

for i in range(N):
  a = A[i-1]
  b = A[i]

  c = b-a - num
  if c % N != 0 or c > 0:
    print('NO')
    exit()
  else:
    t = -c//N
    seq[i] = t
    count += t

if count != num:
  print('NO')
else:
  print('YES')

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

s = sum(aa)
remove = (n+1) * n // 2
if s % remove != 0:
    print('NO')
else:
    k = s // remove
    diffs = [aa[i+1] - aa[i] for i in range(n-1)] + [aa[0] - aa[-1]]
    diffs = [d - k for d in diffs]
    if all(d <= 0 and d % n == 0 for d in diffs):
        print('YES')
    else:
        print('NO')

Solution (Python):



def readln(ch):
    _res = list(map(int,str(input()).split(ch)))
    return _res

def pend(x,f,n):
    b = [0 for i in range(0,n+1)]
    for i in range(1,n+1):
        tmp =  f[i] - f[i-1]
        if tmp % n != 0:
            return 'NO'
        b[i] = -(tmp // n)
    b[0] = 0
    k = 0
    l = 0
    for i in range(0,n):
        b[i] = b[i-1] + b[i]
        k = k + n - i
        l = l + (n - i) * b[i]
    x = x - l
    if x < 0 : return 'NO'
    if x % k > 0: return 'NO'
    a[0] = x // k
    for i in range(1,n):
        a[i] = a[0] + b[i]
    for i in range(0,n):
        if(a[i] < 0):
            return 'NO'
    return 'YES'

n = int(input())
a = readln(' ')
f = [0 for i in range(0,n)]
f[0] = a[0]-a[n-1]
for i in range(1,n):
    f[i] = a[i] - a[i-1]

f.append(f[0])
print(pend(a[n-1],f,n))

Solution (Python):
def main():
    n = int(raw_input())
    a = map(int, raw_input().split())
    s = sum(a)
    t = n * (n + 1) / 2
    if s % t:
        print "NO"
        return
    t = s / t
    a += [a[0]]
    b = [a[i+1] - a[i] - t for i in xrange(n)]
    c = [0] * (n + n)
    d = [0] * (n + n)
    for i, x in enumerate(b):
        if x % n:
            print "NO"
            return
        b[i] = -x / n
        c[i+n] += b[i]
    b += [0] * n
    k = 0
    s = 0
    for i in xrange(n + n):
        k += b[i]
        d[i] += s if s > 0 else 0
        s += k
        k -= c[i]
        s -= c[i] * (n + 1)
    for i in xrange(n):
        if a[i] != d[i] + d[i+n]:
            print "NO"
            return
    print "YES"
main()

Solution (Python):
n = int(raw_input())
a = [int(x) for x in raw_input().split()]

def m():
	s = n * (n + 1) / 2
	sa = sum(a)
	if sa % s != 0:
		return False
	j = sa / s
	sj = 0
	for x, y in zip(a, a[1:] + [a[0]]):
		iN = j - (y - x)
		if iN % n != 0 or iN < 0:
			return False
		i = iN / n
		sj += i
	if sj != j:
		return False
	return True

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
    n = II()
    a = LI()
    nn = n*(n+1)//2
    s = sum(a)
    if s%nn != 0:
        return "NO"
    k = s//nn
    km = k%n
    c = 0
    for i in range(n):
        t = a[i]-a[i-1]
        if t % n != km:
            return "NO"
        if t > k:
            return "NO"
        kt = k-t
        if kt%n != 0:
            return "NO"
        c += kt//n
    if c == k:
        return "YES"
    return 'NO'


print(main())

Solution (Python):
N = input()
A = map(int, raw_input().split())
S = sum(A)
if S%(N*(N+1)/2)==0:
    c = S/(N*(N+1)/2)
    for i in range(N):
        A[i] -= c*(i+1)
    ans = "YES"
    for i in range(N-1):
        t = A[i]-A[(i+1)%N]
        if t<0 or t%N!=0:
            ans = "NO"
    print ans
else:
    print "NO"