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



Sample input:
5
4 5 1 2 3


Sample output:
YES

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
解説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')

Submission status: Accepted

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

bl = True

amount = N * (N + 1) // 2  # 一回の操作で除去される石の量
q1, r1 = divmod(sum(a), amount)  # q: 操作の回数
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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"

Submission status: Accepted

Solution code:
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

# aの合計は1~nの和の倍数
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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()
    # N = 10
    # A = [random.randint(1, 10**9) for _ in range(N)]
    # print(A)
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

Solution code:
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"

Submission status: Accepted

Solution code:
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"

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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
    # print(k, s, m)
    rs = []
    for i in range(N):
        p = A[i - 1]
        q = A[i]
        delta = q - p
        y = m - delta
        # print(p, q, delta, y, N)
        if y % N > 0:
            return False
        x = y // N
        rs.append(x)
    # print("*", rs)
    R = 0
    for i in range(N):
        x = rs[i]
        l = (N - i) % N + 1
        R += l * x
    # print(1, R)
    if R != A[0]:
        return False
    for i in range(1, N):
        R += m - rs[i]
        R -= rs[i] * (N - 1)
        # print(i, R)
        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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
import numpy as np
# import scipy

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

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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

# B = []
C = []
for i in range(N):
    # B.append(A[i] - A[i-1] - K)
    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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
'''
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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")

Submission status: Accepted

Solution code:
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'

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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"

Submission status: Accepted

Solution code:
from operator import sub

N = int(input())
data = list(map(int, input().split()))
step = N * (N+1) // 2
total = sum(data)
#print("-->", total, step)
if total % step:
  print("NO")
else:
  K = total // step
  #print("-->", total, step, K)
  datar = [data[i % N] for i in range(-1, N)] 
  delta = list(map(sub, datar[1:], datar))
  #print(*delta)
  #print("-->", *list(map(lambda x:(K-x) % N, delta)))
  #print("-->", *list(map(lambda x:(K-x) // N, delta)))
  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")

Submission status: Accepted

Solution code:
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"