You are given a sequence of non-negative integers of length N. Perform an operation on the sequence until the largest element becomes N-1 or smaller. The operation involves decreasing the largest element by N and increasing all other elements by 1. Determine how many times this operation needs to be performed. Constraints: 2 ≤ N ≤ 50, 0 ≤ ai ≤ 10^16 + 1000. Input format: N followed by the sequence a1, a2, ..., aN. Output the number of times the operation will be performed.

# Buggy version:
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)

# Fixed version:
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:f=a//n;S=sum(f);a=a-f*n+(S-f);c+=sum(f)
print(c)

# Buggy version:
N, *A = [int(_) for _ in open(0).read().split()]
sumB = max(0, sum(A) - N * (N - 1))
while True:
    B = [0 - (-(a + x + 1 - N)) // (N + 1) for a in A]
    if sumB == sum(B):
        break
    sumB += 1
print(sumB)


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

# Buggy version:
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)




# Fixed version:
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()
if a[-1]>n:
    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)

# Buggy version:
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())


# Fixed version:
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)
                l[i] -= tc[i] * n
        stc = sum(tc)
        for i in range(n):
            l[i] += stc - tc[i]
        c += stc
    return c
print(main())

# Buggy version:
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)


# Fixed version:
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] += x
print(ans)

# Buggy version:
from numpy import int64, divmod

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)


# Fixed version:
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)

# Buggy version:
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)
      
  
        

# Fixed version:
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:
      d=a[i]//N
      ans+=d
      a[i]%=N
      for j in range(N):
        if i!=j:
          a[j]+=d
    else:
      f+=1
  if f==N:
    break
print(ans)

# Buggy version:
from heapq import*
n=int(input())
a=[-int(e)for e in input().split()]
r=0
heapify(a)
while 1:
	x=heappop(a)
	if x>-n:break
	c=-x//n
	x+=c*n
	for _ in range(n-1):a[i]-=c
	heappush(a,x)
	r+=c
print(r)

# Fixed version:
from heapq import*
n=int(input())
a=[-int(e)for e in input().split()]
r=0
heapify(a)
while 1:
	x=heappop(a)
	if x>-n:break
	c=-x//n
	x+=c*n
	for i in range(n-1):a[i]-=c
	heappush(a,x)
	r+=c
print(r)