Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.

Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.


-----Input-----

The first line of the input contains a single integer n (2 ≤ n ≤ 100) — the size of the permutation.

The second line of the input contains n distinct integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n), where a_{i} is equal to the element at the i-th position.


-----Output-----

Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.


-----Examples-----
Input
5
4 5 1 3 2

Output
3

Input
7
1 6 5 3 4 7 2

Output
6

Input
6
6 5 4 3 2 1

Output
5



-----Note-----

In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.

In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.

In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.

Difficulty: interview

Starter code:

Solutions:
read = lambda: list(map(int, input().split()))
n = int(input())
a = list(read())
x, y = a.index(1), a.index(n)
ans = max(x, y, n - x - 1, n - y - 1)
print(ans)


n = int(input())
a = list(map(int, input().split()))
i, j = sorted([a.index(1), a.index(n)])
print(max(j, n - i - 1))


n = int(input())
L = list(map(int, input().split()))
ma = L.index(n)
mi = L.index(1)
if n == 2:
    print(1)
else:
    print(n-1-min(ma,mi,n-1-ma,n-1-mi))


from sys import *
inp = lambda : stdin.readline()

def main():
    n = int(inp())
    a,b = 0,0
    l = [int(i) for i in inp().split()]
    for i in range(len(l)):
        if l[i] == 1:
            a = i
        if l[i] == n:
            b = i
    if a > b:
        a,b = b,a
    ans = max(n-1-a,b)
    print(ans)


def __starting_point():
    main()
__starting_point()

n = int(input())
a = list(map(int,input().split()))
x = a.index(min(a))
y = a.index(max(a))

print(max(x, y, n-x-1, n-y-1))

n = int(input())

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

x, y = arr.index(max(arr)), arr.index(min(arr))

print(max(n - 1 - x, n - 1 - y, x, y))


n = int(input())
a = [int(x) for x in input().split()]
c1, c2 = -1, -1
for i in range(n):
    if a[i] == 1:
        c1 = i
    if a[i] == n:
        c2 = i

print(max(abs(c1 - c2), c1, c2, n - 1 - c1, n - 1 - c2))


n = int(input())
a = list(map(int, input().split()))
pos1 = a.index(1) + 1
posn = a.index(n) + 1

res = abs(pos1 - posn)
res = max(res, abs(1 - pos1))
res = max(res, abs(n - pos1))
res = max(res, abs(1 - posn))
res = max(res, abs(n - posn))

print(res)

n=int(input())
l=list(map(int,input().split()))
mi=l.index(1)+1
ma=l.index(n)+1
print(max(abs(mi-1),abs(mi-n),abs(ma-1),abs(ma-n)))

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

print(max(abs(1 - (l.index(n) + 1)), abs(n - (l.index(n) + 1)), abs(n - (l.index(1) + 1)), abs(1 - (l.index(1) + 1))))

n = int(input())
l = 0
r = 0
a = list(map(int,input().split()))
for i in range(n):
    if a[i] == 1:
        l = i+1
    elif a[i] == n:
        r = i+1
print(max(l-1,r-1,n-l,n-r))

n = int(input())
arr = [int(x) for x in input().split()]
ans = 0
for i in range(n):
    for j in range(i):
        arr[i], arr[j] = arr[j], arr[i]
        mini = min(arr)
        pos_mini = arr.index(mini)
        maxi = max(arr)
        pos_maxi = arr.index(maxi)
        
        ans = max(ans, abs(pos_maxi-pos_mini))
        arr[i], arr[j] = arr[j], arr[i]
print(ans)


n = int(input())
nums = [int(_) for _ in input().split()]

a = nums.index(1)
b = nums.index(n)
print(max(a, n-1-a, b, n-1-b))


def dist(l):
	return abs(l.index(1) - l.index(len(l)))


n = int(input())
l = list(map(int, input().split()))
one_ind = l.index(1)
n_ind = l.index(n)
d = dist(l)
for x in [one_ind, n_ind]:
	l[x], l[0] = l[0], l[x]
	d = max(d, dist(l))
	l[x], l[0] = l[0], l[x]

	l[x], l[-1] = l[-1], l[x]
	d = max(d, dist(l))
	l[x], l[-1] = l[-1], l[x]

print(d)




n = int(input())
ai = list(map(int,input().split()))
mini = 0
maxi = 0
for i in range(n):
    if ai[i] == n:
        maxi = i
    if ai[i] == 1:
        mini = i
print(max(maxi,mini,n-maxi-1,n-mini-1))


n = int(input())

L = list(map(int, input().split()))
index1, index2 = L.index(1), L.index(n)
if index1 > index2 :
    index1, index2 = index2, index1

d = index2 - index1
d = max(d, n - 1 - index1)
d = max(d, index2)

print(d)

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

for i in range(n):
	if a[i]==1: vt1=i
	if a[i]==n: vtn=i
	
print(max(abs(0-vtn), abs(0-vt1), abs(n-vt1-1), abs(n-vtn-1)))

n = int(input())
data = list(map(int, input().split()))
indexmax = data.index(max(data))
indexmin = data.index(min(data))
print(max(indexmax, indexmin, n - indexmax - 1, n - indexmin - 1))

n = int(input())
a = [int(x) for x in input().split()]
pos1 = 0
pos2 = 0
for i in range(n):
	if (a[i] == 1 or a[i] == n) :
		pos1 = i
		break

for i in range(pos1 + 1,n):
	if (a[i] == 1 or a[i] == n):
		pos2 = i
		break

print(pos2 - pos1 + max(n - pos2 - 1,pos1))

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

idx_min = l.index(1)
idx_max = l.index(n)

arr = []
arr.append(abs(0 - idx_max))
arr.append(abs(n - 1 - idx_max))
arr.append(abs(0 - idx_min))
arr.append(abs(n - 1 - idx_min))

print(max(arr))

import sys,math
n=int(input())
z=list(map(int,input().split()))
f=0
d=0
for i in range(n):
    if z[i]==1:
        f=i
    if z[i]==n:
        d=i
bst=0
if math.fabs(d-f)==n-1:
    print(n-1)
    return
bst=max(math.fabs(d),math.fabs(f), math.fabs(n-1-f), math.fabs(n-1-d))
print(int(bst))

n = int(input())
A = list(map(int, input().split()))
mini = 0
maxi = 0
maxim = 0
minim = 10 ** 10
for i in range(n):
    if A[i] > maxim:
        maxim = A[i]
        maxi = i
    if A[i] < minim:
        minim = A[i]
        mini = i
a = abs(n - mini - 1)
b = abs(0 - mini)
c = abs(n - maxi - 1)
d = abs(0 - maxi)
print(max(a, b, c, d))

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

for i in range(n):
    if a[i] == 1:
        p1 = i
    if a[i] == n:
        pn = i

print(max(abs(p1-pn), p1, pn, abs(n - 1 - p1), abs(n - 1 - pn)))


n = int(input())
a = list(map(int, input().split()))
mx = max(a)
mn = min(a)
for i in range(len(a)):
    if a[i] == mn:
        i_min = i
    if a[i] == mx:
        i_max = i
print(max(i_max, i_min, len(a) - i_max - 1, len(a) - i_min - 1))


n = int(input())
a = list(map(int,input().split()))
p1 = a.index(1)
p2 = a.index(n)
op = min(p1-0, n-p1-1, p2-0, n-p2-1)
print(n-op-1)