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

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]

	if (operations - diff) % n != 0:
		print "NO"
		sys.exit()
	# startHere[i] = (operations - diff) / n

# sum = 0
# gathered = 0

# for i in range(n - 1, -1, -1):
# 	v[i] -= sum
# 	sum -= gathered
# 	gathered += startHere[i]
# 	sum += startHere[i] * n

# for i in range(n):
# 	if startHere[(i + n - 1) % n]:
# 		#do stuff

# if sum(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()

while sum(v) > 0:
	biggest, second_biggest = 0, 0
	for i in range(n):
		if v[i] > biggest:
			second_biggest = biggest
			biggest = i
		elif v[i] > second_biggest:
			second_biggest = i

	times = (v[biggest] - v[second_biggest] + n - 1) / n

	for i in range(biggest, -1, -1):
		v[i] -= n - (biggest - i)
	for i in range(biggest + 1, n):
		v[i] -= i - biggest

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

Submission status: Wrong Answer

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

def solve(N, A):
    k = N * (N + 1) // 2
    s = sum(A)
    if s % k > 0:
        return False
    m = s // k
    # print(k, s, m)
    rs = []
    for i in range(N):
        p = A[i - 1]
        q = A[i]
        delta = q - p
        y = m - delta
        # print(p, q, delta, y, N)
        if y % N > 0:
            return False
        x = y // N
        rs.append(x)
    # print("*", rs)
    R = 0
    for i in range(N):
        x = rs[i]
        l = (N - i) % N + 1
        R += l * x
    # print(1, R)
    if R != A[0]:
        return False
    for i in range(1, N):
        R += m - rs[i]
        R -= rs[i] * (N - 1)
        # print(i, R)
        if R != A[i]:
            return False
    return True

def solve(N, A):
    k = N * (N + 1) // 2
    s = sum(A)
    if s % k > 0:
        return False
    m = s // k
    for i in range(N):
        x = A[i - 1] - A[i] + m
        if (x % N) > 0:
            return False
    return True

if solve(N, A):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

def solve(N, A):
    k = N * (N + 1) // 2
    s = sum(A)
    if s % k > 0:
        return False
    m = s // k
    # print(k, s, m)
    rs = []
    for i in range(N):
        p = A[i - 1]
        q = A[i]
        delta = q - p
        y = m - delta
        # print(p, q, delta, y, N)
        if y % N > 0:
            return False
        x = y // N
        rs.append(x)
    # print("*", rs)
    R = 0
    for i in range(N):
        x = rs[i]
        l = (N - i) % N + 1
        R += l * x
    # print(1, R)
    if R != A[0]:
        return False
    for i in range(1, N):
        R += m - rs[i]
        R -= rs[i] * (N - 1)
        # print(i, R)
        if R != A[i]:
            return False
    return True

if solve(N, A):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

def solve(N, A):
    k = N * (N + 1) // 2
    s = sum(A)
    if s % k > 0:
        return False
    m = s // k
    # print(k, s, m)
    rs = []
    for i in range(N):
        p = A[i - 1]
        q = A[i]
        delta = q - p
        y = m - delta
        # print(p, q, delta, y, N)
        if y % N > 0:
            return False
        x = y // N
        rs.append(x)
    #print("*", rs)
    A0 = 0
    for i in range(N):
        x = rs[i]
        l = (N - i) % N + 1
        A0 += l * x
    if A0 != A[0]:
        return False
    return True

if solve(N, A):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

def solve(N, A):
    k = N * (N + 1) // 2
    s = sum(A)
    if s % k > 0:
        return False
    m = s // k
    # print(k, s, m)
    rs = []
    for i in range(N):
        p = A[i - 1]
        q = A[i]
        delta = q - p
        y = m - delta
        # print(p, q, delta, y, N)
        if y % N > 0:
            return False
        rs.append(y // N)
    # print("*", rs)
    return True

if solve(N, A):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

def solve(N, A):
    k = N * (N + 1) // 2
    s = sum(A)
    if s % k > 0:
        return False
    m = s // k
    # print(k, s, m)
    rs = []
    for i in range(N):
        p = A[i - 1]
        q = A[i]
        delta = q - p
        y = m - delta
        print(p, q, delta, y, N)
        if y % N > 0:
            return False
        rs.append(y // N)
    # print("*", rs)
    return True

if solve(N, A):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
s = sum(A)
q, m = divmod(s, N*(N+1)//2)
if m != 0:
    print("NO")
    exit()
D = [A[i]-A[i-1]-q for i in range(N)]
for d in D:
    if d%N != 0:
        print("NO")
        exit()
print("YES")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    an = list(map(int, input().split()))
    assert len(an) == n
    d = np.sum(an)
    if d % (n * (n + 1) // 2) > 0:
        return False
    k = d // (n * (n + 1) // 2)

    diffs = np.roll(np.array(an), -1) - np.array(an)
    diffs -= k
    if np.all(diffs % n == 0):
        return True
    else:
        return False

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

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [int(i) for i in input().split()]
sum1 = int(N * (N+1) / 2)
sum2 = 0
dif = 0
for j in range(len(l)):
    dif += l[j] - l[j-1]
    sum2 += l[j]
if sum2 % sum1 == 0 and dif == 0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

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

S = N*(N+1) // 2
SA = sum(A)

if SA % S != 0:
    print("NO")
    sys.exit(0)

K = SA // S

# B = []
C = []
for i in range(N):
    # B.append(A[i] - A[i-1] - K)
    b = A[i] - A[i-1] - K
    if b > 0:
        print("NO")
        sys.exit(0)
    C.append(-b//N)

print("YES")

Submission status: Wrong Answer

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

K = sum(A) // sum(range(1, N+1))
D = [A[i+1] - A[i] - K for i in range(-1, N-1)]

for d in D:
    if not (d <= 0 and d % N == 0):
        print("NO")
        break
else:
    print("YES")

Submission status: Wrong Answer

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

K = sum(A) // sum(range(1, N+1))
D = [A[i+1] - A[i] - K for i in range(-1, N-1)]

for d in D:
    if not (d <= 0 and d % N == 0):
        print(d)
        print("NO")
        break
else:
    print("YES")

Submission status: Wrong Answer

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

sec = sum(range(1, N+1))
if sum(A) % sec == 0:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
*A, = map(int, input().split())
C = sum(A)
if C % (N*(N+1)//2) == 0:
    k = C // (N*(N+1) // 2)
    B = [A[i-1] - A[i] + k for i in range(N)]
    ok = 1
    for b in B:
        if b % N > 0:
            ok = 0
            break
    if ok:
        print('YES')
        exit(0)
print('NO')

Submission status: Wrong Answer

Solution code:

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

    one = n*(n+1)/2

    if sum(a) % one != 0:
        print("NO")
        return
    else:
        nop = sum(a) / one

    d = [0 for i in range(n)]
    for i in range(n):
        d[i] = a[(i+1)%n] - a[i]
        d[i] = d[i] - nop

    count = 0

    for i in range(n):
        if d[i] != 0:
            if d[i] % n != 0:
                print("NO")
                return
            count = count + (-1*d[i]) / n
            d[i] = 0
            if count > nop:
                print("NO")
                return

    if sum(d) == 0 and count == nop:
        print("YES")
    else:
        print("NO")

solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
src = list(map(int,input().split()))
S = sum(src)
M = N*(N+1)//2

if S%M:
    print('NO')
    exit()

K = S//M
mem = [src[i] - K*i for i in range(N)]
mem.append(mem[0])
sum_d = 0
for a,b in zip(mem,mem[1:]):
    if a == b: continue
    d = abs(a-b)
    if d%N:
        print('NO')
        exit()
    sum_d += d
print('YES' if sum_d in (2*K*N, 2*(K-1)*N) else 'NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
src = list(map(int,input().split()))
S = sum(src)
M = N*(N+1)//2

if S%M:
    print('NO')
    exit()

K = S//M
mem = [src[i] - K*i for i in range(N)]
mem.append(mem[0])
sum_d = 0
for a,b in zip(mem,mem[1:]):
    if a == b: continue
    d = abs(a-b)
    if d%N:
        print('NO')
        exit()
    sum_d += d
print('YES' if sum_d <= 2*K*N else 'NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
src = list(map(int,input().split()))
S = sum(src)
M = N*(N+1)//2

if S%M:
    print('NO')
    exit()

K = S//M
mem = [src[i] - K*i for i in range(N)]
mem.append(mem[0])
for a,b in zip(mem,mem[1:]):
    if (a-b)%N:
        print('NO')
        exit()
print('YES')

Submission status: Wrong Answer

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

if sum(A)*2%(N*(N+1))!=0:
        ans=False
k=sum(A)*2/(N*(N+1))


d=[A[i+1]-A[i]-k for i in range(N-1)]
d.append(A[0]-A[N-1]-k)
for i in range(N):
        if d[i]<=0 and d[i]%N!=0:
                ans=False
if ans:
        print("YES")
else:
        print("NO")

Submission status: Wrong Answer

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

if sum(A)%(int((N*(N+1))/2))!=0:
        ans=False
k=sum(A)*2/(N*(N+1))


d=[A[i+1]-A[i]-k for i in range(N-1)]
d.append(A[0]-A[N-1]-k)
for i in range(N):
        if d[i]%N!=0:
                ans=False
if ans:
        print("Yes")
else:
        print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

k = sum(A) / sum(range(1, N + 1))
D = [(A[(i + 1) % N] - A[i]) - k for i in range(N)]

cnt = k * N + sum(list(filter(lambda x: x % N == 0, D)))
print('YES' if (cnt == 0) else 'NO')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

k = sum(A) / sum(range(1, N + 1))
D = [A[(i + 1) % N] - A[i] for i in range(N)]

cnt = 0
for d in D:
    if abs(d - k) % N == 0:
        cnt += abs(d - k) / N

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

k = sum(A) / sum(range(1, N + 1))
D = [A[(i + 1) % N] - A[i] for i in range(N)]

cnt = 0
for d in D:
    if abs(d - k) / N >= 1:
        cnt += abs(d - k) / N

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

k = sum(A) / sum(range(1, N + 1))
D = [A[(i + 1) % N] - A[i] for i in range(N)]
D = [(d - k) // N for d in D]

print('YES' if (-sum(D) == k) else 'NO')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

mx_idx = A.index(max(A))
diff = A[mx_idx] - A[mx_idx - 1]

for i in range(N):
    A[(i + mx_idx) % N] += N * min(diff, i)

A.sort()
for l, r in zip(A, A[1:]):
    if l + diff != r:
        print('NO')
        break
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

mx_idx = A.index(max(A))
diff = A[mx_idx] - A[mx_idx - 1]

for i in range(N):
    if i + mx_idx < N:
        A[i + mx_idx] += N * min(diff, i)

for l, r in zip(A, A[1:]):
    if l + diff != r:
        print('NO')
        break
else:
    print('YES')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
N=int(input())
A=list(map(int,input().split()))
total=0
for i in range(N):
  total+=A[i]
if total*2/((N+1)*N)%1!=0:
  print("NO")
  sys.exit()
times=int(total*2/((N+1)*N))
if (times-A[0]+A[N-1])/N%1!=0:
  print("NO")
  sys.exit()
B=(times-A[0]+A[N-1])/N
for i in range(N-1):
  B+=(times-A[i+1]+A[i])/N
  if (times-A[i+1]+A[i])/N%1!=0:
    print("NO")
    sys.exit()
if B==times:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
import sys
N=int(input())
A=list(map(int,input().split()))
total=0
for i in range(N):
  total+=A[i]
if total*2/((N+1)*N)%1!=0:
  print("NO")
  sys.exit()
times=int(total*2/((N+1)*N))
B=(times-A[0]+A[N-1])/N
for i in range(N-1):
  B+=(times-A[i+1]+A[i])/N
if B==times:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
total=0
for i in range(N):
  total+=A[i]
times=int(total*2/((N+1)*N))
B=(times-A[0]+A[N-1])/N
for i in range(N-1):
  B+=(times-A[i+1]+A[i])/N
if B==times:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
total=0
for i in range(N):
  total+=A[i]
times=int(total*2/((N+1)*N))
B=(times-A[0]+A[N-1])/N
for i in range(N-1):
  B+=(times-A[i]+A[i-1])/N
if B==times:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
N = int(raw_input().strip())
A = map(int, raw_input().strip().split(" "))

def getMaxIndex(list):
    maxVal = 0
    maxIdx = 0
    for i in range(0, len(list)):
        if(maxVal < list[i]):
            maxIdx = i
            maxVal = list[i]
    return maxIdx

def check(list):
    for i in range(0, N):
        index = getMaxIndex(A)

        for j in range(0, N):
            A[(index + j + 1) % N] -= (j + 1)

        if(min(A) <= 0):
            for j in range(0, N):
                if(A[j] != 0):
                    return False
            return True


print check(A)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
num_N = int(input())
l_stone = list(map(int, input().split()))
print(l_stone)

sum_num_N = sum(list(range(1, num_N + 1)))

def solve():
    if sum(l_stone) % sum_num_N != 0:
        return "NO"

    num_times = sum(l_stone) // sum_num_N

    l_dif = []
    for i in range(num_N - 1):
        l_dif.append((l_stone[i + 1] - l_stone[i]))
    l_dif.append(l_stone[0] - l_stone[num_N - 1])

    l_dif_arr = list(map(lambda x: x - num_times, l_dif))

    num_dif_times = 0

    for dif in l_dif_arr:
        if dif == 0:
            continue
        elif dif % num_N == 0:
            num_dif_times += (dif * -1) // num_N
        else:
            break

    if num_dif_times == num_times:
        return "YES"

    return "NO"

print(solve())

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
k = 0
if sum(L) % ((N * (N + 1)) // 2) == 0:
	k = sum(L)//((N*(N+1))//2)
else:
	print("NO")

L.append(L[0])
L.append(L[1])
A = []
B = []
if k != 0:
	for l in range(N):
		b = (L[l + 1] - L[l])
		a = (L[l+1] - L[l]) - (L[l+2] - L[l + 1])
		if b > k or b < -k*N:
			l = -1
			print("NO")
			break
		if abs(a)%N == 0:
			pass
		else:
			print("NO")
			l = -1
			break
	if l == N-1:
		print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
k = 0
if sum(L) % ((N * (N + 1)) // 2) == 0:
	k = sum(L)//((N*(N+1))//2)
else:
	print("NO")

L.append(L[0])
L.append(L[1])
A = []
B = []
if k != 0:
	for l in range(N):
		a = (L[l+1] - L[l]) - (L[l+2] - L[l + 1])
		if abs(a)%N == 0:
			pass
		else:
			print("NO")
			break
	if l == N-1:
		print("YES")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
if __name__ == '__main__':
  N = int(input())
  A = list(map(int, input().split()))

  q = (1+N)*N/2
  mi = 1000000009
  for i in range(0,N):
    mi = min(mi, A[i])
  p = mi//q
  for i in range(0,N):
    A[i] -= p * q

  ans = False
  while True:
    mi = 0
    ma = 0
    for i in range(0,N):
      if A[i] > A[ma]:
        ma = i
      if A[i] < A[mi]:
        mi = i

    if A[mi] < 0:
      ans = False
      break
    elif A[ma] == 0:
      ans = True
      break

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

  # min(A) < 15
  if ans:
    print("YES")
  else:
    print("NO")

  # 1 2 3 4 5
  # 2 3 4 5 1
  # 3 4 5 1 2
  # 4 5 1 2 3
  # 5 1 2 3 4

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
if __name__ == '__main__':
  N = int(input())
  A = list(map(int, str(input()).split(" ")))

  q = (1+N)*N/2
  mi = 1000000009
  for i in range(0,N):
    mi = min(mi, A[i])
  p = mi//q
  for i in range(0,N):
    A[i] -= p * q

  ans = False
  while True:
    mi = 0
    ma = 0
    for i in range(0,N):
      if A[i] > A[ma]:
        ma = i
      if A[i] < A[mi]:
        mi = i

    if A[mi] < 0:
      ans = False
      break
    elif A[ma] == 0:
      ans = True
      break

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

  # min(A) < 15
  if ans:
    print("YES")
  else:
    print("NO")

  # 1 2 3 4 5
  # 2 3 4 5 1
  # 3 4 5 1 2
  # 4 5 1 2 3
  # 5 1 2 3 4

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
a = [int(x) for x in input().strip().split()]

total = sum(a)
nn = n * (n + 1) / 2
if total % nn != 0 :
  print('NO')
else:
  m = total / nn
  l = 0
  flg = True
  for i in range(n):
    j = i - 1
    if i == 0:
      j = n - 1
    if (a[j] + m - a[i]) % n != 0:
      flg = False
      break
    l += (a[j] + m - a[i]) / n

  if flg == True:                                                                                                                                                                                                                            
    print('YES')
  else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
a = [int(x) for x in input().strip().split()]

total = sum(a)
nn = n * (n + 1) / 2
if total % nn != 0 :
  print('NO')
else:
  m = total / nn
  l = 0
  flg = True
  for i in range(n):
    j = i - 1
    if i == 0:
      j = n - 1
    if (a[j] + m - a[i]) % n != 0:
      flg = False
      break
    l += (a[j] + m - a[i]) / n

  if l == m and flg == True:
    print('YES')
  else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
a = [int(x) for x in input().strip().split()]

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

m = total / nn
l = 0
flg = True
for i in range(n):
  j = i - 1
  if i == 0:
    j = n - 1
  if (a[j] + m - a[i]) % n != 0:
    print('NO')
    sys.exit()
  l += (a[j] + m - a[i]) / n

if l == m:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
D = [A[i + 1] - A[i] for i in range(N - 1)] + [A[0] - A[N - 1]]
k = int(sum(A) * 2 / N / (N + 1))
for d in D:
    if d - k > 0 or (d - k) % N != 0:
        print("NO")
        exit()

print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
D = [A[i + 1] - A[i] for i in range(N - 1)] + [A[0] - A[N - 1]]
k = int(sum(A) * 2 / N / (N + 1))
for d in D:
    if d - k > 0 or (d - k) % N != 0:
        print(d - k)
        print("NO")
        exit()

print("YES")

Submission status: Wrong Answer

Solution code:
n = input()
A = map(int, raw_input().split())
B = [A[i] - A[i-1] for i in xrange(n)]
Bm = min(B)
print "YES"*(all((B[i]-Bm) % n == 0 for i in xrange(n))*(sum(B)==0)) or "NO"

Submission status: Wrong Answer

Solution code:
n = input()
A = map(int, raw_input().split())
B = [A[i] - A[i-1] for i in xrange(n)]
Bm = min(B)
print "YES"*all((B[i]-Bm) % n == 0 for i in xrange(n)) or "NO"

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
if sum(A) % (N * (N + 1) // 2) != 0:
    print("NO")
    quit()
res = sum(A) // (N * (N + 1) // 2)
cnt = 0
for i in range(N):
    d = A[i] - A[(i+1)%N]
    if (N - 1) * res - d < 0 or ((N - 1) * res - d) % N != 0:
        print("NO")
        quit()
    cnt += res - ((N - 1) * res - d) // N
print("YES" if cnt == res else "NO")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

def solve(A):
    n = sum(A) // (N*(N+1)//2)
    if sum(A) % (N*(N+1)//2) != 0:
        return 'NO'

    count = 0

    for i in range(N):
        diff = A[i] - A[i-1] 

        if diff == n:
            continue

        if -1 * (diff - n) % N != 0:
            return 'NO'
        c = -(diff-n)//N
        count += c

    if count == n:
        return 'YES'
    return 'NO'

print(solve(A))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

def solve(A):
    n = sum(A) // (N*(N+1)//2)
    if sum(A) % (N*(N+1)//2) != 0:
        return 'NO'

    count = 0

    for i in range(N):
        diff = A[i] - A[i-1] 

        if diff == n:
            continue

        if -1 * (diff - n) % N != 0:
            return 'NO'
        c = -(diff-n)//N

        if diff == n - N*c:
            count += c
        else:
            return 'NO'

    if count == n:
        return 'YES'
    return 'NO'

print(solve(A))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

def solve(A):
    n = sum(A) // (N*(N+1)//2)
    if sum(A) % (N*(N+1)//2) != 0:
        return 'NO'

    count = 0

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

        if diff == n:
            continue

        if -1 * (diff - n) % N != 0:
            return 'NO'
        c = -(diff-n)//N

        if diff == n - N*c:
            count += c
        else:
            return 'NO'

    if count == n:
        return 'YES'
    return 'NO'

print(solve(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, list(input().split(" "))))
dif = [0] * n
itr = sum(a)/sum(list(range(n+1)))

if itr != int(itr):
	print("NO")
	exit()
 
count = 0
for i in range(n-1):
	dif[i] = a[i+1]-a[i]
	temp = (itr - dif[i])/n
	if temp != int(temp):
		print("NO")
		exit()
	count += temp

if count > itr:
	print("NO")
	exit()

print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
if sum(A) % (N * (N + 1) // 2) == 0:
    A.append(A[0])
    print("YES" if all(abs(A[i] - A[i+1]) <= N for i in range(N)) else "NO")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
if sum(A) % (N * (N + 1) // 2) == 0:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
s = sum(l)
h = n * (n + 1) / 2
if s % h != 0:
    print("NO")
    quit()

p = s / h

for i in range(0, n):
    if l[i] / p < 1:
        print("NO")
        quit()
    if l[i] / p  > n:
        print("NO")
        quit()
print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
start = 0
divide = 2
printStr = 'N0'

for i in range(N):
    for j in range(N - 1):
        index = start + j if start + j < N else start + j - N
        if  A[index] % divide == 0:
            divide += 1
        else:
            start += 1
            divide = 2
            break
    if divide == N + 1:
        printStr = 'YES'
        break

print(printStr)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
start = 0
divide = 2
printStr = 'N0'

for i in range(N):
    for j in range(N - 1):
        index = start + j if start + j < 5 else start + j - 5
        if  A[index] % divide == 0:
            divide += 1
        else:
            start += 1
            divide = 2
            break
    if divide == N + 1:
        printStr = 'YES'
        break

print(printStr)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(n) for n in input().split()]
stones = sum(A)
step = stones / int(N*(1+N)/2)

if step % 1 != 0:
    print("NO")
else:
    D = [(A[(n+1)%N] - A[n%N]) - step for n in range(N)]
    if all(d%N == 0 for d in D):
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(n) for n in input().split()]
stones = sum(A)
step = stones / (N*(1+N) /2 )
if step % 1 != 0:
    print("NO")
    exit()
 
D = [(A[(n+1)%N] - A[n%N]) - step for n in range(N)]
 
ng = [1 for d in D if -d % N != 0]
 
if len(ng):
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
n = int(input())
r = 0
flg = 0
a = list(map(int, input().split()))
if sum(a) % ((1 + n) * n / 2) == 0:
    x = int(sum(a) / ((1 + n) * n / 2))
    for i in range(n):
        d = a[i] - a[i - 1]
        if d % n != x:
            flg = -1
            break
        r += int((d - x) / (-n))
    if flg == 0 and r == x:
        flg = 1
        print('YES')
if flg == 0:
    print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
a = map(int, raw_input().strip().split())

identity = sum(xrange(1, N+1))
sum_a = sum(a)
if sum_a % identity:
    print 'NO'
else:
    lv = sum_a / identity
    if a[0]-a[-1] > lv:
        print "NO"
    else:
        for i in xrange(len(a)-1):
            d = a[i+1]-a[i]
            if d > lv:
                print 'NO'
                break
        else:
            print 'YES'

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
a = map(int, raw_input().strip().split())

if sum(a) % sum(xrange(1, N+1)):
    print 'NO'
else:
    total = a[0]-a[-1]
    for i in xrange(len(a)-1):
        total += a[i+1]-a[i]

    if not total:
        print 'YES'
    else:
        print 'NO'

Submission status: Wrong Answer

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

if sum(seq) % (int(1/2*n*(1+n))) == 0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
arr = map(int, raw_input().split())

tri = n * (n + 1) / 2
s = sum(arr)

if s % tri != 0:
    print "NO"
else:
    num = s / tri
    diff = map(lambda i: arr[(i + 1) % n] - arr[i], range(n))
    diff = map(lambda x: x - num, diff)
    poss = all(map(lambda x: x % n == 0, diff))
    poss = poss and sum(diff) == -n * num
    print "YES" if poss else "NO"

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
arr = map(int, raw_input().split())

tri = n * (n + 1) / 2
s = sum(arr)

if n == 1:
    print "YES"
elif s % tri != 0:
    print "NO"
else:
    num = s / tri
    diff = map(lambda i: arr[(i + 1) % n] - arr[i], range(n))
    diff = map(lambda x: x - num, diff)
    poss = all(map(lambda x: x % n == 0, diff))
    print "YES" if poss else "NO"

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
arr = map(int, raw_input().split())

tri = n * (n + 1) / 2
s = sum(arr)

if s % tri != 0:
    print "NO"
else:
    num = s / tri
    diff = map(lambda i: arr[(i + 1) % n] - arr[i], range(n))
    diff = map(lambda x: x - num, diff)
    poss = all(map(lambda x: x % n == 0, diff))
    print "YES" if poss else "NO"

Submission status: Wrong Answer

Solution code:
import sys

def stones(a, i):
    n = 0
    b = a[:]
    while n < N:
        j = a[n]
        k = i + j
        if k > N:
            k = k % N

        if a[k - 1] >= j:
            a[k - 1] -= j

        n += 1
    if a == b:
        return a
    else:
        return stones(a, i)

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

for i in range(1, N + 1):
    x = stones(list(A), i)
    #print(x)
    if sum(x) == 0:
        print('YES')
        sys.exit()
    i += 1

print('NO')

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().rstrip().split()]
    sum_A = sum(A)
    sum_N = (N + 1) * N // 2
    if sum_A % sum_N:
        print('NO')

    ope_num = sum_A // sum_N
    # diffs = [0] * N
    diffs = [r - l - ope_num for l, r in zip(A[:-1], A[1:])] + [A[0] - A[-1]]
    if all([d % N and d < 0 for d in diffs]):
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()