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

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 = sum(range(1, N + 1))
    if sum_A % sum_N:
        print('NO')
        return

    ope_num = sum_A / sum_N
    diffs = [0] * N
    diffs[:-1] = [r - l for l, r in zip(A[:-1], A[1:])]
    diffs[-1] = A[0] - A[-1]
    sums = 0
    for d in [(diff - ope_num) / N for diff in diffs]:
        if d != int(d):
            print('NO')
            return
        sums -= int(d)
    if sums == ope_num:
        print('YES')
        return
    print("NO")


if __name__ == '__main__':
    main()

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 = sum(range(1, N + 1))
    if sum_A % sum_N:
        print('NO')
        return

    ope_num = sum_A / sum_N
    diffs = [0] * N
    diffs[:-1] = [r - l for l, r in zip(A[:-1], A[1:])]
    diffs[-1] = A[0] - A[-1]
    sums = 0
    for d in [(diff - ope_num) / N == 0 for diff in diffs]:
        if d != int(d):
            print('NO')
            return
        sums += int(d)
    if sums == ope_num:
        print('YES')
    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 = sum(range(1, N + 1))
    if sum_A % sum_N:
        print('NO')
        return

    ope_num = sum_A / sum_N
    diffs = [0] * N
    diffs[:-1] = [r - l for l, r in zip(A[:-1], A[1:])]
    diffs[-1] = A[0] - A[-1]
    if all([(diff - ope_num) % N == 0 for diff in diffs]):
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()

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 = sum(range(1, N + 1))
    if sum_A % sum_N:
        print('NO')
        return

    ope_num = sum_A / sum_N
    diffs = [r - l for l, r in zip(A[:-1], A[1:])]
    if all([(diff - ope_num) % N == 0 for diff in diffs]):
        print("YES")
    else:
        print("NO")



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from functools import reduce
def main():
    N = int(input())
    A = [int(a) for a in input().rstrip().split()]
    sums = sum(A)
    aaa = reduce(lambda x, y: x+y, range(1, N+1))
    if sums % aaa:
        print('NO')
        return
    diff = [0] * N
    diff[:-1] = [r - l for l, r in zip(A[:-1], A[1:])]
    diff[-1] = int(A[0]) - int(A[-1])
    iter_num = max(diff)
    minus_gap = N - 1
    minus_vals = [d for d in diff if d < 0]
    if len(minus_vals) == 0:
        print('YES')

    minus_num = 0
    for mv in minus_vals:
        if (iter_num - mv) % N:
            print('NO')
            return
        minus_num +=int((iter_num - mv) / N)
        if minus_num > iter_num:
            print('NO')
    if minus_num == iter_num:
        print('YES')
        return
    else:
        print('NO')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(raw_input().split()[0])
A=map(int,raw_input().split())
k=sum(A)/(N*(N+1)/2)
D=[A[(i+1)%N]-A[i]-k for i in range(0,N)]
print "YES" if all([(d%N==0 and d<0) or d==0  for d in D]) and sum(D)+N*k==0 else "NO"

Submission status: Wrong Answer

Solution code:
N=int(raw_input().split()[0])
A=map(int,raw_input().split())
k=sum(A)/(N*(N+1)/2)
D=[A[(i+1)%N]-A[i]-k for i in range(0,N)]
print "YES" if all([(d%N==0 and d<0) or d==0  for d in D]) and sum(D)+N==0 else "NO"

Submission status: Wrong Answer

Solution code:
N=int(raw_input().split()[0])
A=map(int,raw_input().split())
k=sum(A)/(N*(N+1)/2)
D=[A[(i+1)%N]-A[i]-k for i in range(0,N)]
print "YES" if all([(d%N==0 and d<0) or d==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:
    up, down = None, None
    change = 0
    for i in xrange(len(a)-1):
        dif = a[i+1]-a[i]
        if not dif:
            print 'NO'
            break

        if a[i+1] > a[i]:
            if not change:
                change = 1
            elif change == 2:
                print 'NO'
                break
                
            if up!=None and dif != up:
                print 'NO'
                break
            else:
                up = dif
        else:
            if not change:
                change = 2
            elif change == 1:
                print 'NO'
                break
                
            if a[i + 1] < a[i]:
                if down != None and dif != down:
                    print 'NO'
                    break
                else:
                    down = dif
    else:
        print 'YES'

Submission status: Wrong Answer

Solution code:
N=int(raw_input().split()[0])
A=map(int,raw_input().split())
k=sum(A)/(N*(N+1)/2)
D=[A[(i+1)%N]-A[i]-k for i in range(0,N)]
print "YES" if all([d%N==0 and d<=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:
    up, down = None, None
    for i in xrange(len(a)-1):
        dif = a[i+1]-a[i]
        if not dif:
            print 'NO'
            break
            
        if a[i+1] > a[i]:
            if up!=None and dif != up:
                print 'NO'
                break
            else:
                up = dif
        else:
            if a[i + 1] < a[i]:
                if down != None and dif != down:
                    print 'NO'
                    break
                else:
                    down = dif
    else:
        print 'YES'

Submission status: Wrong Answer

Solution code:
N=int(raw_input().split()[0])
A=map(int,raw_input().split())
k=sum(A)/(N*(N+1)/2)
print "YES" if all([((A[(i+1)%N]-A[i])-k)%N==0 for i in range(0,N)]) 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:
    up, down = None, None
    for i in xrange(len(a)-1):
        dif = a[i+1]-a[i]
        if a[i+1] > a[i]:
            if up!=None and dif != up:
                print 'NO'
                break
            else:
                up = dif
        else:
            if a[i + 1] < a[i]:
                if down != None and dif != down:
                    print 'NO'
                    break
                else:
                    down = dif
    else:
        print 'YES'

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

n = int(next(sys.stdin))
a = np.array(list(map(int, next(sys.stdin).split())))
j = np.arange(n) + 1

if np.any(a.sum() % j.sum() > 0):
    print('NO')
    exit()

k = a.sum() // j.sum()
if np.all((k - np.hstack((a[1:] - a[:-1], a[:1] - a[-1:]))) % n == 0):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

n = int(next(sys.stdin))
a = np.array(list(map(int, next(sys.stdin).split())))
j = np.arange(n) + 1

if np.any(a.sum() % j.sum() > 0):
    print('NO')
    exit()

k = a.sum() // j.sum()
if np.all((k - (a[1:] - a[:-1])) % n == 0):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

sum=0
for rr in R:
    sum+=rr
ss=(1+N)*N/2
if (sum%ss)==0:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
inList = map(int, raw_input().split())
ans = "NO"
key = sum(range(1,N+1))
flag = True
if(sum(inList)%key != 0):
    flag = False
if(max(inList) > min(inList)*(N-1)):
    flag = False
while(max(inList) > 0 and flag):
    if(min(inList) < 0):
        break
    minId = inList.index(min(inList))
    inList = [inList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(inList)==0 and min(inList)==0):
    ans = "YES"
print ans

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
inList = map(int, raw_input().split())
ans = "NO"
while(max(inList) > 0):
    if(min(inList) < 0):
        break
    minId = inList.index(min(inList))
    inList = [inList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(inList)==0):
    ans = "YES"
print ans

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
inList = map(int, raw_input().split())
ans = "NO"
while(max(inList)>0):
    minId = inList.index(min(inList))
    inList = [inList[(minId + i)%N] - i - 1 for i in range(N)]
    print inList
    if(min(inList) < 0):
        break
    if(max(inList) == 0):
        ans = "YES"
print ans

Submission status: Wrong Answer

Solution code:
from math import *
from collections import Counter

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

diff = Counter()
diff_list = []
for j in range(len(a)):
    if j == len(a) - 1:
        d = int(fabs(a[j] - a[0]))
        diff[d] += 1
        diff_list.append(d)
    else:
        d = int(fabs(a[j+1] - a[j]))
        diff[d] += 1
        diff_list.append(d)

#print(diff)
#print(diff_list)

for a in range(diff_list.index(max(diff_list))):
    diff_list.append(diff_list.pop(0))
#print(diff_list)

m = max(diff_list)
comp = []
for x in range(n-m):
    comp.append(m)
for y in range(m):
    comp.append(n-m)

if diff_list == comp:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
inList = map(int, raw_input().split())
def checkList(inList, N):
    minId = inList.index(min(inList))
    for i in range(N):
        inList[(minId + i)%N] -= i + 1
    if(max(inList) == 0):
        return "YES"
    if(min(inList) < 0):
        return "NO"
    return checkList(inList, N)
print checkList(inList, N)

Submission status: Wrong Answer

Solution code:
from math import *
from collections import Counter

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

diff = Counter()
for j in range(len(a)):
    if j == len(a)-1:
        diff[int(fabs(a[j] - a[0]))] += 1
    else:
        diff[int(fabs(a[j+1] - a[j]))] += 1

# print(diff)

for x in range(n):
    if diff[x] != (n-x) and diff[x] != 0:
        print('NO')
        exit()
print('YES')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
m = N*(N+1)//2
if (sum(A) % m) or (min(A) < sum(A)//m) or (max(A) > sum(A)*N//m):
	print("NO")

else:
	l = N // m
	B = [A[i] - A[i-1] for i in range(N)]
	if not sum(B):
		print("YES")
	else:
		print("NO")

Submission status: Wrong Answer

Solution code:
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N = int(input())
    A = [int(i) for i in input().split()]

    if N == 1:
        print('YES')
        return None

    if sum(A) % (N * (N+1) // 2) != 0:
        print('NO')
        return None
    elif max(A) < N:
        print('NO')
    else:
        K = (sum(A) // (N * (N+1) // 2)) % N
        gaps = set((A[(i + 1) % N] - A[i]) % N for i in range(N))

        if len(gaps) > 1:
            print('NO')
        elif max(A) - min(A) > K * (N-1):
            print('NO')
        else:
            gap = (A[1] - A[0]) % N
            if gap == K:
                print('YES')
            else:
                print('NO')

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
inList = map(int, raw_input().split())
def checkList(inList, N):
    maxId = inList.index(max(inList))
    for i in range(N):
        inList[(maxId-i)%N] -= N - i
    if(max(inList) == 0 and min(inList) == 0):
        return "Yes"
    if(min(inList) < 0):
        return "No"
    return checkList(inList, N)
print checkList(inList, N)

Submission status: Wrong Answer

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

def get_inv_diff(a):
    prev_val = a[-1]
    idx_lst = []
    for idx, cur_val in enumerate(a):
        # print("cur,pre",cur_val,prev_val)
        if cur_val <= prev_val:
            idx_lst.append(idx)
            if idx != 0 and prev_val - cur_val > 3:
                for i in range(prev_val - cur_val / 4):
                    idx_lst.append(idx)
            # print("detect!")
        prev_val = cur_val
    return idx_lst

def check_sum(a):

    sum = 0
    for val in a:
        sum += val
    cmp = [i+1 for i in range(n)]
    cmp_sum = 0
    for val in cmp:
        cmp_sum += val

    if sum % cmp_sum != 0:
        return -1
    else:
        result = sum / cmp_sum
        return result

result = check_sum(a)
if result == -1:
    print("NO")
else:
    indices = get_inv_diff(a)
    if len(indices) != result:
        print("NO")
    else:
        # print("indices:", indices)
        test_lst = [0 for i in range(n)]
        for begin_idx in indices:
            for count in range(n):
                # print("count:",count)
                test_lst[(begin_idx + count) % n] += count+1

            # print(test_lst)

        if test_lst == a:
            print("YES")
        else:
            print("NO")

Submission status: Wrong Answer

Solution code:
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N = int(input())
    A = [int(i) for i in input().split()]

    if N == 1:
        print('YES')
        return None

    if sum(A) % (N * (N+1) // 2) != 0:
        print('NO')
        return None
    elif max(A) < N:
        print('NO')
    else:
        K = (sum(A) // (N * (N+1) // 2)) % N
        gaps = set((A[(i + 1) % N] - A[i]) % N for i in range(N))

        if len(gaps) > 1:
            print('NO')
        else:
            gap = (A[1] - A[0]) % N
            if gap == K:
                print('YES')
            else:
                print('NO')

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
a=map(int,raw_input().split())
sn=n*(n+1)/2
if sum(a)%sn!=0:
    print("NO")
    exit()
c=sum(a)/sn
sa=sorted(a)
if sa[0]<c or sa[n-1]>n*c:
    print("NO")
    exit()
for i in xrange(n):
    if a[i]-a[(i+1)%n]<0:
        if abs(a[i]-a[(i+1)%n])>c:
            print("NO")
            exit()
    elif a[i]-a[(i+1)%n]>0:
        if abs(a[i]-a[(i+1)%n])>c*(n-1):
            print("NO")
            exit()
print("YES")

Submission status: Wrong Answer

Solution code:
from operator import sub

N = int(input())
data = list(map(int, input().split()))
step = N * (N+1) // 2
total = sum(data)
#print("-->", total, step)
if total % step:
  print("NO")
else:
  K = total // step
  #print("-->", total, step, K)
  datar = [data[i % N] for i in range(-1, N)] 
  delta = list(map(sub, datar[1:], datar))
  #print(*delta)
  #print("-->", *list(map(lambda x:(K-x) % N, delta)))
  #print("-->", *list(map(lambda x:(K-x) // N, delta)))
  if any(map(lambda x:(K-x) % N, delta)):
    print("NO")
  else:    
    ops = list(map(lambda x:(K-x) // N, delta))
    if sum(ops) == K:
      for i, v in enumerate(data[0:1]):
        if (i & 1):
          vv = sum([ops[(i-k) % N] * (k+1) for k in range(N)])
          if v != vv:        
            print("NO")
            break
      else:    
        print("YES")
    else:
      print("NO")

Submission status: Wrong Answer

Solution code:
from operator import sub

N = int(input())
data = list(map(int, input().split()))
step = N * (N+1) // 2
total = sum(data)
#print("-->", total, step)
if total % step:
  print("NO")
else:
  K = total // step
  #print("-->", total, step, K)
  datar = [data[i % N] for i in range(-1, N)] 
  delta = list(map(sub, datar[1:], datar))
  #print(*delta)
  #print("-->", *list(map(lambda x:(K-x) % N, delta)))
  #print("-->", *list(map(lambda x:(K-x) // N, delta)))
  if any(map(lambda x:(K-x) % N, delta)):
    print("NO")
  else:    
    ops = list(map(lambda x:(K-x) // N, delta))
    if sum(ops) == K:
      for i, v in enumerate(data[0:min(2,N)]):
        vv = sum([ops[(i-k) % N] * (k+1) for k in range(N)])
        if v != vv:        
          print("NO")
          break
      else:    
        print("YES")
    else:
      print("NO")

Submission status: Wrong Answer

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

if max(a) >= len(a) and sum(a) % (n * (n + 1) / 2) == 0:
    for j in xrange(n + 1):
        i = a.index(max(a))
        a[(i + j) % n] -= j
    if not 0 in a:
        print 'YES'
else:
    print 'NO'

Submission status: Wrong Answer

Solution code:
from operator import sub

N = int(input())
data = list(map(int, input().split()))
step = N * (N+1) // 2
total = sum(data)
#print("-->", total, step)
if total % step:
  print("NO")
else:
  K = total // step
  #print("-->", total, step, K)
  datar = [data[i % N] for i in range(-1, N)] 
  delta = list(map(sub, datar[1:], datar))
  #print(*delta)
  #print("-->", *list(map(lambda x:(K-x) % N, delta)))
  #print("-->", *list(map(lambda x:(K-x) // N, delta)))
  if any(map(lambda x:(K-x) % N, delta)):
    print("NO")
  else:    
    ops = list(map(lambda x:(K-x) // N, delta))
    if sum(ops) == K:
      for i, v in enumerate(data[0:1]):
        vv = sum([ops[(i-k) % N] * (k+1) for k in range(N)])
        if v != vv:        
          print("NO")
          break
      else:    
        print("YES")
    else:
      print("NO")

Submission status: Wrong Answer

Solution code:
if __name__=="__main__":
    N=int(raw_input().split()[0])
    A=map(int,raw_input().split())
    A.append(A[0])
    B=[(A[i+1]-A[i])%N for i in range(0,N)]
    if all(map(lambda b:B[0]==b,B)) and sum(A[:-1])%(N*(N+1)/2)==0 and sum(B)%N==0:
        print "YES"
    else:
        print "NO"

Submission status: Wrong Answer

Solution code:
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N = int(input())
    A = [int(i) for i in input().split()]

    if N == 1:
        print('YES')
        return None

    if sum(A) % (N * (N+1) // 2) != 0:
        print('NO')
        return None
    else:
        K = (sum(A) // (N * (N+1) // 2)) % N
        gaps = set((A[(i + 1) % N] - A[i]) % N for i in range(N))

        if len(gaps) > 1:
            print('NO')
        else:
            gap = (A[1] - A[0]) % N
            if gap == K:
                print('YES')
            else:
                print('NO')

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
nums = input().split()
nums = [int(nums[i]) for i in range(0, len(nums))]

mx = max(nums)
mn = min(nums)
if mx % n == 0:
    if mx / n > mn:
        print("NO")
        quit()
else:
    if mx / n + 1 > mn:
        print("NO")
        quit()

s = (1 + n) * n / 2
sum = 0
for i in range(0, len(nums)):
    sum += nums[i]


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

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
A = [int(n) for n in input().split()]

if N == 1:
    print ('YES')
    sys.exit()


I = sorted(range(len(A)), key=A.__getitem__)
if A[I[0]] == A[I[N-1]]:
    if A[0] % N*(N+1)/2 == 0:
        print('YES')
    else :
        print('NO')
    sys.exit()

i = 0
samecnt = 0
while A[i] > 0:
    samecnt += 1
    while A[(i-1) % N] > A[i]:
        samecnt = 0
        for j in range(1,N+1):
            A[(i+j-1) % N] -= j
    if samecnt > N:
        if A[0] % N*(N+1)/2 == 0:
            print('YES')
            sys.exit()
        else:
            print('NO')
            sys.exit()
    i = (i+1) % N 

if A == [0] * N:
    print ('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
nums = input().split()
nums = [int(nums[i]) for i in range(0, len(nums))]

mx = max(nums)
mn = min(nums)
if mx % n == 0:
    if mx / n > mn:
        print("NO")
        quit()
else:
    if mx / n + 1 > mn:
        print("NO")
        quit()

max_div = 0
if mx % n == 0:
    max_div = mx / n
else:
    max_div = mx / n + 1

for i in range(0, len(nums) - 1):
    if nums[i] - nums[i + 1] > (n - 1) * max_div or nums[i + 1] - nums[i] > max_div:
        print("NO")
        quit()

s = (1 + n) * n / 2
sum = 0
for i in range(0, len(nums)):
    sum += nums[i]


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

Submission status: Wrong Answer

Solution code:
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    if sum(A) % (N * (N+1) // 2) != 0:
        print('NO')
        return None
    else:
        gaps = set((A[(i + 1) % N] - A[i]) % N for i in range(N))

        if len(gaps) > 1:
            print('NO')
        else:
            print('YES')

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = input()
A = map(int, raw_input().split())

min_m = (max(A)-1)/n + 1
max_m = min(A)
if max_m < min_m:
    print "NO"
    exit()

B = [A[(i+1) % n] - A[i] for i in xrange(n)]
C = Counter(B)

ans = False
for m in xrange(min_m, max_m+1):
    x = 0
    f = True
    for k, v in C.items():
        if (m-k) % n != 0:
            f = False
            break
        x += (m-k)/n * v

    if not f:
        continue
    if x == m:
        ans = True
        break

print "YES" if ans else "NO"

Submission status: Wrong Answer

Solution code:

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

def get_inv_diff(a):
    prev_val = a[-1]
    idx_lst = []
    for idx, cur_val in enumerate(a):
        # print("cur,pre",cur_val,prev_val)
        if cur_val <= prev_val:

            idx_lst.append(idx)
            # print("detect!")
        prev_val = cur_val
    return idx_lst

def check_sum(a):

    sum = 0
    for val in a:
        sum += val
    cmp = [i+1 for i in range(n)]
    cmp_sum = 0
    for val in cmp:
        cmp_sum += val

    if sum % cmp_sum != 0:
        return False
    return True

if check_sum(a) == False:
    print("NO")
else:
    indices = get_inv_diff(a)
    # print("indices:", indices)
    if indices == []:
        print("YES")
    else:
        test_lst = [0 for i in range(n)]
        for begin_idx in indices:
            for count in range(n):
                # print("count:",count)
                test_lst[(begin_idx + count) % n] += count+1

            # print(test_lst)

        if test_lst == a:
            print("YES")
        else:
            print("NO")

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
if max(a) >= len(a) and sum(a) % (n * (n + 1) / 2) == 0:
    print 'YES'
else:
    print 'NO'

Submission status: Wrong Answer

Solution code:
from operator import sub

N = int(input())
data = list(map(int, input().split()))
step = N * (N+1) // 2
total = sum(data)
#print("-->", total, step)
if total % step:
  print("NO")
else:
  K = total // step
  #print("-->", total, step, K)
  datar = [data[i % N] for i in range(-1, N)] 
  delta = list(map(sub, datar[1:], datar))
  #print(*delta)
  #print("-->", *list(map(lambda x:(K-x) % N, delta)))
  #print("-->", *list(map(lambda x:(K-x) // N, delta)))
  if any(map(lambda x:(K-x) % N, delta)):
    print("NO")
  else:    
    ops = list(map(lambda x:(K-x) // N, delta))
    if sum(ops) == K:
      print("YES")
    else:
      print("NO")

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().rstrip().split()]
    diff = [0] * N
    diff[:-1] = [r - l for l, r in zip(A[:-1], A[1:])]
    diff[-1] = int(A[0]) - int(A[-1])
    iter_num = max(diff)
    minus_gap = N - 1
    minus_vals = [d for d in diff if d < 0]
    if len(minus_vals) == 0:
        print('YES')
        return

    minus_num = 0
    for mv in minus_vals:
        if (iter_num - mv) % N:
            print('NO')
            return
        minus_num +=int((iter_num - mv) / N)
        if minus_num > iter_num:
            print('NO')
    if minus_num == iter_num:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
if len(list(set(a))) != len(a) and sum(a) % (n * (n + 1) / 2) == 0:
    print 'YES'
else:
    print 'NO'

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
nums = input().split()
nums = [int(nums[i]) for i in range(0, len(nums))]

mx = max(nums)
mn = min(nums)
if mx / n > mn:
    print("NO")
    quit()

s = (1 + n) * n / 2
sum = 0
for i in range(0, len(nums)):
    sum += nums[i]


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

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(raw_input())
n = np.array(map(int, raw_input().split()))

Nsum = np.sum(n)

if Nsum % np.sum(np.arange(N+1)[1:]):
    print 'NO'
    exit()
sa = np.append(n[1:], n[0]) - n

tmp = np.sum(sa % N != (Nsum / np.sum(np.arange(N+1)[1:]))%N)
tmp2 = np.sum(np.abs(sa) / N > (N-1)*Nsum / np.sum(np.arange(N+1)[1:]))
if tmp + tmp2:
    print 'NO'
else:
    print 'YES'

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
if sum(a) % (n * (n + 1) / 2) == 0:
    print 'YES'
else:
    print 'NO'

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(raw_input())
n = np.array(map(int, raw_input().split()))

Nsum = np.sum(n)

if Nsum % np.sum(np.arange(N+1)[1:]):
    print 'NO'
    exit()
sa = np.append(n[1:], n[0]) - n

tmp = np.sum(sa % N != (Nsum / np.sum(np.arange(N+1)[1:]))%N)
tmp2 = 0#np.sum(np.abs(sa) / N > (N-1)*Nsum / np.sum(np.arange(N+1)[1:]))
if tmp + tmp2:
    print 'NO'
else:
    print 'YES'

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
aa = map(int, raw_input().split())
j = 0
min_a = float('inf')

suma = sum(range(1,n+1))
flag = True
for i,a in enumerate(aa):
    if min_a > a:
        min_a = a
        next_j = i

    if a < suma:
        flag = False

if flag == True:
    aa = map(lambda x: x-suma, aa)

while True:
    j = next_j
    for (i,a) in enumerate(aa):
        k = j+i
        if k >= n:
            k -= n
        aa[k] -= i+1
        
        if aa[k] < min_a:
            min_a = aa[k]
            next_j = k

    if min_a <= 0:
        break

flag = True
for a in aa:
    if a != 0:
        flag = False
        break

if flag == True:
    print 'YES'
else:
    print 'NO'

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(raw_input())
n = np.array(map(int, raw_input().split()))

Nsum = np.sum(n)

if Nsum % np.sum(np.arange(N+1)[1:]):
    print 'NO'
    exit()
sa = np.append(n[1:], n[0]) - n

tmp = np.sum(sa % N != Nsum / np.sum(np.arange(N+1)[1:]))
tmp2 = np.sum(np.abs(sa) / N > (N-1)*Nsum / np.sum(np.arange(N+1)[1:]))
if tmp + tmp2:
    print 'NO'
else:
    print 'YES'

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
nums = input().split()
nums = [int(nums[i]) for i in range(0, len(nums))]
s = (1 + n) * n / 2
sum = 0
for i in range(0, len(nums)):
    sum += nums[i]
if sum % s == 0:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

while min(a) > 0:
    mark = a.index(max(a))
    for i in range(mark):
        a.append(a.pop(0))
    for j in range(len(a)):
        a[j] -= j

    if min(a) == 0:
        print('YES')
    elif min(a) < 0:
        print('NO')

Submission status: Wrong Answer

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

tn = N*(N+1)//2
ta = sum(A)


if ta % tn != 0:
  print('NO')
  exit()

num = ta // tn

count = 0
seq = [0]*N

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

  c = b-a - num
  if c % N != 0:
    print('NO')
    exit()
  else:
    t = -c//N
    seq[i] = t
    count += t

if count != num:
  print('NO')

temp = 0
for i,s in enumerate(seq):
  temp += (N-i)*s


for i in range(N):
  i -= 1
  if A[i] != temp:
    print('NO')
    exit()

  temp += num
  temp -= N*seq[i+1]

print('YES')

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
a=map(int,raw_input().split())
sn=n*(n+1)/2
sa=sorted(a)
c=sum(a)/sn
if sa[0]<c or sa[n-1]>n*c:
    print("NO")
    exit()
if sum(a)%sn==0:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

while True:
    sum_res = 0
    min_idx = a.index(min(a))
    for i in range(1, n+1):
        a[(min_idx+i-1)%n] -= i
        sum_res += a[(min_idx+i-1)%n]

    if sum_res == 0:
        print('YES')
        break
    elif sum_res <= -1:
        print('NO')
        break

Submission status: Wrong Answer

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

def get_inv_diff(a):
    prev_val = -1
    idx_lst = []
    for idx, cur_val in enumerate(a):
        # print("cur,pre",cur_val,prev_val)
        if cur_val <= prev_val:
            idx_lst.append(idx)
            # print("detect!")
        prev_val = cur_val
    return idx_lst

indices = get_inv_diff(a)
test_lst = [0 for i in range(n)]
for begin_idx in indices:
    for count in range(n):
        # print("count:",count)
        test_lst[(begin_idx + count) % n] += count+1
    # print(test_lst)

if test_lst == a or indices == []:
    print("YES")
else:
    print("NO")