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: Wrong Answer

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
        
        end += (kire-dif) // n
        
    if end != kire:
        ok = False
        
print("YES") if ok else print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
alist = list(map(int, input().split()))
sumn = sum(range(1, n+1))

if sum(alist) % sum(range(1, n+1)) != 0:
  print('NO')
else:
  if len(set(alist)) == n or (alist[0]%sumn==0 and len(set(alist)) == 1):
    print('YES')
  else:
    print('NO')

Submission status: Wrong Answer

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[-1]-A[0]
for a,b in zip(A,A[1:]):
    if (a-b)%N != d%N:
        print('NO')
        exit()

print('YES')

Submission status: Wrong Answer

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:
    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:
            ok = False
            break
        
        end += (kire-dif) // n
        
    if end != kire:
        ok = False
        
print("YES") if ok else print("NO")

Submission status: Wrong Answer

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 and abs(d[i]) % N != 0:
        print("NO")
        exit()
print("YES")

Submission status: Wrong Answer

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 abs(d[i]) % N != 0:
        print("NO")
        exit()
print("YES")

Submission status: Wrong Answer

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] % N != 0:
        print("NO")
        exit()
print("YES")

Submission status: Wrong Answer

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:
        print("NO")
        exit()
    else:
        m.append(mi)

if sum(m) == k:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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)
m = []
for i in range(n):
    mi = (k - p[i]) / n
    if int(mi) != mi:
        print("NO")
        exit()
    else:
        m.append(mi)

if sum(m) == k:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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)
m = []
for i in range(n):
    mi = (k - p[i]) // n
    if int(mi) != mi:
        print("NO")
        exit()
    else:
        m.append(mi)

if sum(m) == k:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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:
            print("NO")
            break
        else:
            sumcheck += (TotalOperation - A[i+1] + A[i]) // N
    else:
        if (TotalOperation - A[0] + A[-1]) % N != 0: print("NO")
        else: 
            sumcheck += (TotalOperation - A[0] + A[-1]) // N
            if sumcheck == TotalOperation: print("YES")
            else: print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
Diff = [None for i in range(N)]
Diff[-1] = A[0] - A[-1]
for i in range(N-1):
    Diff[i] = A[i+1]- A[i]
 
if sum(Diff) != 0: print("NO")
else:
    if A == [A[0] for i in range(N)]:
        Nsum = N * (N+1) // 2
        if A[0] % Nsum == 0: print("YES")
        else: print("NO")
    else:
        for i in range(N-1):
            if (Diff[i+1] - Diff[i]) % N != 0:
                print("NO")
                break
        else: print("YES")

Submission status: Wrong Answer

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

TotalOperation = 0
for i in range(N-1):
    TotalOperation += A[i+1]- A[i]
if TotalOperation >= 0: print("NO")
else: print("YES")

Submission status: Wrong Answer

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:
        print("NO")
        exit()
    cnt += sa//n

if cnt != trial:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

total = sum(a)
trial = total*2//n//(n+1)

cnt=0
for i in range(n):
    sa = a[i-1] + trial - a[i]
    if sa == 0:
        continue
    if sa % n != 0:
        print("NO")
        exit()
    cnt += sa//n

if cnt != trial:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if n==1:
    print("YES")

total = sum(a)
trial = total*2//n//(n+1)

cnt=0
for i in range(n):
    sa = a[i-1] + trial - a[i]
    if sa == 0:
        continue
    if sa % n is not 0:
        print("NO")
        exit()
    cnt += sa//n
if cnt is not trial:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

total = sum(a)
trial = total*2//n//(n+1)

cnt=0
for i in range(n):
    sa = a[i-1] + trial - a[i]
    if sa == 0:
        continue
    if sa % n is not 0:
        print("NO")
        exit()
    cnt += sa//n
if cnt is not trial:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
a=i2()
k=sum(a)/((n+1)*n//2)
a.append(a[0])
b=[]
for i in range(n):
 b.append(a[i+1]-a[i])
c=max(b)
s="YES"
d=0
for i in b:
 if c-i!=0:
   if (c-i)%n!=0:
     s="NO"
   else:
     d+=(c-i)//n
if d!=k or c!=k or k!=int(k):
    s="NO"
print(s)

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
a=i2()
k=sum(a)//((n+1)*n//2)
a.append(a[0])
b=[]
for i in range(n):
 b.append(a[i+1]-a[i])
c=max(b)
s="YES"
d=0
for i in b:
 if c-i!=0:
   if (c-i)%n!=0:
     s="NO"
   else:
     d+=(c-i)//n
if d!=k or c!=k:
    s="NO"
print(s)

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
a=i2()
a.append(a[0])
b=[]
for i in range(n):
 b.append(a[i+1]-a[i])
c=max(b)
s="YES"
for i in b:
 if c-i!=0 and (c-i)%n!=0:
   s="NO"
print(s)

Submission status: Wrong Answer

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) % N != 0:
            print('NO')
            sys.exit(0)
    print('YES')

Submission status: Wrong Answer

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

while min(a)> 0:
    i = a.index(max(a))
    for j in range(n):
        a[i-j] -= 5-j
if set(a) == {0}:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
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()
D=[]
a.append(a[0])
for i in range(N):
  D.append(a[i+1]-a[i]-k)
for d in D:
  if d%N!=0:
    print("NO")
    exit()
print("YES")

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
k=sum(a)//(N*(N+1)//2)
D=[]
a.append(a[0])
for i in range(N):
  D.append(a[i+1]-a[i]-k)

for d in D:
  if d%N!=0:
    print("NO")
    exit()
print("YES")

Submission status: Wrong Answer

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()
    cnt += (times-dif) // n
if times != cnt:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

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])
ope = 0
for a,b in zip(A,A[1:]):
    if (b-a)%N != k or b-a > k:
        print('NO')
        exit()
    ope += (a-b+k)//N

print('YES' if k==ope else 'NO')

Submission status: Wrong Answer

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)%N != k or b-a > k:
        print('NO')
        exit()

print('YES')

Submission status: Wrong Answer

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)%N != k and (b-a) <= k:
        print('NO')
        exit()

print('YES')

Submission status: Wrong Answer

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)%N != k:
        print('NO')
        exit()

print('YES')

Submission status: Wrong Answer

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:
            print('NO')
            break
            
    if res == c:
        print('YES')
    else:

        print('NO')

Submission status: Wrong Answer

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:
            print('NO')
            break
            
    if res == c:
        print('Yes')
    else:

        print('NO')

Submission status: Wrong Answer

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(1,n):
        if (-b[i]) % n == 0 and b[i] <= 0:
            res += (-b[i])//n
        else:
            print('NO')
            break
            
    if res == c:
        print('Yes')
    else:

        print('NO')

Submission status: Wrong Answer

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(1,n):
        if (-b[i]) % 5 == 0 and b[i] <= 0:
            res += (-b[i])//5
        else:
            print('NO')
            break
            
    if res == c:
        print('Yes')
    else:

        print('NO')

Submission status: Wrong Answer

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
    flag -= i//N
else:
    if flag == k:
        ans = 'YES'
print(ans)

Submission status: Wrong Answer

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):
		print "NO"
		exit()
print "YES"

Submission status: Wrong Answer

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)
print>>sys.stderr, cnt
diff=[value-cnt for value in diff]
print>>sys.stderr, diff
start=[]
for value in diff:
	if value%n:
		print>>sys.stderr, "value%n"
		print "NO"
		exit()
	else:
		start.append(-value/n)
cnt=sum(start)
print>>sys.stderr, cnt
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)
print>>sys.stderr, b
assert b[0]==b[-1]
b=b[:-1]
for i in range(n):
	if a[i]<b[i]:
		print>>sys.stderr, "a[i]<b[i]"
		print "NO"
		exit()
	if (a[i]-b[i])%n:
		print>>sys.stderr, "(a[i]-b[i])%n"
		print "NO"
		exit()
print "YES"

Submission status: Wrong Answer

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:
            exist = False
        
if exist:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
lis=list(map(int,input().split()))
num=(n*(n+1))//2
if sum(lis)%num!=0:
  print("No")
  exit()
li=[lis[i]-lis[i-1]-sum(lis)//num for i in range(n)]
ans=0
for k in range(n):
  if -li[k]%n!=0:
    print("No")
    exit()
  ans+=-li[k]//n
if ans == sum(lis)//num:print("Yes")
else:print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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:
    print('NO')
    exit()

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

print('YES')

Submission status: Wrong Answer

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:
    print('NO')
    exit()

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

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

Submission status: Wrong Answer

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

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:
    print('NO')
    exit()

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

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

Submission status: Wrong Answer

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

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

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

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

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


if d != -1 * k:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
k = sum(A) // (n * (n + 1) // 2)
d = [a1 - a2 + 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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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) == s:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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
  for i in range(n-1):
    m[i]=(l[i+1]-l[i]-k)%n
  if sum(m):
    print("NO")
  else:
    print("YES")

Submission status: Wrong Answer

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:
			ok = False
			break
	if (a[-1] + k) % n != a[0] % n:
		ok = False

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

Submission status: Wrong Answer

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

    ma = min(A)
    if ma >= M:
        m = (ma // M)*M
        for i in range(N):
            A[i] -= m

    while min(A) > 0:
        i = A.index(min(A))
        for j in range(N):
            A[(i+j) % N] -= j+1

    if min(A) == 0 and max(A) == 0:
        return 'YES'

    return 'NO'


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    ma = min(A)
    if ma >= M:
        m = (ma // M)*M
        for i in range(N):
            A[i] -= m

    while min(A) > 0:
        i = A.index(min(A))
        for j in range(N):
            A[(i+j) % N] -= j+1

    if min(A) == 0 and max(A) == 0:
        return 'Yes'

    return 'No'


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

SUM = sum(aa)
S = N*(N+1)//2

if SUM%S != 0:
	print('NO')
else:
	k = SUM // S
	tmp = 0
	for i in range(N):
		d = aa[i-1] - aa[i]
		d += k
		if d % N == 0:
			tmp += d//N
		else:
			print('NO')
			sys.exit()
	if tmp == k:
		print('YES')
	else:
		print('NO')

Submission status: Wrong Answer

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 sum(startHere) == operations and min(v) == 0 and max(v) == 0:
	print "YES"
else:
	print "NO"

Submission status: Wrong Answer

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 += gathered

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

Submission status: Wrong Answer

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

gathered = 0

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

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

Submission status: Wrong Answer

Solution code:
import sys

n = input()
v = map(int, raw_input().split(' '))

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]

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

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

Submission status: Wrong Answer

Solution code:
import sys

n = input()
v = map(int, raw_input().split(' '))

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]

	if (operations - diff) % n != 0:
		print "NO"
		sys.exit()

print "YES"

Submission status: Wrong Answer

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 - 1, -1, -1):
	contribution -= gathered
	gathered += startHere[i]
	contribution += startHere[i] * n
	v[i] -= contribution

contribution = 0
gathered = 0

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

if min(v) == 0 and max(v) == 0:
	print "YES"
else:
	print "NO"

Submission status: Wrong Answer

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 - 1, -1, -1):
	contribution -= gathered
	gathered += startHere[i]
	contribution += startHere[i] * n
	v[i] -= contribution

contribution = 0
gathered = 0

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

if max(v) == 0 and max(v) == 0:
	print "YES"
else:
	print "NO"

Submission status: Wrong Answer

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 - 1, -1, -1):
	contribution -= gathered
	gathered += startHere[i]
	contribution += startHere[i] * n
	v[i] -= contribution

contribution = 0
gathered = 0

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

if sum(v) == 0:
	print "YES"
else:
	print "NO"