n, s = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
m = n // 2
me = a[m]
ct = m
if me == s:
    print(0)
    exit(0)
elif me < s:
    while ct < n and a[ct] < s:
        ct += 1
    ds = sum([(x-s) for x in a[m:ct:1]])
elif me > s:
    while ct >= 0 and a[ct] > s:
        ct -= 1
    ds = sum([(x-s) for x in a[ct+1:m+1:1]])
print(abs(ds))


n, s = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
m = n // 2
me = a[m]
ct = m
if me == s:
    print(0)
    exit(0)
elif me < s:
    while ct < n and a[ct] < s:
        ct += 1
    ds = abs(sum([x for x in a[m:ct:1]]) - (ct-m)*s)
elif me > s:
    while ct >= 0 and a[ct] > s:
        ct -= 1
    ds = abs(sum([x for x in a[ct+1:m+1:1]]) - (m-ct)*s)
print(abs(ds))


n=input().split(' ')
m=input().split(' ')
n=list(map(int,n))
m=list(map(int,m))
m.sort()
global count
count=0
def med(x,y):
    global count
    if len(y)==1:
        if y[0]>x[1]:
            count+=y[0]-x[1]
            y[0]=x[1]
        if y[0]<x[1]:
            count+=x[1]-y[0]
            y[0]=x[1]
    elif y[int((len(y)/2))]==x[1]:
        count+=0
        #print(int((len(y)/2)+1))
    elif x[1]>y[int((len(y)/2))]:
        for i in range(int(len(y)/2),len(y)):
            if y[i]>=x[1]:
                break
            else:
                count+=x[1]-y[i]
                y[i]=x[1]
    else:
        for i in range(int(len(y)/2),0,-1):
            if y[i]<=x[1]:
                break
            else:
                count+=y[i]-x[1]
                y[i]=x[1]
    return count
print(med(n,m))


n=input().split(' ')
m=input().split(' ')
n=list(map(int,n))
m=list(map(int,m))
m.sort()
global count
count=0
def med(x,y):
    global count
    if y[int((len(y)/2))]==x[1]:
        count+=0
        #print(int((len(y)/2)+1))
    elif x[1]>y[int((len(y)/2))]:
        for i in range(int(len(y)/2),len(y)):
            if y[i]>=x[1]:
                break
            else:
                count+=x[1]-y[i]
                y[i]=x[1]
    else:
        for i in range(int(len(y)/2)+1,0):
            if y[i]<=x[1]:
                break
            else:
                count+=y[i]-x[1]
                y[i]=x[1]
    return count
print(med(n,m))


n=input().split(' ')
m=input().split(' ')
n=list(map(int,n))
m=list(map(int,m))
m.sort()
global count
count=0
def med(x,y):
    global count
    if y[int((len(y)/2))]==x[1]:
        count+=0
        #print(int((len(y)/2)+1))
    elif x[1]>y[int((len(y)/2))]:
        for i in range(int(len(y)/2),len(y)):
            if y[i]>=x[1]:
                break
            else:
                count+=x[1]-y[i]
                y[i]=x[1]
    else:
        for i in range(int(len(y)/2),0,-1):
            if y[i]<=x[1]:
                break
            else:
                count+=y[i]-x[1]
                y[i]=x[1]
    return count
print(med(n,m))


n=input().split(' ')
m=input().split(' ')
n=list(map(int,n))
m=list(map(int,m))
m.sort()
global count
count=0
def med(x,y):
    global count
    if len(y)==1:
        if y[0]>x[1]:
            count+=y[0]-x[1]
            y[0]=x[1]
        else:
            count+=x[1]-y[0]
            y[0]=x[1]
    elif y[int((len(y)/2))]==x[1]:
        count+=0
        #print(int((len(y)/2)+1))
    elif x[1]>y[int((len(y)/2))]:
        for i in range(int(len(y)/2),len(y)):
            if y[i]>=x[1]:
                break
            else:
                count+=x[1]-y[i]
                y[i]=x[1]
    else:
        for i in range(int(len(y)/2),-1,-1):
            if y[i]<=x[1]:
                break
            else:
                count+=y[i]-x[1]
                y[i]=x[1]
    return count
print(med(n,m))


n=input().split(' ')
m=input().split(' ')
n=list(map(int,n))
m=list(map(int,m))
m.sort()
global count
count=0
def med(x,y):
    global count
    if len(y)==1:
        if y[0]>x[1]:
            count+=y[0]-x[1]
            y[0]=x[1]
        else:
            count+=x[1]-y[0]
            y[0]=x[1]
    elif y[int((len(y)/2))]==x[1]:
        count+=0
        #print(int((len(y)/2)+1))
    elif x[1]>y[int((len(y)/2))]:
        for i in range(int(len(y)/2),len(y)):
            if y[i]>=x[1]:
                break
            else:
                count+=x[1]-y[i]
                y[i]=x[1]
    else:
        for i in range(int(len(y)/2),0,-1):
            if y[i]<=x[1]:
                break
            else:
                count+=y[i]-x[1]
                y[i]=x[1]
    return count
print(med(n,m))


n,s=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a.sort()
m=a[(n-1)//2]
b=list(filter(lambda x: s<x<=m or s>x>=m,a))
print(abs(sum(b)-len(b)*s))


def ted():
    n,s=[int(i) for i in input().split()]
    a=[int(i) for i in input().split()]
    a.sort()
    m=a[(n-1)//2]

    if s==m:
        return 0
    if s<m:
        b=list(filter(lambda x: s<x<=m,a[:(n-1)//2+1]))
    elif s>m:
        b=list(filter(lambda x: s>x>=m,a[(n-1)//2:]))
    return abs(sum(b)-len(b)*s)
print(ted())


from math import *

n, s = map(int, input().split())
ls = list(map(int, input().split()))
ls.sort()
start = ls[(n-3)//2]
end = ls[(n+1)//2]
if s in list(range(start, end+1)):
    print(abs(ls[(n-1)//2]-s))
elif ls[(n-1)//2]<s:
    index = (n-1)//2
    count = 0
    while index!=n:
        if ls[index]<s:
            count+=s-ls[index]
        index+=1
    print(count)
else:
    index = (n-1)//2
    count = 0
    while index!=-1:
        if ls[index]>s:
            count+=ls[index]-s
        index-=1
    print(count)


from math import *

n, s = map(int, input().split())
if n==1:
    print(abs(int(input())-s))
else:
    ls = list(map(int, input().split()))
    ls.sort()
    start = ls[(n-3)//2]
    end = ls[(n+1)//2]
    if s in list(range(start, end+1)):
        print(abs(ls[(n-1)//2]-s))
    elif ls[(n-1)//2]<s:
        index = (n-1)//2
        count = 0
        while index!=n:
            if ls[index]<s:
                count+=s-ls[index]
            index+=1
        print(count)
    else:
        index = (n-1)//2
        count = 0
        while index!=-1:
            if ls[index]>s:
                count+=ls[index]-s
            index-=1
        print(count)


ligne = input().split(' ')
n = int(ligne[0])
s = int(ligne[1])
tab = input().split(" ")
l = len(tab)
for i in range(l):
	tab[i]=int(tab[i])
tab = sorted(tab,key=abs)
k=0
while(tab[l//2]!=s):
	k += abs(s-tab[l//2])
	tab[l//2] = s
	tab = sorted(tab,key=abs)
print(k)


ligne = input().split(' ')
n = int(ligne[0])
s = int(ligne[1])
tab = input().split(" ")
l = len(tab)
for i in range(l):
	tab[i]=int(tab[i])
tab = sorted(tab,key=abs)
k=0
while(tab[l//2]!=s):
	k += s-tab[l//2]
	tab[l//2] = s
	tab = sorted(tab,key=abs)
print(k)


ligne = input().split(' ')
n = int(ligne[0])
s = int(ligne[1])
tab = input().split(" ")
l = len(tab)
for i in range(l):
	tab[i]=int(tab[i])
tab = sorted(tab,key=abs)
k=0
print(l//2)
while(tab[l//2]!=s):
	k += s-tab[l//2]
	tab[l//2] = s
	tab = sorted(tab,key=abs)
print(tab)
print(k)


ligne = input().split(' ')
n = int(ligne[0])
s = int(ligne[1])
tab = input().split(" ")
l = len(tab)
for i in range(l):
	tab[i]=int(tab[i])
tab = sorted(tab,key=abs)
k=0
if tab[l//2]<s:
	for i in range(l//2,l):
		if (tab[i]<s):
			k += s-tab[i]
		else :
			break
else :
	for i in range(l//2,-1,-1):
		if (tab[i] > s):
			k += abs(s-tab[i])
		else :
			break
print(k)


ligne = input().split(' ')
n = int(ligne[0])
s = int(ligne[1])
tab = input().split(" ")
l = len(tab)
for i in range(l):
	tab[i]=int(tab[i])
tab = sorted(tab,key=abs)
k=0
if tab[l//2-1]<s:
	for i in range(l//2,len(tab)):
		if (tab[i]<s):
			k += s-tab[i]
		else :
			break
else :
	for i in range(0,l//2):
		if (tab[i] != s):
			k += abs(s-tab[i])
print(k)


ligne = input().split(' ')
n = int(ligne[0])
s = int(ligne[1])
tab = input().split(" ")
l = len(tab)
for i in range(l):
	tab[i]=int(tab[i])
tab = sorted(tab,key=abs)
k=0
if tab[l//2-1]<s:
	for i in range(l//2,len(tab)):
		if (tab[i]<s):
			k += s-tab[i]
		else :
			break
else :
	for i in range(l//2-1,-1,-1):
		if (tab[i] > s):
			k += abs(s-tab[i])
		else :
			break
print(k)


ligne = input().split(' ')
n = int(ligne[0])
s = int(ligne[1])
tab = input().split(" ")
l = len(tab)
for i in range(l):
	tab[i]=int(tab[i])
tab = sorted(tab,key=abs)
k=0
for i in range(l//2,len(tab)):
	if (tab[i]<s):
		k += s-tab[i]
	else :
		break
print(k)


ligne = input().split(' ')
n = int(ligne[0])
s = int(ligne[1])
tab = input().split(" ")
l = len(tab)
for i in range(l):
	tab[i]=int(tab[i])
tab = sorted(tab,key=abs)
k=0
if tab[l//2-1]<s:
	for i in range(l//2,len(tab)):
		if (tab[i]<s):
			k += s-tab[i]
		else :
			break
else :
	for i in range(l//2,-1,-1):
		if (tab[i] > s):
			k += abs(s-tab[i])
		else :
			break
print(k)


ligne = input().split(' ')
n = int(ligne[0])
s = int(ligne[1])
tab = input().split(" ")
l = len(tab)
for i in range(l):
	tab[i]=int(tab[i])
tab = sorted(tab,key=abs)
k=0
for i in range(len(tab)-1,l//2-1,-1):
	if (tab[i]<s):
		k += abs(s-tab[i])
		tab[i] = s
print(k)


n, x = map(int, input().split())

arr = sorted(list(map(int, input().split())))

c1 = abs(arr[n // 2] - x)

for i in range(n // 2 - 1, 0):
    if arr[i] > x:
        c1 += arr[i] - x

for i in range(n // 2 + 1, n):
    if arr[i] < x:
        c1 += x - arr[i]

print(c1)


n, x = map(int, input().split())

arr = sorted(list(map(int, input().split())))

c1 = abs(arr[n // 2] - x)

for i in range(n // 2):
    if arr[i] > x:
        c1 += arr[i] - x

for i in range(n // 2 + 1, n):
    if arr[i] < x:
        c1 += x - arr[i]

print(c1)


n, x = map(int, input().split())

arr = sorted(list(map(int, input().split())))

c1 = abs(arr[n // 2] - x)

for i in range(n // 2, 0):
    if arr[i] > x:
        c1 += arr[i] - x

for i in range(n // 2 + 1, n):
    if arr[i] < x:
        c1 += x - arr[i]

print(c1)


import sys
import math
n,x=input().split(" ")
n=int(n)
num=input().split(" ")
num.sort()
mid=n//2
c1=0
c2=98
if (int(num[mid]) == int(x)):
	c1=0

elif (int(num[mid]) < int(x)):
	i=mid
	for i in range(mid,n):
		if (int(num[i]) < int(x)):
			c1=c1+(int(x) - int(num[i]))
		else:
			break

elif (int(num[mid]) > int(x)):
	i=mid
	for i in range(mid,0):
		if (int(num[i]) > int(x)):
			c1=c1+abs( int(x) - int(num[i]))
		else:
			break

print(c1)


import sys
import math
n,x=input().split(" ")
n=int(n)
num=input().split(" ")
num.sort()
mid=n//2
c1=0
c2=98
if (int(num[mid]) == int(x)):
	c1=0

elif (int(num[mid]) < int(x)):
	i=mid
	for i in range(mid,n):
		if (int(num[i]) < int(x)):
			c1=c1+(int(x) - int(num[i]))

elif (int(num[mid]) > int(x)):
	i=mid-i
	for i in range(mid,0):
		if (int(num[i]) > int(x)):
			c1=c1+abs( int(x) - int(num[i]))

print(c1)


import sys
n,x=input().split(" ")
n=int(n)
num=input().split(" ")
num.sort()
mid=n//2
c1=0
c2=98
if (int(num[mid]) == int(x)):
	c1=0

elif (int(num[mid]) < int(x)):
	i=mid
	for i in range(mid,n):
		if (int(num[i]) < int(x)):
			c1=c1+(int(x) - int(num[i]))

elif (int(num[mid]) > int(x)):
	i=mid-i
	for i in range(mid,0):
		if (int(num[i]) > int(x)):
			c1=c1+abs( int(x) - int(num[i]))

print(c1)


n,x=input().split(" ")
n=int(n)
num=input().split(" ")
num.sort()
mid=n//2
c1=0
if (int(num[mid]) == int(x)):
	c1=0
elif (int(num[mid]) < int(x)):
	i=mid
	for i in range(mid,n):
		if (int(num[i]) < int(x)):
			c1=c1+(int(x) - int(num[i]))
		else:
			break;
elif (int(num[mid]) > int(x)):
	i=0
	for i in range(0,mid):
		if (int(num[mid-i]) > int(x)):
			c1=c1+(- int(x) + int(num[mid-i]))
		else:
			break;

print(c1)


import sys
import math
n,x=input().split(" ")
n=int(n)
num=input().split(" ")
num.sort()
mid=n//2
c1=0
c2=98
if (int(num[mid]) == int(x)):
	c1=0

elif (int(num[mid]) < int(x)):
	i=mid
	for i in range(mid,n-1):
		if (int(num[i]) < int(x)):
			c1=c1+(int(x) - int(num[i]))
		else:
			break

elif (int(num[mid]) > int(x)):
	i=mid
	for i in range(mid,0):
		if (int(num[i]) > int(x)):
			c1=c1+abs( int(x) - int(num[i]))
		else:
			break

print(c1)


n,x=input().split(" ")
n=int(n)
num=input().split(" ")
num.sort()
mid=n//2
c1=0
if (int(num[mid]) == int(x)):
	c1=0
elif (int(num[mid]) < int(x)):
	for i in range(mid,n):
		if (int(num[i]) < int(x)):
			c1=c1+(int(x) - int(num[i]))
		else:
			break;
elif (int(num[mid]) > int(x)):
	for i in range(0,mid):
		if (int(num[mid-i]) > int(x)):
			c1=c1+(- int(x) + int(num[mid-i]))
		else:
			break;

print(c1)


n, s = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cnt = 0
if A[n // 2] == s:
    print(0)
elif A[n // 2] > s:
    x = n // 2
    while x >= 0 and A[x] > s:
        cnt += A[x] - s
        x -= 1
else:
    x = n // 2
    while x < n and A[x] < s:
        cnt += s - A[x]
        x += 1
print(cnt)


n, s = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cnt = 0
if A[n // 2] == s:
    print(0)
elif A[n // 2] > s:
    x = n // 2
    while A[x] > s and x >= 0:
        cnt += A[x] - s
        x -= 1
else:
    x = n // 2
    while A[x] < s and x < n:
        cnt += s - A[x]
        x += 1
print(cnt)


n, s = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cnt = 0
if A[n // 2] == s:
    pass
elif A[n // 2] > s:
    x = n // 2
    while x >= 0 and A[x] > s:
        cnt += A[x] - s
        x -= 1
else:
    x = n // 2
    while x < n and A[x] < s:
        cnt += s - A[x]
        x += 1
print(cnt)


from bisect import bisect_right as br
n,s=map(int,input().split())
a=sorted(map(int,input().split()))
q,l=br(a,s),n//2
p=(q-l)*s if l<=q else (l-q+1)*s
for i in range(l,q): p-=a[i]
print(abs(p),a,q)


from bisect import bisect_right as br
n,s=map(int,input().split())
a=sorted(map(int,input().split()))
q,l=br(a,s),n//2
p=(q-l)*s if l<q else (l-q+1)*s
for i in range(l,q): p-=a[i]
print(abs(p))


from bisect import bisect_right as br
n,s=map(int,input().split())
a=sorted(map(int,input().split()))
p=0;l=n//2
if s==a[l]:
    print(0)
elif s>a[l]:
    for i in range(l,n):
        if s>a[i]:
            p+=s-a[i]
        else:
            break
    print(p)
else:
    for i in range(l,-1,-1):
        if s<a[i]:
            p+=a[i]-s
        else:
            break
    print(p)


from bisect import bisect_right as br
n,s=map(int,input().split())
a=sorted(map(int,input().split()))
q,l=br(a,s),n//2
p=(q-l)*s if l<=q else (l-q+1)*s
for i in range(l,q): p-=a[i]
print(abs(p))


from bisect import bisect_right as br
n,s=map(int,input().split())
a=sorted(map(int,input().split()))
p=0;l=n//2
if s==l:
    print(0)
elif s>a[l]:
    for i in range(l,n):
        if s>a[i]:
            p+=s-a[i]
        else:
            break
else:
    for i in range(l,-1,-1):
        if s<a[i]:
            p+=a[i]-s
        else:
            break
print(p)


def median(lst):
    quotient, remainder = divmod(len(lst), 2)
    if remainder:
        return sorted(lst)[quotient]
    return sum(sorted(lst)[quotient - 1:quotient + 1]) / 2.

noe, value = [int(x) for x in input().split()]
arr  = [int(x) for x in input().split()]
meds = median(arr)
nops = abs(meds - value)
arr[arr.index(meds)] = value
meds = median(arr)
nops += abs(meds - value)
print(nops)


# -*- coding: utf-8 -*-
# @Date    : 2018-09-03 08:46:01
# @Author  : raj lath (oorja.halt@gmail.com)
# @Link    : http://codeforces.com/contest/1037/problem/B
# @Version : 1.0.0

import os
from sys import stdin

max_val=int(10e12)
min_val=int(-10e12)

def read_int()     : return int(stdin.readline())
def read_ints()    : return [int(x) for x in stdin.readline().split()]
def read_str()     : return input()
def read_strs()    : return [x for x in stdin.readline().split()]
def read_str_list(): return [x for x in stdin.readline().split().split()]

nb_elemets, value_needed = read_ints()
elements = sorted(read_ints())
mid = nb_elemets//2
ans = abs(elements[mid] - value_needed)
ans += sum( max(0, (a - value_needed)) for a in elements[:mid] )
ans += sum( max(0, (value_needed - a)) for a in elements[mid+1:] )
print(ans)


n,s=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
mid=(n-1)//2
import bisect
suma=0
#print(a)
val=bisect.bisect_left(a,s)
for i in range(mid,val):
    suma+=(s-a[i])
#print(mid,val)
print(suma)


n,s=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
mid=(n-1)//2
import bisect
suma=0
#print(a)
if s>a[mid]:
    val=bisect.bisect_left(a,s)
    for i in range(mid,val):
        suma+=(s-a[i])
    print(suma)
elif s<a[mid]:
    val=bisect.bisect_right(a,s)
    for i in range(val,mid+1):
        suma+=abs(s-a[i])
    print(suma)
else:
    print(0)
#print(mid,val)


n,k = map(int,input().split())
l = sorted(list(map(int,input().split())))
l = [k]  + l + [k]
n += 2
i = n//2
total = 0
if l[i] == k:
    print (total)
elif l[i]<k:
    while l[i]<k:
        total += k-l[i]
        i += 1
    print (total)
else:
    while l[i]>k:
        total += abs(k-l[i])
        i -= 1
    print (total)


n,k = map(int,input().split())
l = sorted(list(map(int,input().split())))
i = n//2
total = 0
if l[i] == k:
    print (total)
elif l[i]<k:
    while l[i]<k:
        total += k-l[i]
        i += 1
    print (total)
else:
    while l[i]>k:
        total += abs(k-l[i])
        i -= 1
    print (total)


n,k = map(int,input().split())
l = sorted(list(map(int,input().split())))
i = n//2
total = 0
while l[i]<k:
    total += k-l[i]
    i += 1
print (total)


n, s=[int(x) for x in input().split()]
A=[int(x) for x in input().split()]
A.sort()
print(A)
res=0
if(s>A[len(A)//2]):
    #res=0
    for i in range(len(A)//2, n):
        if(A[i]<s):
            res+=s-A[i]
else:
    #res=0
    for i in range(len(A)//2+1):
        if(A[i]>s):
            res+=A[i]-s
print(res)


n, s=[int(x) for x in input().split()]
A=[int(x) for x in input().split()]
A.sort()
res=0
for i in range(len(A)//2, n):
    if(A[i]<s):
        res+=s-A[i]
print(res)


n, s=[int(x) for x in input().split()]
A=[int(x) for x in input().split()]
A.sort()
#print(A)
res=0
if(s>A[len(A)//2]):
    #res=0
    for i in range(len(A)//2, n):
        if(A[i]<s):
            res+=s-A[i]
else:
    #res=0
    for i in range(len(A)//2+1):
        if(A[i]>s):
            res+=A[i]-s
print(res)


n, s = map(int, input().split())
a = list(map(int, input().split()))
b = list(enumerate(a))
b = sorted(b,key=lambda x: x[1])
med = b[n//2][1]
ans = 0
for i in range(n//2,n):
	ans += max(s - b[i][1],0)
print (ans)


n, s = map(int, input().split())
a = list(map(int, input().split()))
b = list(enumerate(a))
b = sorted(b,key=lambda x: x[1])
med = b[n//2][1]
ans = 0
if med == s:
	print (0)
	exit()
if med < s:
	for i in range(n//2,n):
		ans += max(s - b[i][1],0)
else:
	for i in range(n//2+1):
		ans += max(b[i][0]-s,0)
print (ans)


n, s = map(int, input().split())
a = list(map(int, input().split()))
b = list(enumerate(a))
b = sorted(b,key=lambda x: x[1])
med = b[n//2][1]
ans = 0
if med == s:
	print (0)
	exit()
if med < s:
	for i in range(n//2,n):
		ans += max(s - b[i][1],0)
else:
	for i in range(n//2+1):
		ans += max(b[i][1]-s,0)
print (ans)


"""http://codeforces.com/problemset/problem/1037/B"""

n, s = map(int, input().split())
a = map(int, input().split())
a = sorted(a)
if n == 1:
    print(abs(s - a[0]))
else:
    index = (n // 2)
    if a[index] == s:
        print(0)
    elif a[index] < s:
        k = [s - el for el in a if a[index] <= el < s]
        print(sum(k))
    else:
        k = [el - s for el in a if a[index] >= el > s]
        print(sum(k))


n, s = map(int, input().split())
a = map(int, input().split())
a = sorted(a)
if n == 1:
    print(abs(s - a[0]))
else:
    index = (n // 2)
    if a[index] == s:
        print(0)
    elif a[index] < s:
        k = [s - el for el in a[index:] if el < s]
        print(sum(k))
    else:
        k = [el - s for el in a[:index] if el < s]
        print(sum(k))


"""http://codeforces.com/problemset/problem/1037/B"""

n, s = map(int, input().split())
a = map(int, input().split())
a = sorted(a)
if n == 1:
    print(abs(s - a[0]))
else:
    index = (n // 2)
    if a[index] == s:
        print(0)
    elif a[index] < s:
        k = [s - el for el in a[index:] if el < s]
        print(sum(k))
    else:
        k = [el - s for el in a[:index+1] if el > s]
        print(sum(k))


n, s = map(int, input().split())
a = map(int, input().split())
a = sorted(a)
if n == 1:
    print(abs(s - a[0]))
else:
    index = (n // 2)
    if a[index] == s:
        print(0)
    elif a[index] < s:
        k = [s - el for el in a[index:] if el < s]
        print(sum(k))
    else:
        k = [el - s for el in a[:index+1] if el > s]
        print(sum(k))


n, s = map(int, input().split())
a = map(int, input().split())
a = sorted(a)
if n == 1:
    print(abs(s - a[0]))
else:
    index = (n // 2)
    if a[index] == s:
        print(0)
    elif a[index] < s:
        k = [s - el for el in a[index:] if el < s]
        print(sum(k))
    else:
        k = [el - s for el in a[:index] if el > s]
        print(sum(k))


from bisect import bisect_right

N, S = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr.sort()
center_index = N // 2
S_index = bisect_right(arr, S) - 1
moves = 0

if N == 1:
    moves = abs(arr[0] - S)
else:
    if S_index > center_index:
        for i in range(center_index, S_index + 1):
            moves += S - arr[i]
    elif S_index < center_index:
        for i in range(S_index + 1, center_index + 1):
            moves += arr[i] - S
    else:
        moves = abs(S - arr[center_index])

print(moves)


from bisect import bisect_right

N, S = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr.sort()
center_index = N // 2
S_index = bisect_right(arr, S) - 1
moves = 0

if N == 1:
    moves = abs(arr[0] - S)
else:
    if S_index > center_index:
        for i in range(center_index, S_index):
            moves += S - arr[i]

    if S_index < center_index:
        for i in range(S_index + 1, center_index + 1):
            moves += arr[i] - S

print(moves)


from bisect import bisect_right

N, S = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr.sort()
center_index = N // 2
S_index = bisect_right(arr, S) - 1
moves = 0

if S_index > center_index:
    for i in range(center_index, S_index):
        moves += S - arr[i]

if S_index < center_index:
    for i in range(S_index + 1, center_index + 1):
        moves += arr[i] - S

print(moves)


N, S = [int(x) for x in input().split()]
diffs = [0] * N

center = N // 2

i = 0
for x in input().split():
    diffs[i] = S - int(x)
    i += 1

# if center is positie then add all values before it.
# if center negative then then add abs values of it.

diffs.sort()

total_moves = 0
if diffs[center] > 0:
    while center != 0:
        if diffs[center] > 0:
            total_moves += diffs[center]
        else:
            break
        center -= 1
else:
    total_moves = abs(diffs[center])

print(total_moves)


from bisect import bisect_right

N, S = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr.sort()
center_index = N // 2
S_index = bisect_right(arr, S) - 1
moves = 0

if N == 1:
    moves = abs(arr[0] - S)
else:
    if S_index > center_index:
        for i in range(center_index, S_index + 1):
            moves += S - arr[i]

    if S_index < center_index:
        for i in range(S_index + 1, center_index + 1):
            moves += arr[i] - S

print(moves)


n, s = map(int, input().split())
a = [-1] + list(map(int, input().split())) + [1000000001]
a.sort()
ans = 0
i = n // 2 + 1
if (a[i] < s):
    while a[i] < s:
        ans += s - a[i]
        i += 1
else:
    while a[i] > s:
        ans += a[i] - s
        i -= 1
print(ans)


n, s = map(int, input().split())
a = list(map(int, input().split())) + [1000000001]
a.sort()
ans = 0
i = n // 2
while a[i] < s:
    ans += s - a[i]
    i += 1
print(ans)


n,s=map(int,input().split())
arr=list(map(int,input().split()))
count=0
arr=sorted(arr)
index=int(n/2)
count=0
while(arr[index]<s and index<n):
     count+=s-arr[index]
     arr[index]=s
     index+=1
index=int(n/2)
while(arr[index]>s and index>0):
     count+=arr[index]-s
     arr[index]=s
     index-=1
print(count)


def aa():
 n,s=map(int,input().split())
 arr=list(map(int,input().split()))
 count=0
 arr=sorted(arr)
 index=int(n/2)
 count=0
 while(arr[index]<s and index<n):
     count+=s-arr[index]
     arr[index]=s
     index+=1
 index=int(n/2)
 while(arr[index]>s and index>0):
     count+=arr[index]-s
     arr[index]=s
     index-=1
 print(count)
import time
start_time = time.time()
aa()
print("--- %s seconds ---" % (time.time() - start_time))


n,s=map(int,input().split())
arr=list(map(int,input().split()))
count=0
arr=sorted(arr)
index=int(n/2)
count=0
while(arr[index]<s ):
     count+=s-arr[index]
     arr[index]=s
     index+=1
     if(index==n):
         break
index=int(n/2)
while(arr[index]>s ):
     count+=arr[index]-s
     arr[index]=s
     index-=1
     if(index==-1):
         break
print(count)


n,s=map(int,input().split())
arr=list(map(int,input().split()))
count=0
arr=sorted(arr)
index=int(n/2)
while(arr[index]!=s):
    dif=s-arr[index]
    if(dif<0):
        count-=dif
    else:
        count+=dif
    arr[index]=s
    arr=sorted(arr)
print(count)


n,s=map(int,input().split())
arr=list(map(int,input().split()))
count=0
arr=sorted(arr)
index=int(n/2)
while(arr[index]!=s):
    dif=s-arr[index]
    if(dif<0):
        count-=dif
    else:
        count+=dif
    arr[index]=s
    while(arr[index]>arr[index+1]):
        tmp=arr[index]
        arr[index]=arr[index+1]
        arr[index+1]=tmp
        index+=1
        if(index==len(arr)-1):
            break
    index=int(n/2)
    while(arr[index]<arr[index-1]):
        tmp=arr[index]
        arr[index]=arr[index-1]
        arr[index-1]=tmp
        index-=1
        if(index==0):
            break
    index=int(n/2)
print(count)


import statistics as stat
n,s=list(map(int,input().split()))
arr = list(map(int,input().split()))
arr.sort()
median = stat.median(arr)
index = arr.index(median)
cost=0;
if n==1:
  cost+=abs(s-median)
else:
  for x in arr[0:n//2]:
    if x>s:
      cost+=(x-s)
  for x in arr[n//2:len(arr)]:
    if x<s:
      cost+=(s-x)
print(cost)


import statistics as stat
n,s=list(map(int,input().split()))
arr = list(map(int,input().split()))
arr.sort()
median = stat.median(arr)
index = arr.index(median)
cost=0;
if n==1:
  cost+=abs(s-median)
else:
  for x in arr[0:n//2+1]:
    if x>s:
      cost+=(x-s)
  for x in arr[n//2:len(arr)]:
    if x<s:
      cost+=(s-x)
print(cost)


import statistics as stat
n,m=list(map(int,input().split()))
arr = list(map(int,input().split()))
arr.sort()
median = stat.median(arr)
index = arr.index(median)
cost=0;
if n==1:
  print(abs(median-m))
else:
  if median==m:
      pass
  elif median > m:
      for x in arr[index:0:-1]:
          if m>x:
              break;
          cost+=(x-m)
  else:
      for x in arr[index:len(arr)]:
          if m<x:
              break;
          cost+=(m-x)
  print(cost)


import statistics as stat
n,m=list(map(int,input().split()))
arr = list(map(int,input().split()))
arr.sort()
median = stat.median(arr)
index = arr.index(median)
cost=0;
if median==m:
    pass
elif median > m:
    for x in arr[index:0:-1]:
        if m>x:
            break;
        cost+=(x-m)
else:
    for x in arr[index:len(arr)]:
        if m<x:
            break;
        cost+=(m-x)
print(cost)


n,s=input().split()
n=int(n)
s=int(s)
array=input().split()
fin=[]
for i in array:
    fin.append(int(i))
fin.sort()
#print(fin)
if(s not in fin):
    sums=abs(fin[(n)//2]-s)
else:

    ind=fin.index(s)+1
    remele=ind-((n+1)//2)
    #print(ind,remele)
    if(remele>0):
        sums=0
        i=1
        while(i<=remele):
            sums+=(s-fin[ind-i-1])
            i+=1
    else:
        remele=-1*remele
        sums=0
        i=1
        while(i<=remele):
            sums+=(fin[ind+i-1]-s)
            i+=1
print(sums)


n,s=input().split()
n=int(n)
s=int(s)
array=input().split()
fin=[]
for i in array:
    fin.append(int(i))
fin.sort()
#print(fin)
ind=fin.index(s)+1
remele=ind-((n+1)//2)
#print(ind,remele)
if(remele>0):
    sums=0
    i=1
    while(i<=remele):
        sums+=(s-fin[ind-i-1])
        i+=1
else:
    remele=-1*remele
    sums=0
    i=1
    while(i<=remele):
        sums+=(fin[ind+i-1]-s)
        i+=1
print(sums)


n,s=input().split()
n=int(n)
s=int(s)
array=input().split()
fin=[]
for i in array:
    fin.append(int(i))
fin.sort()
#print(fin)
ind=fin.index(s)+1
remele=ind-((n+1)//2)
#print(ind,remele)
if(remele>0):
    sums=0
    i=1
    while(i<=remele):
        sums+=(s-fin[ind-i-1])
        i+=1
else:
    sums=0
    i=1
    while(i<=remele):
        sums+=(fin[ind+i-1]-s)
        i+=1
print(sums)


def find(fin,s):
    if(s<fin[0]):
        return -1
    if(s>fin[-1]):
        return len(fin)-1
    i=0
    while(s>fin[i]):
        i+=1
    return i-1

n,s=input().split()
n=int(n)
s=int(s)
array=input().split()
fin=[]
for i in array:
    fin.append(int(i))
fin.sort()
#print(fin)
if(s not in fin):
    mids=n//2
    ind=find(fin,s)
    if(ind<mids):
        ind=ind+1
    #print("before",ind)
    if(ind<mids):
        sums=0
        while(ind<=mids):
            #print("if",ind)
            sums+=abs((fin[ind]-s))
            ind+=1
    else:
        sums=0
        while(ind>=mids):
            #print("else",ind)
            sums+=abs((fin[ind]-s))
            #print(sums)
            ind-=1
else:

    ind=fin.index(s)+1
    remele=ind-((n+1)//2)
    #print(ind,remele)
    if(remele>0):
        sums=0
        i=1
        while(i<=remele):
            sums+=(s-fin[ind-i-1])
            i+=1
    else:
        remele=-1*remele
        sums=0
        i=1
        while(i<=remele):
            sums+=(fin[ind+i-1]-s)
            i+=1
print(sums)


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class Blocks {
    void solve() {
        int n = in.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = in.nextInt();

        int[] dp = new int[n];

        for (int i = 0; i < n; i++) {
            dp[i] = Math.min(i + 1, h[i]);
            if (i > 0) dp[i] = Math.min(dp[i - 1] + 1, dp[i]);
        }

        for (int i = n - 1; i >= 0; i--) {
            dp[i] = Math.min(n - i, h[i]);
            if (i < n - 1) dp[i] = Math.min(dp[i + 1] + 1, dp[i]);
        }

        int ans = dp[0];
        for (int i = 1; i < n; i++) ans = Math.max(ans, dp[i]);
        out.println(ans);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new Blocks().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


/**
 *
 * @author meashish
 */
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.Serializable;
import java.util.InputMismatchException;

public class Main {

    InputReader in;
    PrintStream out;

    private void start() {
        int n = in.nextInt();

        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        int val[] = new int[n];
        val[0] = 1;

        for (int i = 1; i < n; i++) {
            int h = Math.min(a[i] - 1, a[i - 1]);

            val[i] = Math.min(h + 1, 1 + val[i - 1]);
        }

        val[n - 1] = 1;
        for (int i = n - 2; i >= 0; i--) {
            int h = Math.min(a[i] - 1, a[i + 1]);

            val[i] = Math.min(val[i], Math.min(h + 1, 1 + val[i + 1]));
        }

        int max = 0;
        for (int i = 0; i < n; i++) {
            max = Math.max(max, val[i]);
            //out.print(val[i] + " ");
        }
        //out.println();
        out.println(max);
    }

    public static void main(String[] args) {
        //InputReader in = new InputReader(new FileInputStream(new File("in.txt")));
        //PrintStream out = new PrintStream("out.txt");

        InputReader in = new InputReader(System.in);
        PrintStream out = System.out;

        Main main = new Main();

        main.in = in;
        main.out = out;

        main.start();
    }

    private static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {

            public boolean isSpaceChar(int ch);
        }
    }

    private class Pair<K, V> implements Serializable {

        private K key;

        public K getKey() {
            return key;
        }
        private V value;

        public V getValue() {
            return value;
        }

        public Pair(K key, V value) {
            this.key = key;
            this.value = value;
        }

        @Override
        public String toString() {
            return key + "=" + value;
        }

        @Override
        public int hashCode() {
            return key.hashCode() * 13 + (value == null ? 0 : value.hashCode());
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o instanceof Pair) {
                Pair pair = (Pair) o;
                if (key != null ? !key.equals(pair.key) : pair.key != null) {
                    return false;
                }
                if (value != null ? !value.equals(pair.value) : pair.value != null) {
                    return false;
                }
                return true;
            }
            return false;
        }
    }

}


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

public final class BearAndBlocks
{
	public static void main(String[] args)
	{
		new BearAndBlocks(System.in, System.out);
	}

	static class Solver
	{
		// BufferedReader in;
		int n;
		int[] heights, left, right;
		InputReader in;
		PrintWriter out;

		void solve() throws IOException
		{
			n = in.nextInt();
			heights = new int[n];
			left = new int[n];
			right = new int[n];

			for (int i = 0; i < n; i++)
				heights[i] = in.nextInt();

			left[0] = Math.min(1, heights[0]);

			for (int i = 1; i < n; i++)
				left[i] = Math.min(left[i - 1] + 1, heights[i]);

			right[n - 1] = Math.min(1, heights[n - 1]);

			for (int i = n - 2; i >= 0; i--)
				right[i] = Math.min(right[i + 1] + 1, heights[i]);

			int ans = 1;

			for (int i = 0; i < n; i++)
				ans = Math.max(ans, Math.min(left[i], right[i]));

			out.println(ans);
		}

		Solver(InputReader in, PrintWriter out)
		{
			this.in = in;
			this.out = out;
		}

	}

	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public int read()
		{
			if (numChars == -1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}

			return buf[curChar++];
		}

		public int nextInt()
		{
			int c = read();

			while (isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

			int res = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();

				res *= 10;
				res += c & 15;

				c = read();
			} while (!isSpaceChar(c));

			return res * sgn;
		}

		public boolean isSpaceChar(int c)
		{
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public void close()
		{
			try
			{
				stream.close();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
		}

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

	}

	public BearAndBlocks(InputStream inputStream, OutputStream outputStream)
	{
		// uncomment below line to change to BufferedReader
		// BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Solver solver = new Solver(in, out);

		try
		{
			solver.solve();
			in.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}

		out.flush();
		out.close();
	}

}


import java.util.Scanner;

public class BearAndBlocks {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		int heights[] = new int[n + 2];
		for (int i = 1; i <= n; ++i)
			heights[i] = scanner.nextInt();
		scanner.close();

		int results[] = new int[n + 2];
		for (int i = 1; i <= n; ++i)
			results[i] = Math.min(results[i - 1] + 1, heights[i]);

		int max = Integer.MIN_VALUE;
		for (int i = n; i > 0; --i)
			max = Math.max(max,
					results[i] = Math.min(results[i + 1] + 1, results[i]));

		System.out.println(max);

	}

}


import java.util.Scanner;

public class BearAndBlocks {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		int heights[] = new int[n + 2];
		for (int i = 1; i <= n; ++i)
			heights[i] = scanner.nextInt();
		scanner.close();

		int max = 0;
		for (int i = 1; i <= n; ++i) {

			int steps = 0;
			int running = heights[i];

			do {
				++steps;
				running = Math.min(running - 1,
						Math.min(heights[i - steps], heights[i + steps]));
			} while (running != 0);

			max = Math.max(max, steps);
		}

		System.out.println(max);

	}

}


import java.util.*;
import java.io.*;
/*NO RESPECT*/

public class Main implements Runnable {
static boolean showTime = false;
	public void solve() throws IOException {
		int n = nextInt();
                int[] h = new int[n];
                for(int i = 0; i < n; i++) h[i] = nextInt() - 1;
                int[] left = new int[n];
                int[] right = new int[n];

                left[0] = 0;
                for( int i = 1; i < n; i++){
                    left[i] = Math.min(h[i], left[i-1] + 1);
                }

                right[n-1] = 0;
                for(int i = n - 2; i >= 0; i--){
                    right[i] = Math.min(h[i], right[i + 1] + 1);
                }

                int answer = 0;
                for(int i = 0; i < n; i++){
                    //out.println(left[i] + " " + right[i]);
                    int m = Math.min(left[i], right[i]);
                    answer = Math.max(answer, m);
                }

                out.println(answer+1);
	}

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void debug(Object... arr){
            System.out.println(Arrays.deepToString(arr));
        }

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
			tok = null;
			long start = System.currentTimeMillis();
			solve();
                        long end = System.currentTimeMillis();
                        if(showTime)System.err.println( (end - start) / 1000.0);
			in.close();
                        out.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
        PrintWriter out;
	BufferedReader in;
	StringTokenizer tok;
}


//package practice;
/**
 * Created by Rajan Waliya on 03-Sep-15.
 */

import java.io.*;
import java.util.*;

//public
class D574 {

    Reader sc;
    PrintWriter out;

    int n;
    int[] h;

    void solve() throws IOException {
        n = sc.nextInt();
        h = new int[n+2];
        for(int i=1;i<=n;i++){
            h[i]=sc.nextInt();
        }
        int[] res = new int[n+2];// keeps the steps it will take to destroy ith

        //from left to right
        for(int i=1;i<=n;i++){
            res[i]=Math.min(h[i],res[i-1]+1);   //will either finish from left or one day at a time; whatever comes first
        }
        //from right to left
        for(int i=n;i>0;i--){
            res[i]=  Math.min(res[i],res[i+1]+1);
        }
        int ans = 0;
        //find max of these
        for(int i=1;i<=n;i++){
            ans = Math.max(ans,res[i]);
        }
        System.out.println(ans);
    }

    //_______congratulation!!! main logic has ended, no need to understand what is after this line.________
    void runIO() throws Exception {
        sc = new Reader();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws Exception {
        new D574().runIO();
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10L + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            byte c;
            while ((c = read()) <= ' ') ;
            do {
                sb.append((char) c);
            } while ((c = read()) > ' ');
            return sb.toString();
        }

        public int nextInt2() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

}


//package practice;
/**
 * Created by Rajan Waliya on 03-Sep-15.
 */

import java.io.*;
import java.util.*;

//public
class D574 {

    Reader sc;
    PrintWriter out;

    int n;
    int[] h;

    void solve() throws IOException {
        n = sc.nextInt();
        h = new int[n+2];
        for(int i=1;i<=n;i++){
            h[i]=sc.nextInt();
        }
        int[] res = new int[n+2];// keeps the steps it will take to destroy ith
        //from left to right
        for(int i=1;i<=n;i++){
            res[i]=res[i-1]+1;
        }
        //from right to left
        for(int i=n;i>0;i--){
            res[i]=  Math.min(res[i],res[i+1]+1);
        }
        int ans = 0;
        //find max of these
        for(int i=1;i<=n;i++){
            ans = Math.max(ans,res[i]);
        }
        System.out.println(ans);
    }

    //_______congratulation!!! main logic has ended, no need to understand what is after this line.________
    void runIO() throws Exception {
        sc = new Reader();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws Exception {
        new D574().runIO();
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10L + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            byte c;
            while ((c = read()) <= ' ') ;
            do {
                sb.append((char) c);
            } while ((c = read()) > ' ');
            return sb.toString();
        }

        public int nextInt2() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

}


//package practice;
/**
 * Created by Rajan Waliya on 03-Sep-15.
 */

import java.io.*;
import java.util.*;

//public
class D574 {

    Reader sc;
    PrintWriter out;

    int n;
    int[] h;

    void solve() throws IOException {
        n = sc.nextInt();
        h = new int[n];
        boolean sameh = true;
        int hi=0;
        for(int i=0;i<n;i++){
            h[i]=sc.nextInt();
            if(i==0){hi=h[i];}
            else{
                if(h[i]!=hi){sameh=false;}
            }
        }

        if(sameh){
            System.out.println(hi);return;
        }
        int[] a = new int[n];
        int[] b = new int[n];
        int temp;
        int steps = 0;
        while (true){

            //go from left to right
            a[0]=h[0];
            for(int i=1;i<n;i++){
                temp = h[i]-h[i-1];
                a[i]= (temp>1)?temp:1;
            }
            //go from right to left
            b[n-1]=h[n-1];
            for(int i=n-2;i>=0;i--){
                temp = h[i]-h[i+1];
                b[i]= (temp>1)?temp:1;
                a[i]=Math.max(a[i],b[i]);
            }
            a[n-1]=b[n-1];

            boolean allz = true;
            for(int i=0;i<n;i++){
                h[i]-=a[i];
                if(h[i]>0){allz=false;}
            }
            steps++;
            if(allz){break;}
        }

        System.out.println(steps);
    }

    //_______congratulation!!! main logic has ended, no need to understand what is after this line.________
    void runIO() throws Exception {
        sc = new Reader();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws Exception {
        new D574().runIO();
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10L + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            byte c;
            while ((c = read()) <= ' ') ;
            do {
                sb.append((char) c);
            } while ((c = read()) > ' ');
            return sb.toString();
        }

        public int nextInt2() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

}


//package practice;
/**
 * Created by Rajan Waliya on 03-Sep-15.
 */

import java.io.*;
import java.util.*;

//public
class D574 {

    Reader sc;
    PrintWriter out;

    int n;
    int[] h;

    void solve() throws IOException {
        n = sc.nextInt();
        h = new int[n];
        boolean sameh = true;
        int hi=0;
        for(int i=0;i<n;i++){
            h[i]=sc.nextInt();
            if(i==0){hi=h[i];}
            else{
                if(h[i]!=hi){sameh=false;}
            }
        }

        if(sameh){
            int half = n/2;
            if(n%2!=0){half++;}
            half = Math.min(half,hi);
            System.out.println(half);return;
        }
        int[] a = new int[n];
        int[] b = new int[n];
        int temp;
        int steps = 0;
        while (true){

            //go from left to right
            a[0]=h[0];
            for(int i=1;i<n;i++){
                temp = h[i]-h[i-1];
                a[i]= (temp>1)?temp:1;
            }
            //go from right to left
            b[n-1]=h[n-1];
            for(int i=n-2;i>=0;i--){
                temp = h[i]-h[i+1];
                b[i]= (temp>1)?temp:1;
                a[i]=Math.max(a[i],b[i]);
            }
            a[n-1]=b[n-1];

            boolean allz = true;
            for(int i=0;i<n;i++){
                h[i]-=a[i];
                if(h[i]>0){allz=false;}
            }
            steps++;
            if(allz){break;}
        }

        System.out.println(steps);
    }

    //_______congratulation!!! main logic has ended, no need to understand what is after this line.________
    void runIO() throws Exception {
        sc = new Reader();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws Exception {
        new D574().runIO();
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10L + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            byte c;
            while ((c = read()) <= ' ') ;
            do {
                sb.append((char) c);
            } while ((c = read()) > ' ');
            return sb.toString();
        }

        public int nextInt2() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

}


//package practice;
/**
 * Created by Rajan Waliya on 03-Sep-15.
 */

import java.io.*;
import java.util.*;

//public
class D574 {

    Reader sc;
    PrintWriter out;

    int n;
    int[] h;

    void solve() throws IOException {
        n = sc.nextInt();
        h = new int[n+2];
        for(int i=1;i<=n;i++){
            h[i]=sc.nextInt();
        }
        int[] res = new int[n+2];// keeps the steps it will take to destroy ith

        //from left to right
        for(int i=1;i<=n;i++){
            res[i]=Math.min(h[i],res[i-1]+1);
        }
        //from right to left
        for(int i=n;i>0;i--){
            res[i]=  Math.min(res[i],res[i+1]+1);
        }
        int ans = 0;
        //find max of these
        for(int i=1;i<=n;i++){
            ans = Math.max(ans,res[i]);
        }
        System.out.println(ans);
    }

    //_______congratulation!!! main logic has ended, no need to understand what is after this line.________
    void runIO() throws Exception {
        sc = new Reader();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws Exception {
        new D574().runIO();
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10L + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            byte c;
            while ((c = read()) <= ' ') ;
            do {
                sb.append((char) c);
            } while ((c = read()) > ' ');
            return sb.toString();
        }

        public int nextInt2() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

}


//package practice;
/**
 * Created by Rajan Waliya on 03-Sep-15.
 */

import java.io.*;
import java.util.*;

//public
class D574 {

    Reader sc;
    PrintWriter out;

    int n;
    int[] h;

    void solve() throws IOException {
        n = sc.nextInt();
        h = new int[n];
        //boolean sameh = true;
       // int hi=0;
        for(int i=0;i<n;i++){
            h[i]=sc.nextInt();
//            if(i==0){hi=h[i];}
//            else{
//                if(h[i]!=hi){sameh=false;}
//            }
        }

//        if(sameh){
//            System.out.println(hi);return;
//        }
        int[] a = new int[n];
        int[] b = new int[n];
        int temp;
        int steps = 0;
        while (true){

            //go from left to right
            a[0]=h[0];
            for(int i=1;i<n;i++){
                temp = h[i]-h[i-1];
                a[i]= (temp>1)?temp:1;
            }
            //go from right to left
            b[n-1]=h[n-1];
            for(int i=n-2;i>=0;i--){
                temp = h[i]-h[i+1];
                b[i]= (temp>1)?temp:1;
                a[i]=Math.max(a[i],b[i]);
            }
            a[n-1]=b[n-1];

            boolean allz = true;
            for(int i=0;i<n;i++){
                h[i]-=a[i];
                if(h[i]>0){allz=false;}
            }
            steps++;
            if(allz){break;}
        }

        System.out.println(steps);
    }

    //_______congratulation!!! main logic has ended, no need to understand what is after this line.________
    void runIO() throws Exception {
        sc = new Reader();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws Exception {
        new D574().runIO();
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10L + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            byte c;
            while ((c = read()) <= ' ') ;
            do {
                sb.append((char) c);
            } while ((c = read()) > ' ');
            return sb.toString();
        }

        public int nextInt2() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main{

	public static int gcd(int a, int b){
	    if (b == 0)
	       return a;
	    else
	       return gcd(b, a % b);
	}

	public static int mcm(int a, int b){
		return Math.abs(a*b)/gcd(a,b);
	}

	public static void main(String args[])throws IOException {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		int n = Integer.parseInt(in.readLine());
		int arr[] = readInts(in.readLine());
		int r[] = new int[n];
		int r2[] = new int[n];
		r[0] = 1;
		r[n-1] = 1;
		r2[0] = 1;
		r2[n-1] = 1;
		for( int i  = 1; i < n-1 ; i++ ){
			r[i] = Math.min(i+1, n - i);
			r[i] = Math.min(r[i],arr[i]);
			if(arr[i]>arr[i-1]){
				r[i] = Math.min(r[i],r[i-1] + 1);
			}
			//if(arr[i] == arr[i-1])
			//	r[i] = Math.min(r[i],r[i-1] + 1);
		}

		for( int i  = n-2; i >=0; i-- ){
			r2[i] = Math.min(i+1, n - i);
			r2[i] = Math.min(r2[i],arr[i]);
			if(arr[i]>arr[i+1]){
				r2[i] = Math.min(r2[i],r2[i+1] + 1);
			}
			//if(arr[i]==arr[i+1]){
			//	r2[i] = Math.min(r2[i],r2[i+1] + 1);
			//}
		}

		//for( int i  = 0; i < n; i++ ){
		//	System.out.print(r[i]+ " ");
		//}
		//System.out.println();
		//for( int i  = 0; i < n; i++ ){
		//	System.out.print(r2[i]+ " ");
		//}

		int w = -1;
		for( int i  = 0; i < n; i++ ){
			w = Math.max(w, Math.min(r[i],r2[i]));

		}

		out.append(w);
		System.out.println(out);
	}

	public static int[] readInts(String cad){
		String line[] = cad.split(" ");
		int arr[] = new int[line.length];
		for( int i = 0; i < arr.length ; i++ ){
			arr[i] = Integer.parseInt(line[i]);
		}
		return arr;
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main{

	public static int gcd(int a, int b){
	    if (b == 0)
	       return a;
	    else
	       return gcd(b, a % b);
	}

	public static int mcm(int a, int b){
		return Math.abs(a*b)/gcd(a,b);
	}

	public static void main(String args[])throws IOException {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		int n = Integer.parseInt(in.readLine());
		int arr[] = readInts(in.readLine());
		int r[] = new int[n];
		int r2[] = new int[n];
		r[0] = 1;
		r[n-1] = 1;
		r2[0] = 1;
		r2[n-1] = 1;
		for( int i  = 1; i < n-1 ; i++ ){
			r[i] = Math.min(i+1, n - i);
			r[i] = Math.min(r[i],arr[i]);
			r[i] = Math.min(r[i],r[i-1] + 1);

		}

		for( int i  = n-2; i >=1; i-- ){
			r2[i] = Math.min(i+1, n - i);
			r2[i] = Math.min(r2[i],arr[i]);
			r2[i] = Math.min(r2[i],r2[i+1] + 1);

		}

		int w = -1;
		for( int i  = 0; i < n; i++ ){
			w = Math.max(w, Math.min(r[i],r2[i]));

		}

		out.append(w);
		System.out.println(out);
	}

	public static int[] readInts(String cad){
		String line[] = cad.split(" ");
		int arr[] = new int[line.length];
		for( int i = 0; i < arr.length ; i++ ){
			arr[i] = Integer.parseInt(line[i]);
		}
		return arr;
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main{

	public static int gcd(int a, int b){
	    if (b == 0)
	       return a;
	    else
	       return gcd(b, a % b);
	}

	public static int mcm(int a, int b){
		return Math.abs(a*b)/gcd(a,b);
	}

	public static void main(String args[])throws IOException {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		int n = Integer.parseInt(in.readLine());
		int arr[] = readInts(in.readLine());
		int r[] = new int[n];
		int r2[] = new int[n];
		r[0] = 1;
		r[n-1] = 1;
		r2[0] = 1;
		r2[n-1] = 1;
		for( int i  = 1; i < n-1 ; i++ ){
			r[i] = Math.min(i+1, n - i);
			r[i] = Math.min(r[i],arr[i]);
			if(arr[i]>arr[i-1]){
				r[i] = Math.min(r[i],r[i-1] + 1);
			}
			if(arr[i] == arr[i-1])
				r[i] = Math.min(r[i],r[i-1] + 1);
		}

		for( int i  = n-2; i >=0; i-- ){
			r2[i] = Math.min(i+1, n - i);
			r2[i] = Math.min(r2[i],arr[i]);
			if(arr[i]>arr[i+1]){
				r2[i] = Math.min(r2[i],r2[i+1] + 1);
			}
			if(arr[i]==arr[i+1]){
				r2[i] = Math.min(r2[i],r2[i+1] + 1);
			}
		}

		//for( int i  = 0; i < n; i++ ){
		//	System.out.print(r[i]+ " ");
		//}
		//System.out.println();
		//for( int i  = 0; i < n; i++ ){
		//	System.out.print(r2[i]+ " ");
		//}

		int w = -1;
		for( int i  = 0; i < n; i++ ){
			w = Math.max(w, Math.min(r[i],r2[i]));

		}

		out.append(w);
		System.out.println(out);
	}

	public static int[] readInts(String cad){
		String line[] = cad.split(" ");
		int arr[] = new int[line.length];
		for( int i = 0; i < arr.length ; i++ ){
			arr[i] = Integer.parseInt(line[i]);
		}
		return arr;
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class D {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();

        int n = sc.nextInt();
        int[] h = sc.readIntArray(n);
        int[] dp = new int[n];
        for (int i = 0; i < n; i++) {
            dp[i] = Math.min(h[i], Math.min(i + 1, n - i));
        }
        for (int i = 1; i < n; i++) {
            dp[i] = Math.min(dp[i], dp[i-1] + 1);
        }
        for (int i = n - 2; i >= 0; i--) {
            dp[i] = Math.min(dp[i], dp[i+1] + 1);
        }
        int max = Arrays.stream(dp).max().getAsInt();
        System.out.println(max);
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
        long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextLong();
            }
            return a;
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class ProblemD {
	public static void main(String[] args){
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			String line = br.readLine();
			int size = Integer.parseInt(line);
			//System.out.println(line);
			String line2 = br.readLine();
			//System.out.println(line2);
			StringTokenizer st = new StringTokenizer(line2);
			int[] inputArray = new int[size];
			for(int a = 0; a < size; a++){
				inputArray[a] = Integer.parseInt(st.nextToken());
				if(inputArray[a] > 100000){
					inputArray[a] = 100000;
				}
			}
			int[] trackArray = new int[size];
			for(int a = 0; a < size; a++){
				trackArray[a] = 1000000;
			}
			trackArray[0] = 1;
			trackArray[size - 1] = 1;
			for(int a = 1; a < size; a++){
				trackArray[a] = Math.min(Math.min(trackArray[a-1] + 1, inputArray[a]), trackArray[a]);
				trackArray[size - 1 - a] = Math.min(Math.min(trackArray[size - a] + 1, inputArray[size - 1 - a]), trackArray[size - 1 - a]);
			}
			if(size % 2 == 1 && size > 1){
				trackArray[size/2] = Math.min(Math.min(trackArray[size/2 - 1] + 1, trackArray[size/2 + 1] + 1), inputArray[size/2]);
			}
			//we have the end

			int max = -1;
			for(int a = 0; a < size; a++){
				if(max < trackArray[a]){
					max = trackArray[a];
				}
			}
			System.out.println(max);
			//debug(trackArray);
		}
		catch(Exception e){
			//The classic exception handle
			//System.out.println("CRAP");
		}
	}
	public static void debug(int[] test){
		for(int a = 0; a < test.length; a++){
			System.out.print(test[a] + " ");
		}
		System.out.println();
	}
}


import java.util.Scanner;

public class Main {
    public static long min(long x,long y){
        return x<y?x:y;
    }

    public static long count(long[] original){
        int n = original.length;
        long[] left = new long[n];
        long[] right = new long[n];
        long best = 1;
        for(int i=0;i<n;i++){
            best = min(best,original[i]);
            left[i] = best;
            best++;
        }
        best = 1;
        for(int i=n-1;i>=0;i--){
            best = min(best,original[i]);
            right[i] = best;
            best++;
        }
        best = 0;
        for(int i=0;i<n;i++){
            long value = min(left[i],right[i]);
            if(value>best)best = value;
        }
        return best/*min(best,n%2==0?(n/2):(n/2)+1)*/;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] arr = new long[n];
        for(int i=0;i<n;i++){
            arr[i] = sc.nextLong();
        }
        System.out.println(count(arr));
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static long min(long x,long y){
        return x<y?x:y;
    }
    public static void swap(long arr[],int indices[],int i,int j){
        long temp1=arr[i];
        arr[i]=arr[j];
        arr[j]=temp1;
        int temp2=indices[i];
        indices[i]=indices[j];
        indices[j]=temp2;
    }
    public static int partition(long arr[],int indices[],int start,int end){
        int i=start+1;
        long pivot=arr[start];
        for(int j=start+1;j<=end;j++){
            if(arr[j]<pivot){
                swap(arr,indices,i,j);
                i++;
            }
        }
        swap(arr,indices,start,i-1);
        return (i-1);
    }
    public static void quickSort1(long []a,int[] indices,int start,int end)
    {
        if(start>=end)return;
        else{
            int pivot=partition(a,indices,start,end);
            quickSort1(a,indices,start,pivot-1);
            quickSort1(a,indices,pivot+1,end);
        }
    }
    public static long count(long[] original){
        int n = original.length;
        long total = 0;
        long subtract = 0;
        long previous = original[0];
        original[0] = 0;
        int finish = 2;
        for(int i=1;i<n-1;i++){
            total += original[i];
            long x = original[i] - min(previous,original[i+1]);
            previous = original[i];
            if(x <= 0){
                original[i] --;
                subtract ++;
            }

            else{
                original[i] -= x;
                subtract+=x;
            }
            if(original[i] == 0)finish++;
        }
        original[n-1] = 0;
        total -= subtract;
        subtract = 0;
        int[] indices = new int[n];
        long[] sorted = new long[n];
        for(int i=0;i<n;i++){
            sorted[i]= original[i];
            indices[i] = i;
        }
        quickSort1(sorted,indices,0,n-1);
        int current = 0;
        int l=1;
        int r=n-2;
        int nSteps = 1;
        subtract = 0;
        while(total>0){
            nSteps++;
            while(original[l]<=subtract)l++;
            while(original[r]<=subtract)r--;

            //System.out.println(l + " " + r);
            //System.out.println(total);
            //System.out.println(original[l] + " " + original[r]);
            finish+=2;
            //System.out.println(finish);

            total -= (original[l] - subtract);
            total -= (original[r] - subtract);
            total -= (n-finish);
            //System.out.println("total = " + total);
            subtract++;
            while(true){
                //System.out.println(current);
                while(!(indices[current]>l && indices[current]<r)){
                    current++;
                    if(current==n){
                        //System.out.println("will return");
                        return nSteps;
                    }
                }
                if(sorted[current] - subtract == 0){
                    finish++;
                    current++;
                }
                else break;
            }
            original[l] = 0;
            original[r] = 0;
        }
        return nSteps;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] arr = new long[n];
        for(int i=0;i<n;i++){
            arr[i] = sc.nextLong();
        }
        System.out.println(count(arr));
    }
}


import java.util.Scanner;

public class Main {
    public static long min(long x,long y){
        return x<y?x:y;
    }
    public static void swap(long arr[],int indices[],int i,int j){
        long temp1=arr[i];
        arr[i]=arr[j];
        arr[j]=temp1;
        int temp2=indices[i];
        indices[i]=indices[j];
        indices[j]=temp2;
    }
    public static int partition(long arr[],int indices[],int start,int end){
        int i=start+1;
        long pivot=arr[start];
        for(int j=start+1;j<=end;j++){
            if(arr[j]<pivot){
                swap(arr,indices,i,j);
                i++;
            }
        }
        swap(arr,indices,start,i-1);
        return (i-1);
    }
    public static void quickSort1(long []a,int[] indices,int start,int end)
    {
        if(start>=end)return;
        else{
            int pivot=partition(a,indices,start,end);
            quickSort1(a,indices,start,pivot-1);
            quickSort1(a,indices,pivot+1,end);
        }
    }
    public static long count(long[] original){
        int n = original.length;
        long[] left = new long[n];
        long[] right = new long[n];
        long best = Long.MAX_VALUE;
        for(int i=0;i<n;i++){
            best = min(best,original[i]);
            left[i] = best;
            best++;
        }
        best = Long.MAX_VALUE;
        for(int i=n-1;i<=0;i--){
            best = min(best,original[i]);
            left[i] = best;
            best++;
        }
        best = 0;
        for(int i=0;i<n;i++){
            long value = min(left[i],right[i]);
            if(value>best)best = value;
        }
        return best;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] arr = new long[n];
        for(int i=0;i<n;i++){
            arr[i] = sc.nextLong();
        }
        System.out.println(count(arr));
    }
}


import java.util.Scanner;

public class Main {
    public static long min(long x,long y){
        return x<y?x:y;
    }

    public static long count(long[] original){
        int n = original.length;
        long[] left = new long[n];
        long[] right = new long[n];
        long best = Long.MAX_VALUE;
        for(int i=0;i<n;i++){
            best = min(best,original[i]);
            left[i] = best;
            best++;
        }
        best = Long.MAX_VALUE;
        for(int i=n-1;i>=0;i--){
            best = min(best,original[i]);
            right[i] = best;
            best++;
        }
        best = 0;
        for(int i=0;i<n;i++){
            long value = min(left[i],right[i]);
            if(value>best)best = value;
        }
        return best;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] arr = new long[n];
        for(int i=0;i<n;i++){
            arr[i] = sc.nextLong();
        }
        System.out.println(count(arr));
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static long min(long x,long y){
        return x<y?x:y;
    }
    public static void swap(long arr[],int indices[],int i,int j){
        long temp1=arr[i];
        arr[i]=arr[j];
        arr[j]=temp1;
        int temp2=indices[i];
        indices[i]=indices[j];
        indices[j]=temp2;
    }
    public static int partition(long arr[],int indices[],int start,int end){
        int i=start+1;
        long pivot=arr[start];
        for(int j=start+1;j<=end;j++){
            if(arr[j]<pivot){
                swap(arr,indices,i,j);
                i++;
            }
        }
        swap(arr,indices,start,i-1);
        return (i-1);
    }
    public static void quickSort1(long []a,int[] indices,int start,int end)
    {
        if(start>=end)return;
        else{
            int pivot=partition(a,indices,start,end);
            quickSort1(a,indices,start,pivot-1);
            quickSort1(a,indices,pivot+1,end);
        }
    }
    public static long count(long[] original){
        int n = original.length;
        long total = 0;
        long subtract = 0;
        long previous = original[0];
        original[0] = 0;
        int finish = 2;
        for(int i=1;i<n-1;i++){
            total += original[i];
            long x = original[i] - min(previous,original[i+1]);
            previous = original[i];
            if(x <= 0){
                original[i] --;
                subtract ++;
            }

            else{
                original[i] -= x;
                subtract+=x;
            }
            if(original[i] == 0)finish++;
        }
        original[n-1] = 0;
        total -= subtract;
        subtract = 0;
        int[] indices = new int[n];
        long[] sorted = new long[n];
        for(int i=0;i<n;i++){
            sorted[i]= original[i];
            indices[i] = i;
        }
        quickSort1(sorted,indices,0,n-1);
        int current = 0;
        int l=1;
        int r=n-2;
        int nSteps = 1;
        subtract = 0;
        while(total>0){
            nSteps++;
            while(original[l]<=subtract)l++;
            while(original[r]<=subtract)r--;

            //System.out.println(l + " " + r);
            //System.out.println(total);
            //System.out.println(original[l] + " " + original[r]);
            finish+=2;
            //System.out.println(finish);

            total -= (original[l] - subtract);
            total -= (original[r] - subtract);
            total -= (n-finish);
            //System.out.println("total = " + total);
            subtract++;
            while(true){
                //System.out.println(current);
                while(!(indices[current]>l && indices[current]<r)){
                    current++;
                    if(current==n){
                        //System.out.println("will return");return nSteps;
                    }
                }
                if(sorted[current] - subtract == 0){
                    finish++;
                    current++;
                }
                else break;
            }
            original[l] = 0;
            original[r] = 0;
        }
        return nSteps;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] arr = new long[n];
        for(int i=0;i<n;i++){
            arr[i] = sc.nextLong();
        }
        System.out.println(count(arr));
    }
}


import java.util.*;
import java.io.*;
public class Main {
public static void main(String [] args)throws Exception{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int n = Integer.parseInt(br.readLine());
	int array[] = new int[n];
	StringTokenizer st = new StringTokenizer(br.readLine());
	for(int i = 0;i < n;i++){
		array[i] = Integer.parseInt(st.nextToken());
	}
    int low = 0;
    int high = n/2 + 5;

    while(low < high){
    	int mid = (low + high)/2;
    	boolean forward[] = new boolean[n];
    	boolean backward[] = new boolean[n];
    	int cnt = 1;
    	for(int i = 0;i < n;i++){
    		if(array[i] < cnt){
    			cnt = array[i];
    		}
    		if(cnt == mid){
    			forward[i - mid + 1] = true;
    			cnt--;
    		}
    		cnt++;
    	}
    	cnt = 1;
    	for(int i = n - 1;i >= 0;i--){
    		if(array[i] < cnt){
    			cnt = array[i];
    		}
    		if(cnt == mid){
    			backward[i + mid - 1] = true;
    			cnt--;
    		}
    		cnt++;
    	}
    	boolean flag = false;
    	for(int i = 0;i < n;i++){
    		//System.out.println(i + " " + (i + 2*mid - 2));
    		if(i + 2*mid - 2 < n && forward[i] && backward[i + 2*mid - 2]){
    		flag = true;
    	}
    	}
    	//System.out.println(mid + " " + flag);
    	if(!flag)high = mid;
    	else low = mid + 1;
    }
    System.out.print(low - 1);

}
}


import java.io.*;
import java.util.*;

public class D {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		int nbB = sc.nextInt();
		int[] height = new int[nbB];
		// we don't care of the first value
		sc.nextInt();
		height[0] = 1;

		for (int i = 1; i < nbB; i++) {
			int input = sc.nextInt();
			height[i] = min(input, height[i - 1] + 1, nbB - i);
			int distanceToPrevToCheck = 1;
			while (height[i] + distanceToPrevToCheck < height[i - distanceToPrevToCheck]) {
				height[i - distanceToPrevToCheck] = height[i] + distanceToPrevToCheck;
				distanceToPrevToCheck++;
			}

		}
		int max = 1;
		for (int i = 1; i < nbB; i++) {
			if (height[i] > max) {
				max = height[i];
			}
		}
		// System.out.println(Arrays.toString(height));
		System.out.println(max);

	}

	private static int min(int input, int i, int j) {
		return Math.min(input, Math.min(i, j));
	}

	// -----------MyScanner class for faster input thx Flatfoot----------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			this.br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (this.st == null || !this.st.hasMoreElements()) {
				try {
					this.st = new StringTokenizer(this.br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return this.st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = this.br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	// --------------------------------------------------------
}