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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
基本の差は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

#print (M,able)

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

for i in range(N):

    #print ((A[i+1]-A[i]-able)//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")

Submission status: Accepted

Solution code:
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
    #各Aについて何回始点としたか二分探索
    cur = 0
    for i in range(N):
        now = ope - (A[i]-A[i-1])
        if now%N!=0 or now<0:
#            print(now,i)
            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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#初期化
N = int(input())
A = getlist()
S = sum(A)
if S % (N * (N + 1) // 2) != 0:
	print("NO")
#計算
else:
	judge = "YES"
	n = S // (N * (N + 1) // 2)
	for i in range(N):
		val = A[(i + 1) % N] - A[i]
		if val < n * (1 - N) or val > n or (val - n) % N != 0:
			judge = "NO"

	print(judge)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

else:
    change = N * (N + 1) // 2 #一回の操作で全体から減る分


    if s % change != 0: #何回か行って0になるわけだから 総数をchangeで割り切れなきゃ不可能
        print("NO")
        exit()

    change_kaisu = s // change #回数 = 総数/一回の減少分

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os
import sys

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

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

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


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

    S = sum(A)
    if S % ((N + 1) * N // 2) != 0:
        return False
    # 箱を選ぶ回数
    K = S // ((N + 1) * N // 2)

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


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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

sys.setrecursionlimit(1000000)
mod = 1000000007

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

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

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()

Submission status: Accepted

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

Submission status: Accepted

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

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

    S = sum(A)

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

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

    print('YES')


sol()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

import numpy as np

# Aへの加算は、imos法でまとめて行える。
# +[1,2,3,4,5]
# 階差：[-4,1,1,1,1]
# 総回数と最終的な階差から、回数分布がわかる

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

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

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

# 操作の起点となる回数
op = (total_op - diff)//N

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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


if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

v_valid = n_operate
v_sign = n

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

Submission status: Accepted

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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print("YES")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#n,a,b,c,d=map(int,input().split())
n=int(input())
a=[int(i) for i in input().split()]
ans=True
c=[]

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

s = sum(a)

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

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

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

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

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

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

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

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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

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

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

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


print(solve())

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 入力
N = int(input())
A = list(map(int, input().split()))

S = sum(A)

# A_{i + 1} - A_i から解を求める
ans = (
    'YES' if (2 * S) % (N * (N + 1)) == 0 and all(
        k % N == 0 and k >= 0
        for k in (
            (2 * S) // (N * (N + 1)) - (A[i] - A[i - 1])
            for i in range(N)
        )
    ) else
    'NO'
)

# 出力
print(ans)

Submission status: Accepted

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

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


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

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

print('YES')

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def io_generator():
	return input()

#+++++++++++++++++++

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

#++++++++++++++++++++

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

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

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


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

    # 1. Aの総和から操作の回数が分かる
    k, mod = divmod(sum(A), (n * (n + 1) // 2))
    if mod:
        return 'NO'

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

    # 2. 逆に石を配る操作を考える
    # 一回の操作で1つのdkは-(n - 1), それ以外は+1される

    # 3. {di - k}は負かつnの倍数になっている必要がある
    return 'YES' if not any([(d - k) % n or d > k for d in diff]) else 'NO'


print(main())

Submission status: Accepted

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

Submission status: Accepted

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


# 毎回1+2+...+N個の石が取り除かれる
Sum = sum(A)
if Sum % (N * (N + 1) // 2) != 0:
    print('NO')
    exit()


# 操作回数
K = Sum // (N * (N + 1) // 2)

Diff = [A[i] - A[(i - 1)] for i in range(N)]
# 変化量-1が(N-1)箇所、+(N-1)が一か所を、すべて-1した後に、一か所+1と置き換える
Diff = [d - K for d in Diff]

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

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

Submission status: Accepted

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

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

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

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

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

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

Submission status: Accepted

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

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

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

ok = True

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