Problem: 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.

Submission attempts (in order):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
S = sum(A)
last = A[-1]
for i in reversed(range(1, N)):
    A[i] -= A[i-1]
A[0] -= last


ans = "YES"
if S % N != 0 or sum(A) != 0:
    ans = "NO"
else:
    t = S//N
    A = list(map(lambda x: x % N, A))
    if any(a != A[0] for a in A):
        ans = "NO"
    if sum(a//5 for a in A) != -t:
        ans = "NO"
print(ans)


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

N = int(input())
A = list(map(int, input().split()))
S = sum(A)
last = A[-1]
for i in reversed(range(1, N)):
    A[i] -= A[i-1]
A[0] -= last

print(A)
if S % N == 0 and sum(A) == 0:
    print("YES")
else:
    print("NO")


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


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

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

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

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


print(solve())


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

N = int(input())
A = list(map(int, input().split()))
S = sum(A)
last = A[-1]
for i in reversed(range(1, N)):
    A[i] -= A[i-1]
A[0] -= last

T = (N*N+N)//2

ans = "YES"
if S % T != 0 or sum(A) != 0:
    ans = "NO"
else:
    t = S//T
    A = list(map(lambda x: x % N, A))
    if any(a != A[0] for a in A):
        ans = "NO"
    if sum(a//5 for a in A) != -(t % N):
        ans = "NO"
print(ans)


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

N = int(input())
A = list(map(int, input().split()))
S = sum(A)
last = A[-1]
for i in reversed(range(1, N)):
    A[i] -= A[i-1]
A[0] -= last


ans = "YES"
if S % N != 0 or sum(A) != 0:
    ans = "NO"
else:
    t = S//N
    A = list(map(lambda x: x % N, A))
    if any(a != A[0] for a in A):
        ans = "NO"
    if sum(a//5 for a in A) != -(t % N):
        ans = "NO"
print(ans)


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


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

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

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

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


print(solve())


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted