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: Time Limit Exceeded

Solution code:
n = int(raw_input())
aa = map(int, raw_input().split())
d = []
j = 0
min_a = float('inf')

for i,a in enumerate(aa):
    if min_a > a:
        min_a = a
        next_j = i

while True:
    j = next_j
    for (i,a) in enumerate(aa):
        k = j+i
        if k >= n:
            k -= n
        aa[k] -= i+1
        
        if aa[k] < min_a:
            min_a = aa[k]
            next_j = k

    if min_a <= 0:
        break

flag = True
for a in aa:
    if a != 0:
        flag = False
        break

if flag == True:
    print 'YES'
else:
    print 'NO'

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
while True:
    i = a.index(max(a))
    for j in xrange(n + 1):
        a[(i + j) % n] -= j
    if 0 in a:
        break

if len(list(set(a))) == 1:
    print 'YES'
else:
    print 'NO'

Submission status: Time Limit Exceeded

Solution code:
import sys

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

if N == 1:
    print ('YES')
    sys.exit()

while True:
    max_index = 0
    min_index = 0
    for i in range(N):
        if A[i] > A[max_index]:
            max_index = i
        if A[i] < A[min_index]:
            min_index = i

    if A[max_index] == 0 and A[min_index] == 0:
        print('YES')
        sys.exit()

    if A[min_index] < 0:
        print('NO')
        sys.exit()

    A[max_index] -= N
    for i in range(1,N):
        A [ ( i + max_index) % N ] -= i

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
vec = list(map(int,input().split()))
s = sum(list(range(1,n+1)))
if sum(vec)%s != 0:
    print('NO')
else:
    while 1:
        maxVal = max(vec)
        maxID = vec.index(maxVal)
        for i in range(maxID+1):
            if vec[i] >= n-(maxID-i):
                vec[i] -= (n-(maxID-i))
        for j,i in enumerate(range(maxID+1,n),1):
            if vec[i] >= j:
                vec[i] -= j
        if sum(vec) == 0:
            print('YES')
            break
        elif max(vec) < n:
            print('NO')
            break

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
aa = map(int, raw_input().split())
d = {}
j = 0
min_a = float('inf')

while True:
    for i,a in enumerate(aa):
        if min_a > a:
            min_a = a
            j = i

    if min_a <= 0:
        break

    for (i,a) in enumerate(aa):
        if j + i < n:
            aa[j+i] -= i+1
        else:
            aa[j+i-n] -= i+1

flag = True
for a in aa:
    if a != 0:
        flag = False
        break

if flag == True:
    print 'YES'
else:
    print 'NO'

Submission status: Time Limit Exceeded

Solution code:
import sys

next(sys.stdin)
n = list(map(int, next(sys.stdin).split()))

while True:
    k = min(range(len(n)), key=lambda k: n[k])
    n = n[k:] + n[:k]
    for k in range(1, len(n) + 1):
        if k <= n[k - 1]:
            n[k - 1] -= k
        else:
            print('NO')
            exit()
    if sum(n) == 0:
        print('YES')
        exit()

Submission status: Time Limit Exceeded

Solution code:
n=int(raw_input())
a=map(int,raw_input().split())
mx=-1
for i in xrange(n):
    if mx<a[i]:
        mx=a[i]
        idx=i
while True:
    mx=0
    nxidx=0
    for i in xrange(idx+1,idx+n+1):
        if i<n:
            a[i]-=i-idx
            if a[i]<0:
                print("NO")
                exit()
            if mx<a[i]:
                mx=a[i]
                nxidx=i
        else:
            a[i-n]-=i-idx
            if a[i-n]<0:
                print("NO")
                exit()
            if mx<a[i-n]:
                mx=a[i-n]
                nxidx=i-n
    if mx==0:
        print("YES")
        break
    idx=nxidx

Submission status: Accepted

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

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

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

if m != 0:
  no()

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

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

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

Submission status: Accepted

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


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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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


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

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

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

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

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

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

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

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

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

Submission status: Accepted

Solution code:
import sys
# from collections import defaultdict, deque
# import math
# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

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

INF = 10 ** 20
MOD = 1000000007

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

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

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

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

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

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

Submission status: Accepted

Solution code:
import sys
import heapq

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
# debug = lambda *a, **kw: print(*a, **kw, file=sys.stderr)

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


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

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


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

Submission status: Accepted

Solution code:
n = int(input())

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


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

m = sum(a)//(n*(n+1)//2)
# print(m)
d = [a[i]-a[i-1]-m for i in range(n)]

# print(d)
for D in d:
    if D % n == 0:
        m += D//n
    if D % n != 0 or D > 0:
        print("NO")
        exit()
if m == 0:
    print("YES")
else:
    print("NO")

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

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

Submission status: Accepted

Solution code:
# B - Boxes

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

main()

Submission status: Accepted

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


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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#[1,2,...,N]の差配列は[1,1,...,-N+1]である
N=int(input())
A=list(map(int,input().split()))
oneton=(N*(N+1))//2
flag=1
allsum=sum(A)
dif=[]
for i in range(N):
    dif.append(A[(i+1)%N]-A[i%N])#1つ前の数字と比べどれだけ差があるかの配列
#print(dif)
#print(allsum,oneton)
if allsum%oneton!=0:
    flag=0
else:
    opnum=allsum//oneton        #[1~N]のsequenceを何こ使っているか
    l=[opnum]*N                 #差配列を、全て等しく1ずつ(sequence数)回増えたと考え、[(sequence数)]*Nで初期化
    #print(l)
    for i in range(N):
        if l[i]<dif[i]:         #sequence数以上の差が出るのはどう頑張っても無理
            flag=0
            break
        else:                   #l[i]>=dif[i]ということは+1の差を期待した部分がいくつか-N+1になっているということである
            diff=l[i]-dif[i]    #よって(期待しているやつ)-(現実)をして
            useminus=diff//N    #それをNで割り捨てることで、+1→-N+1にする回数を求められる
            opnum=opnum-useminus
            l[i]=l[i]-(useminus*N)
    if opnum!=0:                    #-Nの操作を仕切れてないとダメ
        flag=0
    for i in range(N):              #-Nの操作を仕切った結果ズレててもダメ
        if l[i]!=dif[i]:
            flag=0
if flag==0:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:

N=int(input())
A=list(map(int,input().split()))
oneton=(N*(N+1))//2
flag=1
allsum=sum(A)
dif=[]
for i in range(N):
    dif.append(A[(i+1)%N]-A[i%N])
#print(dif)
#print(allsum,oneton)
if allsum%oneton!=0:
    flag=0
else:
    opnum=allsum//oneton        
    l=[opnum]*N                 
    #print(l)
    for i in range(N):
        if l[i]<dif[i]:         
            flag=0
            break
        else:                   
            diff=l[i]-dif[i]    
            useminus=diff//N    
            opnum=opnum-useminus
            l[i]=l[i]-(useminus*N)
    if opnum!=0:                    
        flag=0
    for i in range(N):              
        if l[i]!=dif[i]:
            flag=0
if flag==0:
    print("NO")
else:
    print("YES")

Submission status: Accepted

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

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

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


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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

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

Submission status: Accepted

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

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()
else:
    count=s//(N*(N+1)//2)

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

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

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

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

mod = 10**9 + 7

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

#################

# 直前要素との差から，自分スタートが何回かわかる
# その和が全試行回数と一致すれば可能

N = I()
A = LI()

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

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

Submission status: Accepted

Solution code:
#modN等差数列が必要...根本的に違う
n=int(input())
a=list(map(int, input().split()))
sa= sum(a)
if sa%(n*(n+1)//2):
    print("NO")
    exit()
k=sa//(n*(n+1)//2)###+
b=[a[i]-a[i-1] -k for i in range(n)]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

if __name__ == "__main__":
    solve()

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

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

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

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

print('NO')

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')
    quit()
K = s // (n*(n+1)//2)
    
d = [a[(i+1)%n]-a[i] for i in range(n)]
cnt = 0
for x in d:
    if (K-x) % n != 0 or K-x < 0:
        print('NO')
        quit()
    cnt += (K-x) // n
print('YES' if cnt == K else 'NO')

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
#b

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

Submission status: Accepted

Solution code:
# 解説AC
N = int(input())
A = [int(i) for i in input().split()]

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

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

flag,cnt = True,0
for i in range(N):
    # 負 かつ Nの倍数
    if sub[i] <= 0 and sub[i] % N == 0:
        cnt += abs(sub[i]) // N
    else:
        flag = False

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

Submission status: Accepted

Solution code:
# 解説AC
N = int(input())
A = [int(i) for i in input().split()]

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

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

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

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

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys

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

N = INT()
A = LIST()

total = sum(A)
each = N*(N+1) // 2
if total % each != 0:
    NO()
    exit()
# 操作回数
K = total // each

# A各値の差分で数列Bを作る
B = [0] * N
for i in range(N):
    j = (i+1) % N
    B[i] = A[j] - A[i]
# ここからK引けば、1度の操作につきBのいずれかの要素を+N、とできる
B = [b-K for b in B]

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