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:
from queue import Queue

  
def get_stone(A, i):
    success = 1
    tstone = [(n + (N-i))%N for n in range(N)]
    tstone[i] = 5
    result = []

    for a, t in zip(A, tstone):
        if a - t < 0:
            success = 0
            break
        else:
           result.append(a-t) 

    if success == 1:
        return result
    else:
        return None

        
N = int(input())
A = [int(n) for n in input().split()] 
q = Queue()
q.put(A)
ok = [0 for n in range(N)]


while not q.empty():
    tmpA = q.get()
    if tmpA == ok:
        q.put(tmpA)
        break
    for i in range(N):
        preA = get_stone(tmpA, i)
        if not preA == None:
            q.put(preA)

if q.empty():
    print("NO")
else:
    print("YES")

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:
        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)]
    print B
    if all(map(lambda b:B[0]==b,B)) and sum(A[:-1])%(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:]))
if tmp:
    print 'NO'
else:
    print 'YES'

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)]
    print B
    if all(map(lambda b:B[0]==b,B)) and sum(A[:-1])%N==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


for s in sa:
    if s % N != Nsum / np.sum(np.arange(N+1)[1:]):
        print 'NO'
        exit()
print 'YES'
exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

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

while True:
    k = n.argmin()
    n = np.hstack((n[k:], n[:k]))

    p = np.floor((n / j)).astype(int).min()

    if p == 0:
        print('NO')
        exit()

    n -= j * p

    if np.all(n == 0):
        print('YES')
        exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
vec = list(map(int,input().split()))
while 1:
    maxVal = max(vec)
    maxID = vec.index(maxVal)
    for i in range(maxID+1):
        vec[i] -= (n-(maxID-i))
    for j,i in enumerate(range(maxID+1,n),1):
        vec[i] -= j
    if sum(vec) == 0:
        print('YES')
        break
    elif min(vec) < 0:
        print('NO')
        break

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

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

  c = b-a
  if c % N != num:
    print('NO')
    exit()
  else:
    count += (num-c)//N

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

Submission status: Wrong Answer

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

while True:
    max_idx = a.index(max(a))
    for i in range(1, n+1):
        a[(max_idx+i)%n] -= i
    sum_res = sum(a)
    if sum_res == 0:
        print('YES')
        break
    elif sum_res <= -1:
        print('NO')
        break

Submission status: Wrong Answer

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

def readln(ch):
    _res = list(map(int,str(input()).split(ch)))
    return _res

def pend(f,n):
    a = [0 for i in range(0,n+1)]
    for i in range(1,n+1):
        a[i] =  (f[i] - f[i-1]) % n
        if a[i] != 0:
            return 'NO'
    return 'YES'

n = int(input())
a = readln(' ')
f = [0 for i in range(0,n)]
f[0] = a[0]-a[n-1]
for i in range(1,n):
    f[i] = a[i] - a[i-1]

f.append(f[0])
print(pend(f,n))

# sum-5x5 = f5
# sum-5x4 = f4
# sum-5x3 = f3
# sum-5x2 = f2
# sum-5x1 = f1

#f1-f2 = 5(x2-x1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

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

while True:
    k = n.argmin()
    n = np.hstack((n[k:], n[:k]))

    p = np.floor((n / j)).astype(int).min()

    if p == 0:
        print('NO')
        exit()

    n -= j * p

    if n.max() == 0:
        print('YES')
        exit()

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

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

  c = b-a
  if c % N != num:
    print('NO')
    exit()
  else:
    count -= (b-a-num)//N

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(raw_input())
    a = map(int, raw_input().split())
    s = sum(a)
    t = n * (n + 1) / 2
    if s % t:
        print "NO"
        return
    t = s / t
    a += [a[0]]
    b = [a[i+1] - a[i] - t for i in xrange(n)]
    c = [0] * (n + n)
    d = [0] * (n + n)
    for i, x in enumerate(b):
        if x % n:
            print "NO"
            return
        b[i] = -x / n
        c[i+n] += b[i]
    b += [0] * n
    k = 0
    s = 0
    for i in xrange(n + n):
        k += b[i]
        d[i] += s
        s += k
        k -= c[i]
        s -= c[i] * (n + 1)
    for i in xrange(n):
        if a[i] != d[i] + d[i+n]:
            print "NO"
            return
    print "YES"
main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

next(sys.stdin)
n = np.array(list(map(int, next(sys.stdin).split())))

while True:
    k = n.argmin()
    n = np.hstack((n[k:], n[:k]))
    p = np.floor((n / (np.arange(len(n)) + 1)).min()).astype(int)

    if p == 0:
        print('NO')
        exit()

    n -= (np.arange(len(n)) + 1) * p

    if n.max() == 0:
        print('YES')
        exit()

Submission status: Wrong Answer

Solution code:


N = int(input())
A = list(map(int, input().split()))
A.append(A[0])
B = [0 for _ in range(len(A)-1)]


for i in range(len(B)):
    B[i] = A[i+1] - A[i]

if len(set(B)) == 2:
    print('YES')
else:
    if len(set(B)) % 2 == 1:
        print('NO')
    else:
        print('YES')

Submission status: Wrong Answer

Solution code:


N = int(input())
A = list(map(int, input().split()))
A.append(A[0])
B = [0 for _ in range(len(A)-1)]


for i in range(len(B)):
    B[i] = A[i+1] - A[i]

if len(set(B)) == 2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
a = [int(x) for x in raw_input().split()]

def m():
	s = n * (n + 1) / 2
	sa = sum(a)
	if sa % s != 0:
		return False
	j = sa / s
	sj = 0
	for x, y in zip(a, a[1:] + [a[0]]):
		iN = j - (y - x)
		if iN % n != 0:
			return False
		i = iN / n
		sj += i
	if sj != j:
		return False
	return True

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

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(raw_input())
    a = map(int, raw_input().split())
    s = sum(a)
    t = n * (n + 1) / 2
    if s % t:
        print "NO"
        return
    t = s / t
    a += [a[0]]
    b = [a[i+1] - a[i] - t for i in xrange(n)]
    c = [0] * (n + n)
    d = [0] * (n + n)
    k = 0
    s = 0
    for i, x in enumerate(b):
        if x % n:
            print "NO"
            return
    print "YES"
main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i)%N for i in input().split()]
A.sort()
if A == [i for i in range(N)]:
	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)):
        print "YES"
    else:
        print "NO"

Submission status: Wrong Answer

Solution code:
N = input()
A = map(int, raw_input().split())
S = sum(A)
if S%(N*(N+1)/2)==0:
    c = S/(N*(N+1)/2)
    for i in range(N):
        A[i] -= c*(i+1)
    ans = "YES"
    for i in range(N):
        if (A[i]-A[(i+1)%N])%N!=0:
            ans = "NO"
    print ans
else:
    print "NO"

Submission status: Time Limit Exceeded

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

#s = int((n*(n-1))/2)
s = n*(n+1)//2
if sum_a%s!=0:
    print("NO")
else:
    times = sum_a//s
    stock = times
    ind = 0
    for _ in range(n):
        next_ind= (ind+1)%n
        now = a[ind]
        tsugi = a[next_ind]
        now += times
        while(tsugi!=now):
            now -= n
            stock -= 1
            if stock<0:
                print("NO")
                exit()      
        ind = next_ind
    if stock==0:
        print("YES")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

total = sum(A)
each = N*(N+1) // 2
if total % each != 0:
    NO()
    exit()
cnt = total // each

for i in range(cnt):
    idx = A.index(min(A))
    for j in range(idx, idx+N):
        sub = j - idx + 1
        j %= N
        A[j] -= sub
if all(a == 0 for a in A):
    YES()
else:
    NO()

Submission status: Time Limit Exceeded

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()
    while sum(a) != 0:
        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]
            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: Time Limit Exceeded

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: Time Limit Exceeded

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:
        if int(x)>=0:
            continue
    elif int(x)+1-m<=x<=int(x)+1+m:
        if int(x)+1>=0:
            continue
    else:
        flag=False
        break
if flag:
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

b = []
for i in range(n):
    a[i] *= -1
    b.append(a[i])

heapq.heapify(b)

while True:
    p = heapq.heappop(b)
    q = a.index(p)
    for i in range(n):
        a[q-i] += n-i
        if a[q-i]>0:
            print('NO')
            exit()
    if set(a) == {0}:
        print('YES')
        exit()
    b = [a[i] for i in range(n)]
    heapq.heapify(b)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lis=list(map(int,input().split()))
num=(n*(n+1))//2
if sum(lis)%num!=0:
  print("NO")
  exit()
ans=0
for i in range(n):
  if abs(lis[i]-lis[i-1]-sum(lis)//num)%n!=0:
    print("NO")
    exit()
  ans+=abs(lis[i]-lis[i-1]-sum(lis)//num)//n
if ans == sum(lis)//num:print("YES")
else:print("NO")

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lis=list(map(int,input().split()))
num=(n*(n+1))//2
if sum(lis)%num!=0:
  print("NO")
  exit()
li=[lis[i]-lis[i-1]-sum(lis)//num for i in range(n)]
ans=0
for k in range(n):
  if -li[k]%n!=0:
    print("NO")
    exit()
  ans+=-li[k]//n
if ans == sum(lis)//num:print("YES")
else:print("NO")

Submission status: Time Limit Exceeded

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

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

while a[0] > 0:
    temp = min(a)
    if temp < 0:
        print('NO')
        exit()
    p = a.index(min(a))
    for i in range(n):
        a[(p + i) % n] -= i + 1

if min(a) < 0 or sum(a) != 0:
    print('NO')
else:
    print('YES')

Submission status: Time Limit Exceeded

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] > v[biggest]:
			second_biggest = biggest
			biggest = i
		elif v[i] > v[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 min(v) < 0:
		print "NO"
		sys.exit()

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
num,flag,x = a.index(min(a)),True,float("inf")
while flag:
	a = a[num:]+a[:num]
	for i in range(n):
		a[i] = a[i]-(i+1)
		if x>a[i]: num,x = i,a[i]
		if x<0:
			flag = False
			break
	if all(a[j]==0 for j in range(n)): break
if flag: print("YES")
else: print("NO")

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
A = [int(x) for x in raw_input().split()]

trialList = [A] 

import copy
while len(trialList)>0:
    aOriginal = trialList.pop()
    if sum(aOriginal) == 0:
        print "YES"
        break
    for i in range(N):
        a = copy.deepcopy(aOriginal)
        isGood = True
        for j in range(1,N+1):
            a[(i+j)%N] -= j
            if a[(i+j)%N]<0:
                isGood = False
                break
        if isGood:
            trialList.append(a)
else:
    print "NO"

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(raw_input())
A = map(lambda x:int(x), raw_input().split())
A = np.asarray(A)

sub_vec = range(N)

while 1:
    ind = A.argmax()
    sub_vec_tmp = map(lambda x:x-ind if x-ind>0 else x-ind+N, sub_vec)
    
    #A = map(lambda a,b:a-b, A, sub_vec_tmp)
    A = A - sub_vec_tmp
    #print A, sub_vec_tmp
    if sum(map(lambda x:True if x<0 else False, A)):
        print 'NO'
        quit()
    if sum(A) == 0:
        print 'YES'
        break
    
"""
5
4 5 1 2 3
"""
"""
5
6 9 12 10 8
"""

Submission status: Time Limit Exceeded

Solution code:
import sys
N=int(input())
A=input().split(" ")
sum=0
for i in range(N):
    A[i]=int(A[i])
    sum+=A[i]

count=2*sum/(N*(N+1))

if count!=int(count):
    print("NO")
    sys.exit()

for i in range(int(count)):
    max_index=0
    max=0
    for j in range(N):
        if max<A[j]:
            max=A[j]
            max_index=j
    for j in range(N):
        A[(max_index+j+1)%N]-=(j+1)

for i in range(N):
    if A[i]!=0:
        print("NO")
        sys.exit()

print("YES")

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
while True:
	i = max(enumerate(A), key=lambda x:x[1])[0]
	if A[i]==0: break
	for j in range(1, N+1):
		ind = (i+j)%N
		A[ind] -= j
		if A[ind] < 0:
			print "NO"
			exit(0)
print "YES"

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input().rstrip())
 
boxes = map(int,raw_input().rstrip().split(" "))

empty_box_count = 0
failed = False

while True:
  max_box = max(boxes)
  max_index = boxes.index(max_box)
  #print max_box,max_index
  for i in xrange(n):
    index = (max_index - i)
    if index >= n:
      index -= n
    boxes[index] -= (n - i)
    if boxes[index] == 0:
      empty_box_count += 1
    if boxes[index] < 0:
      failed = True
  if failed or empty_box_count > 0:
    break

#print boxes
if empty_box_count == n:
  print "YES"
else:
  print "NO"

Submission status: Time Limit Exceeded

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

while s > 0:
    idx = l.index(max(l))
    for i in range(n, 0, -1):
         l[idx] -= i
         idx -= 1
         if idx == -1:
            idx = n -1
    s = sum(l)

for i in range(0, n):
    if l[i] != 0:
        print("NO")
        quit()
print("YES")

Submission status: Time Limit Exceeded

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

while a[0] > 0:
    m = 0
    mi = 0
    for i in range(len(a)):
        if m < a[i]:
            m = a[i]
            mi = i
    for i in range(len(a)):
        a[(mi + i + 1) % n] -= i + 1

x = 0
for i in range(len(a)):
    x |= a[i]
print("YES" if x == 0 else "NO")

Submission status: Time Limit Exceeded

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

while 0 not in a:
    m = 0
    mi = 0
    for i in range(len(a)):
        if m < a[i]:
            m = a[i]
            mi = i
    for i in range(len(a)):
        a[(mi + i + 1) % n] -= i + 1

x = 0
for i in range(len(a)):
    x |= a[i]
print("YES" if x == 0 else "NO")

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
inList = map(int, raw_input().split())
ans = "NO"
key = sum(range(1,N+1))
flag = True
tmpFlag = True
if(sum(inList)%key != 0):
    flag = False
if(max(inList) > min(inList)*N):
    flag = False
    
while(max(inList) > 0 and flag and tmpFlag):
    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: Time Limit Exceeded

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):
    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: Time Limit Exceeded

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: Time Limit Exceeded

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)]
    if(min(inList) < 0):
        break
    if(max(inList) == 0):
        ans = "YES"
print ans

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

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

while True:
    if np.all(n == 0):
        print('YES')
        break

    k = n.argmin()
    n = np.hstack((n[k:], n[:k]))

    d = ((n[1:] - n[0]) // (j[1:] - j[0])).min()
    p = (n // j).min()
    t = min(d + 1, p)

    if t > 0:
        n -= j * t
    else:
        print('NO')
        break

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

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):
        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: Time Limit Exceeded

Solution code:
N = int(raw_input())
a = [int(i) for i in raw_input().split(' ')]
while 1:
    max_indx = a.index(max(a))
    a = a[max_indx+1:]+a[0:max_indx+1]
    a = [b-(i+1) for (i,b) in enumerate(a)]
    if all([x == 0 for x in a]):
        print "YES"
        break
    elif any([x < 0 for x in a]):
        print "NO"
        break

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

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):
        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: Time Limit Exceeded

Solution code:
import sys
import numpy as np

if __name__=="__main__":
    N = int(input().replace("\n",""))
    numbers = np.array(list((map(int, input().replace("\n","").split(" ")))))
    if( np.sum(numbers) % (np.sum(range(N)) + N) != 0):
        print("NO")
        sys.exit(0)
    else:
        hiku_kaisu = int(sum(numbers) / (sum(range(N)) + N))
    cp_numbers = np.roll(numbers, -1)
    sabun = cp_numbers - numbers
    arieru_sabun = hiku_kaisu - N*np.array(range(hiku_kaisu+1))
    sabun_count = 0
    for s in sabun:
        index = np.where(arieru_sabun == s)[0]
        if(index.size == 0):
            print("NO")
            break
        else:
            sabun_count += index[0]
    if(sabun_count == hiku_kaisu):
        print("YES")

Submission status: Time Limit Exceeded

Solution code:
def roll(A, i):
    for j in range(len(A)+1):
        A[(i+j)%(len(A))] -= j
    return all([a >= 0 for a in A])

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

sum_N = 1 / 2 * N * (N+1)
if sum(A)%sum_N != 0:
    print('NO')
else:
    flag = True
    while flag:
        diff = A[-1] - A[-2]
        for i, a in enumerate(A):
            new_diff = a - A[i-1]
            if new_diff > diff:
                flag = roll(A, i-2)
                break
            if new_diff < diff:
                flag = roll(A, i-1)
                break
            diff = new_diff
        if not flag:
            print('NO')
            break
        if all([a == 0 for a in A]):
            print('YES')
            break

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

if __name__=="__main__":
    N = int(input().replace("\n",""))
    numbers = np.array(list((map(int, input().replace("\n","").split(" ")))))
    if( np.sum(numbers) % (np.sum(range(N)) + N) != 0):
        print("NO")
        sys.exit(0)
    else:
        hiku_kaisu = int(sum(numbers) / (sum(range(N)) + N))
    cp_numbers = np.roll(numbers, -1)
    sabun = cp_numbers - numbers
    arieru_sabun = [hiku_kaisu - N*x for x in range(hiku_kaisu+1)]

    sabun_count = 0
    for s in sabun:
        if(s in arieru_sabun):
            index = arieru_sabun.index(s)
            sabun_count += index
        else:
            print("NO")
            break
    if(sabun_count == hiku_kaisu):
        print("YES")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

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

while True:
    k = n.argmin()
    n = np.hstack((n[k:], n[:k]))

    if np.all(n >= j):
        n -= j
    elif np.all(n == 0):
        print('YES')
        break
    else:
        print('NO')
        break

Submission status: Time Limit Exceeded

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

def search(a):
    for i in range(1, N):
        if a[i - 1] > a[i]:
            return i
    return 0

def sub(a):
    fin = True
    for i in range(N):
        if a[i] < 0:
            return False
        elif a[i] > 0:
            fin = False
    
    if fin:
        return True
    
    t = search(a)
    for i in range(N):
        a[(t + i) % N] -= i + 1

    return sub(a)

if sub(A):
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

Solution code:
import sys

if __name__=="__main__":
    N = int(input().replace("\n",""))
    numbers = list(map(int, input().replace("\n","").split(" ")))
    if( sum(numbers) % (sum(range(N)) + N) != 0):
        print("NO")
        sys.exit(0)
    else:
        hiku_kaisu = int(sum(numbers) / (sum(range(N)) + N))
    cp_numbers = numbers[:]
    cp_numbers.append(cp_numbers[0])
    cp_numbers.pop(0)
    sabun = [cp_numbers[i] - numbers[i] for i in range(len(numbers))]
    arieru_sabun = [hiku_kaisu - N*x for x in range(hiku_kaisu+1)]

    sabun_count = 0
    for s in sabun:
        if(s in arieru_sabun):
            index = arieru_sabun.index(s)
            sabun_count += index
        else:
            print("NO")
            break
    if(sabun_count == hiku_kaisu):
        print("YES")