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:
n=int(input())
*a,=map(int, input().split())
sm=sum(a)
if sm%(n*(n+1)//2):
    print("NO")
    exit()
num=sm//(n*(n+1)//2)
for i in range(n):
    if a[(i+1)%n]-a[i]>num:
        print("NO")
        exit()
print("YES")

Submission status: Wrong Answer

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 -= tmp//n

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

Submission status: Wrong Answer

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:
            print("NO")
            exit()
        count += (x-dif)//n
    if count <= x:
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

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:
            print("NO")
            exit()
        count += (x-dif)//n
    if count == x:
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
import numpy as np

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)
for _ in range(5):
    p=sum([i//(n-1)+1 for i in D if i>0]) 
    for i in range(n):
        if D[i]>0:
            q=i//(n-1)+1
            D[i] += p-q*n
        else:
            D[i]+=p
    if np.count_nonzero(D)==0:
        print("YES");exit()

print("NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
import numpy as np

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)
for _ in range(5):
    p=sum([i//(n-1)+1 for i in D if i>0]) 
    for i in range(n):
        if D[i]>0:
            q=i//(n-1)+1
            D[i] += p-q*n
        else:
            D[i]+=p
    if np.count_nonzero(D)==0:
        print("Yes");exit()

print("No")

Submission status: Wrong Answer

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

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)

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

    cnt = 0
    for i in range(n):
        if b[i] % n != 0:
            print("NO")
            return
        else:
            cnt += b[i] // n

    if cnt == c:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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)
    cnt = 0

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

    b = [0] * n
    c = y // x
    for i in range(n):
        b[i] = a[i] - a[(i + 1) % n] + c
        if b[i] != 0:
            if b[i] % n != 0:
                print("NO")
                return
            else:
                cnt += b[i] // n

    if cnt == c:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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)
    if min(a) < t:
        print("NO")
        exit()
    d = [a[i]-a[i-1] for i in range(n)]
    md = d[0]%n
    for i in d:
        if i%n != md:
            print("NO")
            exit()
    print("YES")

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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)]
    md = d[0]%n
    for i in d:
        if i%n != md:
            print("NO")
            exit()
    print("YES")

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

'''
import random
N = 3
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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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
    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:
        b -= s
        if (bmax - b) % N != 0:
            return False
        k = (bmax - b) // N
        s += k
        bmax -= k
        if bmax < 0:
            return False
    return True


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

Submission status: Wrong Answer

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
    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)
    for b in B:
        if (bmax - b) % N != 0:
            return False
    return True


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

Submission status: Wrong Answer

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

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:
        print("NO")
        exit()
if m == 0:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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 != 0 and D % n == 0:
        m += (D//n)
    if D != 0 and D % n != 0:
        print("NO")
        exit()
if m == 0:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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-1]-a[i]+m for i in range(n)]

for D in d:
    if D != 0 and D % n == 0:
        m -= 1
    if D != 0 and D % n != 0:
        print("NO")
        exit()
if m == 0:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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-1]-a[i]+m for i in range(n)]

for D in d:
    if D != 0 and D % n == 0:
        m -= 1
    if D != 0 and D % n != 0:
        print("NO")
        exit()

print("YES")

Submission status: Wrong Answer

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-1]-a[i]+m for i in range(n)]

for D in d:
    if D != 0 and D % n == 0:
        m -= 1
    if D != 0 and D % n != 0:
        print("NO")
        exit()

print("YES")

Submission status: Wrong Answer

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
    ans = 0
    for i in range(N):
        d = A[(i+1)%N]-A[i]-k
        if d%N!=0:
            print('NO')
            return
    print('YES')

main()

Submission status: Wrong Answer

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
    ans = 0
    for i in range(N):
        d = A[(i+1)%N]-A[i]-k
        if -d%N!=0:
            print('NO')
            return
        ans += -d//N
    if k==ans:
        print('YES')
    else:
        print('NO')

main()

Submission status: Wrong Answer

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
    d = [0]*N
    for i in range(N):
        d[i] = A[(i+1)%N]-A[i]-k
    if k==sum(-x//N for x in d):
        print('YES')
    else:
        print('NO')

main()

Submission status: Wrong Answer

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 m:
            ans = "NO"
            break
        count[i-1] = x
    else:
        ans = "YES"
#         if sum(count)==k and sum(c*(n-i) for i,c in enumerate(count)):
#             ans = "YES"
#         else:
#             ans = "NO"
print(ans)

Submission status: Wrong Answer

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

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 = [0] * n # iを選んだ回数
    for i in range(n):
        diff = a[i] - a[i-1]
        x, m = divmod(k- diff, n)
        if m:
            ans = "NO"
            break
        count[i-1] = x
    else:
        if sum(count)==k:
            ans = "YES"
        else:
            ans = "NO"
print(ans)

Submission status: Wrong Answer

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()))
    
    tot = sum(A)
    su = N*(N + 1)//2
    x = 0
    idx = 0
    while x <= tot:
        if x == tot:
            break
        x += su
        idx += 1
    if idx == 0:
        print('NO')
        return
    
    diff = []
    for i in range(N - 1):
        diff.append(A[i + 1] - A[i])
    diff.append(A[0] - A[-1])

    cnt = 0
    flag = True
    for i in range(N):
        diff[i] -= idx
        if diff[i] > 0:
            flag = False
            return
        else:
            diff[i] = -diff[i]
            if diff[i]%N == 0:
                cnt += diff[i]//N
            else:
                flag = False
                break
    print('YES' if flag and (cnt == idx) else 'NO')
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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
    for i in range(N):
        a0, a1 = A[i-1], A[i]
        if -(a1 - a0 - t) % N != 0:
            ok = False
            break
YESNO = lambda tf: print('YES') if tf else print('NO')
YESNO(ok)

Submission status: Wrong Answer

Solution code:
import sys
N,*A = map(int, open(0).read().split())
S = sum(range(1,N+1))
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 i,c in enumerate(B):
  if c%(-N)!=0:
    print('NO')
    break
  X += c//(-N)
else:
  if X==M:
    print('YES')
  else:
    print('NO')

Submission status: Wrong Answer

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)]
cnt = 0
for i in range(N):
    if (c - d[i]) % N != 0:
        print('NO')
        exit()
    cnt += (c - d[i]) // N
if cnt == c:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import sys
N,*A = map(int, open(0).read().split())
S = sum(range(1,N+1))
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 i,c in enumerate(B):
  if c%(-N)!=0:
    print('NO')
    break
else:
  print('YES')

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
d = [A[(i + 1) % N] - A[i] for i in range(N)]
d2 = [d[(i + 1) % N] - d[i] for i in range(N)]
s = sum(A)
if any(d2[i] % N != 0 for i in range(N)):
    print('NO')
    exit()
if any(d2[i] > 0 for i in range(N)):
    i = 0
    t = 0
    for j in range(N):
        t += d2[j]
        if t > 0:
            i = (j + 1) % N
    cnt = 0
    for j in range(N):
        k = (i + j) % N
        if d2[k] < 0:
            cnt += (-d2[k] // N)
            d2[(k+1) % N] += d2[k]
            d2[k] = 0
    s -= N * (N + 1) // 2 * cnt
if s < 0 or s % (N * (N + 1) // 2) != 0:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
d = [A[(i + 1) % N] - A[i] for i in range(N)]
d2 = [d[(i + 1) % N] - d[i] for i in range(N)]
s = sum(A)
if any(d2[i] % N != 0 for i in range(N)) or sum(d2) != 0:
    print('NO')
    exit()
if any(d2[i] > 0 for i in range(N)):
    i = 0
    while i < N and d[i] > 0:
        i += 1
    cnt = 0
    for j in range(N):
        k = (i + j) % N
        if d2[k] < 0:
            cnt += (-d2[k] // N)
            d2[(k+1) % N] += d2[k]
            d2[k] = 0
    s -= N * (N + 1) // 2 * cnt
if s < 0 or s % (N * (N + 1) // 2) != 0:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
d = [A[(i + 1) % N] - A[i] for i in range(N)]
d2 = [d[(i + 1) % N] - d[i] for i in range(N)]
s = sum(A)
if any(d2[i] % N != 0 for i in range(N)) or sum(d2) != 0:
    print('NO')
    exit()
if any(d2[i] > 0 for i in range(N)):
    i = 0
    while i < N and d[i] > 0:
        i += 1
    cnt = 0
    for j in range(N):
        k = (i + j) % N
        if d2[k] < 0:
            cnt += (-d2[k] // N)
            d2[(k+1) % N] += d2[k]
            d2[k] = 0
    s -= N * (N + 1) // 2 * cnt
if s % (N * (N + 1) // 2) != 0:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
d = [A[(i + 1) % N] - A[i] for i in range(N)]
d2 = [d[(i + 1) % N] - d[i] for i in range(N)]
s = sum(A)
if any(d2[i] % N != 0 for i in range(N)) or sum(d2) != 0:
    print('NO')
    exit()
if any(d2[i] > 0 for i in range(N)):
    i = 0
    while i < N and d[i] > 0:
        i += 1
    cnt = 0
    for j in range(N):
        k = (i + j) % N
        if d2[k] < 0:
            d2[(k+1) % N] += d2[k]
            d2[k] = 0
            cnt += (-d2[k] // N)
    s -= N * (N + 1) // 2 * cnt
if s % (N * (N + 1) // 2) != 0:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
d = [A[(i + 1) % N] - A[i] for i in range(N)]
d2 = [d[(i + 1) % N] - d[i] for i in range(N)]
s = sum(A)
if any(d2[i] % N != 0 for i in range(N)) or sum(d2) != 0:
    print('NO')
    exit()
if any(d2[i] > 0 for i in range(N)):
    i = 0
    while i < N and d[i] > 0:
        i += 1
    cnt = 0
    for j in range(N):
        k = (i + j) % N
        if d2[k] < 0:
            d2[(k+1) % N] += d2[k]
            d2[k] = 0
            cnt += 1
    s -= N * (N + 1) // 2 * cnt
if s % (N * (N + 1) // 2) != 0:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
diff = [A[(i + 1) % N] - A[i] for i in range(N)]
for i in range(N):
    if (diff[(i + 1) % N] - diff[i]) % N != 0:
        print('NO')
        exit()
print('YES')

Submission status: Wrong Answer

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:
        print("NO")
        quit()
    else:
        x+=(l[i-1]-l[i]+t)//n
if t==x:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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]-l[i-1]==t:
        pass
    elif (l[i-1]-l[i]+t)%n:
        print("NO")
        quit()
    else:
        x+=(l[i-1]-l[i]+t)//n
if t==x:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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]-l[i-1]==t:
        pass
    elif (l[i-1]-l[i]+t)%n:
        print("No")
        quit()
    else:
        x+=(l[i-1]-l[i]+t)//n
if t==x:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

sa = sum(a)
at = (n+1)*n//2

if sa%at!=0:
    print('NO')
    exit()

kaisu = sa//at

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

diff[n-1] = a[n-1]-a[0]

if sum(diff)==0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
#modN等差数列が必要
import numpy as np
n=int(input())
a=np.array(list(map(int, input().split())))
a2=a
a_l = a[-1]-a[0]
a[:-1] -= a[1:]
a[-1] = a_l
a%=n
if len(set(a))>1 or max(a2)-min(a2)>a[0]*n:
    print("NO")
    exit()
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:
	times = sum(a)//(n*(n+1)//2)
	jud = 'YES'
	x = a[n-1]-a[0]+times
	if (x < 0 | x % n != 0):
		jud = 'NO'
	for i in range(1,n):
		x = a[i-1]-a[i]+times
		if (x < 0 | x % n != 0):
			jud = 'NO'
			break
	print(jud)

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:
	times = sum(a)//(n*(n+1)//2)
	jud = True
	x = a[n-1]-a[0]+times
	if (x < 0 | x % n != 0):
		jud = False
	for i in range(1,n):
		x = a[i-1]-a[i]+times
		if (x < 0 | x % n != 0):
			jud = False
			break
	print(jud)

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:
	times = sum(a)//(n*(n+1)//2)
	jud = True
	x = a[n-1]-a[0]+times
	if x % n != 0:
		jud = False
	for i in range(1,n):
		x = a[i-1]-a[i]+times
		if (x < 0 | x % n != 0):
			jud = False
			break
	print(jud)

Submission status: Wrong Answer

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

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

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)

cnt = 0
x = a[n-1]-a[0]+times
if x % n != 0:
	print('NO')
	exit()
else:
	cnt += x//n
for i in range(1,n):
	x = a[i-1]-a[i]+times
	#print(i, x, times)
	if x < 0:
		print('NO')
	elif x % n != 0:
		print('NO')
		exit()
	else:
		cnt += x//n
if cnt == times:
	print('YES')
else:
	print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
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)

cnt = 0
x = a[n-1]-a[0]+times
if x % n != 0:
	print('NO')
	exit()
else:
	cnt += x//n
for i in range(1,n):
	x = a[i-1]-a[i]+times
	#print(i, x, times)
	if x < 0:
		print('NO')
	elif x % n != 0:
		print('NO')
		exit()
	else:
		cnt += x//n
if cnt == times:
	print('YES')
else:
	print('NO')

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    subA = [A[(i + 1) % N] - A[i] for i in range(N)]
    modA = subA[0] % N
    for i, a in enumerate(subA):
        if a % N != modA:
            print("NO")
            break
    else: print("YES")
    
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
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)

cnt = 0
x = a[n-1]-a[0]+times
if x % n != 0:
	print('NO')
	exit()
else:
	cnt += x//n
for i in range(1,n):
	x = a[i-1]-a[i]+times
	#print(i, x, times)
	if x % n != 0:
		print('NO')
		exit()
	else:
		cnt += x//n
if cnt == times:
	print('YES')
else:
	print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
if n < 5:
	print('NO')
	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)

cnt = 0
x = a[n-1]-a[0]+times
if x % n != 0:
	print('NO')
	exit()
else:
	cnt += x//n
for i in range(1,n):
	x = a[i-1]-a[i]+times
	#print(i, x, times)
	if x % n != 0:
		print('NO')
		exit()
	else:
		cnt += x//n
if cnt == times:
	print('YES')
else:
	print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
K = 0
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:
        print('NO')
        quit()
    cnt += (K-x) // n
print('YES' if cnt == K else 'NO')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
d = [0] * N
for i in range(N): d[i] = a[i - 1] - a[i]

if N == 1:
  print("YES")
  exit(0)
if len(set(d)) != 2 or (sum(d) > 0) or (sum(a) % (N * (N + 1) // 2)): print("NO")
else: print("YES")

Submission status: Wrong Answer

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

B = [a % N for a in A]
B.sort()

if B == list(range(N)):
    print('YES')
else:
    print('NO')