Problem:


Score : 600 points

Problem Statement

We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)

Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.

It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.

You are given the sequence a_i. Find the number of times we will perform the above operation.

Constraints

2 ≤ N ≤ 50

0 ≤ a_i ≤ 10^{16} + 1000

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the number of times the operation will be performed.

Sample Input 1

4
3 3 3 3

Sample Output 1

0

Sample Input 2

3
1 0 3

Sample Output 2

1

Sample Input 3

2
2 2

Sample Output 3

2

Sample Input 4

7
27 0 0 0 0 0 0

Sample Output 4

3

Sample Input 5

10
1000 193 256 777 0 1 1192 1234567891011 48 425

Sample Output 5

1234567894848



Sample input:
4
3 3 3 3


Sample output:
0

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
m = min(A)
cnt = 0
for i in range(n):
  t = (A[i]-m)//(n+1)
  cnt += t
  A[i] -= t*(n+1)
  if A[i]-m == n:
    A[i] -= n+1
    cnt += 1
for i in range(n):
  A[i] += cnt
M = max(A)
ans = cnt + max(M-(n-1), 0)*n
print(ans)

Submission status: Wrong Answer

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

    cnt = 0
    while True:
        min_x = min(a)
        max_i, max_x = max(enumerate(a), key=lambda x: x[1])

        if max_x - min_x < n - 1 or max_x < n:
            break

        num = max(1, (max_x - min_x) // (n + 1))
        cnt += num
        a[max_i] -= (n + 1) * num
        for i in range(n):
            a[i] += num

    print(cnt + max(0, (max(a) - n + 1) * n))

main()

Submission status: Wrong Answer

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

    cnt = 0
    while True:
        min_x = min(a)
        max_i, max_x = max(enumerate(a), key=lambda x: x[1])

        if max_x - min_x < n - 1 or max_x < n:
            break

        num = max(1, (max_x - min_x) // n)
        cnt += num
        a[max_i] -= (n + 1) * num
        for i in range(n):
            a[i] += num

    print(cnt + max(0, (max(a) - n + 1) * n))

main()

Submission status: Wrong Answer

Solution code:
import numpy as np
I,S=input,sum
n,c=int(I()),0
a=np.array(list(map(int, I().split())))
while max(a)>=n:c+=S(a//n);a=a-a//n*n-(S(a//n)-a//n)
print(c)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

from math import ceil

n = readint()
a = readints()

ans = 0
for i in range(n):
    a.sort()
    if a[-1]<n:
        break
    ans += 1
    for j in range(n-1):
        a[j]+=1
    a[-1]-=n

a.sort()
while a[-1]-a[0]>n+1:
    x = ceil((a[-1]-a[0]-n-1)/(n+1))
    ans += x
    for j in range(n-1):
        a[j] += x
    a[-1] -= n*x
    a.sort()

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

while a[-1]>=n:
    ans += 1
    for j in range(n-1):
        a[j]+=1
    a[-1]-=n
    a.sort()

print(ans)

Submission status: Wrong Answer

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

ng = max(0, sum(list_of_a)-(N-1)*N) - 1
ok = max(0, (max(list_of_a) - (N-1)) * N)
while ok - ng > 1:
    mid = (ok + ng) // 2
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ok = mid
    else:
        ng = mid

#'ok'-i (i=1..N) may be better

for i in range(0, 5 * N + 1):
    mid = ok - i
    if mid < 0:
        break
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count == mid:
        ans = mid

print(ans)

Submission status: Wrong Answer

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

ng = max(0, sum(list_of_a)-(N-1)*N) - 1
ok = max(0, (max(list_of_a) - (N-1)) * N)
while ok - ng > 1:
    mid = (ok + ng) // 2
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ok = mid
    else:
        ng = mid

#'ok'-i (i=1..N) may be better

for i in range(0, 3 * N + 1):
    mid = ok - i
    if mid < 0:
        break
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count == mid:
        ans = mid

print(ans)

Submission status: Wrong Answer

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

ng = max(0, sum(list_of_a)-(N-1)*N) - 1
ok = max(0, (max(list_of_a) - (N-1)) * N)
while ok - ng > 1:
    mid = (ok + ng) // 2
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ok = mid
    else:
        ng = mid

#'ok'-i (i=1..N) may be better

for i in range(0, 2 * N + 1):
    mid = ok - i
    if mid < 0:
        break
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count == mid:
        ans = mid

print(ans)

Submission status: Wrong Answer

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

ng = max(0, sum(list_of_a)-(N-1)*N) - 1
ok = max(0, (max(list_of_a) - (N-1)) * N)
while ok - ng > 1:
    mid = (ok + ng) // 2
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ok = mid
    else:
        ng = mid

#'ok'-i (i=1..N) may be better

for i in range(0, N+1):
    mid = ok - i
    if mid < 0:
        break
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count == mid:
        ans = mid

print(ans)

Submission status: Wrong Answer

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

ng = max(0, sum(list_of_a)-(N-1)*N) - 1
ok = max(0, (max(list_of_a) - (N-1)) * N)
while ok - ng > 1:
    mid = (ok + ng) // 2
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ok = mid
    else:
        ng = mid

#'ok'-i (i=1..N) may be better

ans = ok
for i in range(1, N+1):
    mid = ok - i
    if mid < 0:
        break
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ans = mid

print(ans)

Submission status: Wrong Answer

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

ng = max(0, sum(list_of_a)-(N-1)*N) - 1
ok = max(0, (max(list_of_a) - (N-1)) * N)
while ok - ng > 1:
    mid = (ok + ng) // 2
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ok = mid
    else:
        ng = mid

#'ok'-i (i=1..N) may be better

ans = ok
for i in range(1, N+1):
    mid = ok - i
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ans = mid

print(max(ans, 0))

Submission status: Wrong Answer

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

ng = max(0, sum(list_of_a)-(N-1)*N) - 1
ok = max(0, (max(list_of_a) - (N-1)) * N)
while ok - ng > 1:
    mid = (ok + ng) // 2
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ok = mid
    else:
        ng = mid

#'ok'-i (i=1..N) may be better

ans = ok
for i in range(1, N+1):
    mid = ok - i
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ans = mid

print(ans)

Submission status: Wrong Answer

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

ng = max(0, sum(list_of_a)-(N-1)*N) - 1
ok = max(0, (max(list_of_a) - (N-1)) * N)
while ok - ng > 1:
    mid = (ok + ng) // 2
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

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

ng = max(0, sum(list_of_a)-(N-1)*N) - 1
ok = max(0, (max(list_of_a) - (N-1)) * N)
print(ng, ok)
while ok - ng > 1:
    mid = (ok + ng) // 2
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

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

ng = min(0, sum(list_of_a)-(N-1)*N) - 1
ok = (max(list_of_a) - (N-1)) * N
while ok - ng > 1:
    mid = (ok + ng) // 2
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

Solution code:
import math
def main():
    n = int(input())
    l = list(map(int, input().split()))
    c = 0
    while max(l) > n-1:
        l.sort(reverse=True)
        tc = [0] * n
        for i in range(n):
            if l[i] >= n:
                tc[i] = math.ceil((l[i] - n + 1)/(n-1))
                l[i] -= tc[i] * n
        stc = sum(tc)
        for i in range(n):
            l[i] += stc - tc[i]
        c += stc
    return c
print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
def ok(x):
    cnt = 0
    for a in A:
        cnt += (a+x-n)//(n+1) + 1
    return (cnt <= x)
# for a in A:
#     if a > n-1:break
# else:
if ok(0):
    print(0)
    exit(0)
top = pow(10,20)
bottom = 0
while top - bottom > 1:
    mid = (top + bottom)//2
    if ok(mid):
        top = mid
    else:
        bottom = mid
print(top)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array(input().split(), np.int64)


def check(x):
    cnt = np.maximum((a + x + 1) // (n + 1), 0)
    return cnt.sum() <= x


l = -1
r = 10 ** 18

while r - l > 1:
    m = (l + r) // 2
    if check(m):
        r = m
    else:
        l = m

for i in range(max(r - n, 0), r + 1):
    if check(i):
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array(input().split(), np.int64)


def check(x):
    cnt = np.maximum((a + x + 1) // (n + 1), 0)
    if cnt.sum() <= x:
        return True

    return False


l = -1
r = 10 ** 18

while r - l > 1:
    m = (l + r) // 2
    if check(m):
        r = m
    else:
        l = m

for i in range(r - n, r + n + 1):
    if check(i):
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    low, high = -1, 10 ** 20
    while high - low > 1:
        mid = (low + high) // 2
        count = 0
        for a in A:
            if a + mid > N - 1:
                count += ((a + mid - N) // (N + 1)) + 1
        print(count, mid)
        if count > mid: low = mid
        elif count <= mid: high = mid
    else: print(high)
            
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

if all(a < N for a in A):
    print(0)
    exit()

def isOk(k):
    B = [a + k for a in A]
    cnt = 0
    for b in B:
        cnt += b // (N + 1)
    return cnt >= k

ok = 0
ng = 10**20
while ng - ok > 1:
    mid = (ok + ng) // 2
    if isOk(mid):
        ok = mid
    else:
        ng =  mid
print(ok)

Submission status: Wrong Answer

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

def isOk(k):
    B = [a + k for a in A]
    cnt = 0
    for b in B:
        cnt += b // (N + 1)
    return cnt >= k

ok = 0
ng = 10**20
while ng - ok > 1:
    mid = (ok + ng) // 2
    if isOk(mid):
        ok = mid
    else:
        ng =  mid
print(ok)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
a = list(map(int, input().split()))

l = -1
r = sum(a)
s = r
flag = True
for x in a:
    if x < N:
        continue
    else:
        flag = False
        break
if flag:
    print(0)
    exit(0)

while(l+1 < r):
    mid = (l+r) // 2
    if (s - mid)/N > N-1:
        l = mid
    else:
        tmp = 0
        for x in a:
            tmp += math.ceil(((x+mid - N+1)/(N+1)))
        if tmp <= mid:
            r = mid
        else:
            l = mid


print(r)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
cnt = [0]*n
ans = 0
for i in range(100000):
  j = i%n
  if a[j]<n:
    continue
  x = a[j]//n
  y = a[j]%n
  a[j] = y
  ans += x
  for k in range(n):
    if j == k:
      continue
    a[k] += y
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
cnt = [0]*n
ans = 0
for i in range(10000):
  j = i%n
  if a[j]<n:
    continue
  x = a[j]//n
  y = a[j]%n
  a[j] = y
  ans += x
  for k in range(n):
    if j == k:
      continue
    a[k] += y
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
cnt = [0]*n
ans = 0
for i in range(10000):
  j = i%n
  x = sum(cnt)-cnt[j]
  if a[j]+x<n:
    cnt[j] = 0
    continue
  y = (a[j]+x)//n
  z = (a[j]+x)%n
  ans += y
  cnt[j] = y
  a[j] = z
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
cnt = [0]*n
ans = 0
for i in range(10000):
  j = i%n
  x = sum(cnt)-cnt[j]
  if a[j]+x<n:
    continue
  y = (a[j]+x)//n
  z = (a[j]+x)%n
  ans += y
  cnt[j] = y
  a[j] = z
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
if max(a) < N:
  print(0)
  exit(0)
ng = 0
ok = max(a) * N
def check(x):
  c = 0
  for i in range(N):
    c += max(-(-(a[i] + x - N + 1) // (N + 1)), 0)
  return x >= c

while ok - ng > 1:
  m = (ok + ng) // 2
  if check(m): ok = m
  else: ng = m

res = ok + 0

ok = 0
ng = -(-res // N)
while ng - ok > 1:
  m = (ok + ng) // 2
  if check(res - m * N): ok = m
  else: ng = m
res -= ok * N
print(res)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
if max(a) < N:
  print(0)
  exit(0)
ng = 0
ok = max(a) * N
def check(x):
  c = 0
  for i in range(N):
    c += max((a[i] + x) // (N + 1), 0)
  return x >= c

while ok - ng > 1:
  m = (ok + ng) // 2
  if check(m): ok = m
  else: ng = m
print(ok)

Submission status: Wrong Answer

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

def check(x):
	count = 0
	for i in range(N):
		a = max(A[i] + x - N + 1,0)
		#print(a)
		if a%(N+1)==0:
			count += a//(N+1)
		else:
			count += a//(N+1) + 1
	return count <= x

l = 0
r = 10**17

if check(l):
	print(l)
else:
	while r-l>1:
		if check((l+r)//2):
			r = (l+r)//2
		else:
			l = (l+r)//2

	print(r)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
As = list(map(int, input().split()))
def f(K):
    c = 0
    for a in As:
        c += (a+K)//(N+1)
#    print(K, K-c)
    return c<=K
for a in As:
    if a>=N:
        break
else:
    print(0)
    sys.exit()
mn, mx = 0, 10**18
idx = mx//2
while mx-mn>1:
    if f(idx):
        mx, idx = idx, (idx+mn)//2
        continue
    mn, idx = idx, (mx+idx)//2
print(idx+1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    k=int(input())
    n=50
    q=k//n
    r=k%n
    A=[q+n-r+1+i for i in range(r)]+[q+i for i in range(n-r)]
    print(n)
    print(*A)
resolve()

Submission status: Wrong Answer

Solution code:
from numpy import int64

N, A = open(0)
N, A = int(N), int64(A.split())

ans = 0
S = -1
while S:
    B, A = A % N, A // N
    S = B.sum()
    ans += S
    A += S - B

print(ans)

Submission status: Wrong Answer

Solution code:
import math
N, *A = [int(_) for _ in open(0).read().split()]
sumB = max(0, sum(A) - N * (N - 1))
while True:
    B = [math.ceil((a + sumB - (N - 1)) / (N + 1)) for a in A]
    if sumB == sum(B):
        break
    sumB += 1
print(sumB)

Submission status: Wrong Answer

Solution code:
##create with UTF-8

n = int( input() )
da=list(map(int, input(). split()))
li=[da[i]%(n+1) for i in range(n)]
su=0
ans=0
for i in range(n):
	su+=da[i]
for i in range(n):
	div=(n-1)-(da[i]%(n+1))
	now=0
	ju=True
	for j in range(n):
		if (n+1+div+da[j])%(n+1)==n:
			ju=False
			break
		now+=(n+1+div+da[j])%(n+1)
	if ju and su >= now:
		print(now)
		ans = max(ans,now)
print(su-ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

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

s = sum(a)

def binarysearch(a,ok,ng): #二分探索
    def isOK(k): #判定関数（個別に書き換え）
        res = 0
        for ai in a:
            c = ai + k - (n-1)
            res += (c+n)//(n+1)
        if res <= k: return True
        else: return False

    while(abs(ok-ng) > 1):
        mid = (ok + ng)//2
        if isOK(mid): ok = mid
        else: ng = mid
    
    for i in range(max(0,ok-100),ok):
        if isOK(i):
            ok = i
            break

    return ok


print(binarysearch(a,ok=s,ng=-1))

Submission status: Wrong Answer

Solution code:
import sys


def bisect_left_callable(fn, x, lo, hi):
    """
    lo から hi-1 のうち、fn の結果が x 以上となる、最も左の値
    bisect.bisect_left と同じ
    https://docs.python.org/ja/3/library/bisect.html
    :param callable fn:
    :param x:
    :param int lo: 最小値
    :param int hi: 最大値 + 1
    :return: lo <= ret <= hi
    """
    while lo < hi:
        mid = (lo + hi) // 2
        if fn(mid) < x:
            lo = mid + 1
        else:
            hi = mid
    return lo


sys.setrecursionlimit(100000)
INF = float('inf')

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

MAX = 10 ** 20


def check(k):
    """
    :param int k: 
    :return: k 回操作して条件を満たせば 0、k が大きすぎたらプラス、小さすぎたらマイナス
    """
    # k を全体に足す
    # N + 1 をちょうど k 回引ければそれが答え
    li = [a + k for a in A]
    sub = 0
    for a in li:
        sub += (a + 1) // (N + 1)
    return k - sub


if max(A) < N:
    print(0)
    exit()

# このへんに答えがある
ans = bisect_left_callable(check, 0, 1, MAX)
# このへん小さい順に全部調べる（あたまわるい）
ans = max(1, ans - 100)
for i in range(200):
    if check(ans + i) == 0:
        print(ans + i)
        break

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
ans=0
while True:
  f=0
  for i in range(N):
    if a[i]>N:
      ans+=a[i]//N
      a[i]%=N
      for j in range(N):
        if i!=j:
          a[j]+=1
      f=1
      break
  if f==0:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = inp()
aa = inpl()

def check(x):
	if x < 0:
		return False
	aa_dush = list(map(lambda s:s+x, aa))
	tmp = 0
	for a in aa_dush:
		tmp += (a-(N-1)-1)//(N+1) + 1
	if tmp <= x:
		return True
	else:
		return False


NG = -1
OK = 10**17

while OK-NG > 1:
	mid = (OK+NG)//2
	if check(mid):
		OK = mid
	else:
		NG = mid

for i in range(OK-10**5,OK+1):
	if check(i):
		print(i)
		break

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = inp()
aa = inpl()

def check(x):
	if x < 0:
		return False
	aa_dush = list(map(lambda s:s+x, aa))
	tmp = 0
	for a in aa_dush:
		tmp += (a-(N-1)-1)//(N+1) + 1
	if tmp <= x:
		return True
	else:
		return False


NG = -1
OK = 10**17

while OK-NG > 1:
	mid = (OK+NG)//2
	if check(mid):
		OK = mid
	else:
		NG = mid

for i in range(OK-100,OK+1):
	if check(i):
		print(i)
		break

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = inp()
aa = inpl()

def check(x):
	aa_dush = list(map(lambda s:s+x, aa))
	tmp = 0
	for a in aa_dush:
		tmp += (a-(N-1)-1)//(N+1) + 1
	if tmp <= x:
		return True
	else:
		return False


NG = -1
OK = 10**17

while OK-NG > 1:
	mid = (OK+NG)//2
	if check(mid):
		OK = mid
	else:
		NG = mid

for i in range(OK-100,OK):
	if check(i):
		print(i)
		break

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = inp()
aa = inpl()

def check(x):
	aa_dush = list(map(lambda s:s+x, aa))
	tmp = 0
	for a in aa_dush:
		tmp += (a-(N-1)-1)//(N+1) + 1
	if tmp <= x:
		return True
	else:
		return False


NG = -1
OK = 10**17

while OK-NG > 1:
	mid = (OK+NG)//2
	if check(mid):
		OK = mid
	else:
		NG = mid

print(OK)

Submission status: Wrong Answer

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

def under_n(a, n):
    for ai in a:
        if ai >= n: return True
    return False

while under_n(a, n):
    idx = a.index(max(a))
    r, q = int(a[idx] / n), a[idx] % n
    a = list(map(lambda x:x+r, a))
    a[idx] = q
    cnt += r
    
print(cnt)

Submission status: Wrong Answer

Solution code:
n,*A=map(int,open(0).read().split())
ans = 0
while 1:
    A.sort(reverse=1)
    if A[0] > A[-1]+n:
        p = (A[0] - A[-1]) // (n+1)
        for j in range(n):
            A[j] += p
        A[0] -= p*(n+1)
        ans += p
    else:
        break
if max(A) >= n+1:
    ans += (max(A) - 2*n)*n
    ma = max(A) - 2*n
    for i in range(n):
        A[i] -= ma
while max(A) >= n:
    for i in range(n):
        A[i] += 1
    A[A.index(max(A))] -= n+1
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,*A=map(int,open(0).read().split())
A.sort(reverse=1)
ans = 0
for i in range(n):
    if A[i] > A[-1]+n:
        p = (A[i] - A[-1]) // (n+1)
        for j in range(n):
            A[j] += p
        A[i] -= p*(n+1)
        ans += p
if max(A) >= n+1:
    ans += (max(A) - (n+1))*n
    ma = max(A) - (n+1)
    for i in range(n):
        A[i] -= ma
while max(A) >= n:
    for i in range(n):
        A[i] += 1
    A[A.index(max(A))] -= n+1
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
b=input();a=b/50+49;b%=50;c=50-b;print 50,(`a-b`+" ")*c+(`a+c`+" ")*b

Submission status: Wrong Answer

Solution code:
def check(_a):
    for i in range(0, len(_a)):
        if N <= _a[i]:
            return True
    else:
        return False


if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))

    divide_num = [0 for i in range(N)]
    ans = 0
    while check(a):
        sum_num = 0
        for i in range(0, N):
            tmp = int(a[i] / N)
            divide_num[i] = tmp
            sum_num += tmp
            ans += tmp

        a = [(a[i] % N + sum_num - divide_num[i]) for i in range(0, N)]

    print(ans)

Submission status: Wrong Answer

Solution code:
N = long(raw_input())
ns = map(long, raw_input().split(" "))

ns.sort()
total_count = 0L
while ns[-1] - ns[0] > N:
  delta = ns[-1] - ns[0]
  count = long(delta / (N+1))
  total_count += count
  ns[-1] -= N*count
  for i in xrange(N-1):
    ns[i] += count
  ns.sort()

m = ns[-1]
if m <= N-1:
  answer = total_count
else:
  delta = 0L
  for i in xrange(1, N):
    delta += ns[N-i] - ns[N-i-1] - 1
    if delta > 0L:
      answer = total_count + N*max(0, m-(N-1)-delta) + i
      break
  else:
    answer = total_count + N*(m-(N-1))
print answer

Submission status: Wrong Answer

Solution code:
N = long(raw_input())
ns = map(long, raw_input().split(" "))

ns.sort()
total_count = 0L
while ns[-1] - ns[0] > N:
  delta = ns[-1] - ns[0]
  count = long(delta / (N+1))
  total_count += count
  ns[-1] -= N*count
  for i in xrange(N-1):
    ns[i] += count
  ns.sort()

m = ns[-1]
if m <= N-1:
  answer = total_count
else:
  delta = 0
  for i in xrange(1, N):
    delta += ns[N-i] - ns[N-i-1] - 1
    if delta > 0:
      answer = total_count + N*max(0, m-(N-1)-delta) + i
      break
  else:
    answer = total_count + N*(m-(N-1))
print answer

Submission status: Wrong Answer

Solution code:
N = long(raw_input())
ns = map(long, raw_input().split(" "))

ns.sort()
total_count = 0L
counts = []
for i in xrange(N):
  delta = ns[i] - ns[0]
  count = long(delta / (N+1))
  counts.append(count)
  total_count += count

for i in xrange(N):
  ns[i] = ns[i] - N*counts[i] + (total_count-counts[i])

ns.sort()
m = ns[-1]
if m <= N-1:
  answer = total_count
else:
  delta = 0
  for i in xrange(1, N):
    delta += ns[N-i] - ns[N-i-1] - 1
    if delta > 0:
      answer = total_count + N*max(0, m-(N-1)-delta) + i
      break
  else:
    answer = total_count + N*(m-(N-1))
print answer

Submission status: Wrong Answer

Solution code:
# encoding:utf-8

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

	print(calc(a))
	
def calc(temp):
	i = 0
	# print(temp)
	while len([x for x in temp if x >= len(temp)]) > 0:
		if len([x for x in temp if x < len(temp)]) == 0 and max(temp) > len(temp) + 1:
			i += min(temp)
			temp = [x - 1 for x in temp]
		else:
			temp, i = query1(temp, i)
	return i

def query1(temp, i):
	temp.sort()
	num = temp[-1] // len(temp)
	temp = [x + num for x in temp]
	temp[-1] = temp[-1] - len(temp) * (num + 1)
	return temp, num + i

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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


def f(k):
    s = 0
    for ai in a:
        s += max(0, (ai - (n - 1 - k) + n) // (n + 1))
    return s <= k


lb = 0
ub = 1000000000000000001

while lb + 1 < ub:
    mid = (lb + ub) // 2
    if f(mid):
        ub = mid
    else:
        lb = mid

for i in xrange(max(0, lb - 50), lb + 2):
    if f(i):
        print i
        break

Submission status: Wrong Answer

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


def f(k):
    s = 0
    for ai in a:
        s += (ai - (n - 1 - k) + n) // (n + 1)
    return s <= k


lb = 0
ub = 500000000000000001

while lb + 1 < ub:
    mid = (lb + ub) // 2
    if f(mid):
        ub = mid
    else:
        lb = mid

for i in xrange(max(0, lb - 50), lb + 2):
    if f(i):
        print i
        break

Submission status: Wrong Answer

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


def f(k):
    s = 0
    for ai in a:
        s += (ai - (n - 1 - k) + n) // (n + 1)
    print (k, s, s <= k)
    return s <= k


lb = 0
ub = 500000000000000001

while lb + 1 < ub:
    mid = (lb + ub) // 2
    if f(mid):
        ub = mid
    else:
        lb = mid

for i in xrange(max(0, lb - 50), lb + 2):
    if f(i):
        print i
        break

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env pypy3
# -*- coding: UTF-8 -*-
import sys
import re
import math
import itertools
import collections
import bisect
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.1415926535897932
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)]
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

n=int(input())
#n,k=map(int,input().split())
l=[int(i) for i in input().split()]
#ans=chk=0
if n%2==0:
    tmp=(1+n)*(n//2)
else:
    tmp=(1+n)*(n//2)+n//2+1
print(sum(l)-tmp)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
c=0
while max(a)>=n:
	t=0
	for i in range(n):
		if a[i]>a[t]:
			t=i
	c+=int(a[t]/n)
	for i in range(n):
		if i==t:continue
		a[i]+=int(a[t]/n)
	a[t]%=n
print(c)

Submission status: Wrong Answer

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


def judge(k):
  cnt = sum(max((a+k+1)//(N+1),0) for a in A)
  return cnt <= k

if judge(0):
  print(0)
  exit(0)

low = 0
high = 10**18

while low + 1 < high:
  mid = (low+high)//2
  if judge(mid):
    high = mid
  else:
    low = mid

r = high

for i in range(max(r-N*2,0),r):
  if judge(i):
    r = i
    break

print(r)

Submission status: Wrong Answer

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


def judge(k):
  cnt = 0
  for a in A:
    cnt += max((a+k+1)//(N+1),0)
  return cnt <= k

if judge(0):
  print(0)
  exit(0)

low = 0
high = 50*10**16

while low + 1 < high:
  mid = (low+high)//2
  if judge(mid):
    high = mid
  else:
    low = mid

r = high

for i in range(max(r-N,0),r):
  if judge(i):
    r = i
    break

print(r)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
count=0
while(1):
	#print(max(L))
	tmp=0
	if max(L)<N:
		print(count)
		exit()
	else:
		M=max(L)//N
		count+=M
		for i in range(N):
			if L[i]==max(L) and tmp==0:
				tmp=1
				L[i]-=M*N
			else:
				L[i]+=M

Submission status: Time Limit Exceeded

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

ans = 0
while 1:
    j = -1
    for i,a in enumerate(A):
        if a >= N:
            j = i
            break
    else:
        break
    d,m = divmod(A[j],N)
    ans += d
    A[j] = m
    for i in range(N):
        if i==j: continue
        A[i] += d
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
flag = True
while flag:
    flag = False
    for i in range(N):
        if A[i] >= N:
            count = A[i] // N
            ans += count
            for j in range(N):
                A[j] += count
            A[i] -= count
            A[i] %= N
            flag = True
            break

print(ans)

Submission status: Time Limit Exceeded

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

ans,ni=0,-1
for i in range(N):
    if A[i]>=2*N:
        ni=i

while ni >= 0:
    c = A[ni]//N
    A[ni]-=(N*c)
    ans += c
    pi,ni=ni,-1
    for j in range(N):
        if j!=pi:
            A[j]+=c
            if A[j]>=2*N:
                ni=j

mi=0
for i in range(1,N):
    if A[i]>A[mi]:
        mi=i

while A[mi] >= N:
    ans += 1
    A[mi]-=N
    pmi = mi
    for i in range(N):
        if i != pmi:
            A[i]+=1
            if A[i]>A[mi]:
                mi=i

print(ans)