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: Accepted

Solution code:
def solve(ar):
  n = len(ar)
  if sum(ar) % (n * (n+1) // 2) != 0:
    return False
  l = sum(ar) // (n * (n+1) // 2)
  ar2 = []
  for i in range(n-1):
    if i == 0:
      ar2.append(ar[0])
    else:
      ar2.append(ar[i] - ar[i-1] - l)

  b = [0]
  for i in range(1, n-1):
    if ar2[i] % n != 0:
      return False
    bi = - ar2[i] // n
    if bi < 0:
      return False
    b.append(bi)

  a = ar[0]
  a2 = l
  for i in range(1, n-1):
    a -= b[i] * (n-i+1)
    a2 -= b[i]

  bn = a - a2
  b0 = a2 - bn
  if bn < 0 or b0 < 0:
    return False

  return True

n = int(input())
ar = [int(x) for x in input().split()]
if solve(ar):
  print("YES")
else:
  print("NO")

Submission status: Accepted

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')
        return

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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()]
    K, r = divmod(sum(A), N * (N+1) // 2)

    if r != 0:
        print('NO')
        return None

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

    for i in range(N):
        if dif[i] > K or (K - dif[i]) % N != 0:
            print('NO')
            return None

    print('YES')


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

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 or c > 0:
    print('NO')
    exit()
  else:
    t = -c//N
    seq[i] = t
    count += t

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

Submission status: Accepted

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

s = sum(aa)
remove = (n+1) * n // 2
if s % remove != 0:
    print('NO')
else:
    k = s // remove
    diffs = [aa[i+1] - aa[i] for i in range(n-1)] + [aa[0] - aa[-1]]
    diffs = [d - k for d in diffs]
    if all(d <= 0 and d % n == 0 for d in diffs):
        print('YES')
    else:
        print('NO')

Submission status: Accepted

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

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

def pend(x,f,n):
    b = [0 for i in range(0,n+1)]
    for i in range(1,n+1):
        tmp =  f[i] - f[i-1]
        if tmp % n != 0:
            return 'NO'
        b[i] = -(tmp // n)
    b[0] = 0
    k = 0
    l = 0
    for i in range(0,n):
        b[i] = b[i-1] + b[i]
        k = k + n - i
        l = l + (n - i) * b[i]
    x = x - l
    if x < 0 : return 'NO'
    if x % k > 0: return 'NO'
    a[0] = x // k
    for i in range(1,n):
        a[i] = a[0] + b[i]
    for i in range(0,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(a[n-1],f,n))
# an-1 = nx1+n-1x2

Submission status: Accepted

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 if s > 0 else 0
        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: Accepted

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 or iN < 0:
			return False
		i = iN / n
		sj += i
	if sj != j:
		return False
	return True

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
    n = II()
    a = LI()
    nn = n*(n+1)//2
    s = sum(a)
    if s%nn != 0:
        return "NO"
    k = s//nn
    km = k%n
    c = 0
    for i in range(n):
        t = a[i]-a[i-1]
        if t % n != km:
            return "NO"
        if t > k:
            return "NO"
        kt = k-t
        if kt%n != 0:
            return "NO"
        c += kt//n
    if c == k:
        return "YES"
    return 'NO'


print(main())

Submission status: Accepted

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-1):
        t = A[i]-A[(i+1)%N]
        if t<0 or t%N!=0:
            ans = "NO"
    print ans
else:
    print "NO"

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
t = n * (n + 1) // 2
s = sum(a)
if s % t:
    print('NO')
else:
    c = s // t
    b = [0] * n
    for i in range(n):
        b[i] = a[i] - a[i - 1] - c
    for i in range(n):
        if b[i] % n or k < 0:
            print('NO')
            break
    else:
        print('YES')

Submission status: Runtime Error

Solution code:
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.22 22:36:27
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    ll n; cin >> n;
    vector<int> a(n),b(n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    if (sum % (n * (n + 1) / 2) != 0) {
        puts("NO");
        return 0;
    }
    ll k = sum / (n * (n + 1) / 2);
    for (int i = 0; i < n; i++) {
        b[i] = a[(i+1)%n] - a[i];
        b[i] -= k;
        b[i] = -b[i];
    }
    for (int i = 0; i < n; i++) {
        if (b[i] % n != 0) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

sa = sum(a)
at = (n+1)*n//2

if sa%at!=0:
    print('NO')

kaisu = sa//at

diff = [0]*n
for i in range(n-1):
    diff = a[i]-a[i+1]
diff[n-1] = a[n]-a[1]

if sum(diff)==0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
#editorial参照
n=int(input())
a=list(map(int, input().split()))
sa= sum(a)
if sa%(n*(n+1)//2):
    print("NO")
    exit()
k=sa//(n*(n-1)//2)
b=[a[i]-a[i-1] -k for i in range(n)]

for i in range(n):
    if b[i]%n or b[i]>0:
        print("NO")
        exit()
print("YES")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
3
6 6 6

Submission status: Runtime Error

Solution code:
import sys

N = int(input())

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

M = N*(N+1)//2

if sum(A) % M != 0:
    print ("NO")
    sys.exit()

able = sum(A) // M

print (M,able)

A.append(A[0])
now = 0

for i in range(N):

    if A[i+1] - A[i] == able:
        continue

    else:
        #print (A[i+1],A[i],able,1-N)
        if ((A[i+1]-A[i])-able) % (1-N) != 0:
            print ("NO")
            sys.exit()

        else:
            now += ((A[i+1]-A[i])-able) // (1-N)


if now <= able:
    print ("YES")
else:
    print ("NO")

Submission status: Runtime Error

Solution code:
n,*a=map(int,open(0).read().split())
d=[j-i for i,j in zip(a,a[1:]+[a[0]])]
M=max(d)
dd=[M-x for x in d]
if (n==2 and sum(a)%3) or any(x%n for x in dd) or sum(x//n for x in dd)!=M or sum(a)//M!=n*(n+1)//2:
	print("NO")
else:
	print("YES")

Submission status: Runtime Error

Solution code:
n,*a=map(int,open(0).read().split())
d=[j-i for i,j in zip(a,a[1:]+[a[0]])]
M=max(d)
dd=[M-x for x in d]
if n==1 or (all(x%n==0 for x in dd) and sum(x//n for x in dd)==M and sum(a)//M==n*(n+1)//2):
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

Solution code:
n,*a=map(int,open(0).read().split())
d=[j-i for i,j in zip(a,a[1:]+[a[0]])]
M=max(d)
dd=[M-x for x in d]
if all(x%n==0 for x in dd) and sum(x//n for x in dd)==M and sum(a)//M==n*(n+1)//2:
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:

import math
n=int(input())
a=list(map(int, input().split()))
tmp=0
for i in range(n-1):
    if a[i]>(a[i+1]+tmp*n):
        tmp=math.ceil((a[i]-a[i+1])/n)
    a[i+1]+=tmp*n
tmp = a[1]-a[0]
if all(a[i+1]-a[i]==tmp for i in range(1, n-1)):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
global count
count = 0
def solve(a):
    count += 1
    if count > 10**7:
        print('NO')
        exit()
    if min(a) < 0:
        return False

    for i in range(n):
        if a[i] != 0:
            break
        if i == n-1:
            return True

    for i in range(n):
        b = []
        for j in range(n):
            c = a[(i+j)%n]-j-1
            b.append(c)

        if solve(b):
            return True

if solve(a):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

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

def solve(a):
    if min(a) < 0:
        return False
    
    for i in range(n):
        if a[i] != 0:
            break
        if i == n-1:
            return True

    for i in range(n):
        b = []
        for j in range(n):
            c = a[(i+j)%n]-j-1
            b.append(c)

        if solve(b):
            return True

if solve(a):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

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

def solve(a):
    print(a)
    for i in range(n):
        if a[i] != 0:
            break
        if i == n-1:
            return True

    for i in range(n):
        b = []
        for j in range(n):
            if a[j] < 0:
                return False
            c = a[(i+j)%n]-j-1
            b.append(c)

        if solve(b):
            return True

if solve(a):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int sum;
Int sumone, n, cnt;
Int a[216000];
void ok(){
  cout << "YES" << endl;
  exit(0);
}

void ng(){
  cout <<  "NO" << endl;
  exit(0);
}


int main(){
  cin >> n;
  for(int i = 0;i < n;i++)cin >> a[i], sum += a[i];
  sumone = n * (n+1) / 2;
  if(sum % sumone)ng();
  sumone /= sum;
  for(int i = 0;i < n;i++){
    int b = (i + n - 1) % n;
    int diff = a[b] - a[i];
    diff += sumone;
    if(diff < 0 || diff % n)ng();
    cnt += diff / (n-2);
  }
  if(sumone != cnt)ng();
  ok();
  return 0;
}

Submission status: Runtime Error

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
k=sum(a)//(N*(N-1)//2)
D=[]
a.append(a[0])
for i in range(N):
  D.append(a[i+1]-a[i]-k)

for d in D:
  if d%N!=0:
    print("NO")
    exit()
print("YES")

Submission status: Runtime Error

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 k in range(n):
  if -(lis[i]-lis[i-1]-sum(lis)//num)%n!=0:
    print("NO")
    exit()
  ans+=-(lis[i]-lis[i-1]-sum(lis)//num)//n
if ans == sum(lis)//num:print("YES")
else:print("NO")

Submission status: Runtime Error

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: Runtime Error

Solution code:
n=int(input())
*l,=map(int,input().split())
m=[0]*n
a=n*(n+1)//2
b=sum(l)

if b%a:
  print("NO")
else:
  k=b//a
  for i in range(n):
    m[i]=(l[(i+1)%n]-l[i]-k)

*o,=filter(lambda x:x<0 and x%n==0,m)
if len(o)==k:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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")
    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: Runtime Error

Solution code:
N = int(input())
src = 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: Runtime Error

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! or times-A[0]+A[N-1]<0=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 or times-A[i+1]+A[i]<0:
    print("NO")
    sys.exit()
if B==times:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
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: Runtime Error

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
    
minKey = min(inList) / key
tmpList = [inList[(minId + i)%N] - minKey * key for i in range(N)]
#while(max(tmpList) > 0 and flag):
#    if(min(tmpList) < 0):
#        break
#    minId = tmpList.index(min(tmpList))
#    tmpList = [tmpList[(minId + i)%N] - i - 1 for i in range(N)]
#if(max(tmpList)==0 and min(tmpList)==0):
#    ans = "YES"
#    tmpFlag = 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: Runtime Error

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
    
minKey = min(inList) / key
tmpList = [inList[(minId + i)%N] - minKey * key for i in range(N)]
while(max(tmpList) > 0 and flag):
    if(min(tmpList) < 0):
        break
    minId = tmpList.index(min(tmpList))
    tmpList = [tmpList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(tmpList)==0 and min(tmpList)==0):
    ans = "YES"
    tmpFlag = 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: Runtime Error

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
    
minKey = min(inList) / key
print key, minKey
tmpList = [inList[(minId + i)%N] - minKey * key for i in range(N)]
print tmpList
while(max(tmpList) > 0 and flag):
    if(min(tmpList) < 0):
        break
    minId = tmpList.index(min(tmpList))
    tmpList = [tmpList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(tmpList)==0 and min(tmpList)==0):
    ans = "YES"
    tmpFlag = 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: Runtime Error

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
    
minKey = min(inList) / key
tmpList = [inList[(minId + i)%N] - i - 1 - minKey * key for i in range(N)]
while(max(tmpList) > 0 and flag):
    if(min(tmpList) < 0):
        break
    minId = tmpList.index(min(inList))
    tmpList = [tmpList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(tmpList)==0 and min(tmpList)==0):
    ans = "YES"
    tmpFlag = 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: Runtime Error

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 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: Runtime Error

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])>c:
            print("NO")
            exit()
    elif a[i]-a[(i+1)%n]>0:
        if abs(a[i]-a[i+1])>c*(n-1):
            print("NO")
            exit()
print("YES")

Submission status: Runtime Error

Solution code:
import sys
N = int(next(sys.stdin))
inList = map(int, next.stdin.split())
def checkList(inList, N):
    maxId = inList.index(max(inList))
    for i in range(N):
        inList[(maxId-i)%N] -= N - i
    print inList
    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: Runtime Error

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

if 0  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: Runtime Error

Solution code:
N=int(input())
A_list=map(int, input().split())
# N=7
# A_list=[1,2,3,4,5,6,7]
# N=5
# A_list=[4,5,1,2,3]
# A_list=[6,9,12,10,8]
# N=4
# A_list=[1,2,3,1]

d_list=[A_list[j]-A_list[j-1] for j in range(0, N)]
if 0 in d_list:
    print("NO")
else:
    if sum(d_list)==0:
        print("YES")
    else:
        print("NO")

Submission status: Runtime Error

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 or tmp2:
    print 'NO'
else:
    print 'YES'

Submission status: Runtime Error

Solution code:
N=int(input())
A_list=map(int, input().split())
# N=7
# A_list=[1,2,3,4,5,6,7]
# N=5
# A_list=[4,5,1,2,3]
# A_list=[6,9,12,10,8]
# N=4
# A_list=[1,2,3,1]

m=1
while m>0: 
    i=(A_list.index(max(A_list)))
    A_list=[A_list[(i+j)%N]-j for j in range(1, N+1)]
    m=min(A_list)
if m<0:
    print("NO")
elif m==0:
    if max(A_list)==0:
        print("YES")
    else:
        print("NO")

Submission status: Runtime Error

Solution code:
import numpy as np

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

Nsum = np.sum(n)

if not Nsum % np.cumsum(np.arange(N)):
    print 'NO'
    return
    
sa = n[1:-1] - n
for s in sa:
    if s % n != Nsum / np.cumsum(np.arange(N)):
        print 'NO'
        return
print 'YES'
return