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
input = sys.stdin.buffer.readline
N = int(input())
a = list(map(int, input().split()))
d = [0] * N
for i in range(1, N):
  d[i] = a[i] - a[i - 1]
d[0] = a[0] - a[-1]
l = min(a) // N
r = max(a)
f = 0
for _ in range(100):
  m = int((l + r) / 2)
  if m == 0: break
  t = [m] * N
  c = 0
  for i in range(N):
    if (t[i] - d[i]) % N: break
    c += (t[i] - d[i]) // N
    if c == m:
      f = 1
    else: f = 0
  if f: break
  if c == 0:
    r = m
  if c > m:
    l = m
if f: print("Yes")
else: print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

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


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

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

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

Submission status: Wrong Answer

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

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

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


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

    change_kaisu = s // change

    acc = list(map(lambda x: x - change_kaisu, acc))
    if acc.count(0) == (N - change_kaisu) and acc.count(-N) == change_kaisu:
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

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

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

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

elif s % N != 0:
    print("NO")
else:
    change = N * (N + 1) // 2
    if s % change  != 0:
        print("NO")

    change_kaisu = s // change

    acc = list(map(lambda x: x - change_kaisu, acc))
    if acc.count(0) == (N - change_kaisu) and acc.count(-N) == change_kaisu:
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

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

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

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

elif s % N != 0 :
  print("NO")
else:
  change = N*(N+1)//2
  change_kaisu = s//change

  acc = list(map(lambda x:x-change_kaisu ,acc))
  if acc.count(0) == (N - change_kaisu) and acc.count(-N) == change_kaisu:
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

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

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

if s % N != 0 :
  print("NO")
else:
  change = N*(N+1)//2
  change_kaisu = s//change

  acc = list(map(lambda x:x-change_kaisu ,acc))
  if acc.count(0) == (N - change_kaisu) and acc.count(-N) == change_kaisu:
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

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

acc = [i-j for i,j in zip(nums[0:N-1],nums[1:N]) ]
acc.append(nums[-1] - nums[0])
s = sum(nums)
if s % N == 0 and sum(acc) == 0:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

diff = [0] * N
for i in range(N):
    diff[i] = A[i] - A[i - 1]
for i in range(N):
    if (diff[i] - (1 - N) * M) % N != 0:
        ok = 0

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

Submission status: Wrong Answer

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

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

sys.setrecursionlimit(1000000)
mod = 1000000007

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

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

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

    return

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

    return

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

    return

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

    return

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

Submission status: Wrong Answer

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

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

sys.setrecursionlimit(1000000)
mod = 1000000007

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

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

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

    return

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

    return

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

    return

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

    return

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

Submission status: Wrong Answer

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

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

sys.setrecursionlimit(1000000)
mod = 1000000007

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

#B
def B():
    n = I()
    a = LI()
    b = [0]*2*n
    f = [0]*2*n
    while sum(a) != 0:
        for i in range(n):
            if a[i-1] >= a[i]:
                b[i] += 1
                b[i+n] -= 1
                f[i] += 1
                f[i+n] -= 1+n
        for i in range(2*n-1):
            b[i+1] += b[i]
            f[i+1] += f[i]+b[i]
        for i in range(n):
            f[i] += f[i+n]
            a[i] -= f[i]
            if a[i] < 0:
                print("NO")
                return
    print("YES")
    return

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

    return

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

    return

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

    return

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

    return

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

Submission status: Wrong Answer

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

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

sys.setrecursionlimit(1000000)
mod = 1000000007

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

#B
def B():
    n = I()
    a = LI()
    b = [0]*2*n
    f = [0]*2*n
    for i in range(n):
        if a[i-1] >= a[i]:
            b[i] += 1
            b[i+n] -= 1
            f[i] += 1
            f[i+n] -= 1+n
    for i in range(2*n-1):
        b[i+1] += b[i]
        f[i+1] += f[i]+b[i]
    for i in range(n):
        f[i] += f[i+n]
    f = f[:n]
    if a == f:
        print("YES")
    else:
        print("NO")
    return

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

    return

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

    return

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

    return

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

    return

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

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
from itertools import accumulate
def main():
    N = int( input())
    A = list( map( int, input().split()))
    C = [0]*(N*2+2)
    L = [0]*(N*2+2)
    cnt = 0
    if sum(A)%(N*(N+1)//2) != 0:
        print("NO")
        return
    t = sum(A)//(N*(N+1)//2)
    for i in range(N):
        if (A[i] - A[i-1] + (N-1)*t)%N != 0:
            print("NO")
            return
        k =  (A[i] - A[i-1] + (N-1)*t)//N
        C[i] += t-k
        C[i+N] -= t-k
        cnt += t-k
        L[i+N] -= (t-k)*N
    S = list( accumulate(C))
    if cnt > t:
        print("NO")
        return
    for i in range(N*2+1):
        S[i+1] += S[i] + L[i+1]

    for i in range(N):
        if A[i] != S[i] + S[i+N]:
            print("NO")
            return
    print("YES")
    
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
from itertools import accumulate
def main():
    N = int( input())
    A = list( map( int, input().split()))
    C = [0]*(N*2+2)
    L = [0]*(N*2+2)
    if sum(A)%(N*(N+1)//2) != 0:
        print("NO")
        return
    t = sum(A)//(N*(N+1)//2)
    for i in range(N):
        if (A[i] - A[i-1] + (N-1)*t)%N != 0:
            print("NO")
            return
        k =  (A[i] - A[i-1] + (N-1)*t)//N
        C[i] += t-k
        C[i+N] -= t-k
        L[i+N] -= (t-k)*N
    S = list( accumulate(C))

    for i in range(N*2+1):
        S[i+1] += S[i] + L[i+1]

    for i in range(N):
        if A[i] != S[i] + S[i+N]:
            print("NO")
            return
    print("YES")
    
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
from itertools import accumulate
def main():
    N = int( input())
    A = list( map( int, input().split()))
    C = [0]*(N*2+2)
    L = [0]*(N*2+2)
    l = (N*(N+1))//2
    if sum(A)%(N*(N+1)//2) != 0:
        print("NO")
        return
    t = sum(A)//(N*(N+1)//2)
    for i in range(N):
        if i == 0:
            if (A[0] - A[-1] + (N-1)*t)%N != 0:
                print("NO")
                return
            k = (A[0] - A[-1] + (N-1)*t)//N
        else:
            if (A[i] - A[i-1] + (N-1)*t)%N != 0:
                print("NO")
                return
            k =  (A[i] - A[i-1] + (N-1)*t)//N
        C[i] += t-k
        C[i+N] -= t-k
        L[i+N] -= (t-k)*N
    S = list( accumulate(C))

    for i in range(N*2+1):
        S[i+1] += S[i] + L[i+1]

    for i in range(N):
        if A[i] != S[i] + S[i+N]:
            print("NO")
            return
    print("YES")
    
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
from itertools import accumulate
def main():
    N = int( input())
    A = list( map( int, input().split()))
    C = [0]*(N*2+2)
    L = [0]*(N*2+2)
    l = (N*(N+1))//2
    if sum(A)%(N*(N+1)//2) != 0:
        print("No")
        return
    t = sum(A)//(N*(N+1)//2)
    for i in range(N):
        if i == 0:
            if (A[0] - A[-1] + (N-1)*t)%N != 0:
                print("No")
                return
            k = (A[0] - A[-1] + (N-1)*t)//N
        else:
            if (A[i] - A[i-1] + (N-1)*t)%N != 0:
                print("No")
                return
            k =  (A[i] - A[i-1] + (N-1)*t)//N
        C[i] += t-k
        C[i+N] -= t-k
        L[i+N] -= (t-k)*N
    S = list( accumulate(C))

    for i in range(N*2+1):
        S[i+1] += S[i] + L[i+1]

    for i in range(N):
        if A[i] != S[i] + S[i+N]:
            print("No")
            return
    print("Yes")
    
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

import numpy as np

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

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

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

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

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

v_valid = n_operate
v_sign = n

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

Submission status: Wrong Answer

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

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

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

v_valid = n_operate
v_sign = n

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

# if n_operate == 0:
#     print("YES")
# else:
#     print("NO")
print("YES")

Submission status: Wrong Answer

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

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

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

v_valid = n_operate
v_sign = n

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

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

Submission status: Wrong Answer

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

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

n = getN()
nums = getList()

n_operate = sum(nums) // ((n * (n+1)) // 2)

v_valid = n_operate
v_sign = n

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

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    *A, = map(int,input().split())
    
    S = sum(A)
    s = N*(N+1)//2
    if S%s : print("NO");return
    k = S//s
    B = [a-i*k for i,a in enumerate(A,1)]
    D = [(b-c)%N for b,c in zip(B[1:],B[:-1])]
    if sum(D)==0:print("YES")
    else:print("NO")

main()

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import collections
n=int(input())
A=[int(i) for i in input().split()]
AA,AAA=[0]*n,[0]*n
for i in range(n):
  if i==n-1:
    AA[i]=A[0]-A[-1]
  else:
    AA[i]=A[i+1]-A[i]
for i in range(n):
  if i==n-1:
    AAA[i]=AA[0]-AA[-1]
  else:
    AAA[i]=AA[i+1]-AA[i]
c=collections.Counter(AAA)
n1,n2,n3=c[n],c[-n],c[0]
if n1!=0 and n1==n2 and n1+n2+n3==n:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import collections
n=int(input())
A=[int(i) for i in input().split()]
AA,AAA=[0]*n,[0]*n
for i in range(n):
  if i==n-1:
    AA[i]=A[0]-A[-1]
  else:
    AA[i]=A[i+1]-A[i]
for i in range(n):
  if i==n-1:
    AAA[i]=AA[0]-AA[-1]
  else:
    AAA[i]=AA[i+1]-AA[i]
c=collections.Counter(AAA)
n1,n2,n3=c[n],c[-n],c[0]
if n1==n2 and n1+n2+n3==n:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
Ans = [0 for _ in range(n)]
cnt=0
for a in A:
    cnt+=a
sum_ = n*(n+1)/2

if cnt % sum_ != 0:
    print("No")
    exit()
else:
    times = cnt / sum_
    while times>0:
        times-=1
        # print(A)
        ma=-1
        ma_idx=0
        for i in range(n):
            if A[i] > ma:
                ma = A[i]
                ma_idx = i
        for j in range(0,n):
            A[ma_idx-j] -= (n-j)
    ok = True
    for i in range(n):
        if A[i] != Ans[i]:
            ok = False
    # print("last A ",A)
    if ok:
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

n=int(input())
arr=list(map(int,input().split()))
sum1=sum(arr)
sum2=(n*(n+1))//2
cnt=sum1//sum2
if sum1%sum2!=0:
  print('NO')
else:
  dic={}
  num=gcd(n,cnt)
  l=n//num
  for val in arr:
    if val%n not in dic:
      dic[val%n]=1
    else:
      dic[val%n]+=1
  if len(dic)!=l:
    print('NO')
  else:
    for val in dic.values():
      if val!=num:
        print('NO')
        break
    else:
      print('YES')

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

n=int(input())
arr=list(map(int,input().split()))
sum1=sum(arr)
sum2=(n*(n+1))//2
cnt=sum1//sum2
if sum1%sum2!=0:
  print('NO')
else:
  s=set()
  l=n//(gcd(n,cnt))
  for val in arr:
    s.add(val%n)
  if len(s)==l:
    print('YES')
  else:
    print('NO')

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
sum1=sum(arr)
sum2=(n*(n+1))//2
if sum1%sum2!=0:
  print('NO')
else:
  s=set()
  for val in arr:
    s.add(val%n)
  if len(s)==n:
    print('YES')
  else:
    print('NO')

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')
    exit()
ALL=sum(A)//(N*(N+1)//2)
X=[0]*N
if (A[N-1]-A[0]+ALL)%N!=0:
    print('NO')
    exit()
for i in range(1,N):
    if (A[N-1]-A[0]+ALL)%N!=0:
        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')
    exit()
import numpy as np
from numpy.linalg import inv
D=np.array(([[1+(N+i-j)%N for j in range(N)] for i in range(N)]))
A=np.array(A)
X=np.dot(inv(D),A.T)
flag=True
m=10**(-8)
for x in X:
    xx=x
    if int(x)-m<=x<=int(x)+m:
        print(int(x))
        if int(x)>=0:
            continue
    elif int(x)+1-m<=x<=int(x)+1+m:
        print(int(x)+1)
        if int(x)+1>=0:
            continue
    else:
        flag=False
        break
if flag:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

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

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

print("YES")

Submission status: Wrong Answer

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

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

# mod(n) diff must be same
amod = []
for item in a:
    amod.append(item % n)
amod.append(a[0] % n)
for i in range(n):
    if (amod[i+1] - amod[i] + n) % n != mod:
        print("NO")
        exit()

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

print("YES")

Submission status: Wrong Answer

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

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

# mod(n) diff must be same
amod = []
for item in a:
    amod.append(item % n)
amod.append(a[0] % n)
for i in range(n):
    if (amod[i+1] - amod[i] + n) % n != mod:
        print("NO")
        exit()
print("YES")

Submission status: Wrong Answer

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

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

# mod(n) diff must be same
amod = []
for item in a:
    amod.append(item % n)
amod.append(a[0] % n)
for i in range(n):
    if (amod[i+1] - amod[i] + n) % n != mod:
        print("NO")
        exit()
print("YES")

Submission status: Wrong Answer

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

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

# mod(n) diff must be same
amod = []
for item in a:
    amod.append(item % n)
amod.append(a[0] % n)
mod = (amod[1] - amod[0] + n) % n
for i in range(n):
    if (amod[i+1] - amod[i] + n) % n != mod:
        print("NO")
        exit()
print("YES")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ans=False
c=[]

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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