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

Solutions:
N = int(input(''))
Line2 = input('')
Array = list(map(int, Line2.split(' ')))
min_elem_index = Array.index(min(Array))
max_elem_index = Array.index(max(Array))
min_index = 0
max_index = N - 1
L_inv1 = abs(min_elem_index - min_index)
R_inv1 = abs(max_index - min_elem_index)
ans1 = 0
if L_inv1 >= R_inv1:
	ans1 = L_inv1
elif L_inv1 < R_inv1:
	ans1 = R_inv1
ans2 = 0
L_inv2 = abs(max_elem_index - min_index)
R_inv2 = abs(max_index - max_elem_index)
if L_inv2 >= R_inv2:
	ans2 = L_inv2
elif L_inv2 < R_inv2:
	ans2 = R_inv2
if ans1 >= ans2:
	print(ans1)
elif ans1 < ans2:
	print(ans2)


n = int(input().strip())
ll = list(map(int, input().split()))
minn = min(ll)
maxx = max(ll)
for i in range(n):
	if ll[i] == minn:
		minn1 = i + 1
	elif ll[i] == maxx:
		maxx1 = i + 1
print(max(abs(1 - minn1), abs(n - minn1), abs(1 - maxx1), abs(n - maxx1)))


n = int(input())
l = list(map(int, input().split()))
p1 = 0
p2 = 0
ma = 0
mi = 10000000
for i in range(n):
	if mi > l[i]:
		mi = l[i]
		p1 = i
	if ma < l[i]:
		ma = l[i]
		p2 = i
if p1 > p2:
	if n - p2 - 1 > p1:
		print(n - p2 - 1)
	else:
		print(p1)
elif n - p1 - 1 > p2:
	print(n - p1 - 1)
else:
	print(p2)


n = int(input())
t = list(map(int, input().split()))
mx = max(t)
mi = min(t)
a = t.index(mx)
b = t.index(mi)
print(max(abs(n - 1 - a), abs(n - 1 - b), abs(0 - a), abs(0 - b)))


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 = list(map(int, input().split()))
ind1 = l.index(1)
indn = l.index(n)
print(max(ind1, indn, n - ind1 - 1, n - 1 - indn))


n = int(input())
a = list(map(int, input().split()))
t1 = a.index(1)
t2 = max(abs(t1 - n + 1), abs(t1))
t3 = a.index(n)
t4 = max(abs(t3 - n + 1), abs(t3))
print(max(t2, t4))


n = int(input())
A = list(map(int, input().split()))
for i in range(n):
	if A[i] == 1:
		posMin = i
	if A[i] == n:
		posMax = i
if posMin > posMax:
	(posMin, posMax) = (posMax, posMin)
print(max(posMax, n - posMin - 1))


n = int(input())
a = list(map(int, input().split()))
idx = a.index(min(a))
jdx = a.index(max(a))
print(max(max(jdx, n - 1 - jdx), max(idx, n - 1 - idx)))


n = int(input())
a = list(map(int, input().split()))
minIndex = a.index(1)
maxIndex = a.index(n)
print(max(minIndex, n - 1 - minIndex, maxIndex, n - 1 - maxIndex))


n = int(input().strip())
arr = list(map(int, input().strip().split()))
minInd = arr.index(min(arr))
maxInd = arr.index(max(arr))
print(max(max(minInd, maxInd), n - min(minInd, maxInd) - 1))


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())
s = input()
A = []
for i in s.split():
	A.append(int(i))
a = A.index(min(A)) + 1
b = A.index(max(A)) + 1
if abs((n + 1) / 2 - a) >= abs((n + 1) / 2 - b):
	if a > (n + 1) / 2:
		print(a - 1)
	else:
		print(n - a)
elif b > (n + 1) / 2:
	print(b - 1)
else:
	print(n - b)


Input = lambda : map(int, input().split())
n = int(input())
l = list(Input())
if l[0] in [1, n] or l[n - 1] in [1, n]:
	print(n - 1)
else:
	i = l.index(1)
	j = l.index(n)
	if i < j:
		print(max(n - 1 - i, j))
	else:
		print(max(n - 1 - j, i))


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


def solve(n, data):
	for i in range(n):
		if data[i] == n:
			b2 = i + 1
		if data[i] == 1:
			b1 = i + 1
	res = max(n - b2, n - b1, b1 - 1, b2 - 1)
	return res
n = int(input())
data = [int(x) for x in input().split()]
print(solve(n, data))


from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

def array2d(d1, d2, init=None):
	return [[init for _ in range(d1)] for _ in range(d2)]
n = int(input())
al = list(map(int, input().split(' ')))
ind_1 = al.index(1)
ind_n = al.index(n)
md = (n - 1) / 2.0
d1 = abs(ind_1 - md)
dn = abs(ind_n - md)
if d1 > dn:
	print(max(ind_1, n - ind_1 - 1))
else:
	print(max(ind_n, n - ind_n - 1))


n = int(input())
x = [int(y) for y in input().split()]
occ = []
for i in range(n):
	if x[i] == 1 or x[i] == n:
		occ.append(i)
	if len(occ) == 2:
		break
print(max([occ[0], occ[1], n - occ[0] - 1, n - occ[1] - 1]))


n = int(input())
x = list(map(int, input().split()))
a = x.index(1)
b = x.index(n)
print(max(abs(a - b), b, a, n - 1 - b, n - 1 - a))


n = int(input())

def maxi(a, b, c, d):
	x = max(a, b)
	y = max(c, d)
	return max(x, y)
a = [int(i) for i in input().split()]
p = a.index(min(a))
q = a.index(max(a))
print(maxi(abs(p - 0), abs(p - (n - 1)), abs(q - 0), abs(q - (n - 1))))


n = input()
a = input()
a = a.split()
low = int()
high = int()
for i in range(int(n)):
	if a[i] == '1':
		low = i + 1
	if a[i] == n:
		high = i + 1
if low < high:
	if low - 1 <= int(n) - high:
		print(int(n) - low)
	else:
		print(high - 1)
elif high - 1 <= int(n) - low:
	print(int(n) - high)
else:
	print(low - 1)


n = int(input())
a = list(map(int, input().split()))
idx1 = a.index(1)
idxN = a.index(n)
if idxN - idx1 > 0:
	if n - 1 - idxN > idx1 - 0:
		ans = n - 1 - idx1
	else:
		ans = idxN
elif n - 1 - idx1 > idxN - 0:
	ans = n - 1 - idxN
else:
	ans = idx1
print(ans)


from sys import stdin
n = int(input())
arr = list(map(int, stdin.readline().split()))
low = min(arr)
big = max(arr)
lindex = arr.index(low)
bindex = arr.index(big)
if lindex == 0 or lindex == n - 1 or bindex == 0 or (bindex == n - 1):
	print(n - 1)
elif lindex < bindex:
	a = bindex
	b = n - 1 - lindex
	print(max(a, b))
else:
	a = lindex
	b = n - 1 - bindex
	print(max(a, b))


def nicholas(a):
	min_ele = 1000
	max_ele = -1
	for i in range(len(a)):
		if a[i] < min_ele:
			min_ele = a[i]
			min_pos = i
	for i in range(len(a)):
		if a[i] > max_ele:
			max_ele = a[i]
			max_pos = i
	if min_pos == len(a) - 1 or max_pos == len(a) - 1 or min_pos == 0 or (max_pos == len(a) - 1):
		dist = len(a) - 1
		print(dist)
		return
	else:
		dist = abs(min_pos - max_pos) + max(min(min_pos, max_pos), len(a) - 1 - max(min_pos, max_pos))
		print(dist)
		return
n = int(input(''))
a = list(map(int, input('').split()))
nicholas(a)


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())
a = list(map(int, input().split()))
pos_1 = None
pos_N = None
for (i, e) in enumerate(a):
	if e == 1:
		pos_1 = i
	if e == n:
		pos_N = i
p = []
p.append([0, pos_1])
p.append([0, pos_N])
p.append([pos_1, n - 1])
p.append([pos_N, n - 1])
answ = max(map(lambda e: abs(e[0] - e[1]), p))
print(answ)


n = int(input())
a = list(map(int, input().split()))
x = 0
y = n - 1
for i in range(n):
	if a[i] == 1:
		x = i
	if a[i] == n:
		y = i
old = abs(x - y)
if n == 2:
	print(1)
else:
	print(max(old, x, n - 1 - x, y, n - 1 - y))


n = int(input())
l = [int(i) for i in input().split()]
z = l.index(1)
z1 = l.index(n)
print(max(z, z1, n - z - 1, n - z1 - 1))


def nicholas():
	n = int(input())
	a = list(map(int, input().split()[0:n]))
	pos1 = a.index(1)
	posn = a.index(n)
	vmax = abs(posn - pos1)
	n = n - 1
	if vmax < abs(posn - 0):
		vmax = abs(posn - 0)
	if vmax < abs(posn - n):
		vmax = abs(posn - n)
	if vmax < abs(pos1 - 0):
		vmax = abs(pos1 - 0)
	if vmax < abs(pos1 - n):
		vmax = abs(pos1 - n)
	return vmax
print(nicholas())


n = int(input())
a = [int(x) for x in input().split()]
minIndex = a.index(1)
maxIndex = a.index(n)
if minIndex < maxIndex:
	print(max(maxIndex, n - 1 - minIndex))
else:
	print(max(minIndex, n - 1 - maxIndex))


n = int(input())
l = list(map(int, input().split()))
i1 = l.index(min(l))
i2 = l.index(max(l))
print(max(n - 1 - min(i1, i2), max(i1, i2)))


n = int(input())
l = list(map(int, input().split()))
a = min(l.index(max(l)), l.index(min(l)))
b = min(l[::-1].index(max(l)), l[::-1].index(min(l)))
print(n - min(a, b) - 1)


n = int(input())
arr = list(map(int, input().split()))
dist1 = distn = 0
for i in range(n):
	if arr[i] == 1:
		dist1 = i
	if arr[i] == n:
		distn = i
if dist1 == 0 or dist1 == n - 1:
	print(n - 1)
elif distn == 0 or distn == n - 1:
	print(n - 1)
else:
	aux = n / 2
	if dist1 > aux:
		dist1 = n - dist1 - 1
	if distn > aux:
		distn = n - distn - 1
	print(n - 1 - min(distn, dist1))


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


n = int(input())
array = [i for i in map(int, input().split())]
if array[0] == 1 or array[0] == n or array[n - 1] == 1 or (array[n - 1] == n):
	print(n - 1)
else:
	i = 1
	while i < n - 3:
		if array[i] == 1 or array[i] == n:
			i_num = i
			break
		else:
			i += 1
	j = n - 2
	while j > 1:
		if array[j] == 1 or array[j] == n:
			j_num = j
			break
		else:
			j -= 1
	print(max(i, j, n - 1 - i, n - 1 - j))


n = int(input())
a = list(map(int, input().split()))
imax = 0
imin = 0
vmax = 0
vmin = 100001
for i in range(n):
	if vmax < a[i]:
		vmax = a[i]
		imax = i
	if vmin > a[i]:
		vmin = a[i]
		imin = i
mi = min(imax, imin)
ma = max(imax, imin)
res = max(n - 1 - mi, ma)
print(res)


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


n = int(input())
list = [int(i) for i in input().split()]
a = list.index(min(list))
b = n - 1 - list.index(min(list))
c = list.index(max(list))
d = n - 1 - list.index(max(list))
print(max(a, b, c, d))


n = int(input())
l = list(map(int, input().split()))
pos_n = l.index(n)
pos_1 = l.index(1)
if pos_n - pos_1 == n - 1:
	print(n - 1)
else:
	print(max(n - 1 - min(pos_1, pos_n), max(pos_1, pos_n)))


n = int(input())
row = input().split()
idx = 0
for i in row:
	row[idx] = int(i)
	idx += 1
idxmax = row.index(max(row)) + 1
idxmin = row.index(min(row)) + 1
if idxmax > idxmin:
	if n - idxmax >= idxmin:
		print(n - idxmin)
	else:
		print(idxmax - 1)
elif n - idxmin >= idxmax:
	print(n - idxmax)
else:
	print(idxmin - 1)


import math
n = int(input())
a = [int(i) for i in input().split()]
a1 = max(a)
a2 = min(a)
for i in range(n):
	if a[i] == a1:
		max = i
	if a[i] == a2:
		min = i
d = []
s = math.fabs(max - (n - 1))
s = int(s)
d.append(s)
s = math.fabs(min - (n - 1))
s = int(s)
d.append(s)
d.append(max)
d.append(min)
min = d[0]
for i in range(len(d)):
	if d[i] > min:
		min = d[i]
print(min)


import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
(x, y) = (a.index(1), a.index(n))
ans = max(x, y, n - x - 1, n - y - 1)
print(ans)


N = int(input())
A = [int(a) for a in input().split()]
pos = [-1, -1]
for i in range(N):
	if A[i] == 1:
		pos[0] = i
	elif A[i] == N:
		pos[1] = i
	if pos[0] != -1 and pos[1] != -1:
		break
if pos[0] < pos[1]:
	if pos[0] > N - 1 - pos[1]:
		pos[0] = 0
	else:
		pos[1] = N - 1
elif pos[0] > pos[1]:
	if pos[1] > N - 1 - pos[0]:
		pos[1] = 0
	else:
		pos[0] = N - 1
print(abs(pos[0] - pos[1]))


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


N = int(input())
X = list(map(int, input().split()))
print(max(X.index(1), N - 1 - X.index(1), X.index(N), N - 1 - X.index(N)))


n = int(input())
numbers = list(map(int, input().split()))
minpos = numbers.index(1)
maxpos = numbers.index(n)
print(max(minpos, maxpos, n - minpos - 1, n - maxpos - 1))


import math
n = int(input())
a = map(int, input().split(' '))
a = [i for i in a]
mi = min(a)
ma = max(a)
for i in range(n):
	if a[i] == mi:
		minI = i
	if a[i] == ma:
		maxI = i
maxRet = math.fabs(minI - maxI)
for i in range(n):
	maxRet = max(maxRet, math.fabs(minI - i), math.fabs(i - maxI))
print(int(maxRet))


n = int(input())
a = list(map(int, input().split()))
k = max(a)
p = min(a)
maxidx = a.index(k)
minidx = a.index(p)
length = n - 1
leftmovidx = min(maxidx, minidx)
rightmovidx = max(maxidx, minidx)
scopeleft = leftmovidx - 0
scoperight = length - rightmovidx
if scopeleft > scoperight:
	leftmovidx -= scopeleft
else:
	rightmovidx += scoperight
print(rightmovidx - leftmovidx)


n = int(input())
num = list(map(int, input().split()))
a = num.index(n)
b = num.index(1)
ans = [b - a]
if b > a:
	ans.append(n - a - 1)
	ans.append(b - 0)
elif a > b:
	ans.append(n - b - 1)
	ans.append(a - 0)
print(max(ans))


n = int(input())
l = list(map(int, input().split()))
first = l.index(1)
last = l.index(n)
if first == 0 and last == n - 1:
	print(n - 1)
else:
	print(max(abs(0 - last), abs(0 - first), abs(first - (n - 1)), abs(last - (n - 1))))


def single_integer():
	return int(input())

def multi_integer():
	return map(int, input().split())

def string():
	return input()

def multi_string():
	return input().split()
n = single_integer()
permutation = tuple(multi_integer())
i = 1
max_value = min_value = permutation[0]
max_index = min_index = 1
while i < n:
	if permutation[i] > max_value:
		(max_index, max_value) = (i + 1, permutation[i])
	if permutation[i] < min_value:
		(min_index, min_value) = (i + 1, permutation[i])
	i += 1
print(max(abs(n - max_index), abs(n - min_index), abs(1 - max_index), abs(1 - min_index)))


import copy, itertools

def dist(v, n):
	return abs(v.index(1) - v.index(n))
n = int(input())
a = list(map(int, input().split()))
best = dist(a, n)
for (lo, hi) in itertools.product(range(n), range(n)):
	if lo == hi:
		continue
	(a[lo], a[hi]) = (a[hi], a[lo])
	best = max(best, dist(a, n))
	(a[lo], a[hi]) = (a[hi], a[lo])
print(best)


from sys import stdin
N = 100

def parse():
	global N, SAMPLE
	N = int(stdin.readline().strip())
	(pos1, pos2) = (-1, -1)
	line = stdin.readline().split()
	for i in range(N):
		num = int(line[i])
		if num == N:
			pos2 = i
		elif num == 1:
			pos1 = i
		if pos1 != -1 and pos2 != -1:
			break
	if pos1 > pos2:
		temp = pos2
		pos2 = pos1
		pos1 = temp
	result = max(N - pos1 - 1, pos2)
	print(result)
parse()


n = int(input())
l = list(map(int, input().split()))
mi = min(l)
ma = max(l)
mi_pos = l.index(mi)
ma_pos = l.index(ma)
l = min(mi_pos, ma_pos)
r = max(mi_pos, ma_pos)
ans = r - l
r_dist = n - 1 - r
ans = ans + max(l, r_dist)
print(ans)


def nicholas():
	par1 = int(input())
	if par1 == 2:
		return 1
	par2 = list(map(int, input().split()[0:par1]))
	indexMax = par2.index(par1)
	indexMin = par2.index(1)
	if indexMax == 0 or indexMax == par1 - 1 or indexMin == 0 or (indexMin == par1 - 1):
		return par1 - 1
	listresult = []
	listresult.append(par1 - 1 - indexMax)
	listresult.append(indexMax)
	listresult.append(par1 - 1 - indexMin)
	listresult.append(indexMin)
	return max(listresult)
print(nicholas())


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())
a = list(map(int, input().split()))
for x in range(n):
	if a[x] == 1:
		index1 = x
	if a[x] == n:
		indexn = x
if abs(index1 - indexn) == n - 1:
	print(n - 1)
else:
	maximum = max(index1, abs(index1 - (n - 1)), indexn, abs(indexn - (n - 1)))
	print(maximum)


x = int(input())
s = list(map(int, input().split()))
if s[0] == 1 and s[x - 1] == x:
	print(x - 1)
else:
	for n in range(0, x):
		if s[n] == 1:
			a = n + 1
		if s[n] == x:
			b = n + 1
	if a < b:
		c = x - a
		d = b - 1
		if c >= d:
			print(c)
		else:
			print(d)
	elif a > b:
		c = x - b
		d = a - 1
		if c >= d:
			print(c)
		else:
			print(d)


k = int(input())
n = list(map(int, input().split()))
if n[0] == 1 and n[k - 1] == k or (n[0] == k and n[k - 1] == 1):
	print(k - 1)
else:
	a = n.index(1) + 1
	b = n.index(k) + 1
	if a == k or b == k:
		print(k - 1)
	elif a > b:
		print(max(a - 1, k - b))
	else:
		print(max(b - 1, k - a))


n = int(input())
a = list(map(int, input().split()))
mina = 0
maxa = 0
for i in range(n):
	if a[i] > a[maxa]:
		maxa = i
	elif a[i] < a[mina]:
		mina = i
if abs(maxa - mina) == n - 1:
	print(n - 1)
	exit()
out = abs(maxa - mina)
for i in range(n):
	if i != maxa and i != mina:
		if abs(maxa - i) > out:
			out = abs(maxa - i)
		if abs(mina - i) > out:
			out = abs(mina - i)
print(out)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
n = get_int()
lst = get_int_list()
mi = lst.index(min(lst))
mx = lst.index(max(lst))
if mi < mx:
	a = abs(mi - 0)
	b = abs(n - 1 - mx)
	print(abs(mx - mi) + max(a, b))
else:
	a = abs(n - 1 - mi)
	b = abs(mx - 0)
	print(abs(mx - mi) + max(a, b))


import math
n = int(input())
a = list(map(int, input().split(' ')))
for i in range(len(a)):
	if a[i] == 1:
		small = i
	elif a[i] == n:
		big = i
if abs(n / 2.0 - small) < abs(n / 2.0 - big):
	if big > n / 2.0:
		print(big)
	else:
		print(n - 1 - big)
elif abs(n / 2.0 - small) > abs(n / 2.0 - big):
	if small > n / 2.0:
		print(small)
	else:
		print(n - 1 - small)
else:
	print(int(n / 2 + math.ceil(abs(n / 2.0 - small))))


n = int(input())
L = list(map(int, input().split()))
ans = 1
ii = 0
iip = 0
for i in range(n):
	if L[i] == max(L):
		ii = i
	elif L[i] == min(L):
		iip = i
m = abs(ii - 0)
k = abs(ii - (n - 1))
ans1 = max(m, k)
m1 = abs(iip - 0)
m2 = abs(iip - (n - 1))
ans2 = max(m1, m2)
print(max(ans1, ans2))


n = int(input())
a = list(map(int, input().split()))
i_max = a.index(n)
i_min = a.index(1)
res = max(i_max, n - i_max - 1, i_min, n - i_min - 1)
print(res)


n = int(input())
arr = list(map(int, input().split()))
max_i = 0
min_i = 0
for (i, val) in enumerate(arr):
	if arr[i] == 1:
		min_i = i
	if arr[i] == n:
		max_i = i
last_index = n - 1
ans = max(abs(last_index - max_i), abs(max_i))
ans = max(ans, abs(last_index - min_i))
ans = max(ans, abs(min_i))
print(ans)


n = int(input())
q = [int(x) for x in input().split()]
maxindex = q.index(n)
minindex = q.index(1)
print(max(abs(maxindex - minindex), abs(maxindex - 0), abs(minindex - 0), abs(maxindex - (n - 1)), abs(minindex - (n - 1))))


n = int(input())
a = list(map(int, input().split()))
i1 = a.index(1)
i2 = a.index(n)
if i1 > i2:
	(i1, i2) = (i2, i1)
dif1 = i1
dif2 = n - i2 - 1
if dif1 > dif2:
	i1 = 0
else:
	i2 = n - 1
print(i2 - i1)


n = int(input())
arr = [int(x) for x in input().split()]
aaa = []
for i in range(n):
	if arr[i] == 1:
		aaa.append(i)
	elif arr[i] == n:
		aaa.append(i)
a = aaa[0]
b = n - 1 - aaa[1]
if a > b:
	print(n - b - 1)
else:
	print(n - a - 1)


n = int(input())
l = list(map(int, input().split()))
mx = l.index(max(l))
mn = l.index(min(l))
if mn > mx:
	(mn, mx) = (mx, mn)
print(max(mx, n - mn - 1))


n = int(input().strip()) - 1
arr = list(map(int, input().strip().split(' ')))
big = arr.index(max(arr))
little = arr.index(min(arr))
distance = max([abs(big), abs(n - big), abs(little), abs(n - little)])
print(distance)


n = int(input()) - 1
x = list(map(int, input().split()))
a = x.index(1)
b = x.index(n + 1)
if min(a, b) == 0 or max(a, b) == n:
	print(n)
else:
	print(max(a, b, n - a, n - b))


a = int(input())
b = list(map(int, input().split()))
x = b.index(1)
y = b.index(a)
print(max(abs(x - 0), abs(x - a + 1), abs(y - 0), abs(y - a + 1)))


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())
m = list(map(int, input().split()))
a = m.index(1) + 1
b = m.index(n) + 1
print(max(n - a, n - b, a - 1, b - 1))


v = [int(x) for x in input().split()]
v = [int(x) for x in input().split()]
poz_min = 0
poz_max = 0
for (i, x) in enumerate(v):
	if x == 1:
		poz_min = i + 1
	elif x == len(v):
		poz_max = i + 1
x = max(abs(poz_min - 1), abs(len(v) - poz_min))
y = max(abs(poz_max - 1), abs(len(v) - poz_max))
print(max(x, y))


n = int(input())
nums = list(map(int, input().split()))
small = nums.index(min(nums))
large = nums.index(max(nums))
print(max([small - 0, n - 1 - small, large - 0, n - 1 - large]))


n = input()
arr = [int(i) for i in input().split()]
inmin = arr.index(min(arr))
inmax = arr.index(max(arr))
a = [inmin, inmax, int(n) - 1 - inmin, int(n) - 1 - inmax]
print(max(a))


n = int(input())
a = list(map(int, input().split()))
m1 = 0
m2 = 0
for (i, v) in enumerate(a):
	if v == 1:
		m1 = i + 1
	elif v == n:
		m2 = i + 1
print(max([m1 - 1, n - m1, m2 - 1, n - m2]))


n = int(input())
A = list(map(int, input().split()))
indMax = A.index(max(A))
indMin = A.index(min(A))
print(max(indMax, indMin, n - 1 - indMax, n - 1 - indMin))


n = int(input())
a = list(map(int, input().split(' ')))
(mini, maxi) = (1000, 0)
(ni, xi) = (0, 0)
for i in range(n):
	if a[i] < mini:
		mini = a[i]
		ni = i
	if a[i] > maxi:
		maxi = a[i]
		xi = i
if ni < xi:
	dis_ni = ni
	dis_xi = n - xi - 1
	if dis_ni > dis_xi:
		ni = 0
	else:
		xi = n - 1
	dis_n_x = xi - ni
else:
	dis_ni = n - ni - 1
	dis_xi = xi
	if dis_xi > dis_ni:
		xi = 0
	else:
		ni = n - 1
	dis_n_x = ni - xi
print(dis_n_x)


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()))
amin = min(a)
amax = max(a)
res = 0
for i in range(len(a)):
	for j in range(i + 1, len(a)):
		(a[i], a[j]) = (a[j], a[i])
		pmin = 0
		pmax = n - 1
		for k in range(len(a)):
			if a[k] == amin:
				pmin = k
				break
		for k in range(len(a)):
			if a[k] == amax:
				pmax = k
		res = max(res, abs(pmin - pmax))
		for k in range(len(a)):
			if a[k] == amin:
				pmin = k
		for k in range(len(a)):
			if a[k] == amax:
				pmax = k
				break
		res = max(res, abs(pmin - pmax))
		(a[i], a[j]) = (a[j], a[i])
print(res)


def max(a, b):
	if a > b:
		return a
	else:
		return b

def magic(lista):
	for i in range(len(lista)):
		lista[i] = int(lista[i])
	return lista
n = int(input())
lis = input()
lis = lis.split()
lis = magic(lis)
mith = -1
math = -1
for i in range(n):
	if lis[i] == 1:
		mith = i
	if lis[i] == n:
		math = i
	if mith != -1 and math != -1:
		break
ans = max(max(mith, math), max(n - 1 - mith, n - 1 - math))
print(ans)


import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
a1 = a.index(1)
an = a.index(n)
ans = max(a1, n - a1 - 1, an, n - an - 1)
print(ans)


n = int(input())
a = list(map(int, input().split()))
maxPos = a.index(max(a)) + 1
minPos = a.index(min(a)) + 1
end = len(a)
print(max([maxPos - 1, minPos - 1, end - maxPos, end - minPos]))


n = int(input())
l = list(map(int, input().split()))
s = [(l[i], i) for i in range(n)]
(mi, ma) = (min(s)[1] + 1, max(s)[1] + 1)
print(max(n - mi, abs(mi - ma), mi - 1, ma - 1, n - ma))


n = int(input())
a = list(map(int, input().split()))
mi = 101
ma = 0
for x in range(n):
	if a[x] > ma:
		ma = a[x]
		pos_ma = x
	if a[x] < mi:
		mi = a[x]
		pos_mi = x
pos_ma += 1
pos_mi += 1
ans_1 = max(abs(n - pos_mi), abs(n - pos_ma))
ans_2 = max(abs(1 - pos_mi), abs(1 - pos_ma))
print(max(ans_1, ans_2))


n = int(input())
x = list(map(int, input().split()))
ind1 = -1
indn = -1
for i in range(n):
	if x[i] == 1:
		ind1 = i
	if x[i] == n:
		indn = i
print(max(abs(max(ind1, indn)), abs(n - 1 - min(ind1, indn))))


n = int(input())
ans = 0
s = input().split()
for i in range(len(s)):
	if int(s[i]) == 1 or int(s[i]) == n:
		if ans < i:
			ans = i
		if ans < n - i - 1:
			ans = n - i - 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
(a1, a2) = (a.index(1) + 1, a.index(n) + 1)
print(max(n - min(a1, a2), max(a1, a2) - 1))


n = int(input())
l = list(map(int, input().split()))
max_element = l.index(n)
one = l.index(1)
best = lambda x: max(abs(x - 0), abs(x - n + 1))
print(max(best(max_element), best(one)))


x = int(input())
y = [int(i) for i in input().split()]
print(max(x - 1 - y.index(max(y)), x - 1 - y.index(min(y)), y.index(max(y)), y.index(min(y))))


def count(L):
	maxIndex = 0
	minIndex = 0
	n = len(L)
	for i in range(n):
		if L[i] == 1:
			minIndex = i
		if L[i] == n:
			maxIndex = i
	if minIndex > maxIndex:
		(minIndex, maxIndex) = (maxIndex, minIndex)
	(minIndex, maxIndex) = (minIndex + 1, maxIndex + 1)
	return max(minIndex - 1, n - maxIndex) + (maxIndex - minIndex)

def for_input():
	l = []
	n = int(input())
	for i in range(n):
		l += dear_number_input()
		if len(l) >= n:
			break
	return l

def dear_number_input():
	a = input()
	b = a.split(' ')
	l = []
	for i in range(len(b)):
		l.append(int(b[i]))
	return l
l = for_input()
print(count(l))


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	c = 0
	n = inp()
	l = li()
	a = l.index(1)
	b = l.index(n)
	print(max(a, b, abs(a - n + 1), abs(b - n + 1)))
for _ in range(1):
	solve()


n = int(input())
ls = list(map(int, input().split()))
for i in range(n):
	if ls[i] == 1:
		first_pos = i
	if ls[i] == n:
		second_pos = i
max_pos = max(first_pos, second_pos)
min_pos = min(first_pos, second_pos)
delta_left = min_pos
delta_right = n - 1 - max_pos
print(max_pos - min_pos + max(delta_left, delta_right))


n = int(input())
arr = [int(i) for i in input().split()]
min_loc = arr.index(1)
max_loc = arr.index(n)
print(max(max_loc, min_loc, n - max_loc - 1, n - min_loc - 1))


def main():
	number_of_elements = int(input())
	nicholas_lst = [int(i) for i in input().split()]
	max_idx = nicholas_lst.index(max(nicholas_lst))
	min_idx = nicholas_lst.index(min(nicholas_lst))
	len_lst = len(nicholas_lst)
	distance = abs(max_idx - min_idx)
	max_distance = 0
	if distance == len_lst - 1:
		return len_lst - 1
	if max_idx > min_idx:
		distance_from_max_to_end = len_lst - max_idx
		distance_from_min_to_start = min_idx
		if distance_from_max_to_end > distance_from_min_to_start:
			return len_lst - min_idx - 1
		return max_idx
	distance_from_min_to_end = len_lst - min_idx
	distance_from_max_to_start = max_idx
	if distance_from_min_to_end > distance_from_max_to_start:
		return len_lst - max_idx - 1
	return min_idx
print(main())


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


n = int(input())
a = [int(x) for x in input().split(' ')]
ima = a.index(max(a))
imi = a.index(min(a))
if ima <= imi:
	(left, right) = (ima, imi)
else:
	(left, right) = (imi, ima)
d_left = left
d_right = len(a) - 1 - right
if d_left <= d_right:
	ans = len(a) - 1 - left
else:
	ans = right
print(ans)


from sys import stdin

def main():
	n = int(stdin.readline()[0:-1])
	numbers = stdin.readline().split()
	(minPos, maxPos) = (-1, -1)
	for i in range(0, n):
		if numbers[i] == '1':
			minPos = i
		elif numbers[i] == str(n):
			maxPos = i
	if minPos > maxPos:
		(minPos, maxPos) = (maxPos, minPos)
	if minPos == 0 and maxPos == n - 1:
		print(n - 1)
	elif maxPos > n - 1 - minPos:
		print(maxPos)
	else:
		print(n - 1 - minPos)
main()


Narray = int(input())
Barray = input().split()
Barray = [int(y) for y in Barray]
a = Barray.index(max(Barray))
b = Barray.index(min(Barray))
g = max([len(Barray[:a + 1]), len(Barray[a:]), len(Barray[:b + 1]), len(Barray[b:])]) - 1
print(g)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = int_array()
x = a.index(1)
y = a.index(n)
print(max(x, n - 1 - x, y, n - 1 - y))


n = int(input())
arr = [int(x) for x in input().split()]
max1 = max(arr)
i2 = arr.index(max1) + 1
min1 = min(arr)
i1 = arr.index(min1) + 1
ans = max(abs(n - i1), abs(n - i2), abs(1 - i1), abs(1 - i2))
print(ans)


n = int(input())
t = list(map(int, input().split()))
(pa, pb) = (t.index(1), t.index(n))
print(max(pb, n - 1 - pa, pa, n - 1 - pb))


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())
lst = list(map(int, input().split()))
print(max(lst.index(1), lst.index(n), n - 1 - lst.index(n), n - 1 - lst.index(1)))


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

def main():
	min_pos = a.index(1)
	max_pos = a.index(n)
	if len(a) % 2 == 0:
		mid = len(a) // 2 - 0.5
	else:
		mid = len(a) // 2
	if abs(min_pos - mid) < abs(max_pos - mid):
		if min_pos > mid:
			if max_pos > mid:
				print(max_pos)
			else:
				print(n - max_pos - 1)
		elif max_pos < mid:
			print(n - max_pos - 1)
		else:
			print(max_pos)
	elif max_pos > mid:
		if min_pos > mid:
			print(min_pos)
		else:
			print(n - min_pos - 1)
	elif min_pos < mid:
		print(n - min_pos - 1)
	else:
		print(min_pos)
	return
main()


n = int(input())
l = list(map(int, input().split()))
x = 0
y = 0
for i in range(n):
	if l[i] == 1:
		x = i
	if l[i] == n:
		y = i
a = min(x, y)
b = max(x, y)
print(max(b, n - a - 1))


n = input()
s = input().split(' ')
M = s.index(n)
n = int(n)
m = s.index('1')
print(max(m, M, n - m - 1, n - 1 - M))


n = int(input())
a = [int(i) for i in input().split()]
b = a.index(n)
c = a.index(1)
ans = 0
if c < b:
	d = n - 1 - c
	ans = max(b, d)
else:
	d = n - 1 - b
	ans = max(d, c)
print(ans)


n = int(input())
a = list(map(int, input().split()))
(mini, minx, maxi, maxx) = (0, a[0], 0, a[0])
for i in range(n):
	x = a[i]
	if x > maxx:
		(maxx, maxi) = (x, i)
	if x < minx:
		(minx, mini) = (x, i)
m = max(abs(mini - maxi), maxi, abs(n - 1 - maxi), mini, abs(n - 1 - mini))
print(m)


n = int(input())
s = list(map(int, input().split()))
q = min(s)
q = s.index(q) + 1
p = s.index(n) + 1
if p == n or q == n:
	print(n - 1)
else:
	a = abs(1 - p)
	b = abs(n - p)
	c = abs(1 - q)
	d = abs(n - q)
	e = max(a, b)
	f = max(c, d)
	print(max(e, f))


from sys import *

def input():
	return stdin.readline()
n = int(input())
l = list(map(int, input().split()))
mini = float('inf')
maxi = float('-inf')
for (i, ai) in enumerate(l):
	if ai < mini:
		imini = i
		mini = ai
	if ai > maxi:
		imaxi = i
		maxi = ai
(iser, iber) = (min(imini, imaxi), max(imini, imaxi))
if iser <= n - iber - 1:
	ans = n - iser - 1
else:
	ans = iber
print(ans)


n = int(input())
m = input().split(' ')
intm = []
for i in m:
	i = int(i)
	intm.append(i)
v1 = 0
v2 = 0
v3 = 0
v4 = 0
maxm = int(intm.index(max(intm)))
minm = int(intm.index(min(intm)))
v1 = abs(maxm - 0)
v2 = abs(maxm - n + 1)
v3 = abs(minm - 0)
v4 = abs(minm - n + 1)
v = max(v1, v2, v3, v4)
print(v)


n = input()
indexes = [k for (k, v) in enumerate(input().split()) if v == '1' or v == n]
print(max(indexes[1], int(n) - indexes[0] - 1))


n = int(input())
l = list(map(int, input().split()))
for i in range(n):
	if l[i] == 1 or l[i] == n or l[n - 1 - i] == 1 or (l[n - 1 - i] == n):
		print(n - 1 - i)
		break


n = int(input())
a = [int(x) for x in input().split()]
(x, y) = (0, 0)
for i in range(n):
	if a[i] < a[x]:
		x = i
	if a[i] > a[y]:
		y = i
print(max([x, y, n - 1 - x, n - 1 - y, abs(x - y)]))


n = int(input())
a = list(map(int, input().split()))
print(max(abs(a.index(max(a)) - n + 1), abs(a.index(min(a)) - n + 1), abs(a.index(max(a))), abs(a.index(min(a)))))


n = int(input())
a = [int(x) for x in input().split()]
x1 = a.index(1)
x2 = a.index(n)
print(max(n - 1 - x1, x1, n - 1 - x2, x2))


n = int(input())
l = [int(i) for i in input().split()]
mi = min(l)
ma = max(l)
initial = abs(l.index(ma) - l.index(mi))
s = n - max(l.index(mi), l.index(ma)) - 1
f = n - initial - s - 1
print(initial + max(f, s))


n = int(input())
l = list(map(int, input().split()))
a = l.index(1)
b = l.index(n)
t = abs(a - b)
if a > b:
	p = n - (a + 1)
	q = b
else:
	p = n - (b + 1)
	q = a
if p > q:
	print(t + p)
else:
	print(t + q)


n = int(input())
ls = [int(x) for x in input().split()]
poz1 = ls.index(1)
pozn = ls.index(n)
print(str(max(poz1, n - poz1 - 1, pozn, n - pozn - 1)))


import time
n = int(input())
a = [int(i) for i in input().split()]
start = time.time()
mn = 0
mx = 0
for i in range(n):
	if a[i] < a[mn]:
		mn = i
	elif a[i] > a[mx]:
		mx = i
print(max(mn, mx, n - mn - 1, n - mx - 1))
finish = time.time()


n = int(input())
x = list(map(int, input().split()))
left = min(x.index(min(x)), x.index(max(x))) + 1
right = max(x.index(min(x)), x.index(max(x))) + 1
if left != 1 and right != n:
	print(max(right - 1, n - left))
else:
	print(n - 1)


n = int(input())
a = list(map(int, input().split()))
minindex = a.index(1)
maxindex = a.index(n)
print(max(minindex, n - 1 - minindex, maxindex, n - 1 - maxindex))


n = int(input())
lst = [int(i) for i in input().split()]
a = lst.index(min(lst))
b = lst.index(max(lst))
min1 = min([a, b])
max1 = max([a, b])
print(max([max1, n - 1 - min1]))


n = int(input()) - 1
arr = list(map(int, input().split()))
m = arr.index(min(arr))
M = arr.index(max(arr))
l = abs(M - m)
print(max(l, m - 0, M - 0, n - m, n - M))


n = int(input())
array = input()
array = array.split()
for i in range(n):
	if int(array[i]) == 1:
		n1 = i
	elif int(array[i]) == n:
		n2 = i
n3 = n - n1 - 1
n4 = n - n2 - 1
out = max(n1, n2, n3, n4)
print(out)


n = int(input())
a = list(map(int, input().split()))
mini = a.index(min(a))
maxi = a.index(max(a))
mid = n // 2
if maxi > mini and maxi > mid and (mini > mid):
	print(maxi)
elif maxi > mini and maxi > mid and (mini == 0):
	print(n - 1)
elif maxi > mini and maxi > mid and (mini < mid):
	print(max(maxi, abs(mini - (n - 1))))
elif mini > maxi and mini > mid and (maxi < mid):
	print(max(mini, abs(maxi - (n - 1))))
elif maxi > mini and maxi <= mid:
	print(abs(mini - (n - 1)))
elif mini > maxi and mini <= mid:
	print(abs(maxi - (n - 1)))
elif mini > maxi:
	print(mini)
elif maxi > mini:
	print(maxi)
else:
	print(1)


n = int(input())
a = list(map(int, input().split()))
k1 = a.index(1)
kn = a.index(n)
print(max(max(k1, kn), n - 1 - min(k1, kn)))


def main():
	(n, l) = (int(input()), list(map(int, input().split())))
	(lo, hi) = (l.index(1), l.index(n))
	if lo > hi:
		(lo, hi) = (hi, lo)
	print(max(hi, n - lo - 1))
main()


n = int(input())
x = list(map(int, input().split(' ')))
(Max, Min) = (x.index(max(x)) + 1, x.index(min(x)) + 1)
print(max(abs(Max - n), abs(Max - 1), abs(Min - n), abs(Min - 1)))


n = int(input())
a = list(map(int, input().split()))
ind_min = a.index(min(a))
ind_max = a.index(max(a))
left = ind_min if ind_min < ind_max else ind_max
right = ind_min if ind_min >= ind_max else ind_max
if left > n - right - 1:
	print(right)
else:
	print(n - left - 1)


n = int(input())
a = list(map(int, input().split()))
mini = 0
maxi = 0
for i in range(n):
	if a[i] < a[mini]:
		mini = i
	if a[i] > a[maxi]:
		maxi = i
dist0 = abs(maxi - mini)
dist1 = abs(0 - mini)
dist2 = abs(n - 1 - mini)
dist3 = abs(0 - maxi)
dist4 = abs(n - 1 - maxi)
print(max((dist0, dist1, dist2, dist3, dist4)))


n = int(input().strip())
a = list(map(int, input().split()))
max_index = a.index(n)
min_index = a.index(1)
result = max(max_index, n - 1 - max_index, min_index, n - 1 - min_index)
print(str(result))


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	if a[i] == n:
		index_max = i
	elif a[i] == 1:
		index_min = i
print(max(n - 1 - min(index_max, index_min), max(index_max, index_min)))


n = int(input())
arr = input().split()
arr = [int(x) for x in arr]
inx = [0, n - 1, arr.index(1), arr.index(n)]
print(max([abs(inx[0] - inx[2]), abs(inx[1] - inx[2]), abs(inx[0] - inx[3]), abs(inx[1] - inx[3])]))


n = int(input())
a = list(map(int, input().split()))
mx = max(a)
mn = min(a)
mxind = a.index(mx) + 1
mnind = a.index(mn) + 1
print(max(abs(mxind - 1), abs(mnind - 1), abs(n - mnind), abs(n - mxind)))


import sys
import math
import bisect
import itertools
import random
import re

def main():
	n = int(input())
	A = list(map(int, input().split()))
	B = []
	for i in range(n):
		if A[i] == 1 or A[i] == n:
			B.append(i)
	ans = max(n - 1 - B[0], B[1])
	print(ans)
main()


n = int(input())
A = list(map(int, input().split()))
minIndex = A.index(1)
maxIndex = A.index(n)
distance = n - 1
if abs(minIndex - maxIndex) == n - 1:
	distance = n - 1
if minIndex < maxIndex:
	if minIndex < n - 1 - maxIndex:
		distance = n - 1 - minIndex
	else:
		distance = maxIndex
elif maxIndex < n - 1 - minIndex:
	distance = n - 1 - maxIndex
else:
	distance = minIndex
print(distance)


n = int(input())
ls = list(map(int, input().split()))
max_index = ls.index(n)
min_index = ls.index(1)
delta_left = min(max_index, min_index)
delta_right = min(n - 1 - max_index, n - 1 - min_index)
max_distance = abs(max_index - min_index) + max(delta_right, delta_left)
print(max_distance)


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	l = LI()
	x = l.index(1) + 1
	y = l.index(n) + 1
	return max(n - x, n - y, x - 1, y - 1)
print(main())


n = int(input())
a = list(map(int, input().split()))
min = a[0]
id_min = 0
for i in range(1, n):
	if a[i] < min:
		min = a[i]
		id_min = i
max = a[0]
id_max = 0
for i in range(1, n):
	if a[i] > max:
		max = a[i]
		id_max = i
result = id_max
if result < n - 1 - id_max:
	result = n - 1 - id_max
if result < id_min:
	result = id_min
if result < n - 1 - id_min:
	result = n - 1 - id_min
print(result)


n = int(input())
A = [int(x) for x in input().split()]
(a, b) = (A.index(1), A.index(n))
print(max(a, b, n - a - 1, n - b - 1))


n = int(input())
a = list(map(int, input().split()))
(x, y) = (a.index(1), a.index(n))
if x > y:
	(x, y) = (y, x)
if x == 0 or y == n - 1:
	print(n - 1)
else:
	print(max(n - 1 - x, y))


n = int(input())
a = [int(i) for i in input().split()]
b = a.index(max(a))
e = a.index(min(a))
c = b - 0
d = n - 1 - b
f = e - 0
g = n - 1 - e
print(max(c, d, f, g))


n = int(input())
a = list(map(int, input().split()))
pos = []
for i in range(n):
	if a[i] == 1 or a[i] == n:
		pos.append(i)
if pos[0] > pos[1]:
	t = pos[0]
	pos[0] = pos[1]
	pos[1] = t
print(max(n - 1 - pos[0], pos[1] - 0))


n = int(input())
arr = list(map(int, input().split()))
mini = arr.index(min(arr))
maxi = arr.index(max(arr))
print(max(max(mini, maxi), n - min(mini, maxi) - 1))


n = int(input())
a = [int(x) for x in input().split()]
mx = a.index(max(a))
mi = a.index(min(a))
l = len(a) - 1
print(max(mx - mi, l - mx, l - mi, mx, mi))


n = int(input(''))
s1 = input('').split(' ')
myList = []
s = []
counter = 0
while counter < n:
	s.append(int(s1[counter]))
	counter = counter + 1
max_value = max(s)
max_index = s.index(max_value)
min_value = min(s)
min_index = s.index(min_value)
min_toend = n - min_index - 1
max_toend = n - max_index - 1
l1 = min_index
myList.append(l1)
l2 = max_index
myList.append(l2)
l3 = min_toend
myList.append(l3)
l4 = max_toend
myList.append(l4)
sol = max(myList)
print(str(sol))


arrsize = int(input())
arr = input().split(' ')
intarr = [int(i) for i in arr]
max_index = intarr.index(max(intarr))
min_index = intarr.index(min(intarr))
mm = []
ldistm = min_index
rdistm = len(intarr) - 1 - min_index
if ldistm >= rdistm:
	mm.append(ldistm)
else:
	mm.append(rdistm)
ldistn = max_index
rdistn = len(intarr) - 1 - max_index
if ldistn >= rdistn:
	mm.append(ldistn)
else:
	mm.append(rdistn)
print(max(mm))


n = int(input())
arr = list(map(int, input().split()))[:n]
mini = 0
maxu = 1
maxi = 0
for i in range(0, n):
	if arr[i] == 1:
		mini = i
	elif arr[i] > maxu:
		maxu = arr[i]
		maxi = i
if abs(maxi - mini) == n - 1:
	print(abs(maxi - mini))
else:
	c = mini
	d = maxi
	e = max(n - mini - 1, n - maxi - 1)
	print(max(c, d, e))


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)
	sys.exit()
bst = max(math.fabs(d), math.fabs(f), math.fabs(n - 1 - f), math.fabs(n - 1 - d))
print(int(bst))


n = int(input())
arr = list(map(int, input().split()))
small = arr.index(min(arr))
big = arr.index(max(arr))
maxx = abs(big - small)
n = n - 1
v = max(abs(n - small), abs(big - n))
dd = max(small, big)
fu = max(v, dd)
print(max(fu, maxx))


n = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(n):
	for j in range(n):
		(L[i], L[j]) = (L[j], L[i])
		ans = max(ans, abs(L.index(1) - L.index(n)))
		(L[i], L[j]) = (L[j], L[i])
print(ans)


def main():
	n = int(input())
	permutation = [0] + [int(_) for _ in input().split()]
	index_1 = permutation.index(1)
	index_n = permutation.index(n)
	print(max(max(index_1, index_n) - 1, n - min(index_1, index_n)))
main()


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())
arr = [int(i) for i in input().split()]
mn_in = arr.index(1)
mx_in = arr.index(n)
first = max(abs(mn_in), abs(mn_in - (n - 1)))
second = max(abs(mx_in), abs(mx_in - (n - 1)))
print(max(first, second))


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


from math import ceil
from sys import stdin
input = stdin.readline
n = int(input())
arr = list(map(int, input().split()))
fp = None
sp = None
for (i, x) in enumerate(arr):
	if x == n or x == 1:
		if fp is None:
			fp = i
		else:
			sp = i
print(max(n - fp - 1, sp))


n = int(input())
lst = list(map(int, input().split()))
if n % 2 == 0:
	middle = (n - 1) / 2
else:
	middle = (n - 1) / 2
if abs(lst.index(1) - middle) < abs(lst.index(n) - middle):
	if lst.index(1) < lst.index(n):
		print(lst.index(n))
	else:
		print(n - lst.index(n) - 1)
elif lst.index(n) < lst.index(1):
	print(lst.index(1))
else:
	print(n - lst.index(1) - 1)


n = int(input())
arr = list(map(int, input().split()))
ans = max(n - arr.index(1) - 1, n - arr.index(n) - 1, arr.index(n), arr.index(1))
print(ans)


def max(a, b):
	if a > b:
		return a
	return b
n = int(input())
a = list(map(int, input().split()))
pos1 = 0
posn = 0
for i in range(n):
	if a[i] == 1:
		pos1 = i
	if a[i] == n:
		posn = i
print(max(pos1, max(n - 1 - pos1, max(posn, n - 1 - posn))))


n = int(input())
s = [int(i) for i in input().split()]
a = s.index(min(s))
b = s.index(max(s))
if a > b:
	if n - 1 - a > b:
		print(n - 1 - b)
	else:
		print(a)
elif n - 1 - b > a:
	print(n - 1 - a)
else:
	print(b)


n = int(input())
arr = list(map(int, input().split()))
for i in range(n):
	if arr[i] == 1:
		fir = i + 1
	elif arr[i] == n:
		lst = i + 1
print(max(n - fir, n - lst, fir - 1, lst - 1) if (fir != 1 or fir != n) and (lst != 1 or lst != n) else n - 1)


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

def m(a, b):
	return abs(a - b)
(_max, _min) = (0, 0)
for i in range(n):
	if a[i] == n:
		_max = i
	elif a[i] == 1:
		_min = i
print(max(m(_max, _min), m(0, _min), m(0, _max), m(n - 1, _min), m(n - 1, _max)))


n = int(input())
a = list(map(int, input().split()))
seqMin = a.index(1)
seqMax = a.index(n)
if seqMin < seqMax:
	print(max(n - 1 - seqMin, seqMax))
else:
	print(max(n - 1 - seqMax, seqMin))


n = int(input())
A = list(map(int, input().split()))
min = 0
max = n - 1
for i in range(n):
	if A[i] > A[max]:
		max = i
	if A[i] < A[min]:
		min = i
if min == 0 or min == n - 1 or max == 0 or (max == n - 1):
	print(n - 1)
else:
	distance1 = 0
	distance2 = 0
	if n - 1 - min > n - 1 - max:
		distance1 = n - 1 - min
	else:
		distance1 = n - 1 - max
	if min - 0 > max - 0:
		distance2 = min - 0
	else:
		distance2 = max - 0
	if distance1 > distance2:
		print(distance1)
	else:
		print(distance2)


import sys
import math
import collections
from pprint import pprint
mod = 1000000007

def vector(size, val=0):
	vec = [val for i in range(size)]
	return vec

def matrix(rowNum, colNum, val=0):
	mat = []
	for i in range(rowNum):
		collumn = [val for j in range(colNum)]
		mat.append(collumn)
	return mat
n = int(input())
a = list(map(int, input().split()))
x = 0
y = 0
ans = 0
for i in range(n):
	if a[i] == 1:
		x = i
		break
for i in range(n):
	if a[i] == n:
		y = i
		break
ans = abs(y - x)
if x < y:
	ans += max(x, n - y - 1)
else:
	ans += max(n - x - 1, y)
print(ans)


n = int(input())
l = [int(i) for i in input().split()]
if l[0] == n or l[0] == 1 or l[n - 1] == 1 or (l[n - 1] == n):
	print(n - 1)
else:
	i = l.index(1)
	j = l.index(n)
	if i > j:
		k = n - i
		print(max(n - j - 1, i))
	else:
		k = n - j
		print(max(n - i - 1, j))


n = int(input())
a = [int(i) for i in input().split()]
(k, l) = (a.index(1), a.index(n))
print(max(k, l, n - k - 1, n - l - 1))


n = int(input())

def test(A):
	ni = -1
	i1 = -1
	for i in range(len(A)):
		if A[i] == n:
			ni = i
		if A[i] == 1:
			i1 = i
	return abs(ni - i1)
A = list(map(int, input().split()))
ans = 0
for i in range(n):
	for j in range(i):
		(A[i], A[j]) = (A[j], A[i])
		ans = max(ans, test(A))
		(A[i], A[j]) = (A[j], A[i])
print(ans)


size = int(input())
array = input().split(' ')
for i in range(0, size):
	array[i] = int(array[i])
min_value = min(array)
min_to_head = array.index(min_value)
min_to_tail = size - min_to_head - 1
max_value = max(array)
max_to_head = array.index(max_value)
max_to_tail = size - max_to_head - 1
max_distance = max(min_to_head, min_to_tail, max_to_head, max_to_tail)
print(max_distance)


n = int(input())
a = list(map(int, input().split()))
max_pos = a.index(max(a))
min_pos = a.index(min(a))
c = [max_pos, n - max_pos - 1, min_pos, n - min_pos - 1]
print(max(c))


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())
ints = list(map(int, input().split()))
leftest = min(ints.index(1), ints.index(n))
rightest = max(ints.index(1), ints.index(n))
print(max(n - 1 - rightest, leftest) + rightest - leftest)


n = int(input())
a = list(map(int, input().split()))
x = a.index(1)
y = a.index(n)
if abs(x - y) == n - 1:
	print(n - 1)
else:
	print(max(x, n - 1 - y, n - 1 - x, y))


a = int(input())
b = list(map(int, input().split()))
c = len(b) - 1
print(max(c - b.index(a), c - b.index(1), b.index(a), b.index(1)))


n = int(input())
a = list(map(int, input().split()))
posa = a.index(1)
posb = a.index(n)
if posa > posb:
	tmp = posa
	posa = posb
	posb = tmp
print(max(n - posa - 1, posb))


n = int(input())
m = list(map(int, input().split()))
mini = min(m)
maxi = max(m)
x = m.index(mini)
y = m.index(maxi)
if y > x:
	temp = x
	x = y
	y = temp
if x - y == n - 1:
	print(n - 1)
elif y >= n - x:
	print(x)
else:
	print(n - y - 1)


import sys
num = int(input())
numbers = input()
number = [int(x) for x in numbers.split()]
for (id, value) in enumerate(number):
	if number[id] == max(number):
		max_offset = id
	if number[id] == min(number):
		min_offset = id
if max_offset < min_offset:
	distance_end = len(number) - min_offset - 1
	if distance_end == 0:
		max_offset = 0
		result = min_offset - max_offset
		print(result)
		sys.exit()
	distance_head = max_offset - 0
	if distance_head == 0:
		min_offset = len(number) - 1
		result = min_offset - max_offset
		print(result)
		sys.exit()
	if distance_head == distance_end:
		max_offset = 0
		result = min_offset - max_offset
		print(result)
		sys.exit()
	elif distance_head > distance_end:
		max_offset = 0
	else:
		min_offset = len(number) - 1
	result = min_offset - max_offset
	print(result)
	sys.exit()
else:
	distance_end = len(number) - max_offset - 1
	distance_head = min_offset - 0
	if distance_end == 0:
		min_offset = 0
		result = max_offset - min_offset
		print(result)
		sys.exit()
	if distance_head == 0:
		max_offset = len(number) - 1
		result = max_offset - min_offset
		print(result)
		sys.exit()
	if distance_head == distance_end:
		min_offset = 0
		result = max_offset - min_offset
		print(result)
		sys.exit()
	elif distance_head > distance_end:
		min_offset = 0
	else:
		max_offset = len(number) - 1
	result = max_offset - min_offset
	print(result)


n = int(input())
lst = list(map(int, input().split()))
index_one = lst.index(1)
index_n = lst.index(n)
print(max(n - index_one - 1, n - index_n - 1, index_one, index_n))


n = int(input())
l = list(map(int, input().split()))
h = max(l)
m = min(l)
p1 = l.index(h) + 1
p2 = l.index(m) + 1
t = abs(p1 - p2)
t1 = abs(p1 - n)
t2 = abs(p2 - n)
t3 = abs(1 - p2)
t4 = abs(1 - p1)
print(max(t, t1, t2, t3, t4))


(n, A) = (int(input()), list(map(int, input().split())))
(i, j) = (A.index(min(A)), A.index(max(A)))
print(max(i, j, n - i - 1, n - j - 1))


n = int(input())
l = [int(x) for x in input().split()]
(mini, maxi) = (l.index(min(l)), l.index(max(l)))
print(max(mini, maxi, n - maxi - 1, n - mini - 1))


n = int(input())
L = [int(x) for x in input().split()]
[m, M] = [min(L.index(1), L.index(n)), max(L.index(1), L.index(n))]
print(max(n - 1 - m, M))


n = int(input())
a = [int(x) for x in input().split()]
x = a.index(1)
y = a.index(n)
hsl = max(abs(x - y), abs(n - 1 - x), abs(n - 1 - y), x, y)
print(hsl)


def swap(a, b):
	return (b, a)
n = int(input())
a = list(map(int, input().split()))
posL = 0
posR = 0
for i in range(n):
	if a[i] == 1:
		posL = i
	if a[i] == n:
		posR = i
if posL > posR:
	(posL, posR) = swap(posL, posR)
print(max(n - posL - 1, posR))


n = int(input())
a = [int(s) for s in input().split(' ')]
m = [a.index(1), a.index(n)]
print(max(max(m), n - min(m) - 1))


count = int(input())
a = [int(x) for x in input().split()]
lowIndex = a.index(1)
highIndex = a.index(count)
print(max(highIndex - 0, lowIndex - 0, count - 1 - lowIndex, count - 1 - highIndex))


n = int(input())
l = list(map(int, input().split()))
indexN = l.index(n)
index1 = l.index(1)
t = max(index1, len(l) - 1 - index1, indexN, len(l) - 1 - indexN)
print(t)


n = int(input())
l = list(map(int, input().split()))
x = max(l)
y = min(l)
c = 0
t1 = 0
t2 = 0
for i in range(n):
	if x == l[i]:
		t1 = i
for i in range(n):
	if y == l[i]:
		t2 = i
p = [0] * 7
p[1] = t1 - t2
p[2] = t1 - 0
p[3] = n - 1 - t1
p[4] = t2 - t1
p[5] = n - 1 - t2
p[6] = t2 - 0
print(max(p))


n = int(input())
permu = map(int, input().split())
minimum = 1000
maximum = -1
minPos = -1
maxPos = -1
for (pos, nombre) in enumerate(permu):
	if nombre < minimum:
		minimum = nombre
		minPos = pos
	if nombre > maximum:
		maximum = nombre
		maxPos = pos
print(max(minPos, maxPos, n - minPos - 1, n - maxPos - 1))


n = int(input())
a = [int(x) for x in input().split()]
for i in range(len(a)):
	if a[i] == 1:
		b = i
	if a[i] == n:
		c = i
print(max([abs(b - c), abs(c), abs(b), abs(n - 1 - b), abs(n - 1 - c)]))


n = int(input())
a = list(map(int, input().split()))
mi = -1
ma = -1
for i in range(n):
	if a[i] == 1:
		mi = i + 1
	elif a[i] == n:
		ma = i + 1
if mi > ma:
	(mi, ma) = (ma, mi)
print(max(min(n - 1, abs(n - mi)), min(n - 1, abs(ma - 1))))


n = int(input())
x = 0
y = 0
arr = list(map(int, input().split()))
for i in range(n):
	if arr[i] == 1:
		x = i
	elif arr[i] == n:
		y = i
if x > y:
	(x, y) = (y, x)
print(max(n - 1 - x, y))


n = int(input())
nums = list(zip(map(int, input().split()), range(0, 100)))
xmin = min(nums)
xmax = max(nums)
a = abs(xmax[1] - xmin[1])
b = abs(xmax[1])
c = abs(n - xmax[1] - 1)
d = abs(xmin[1])
e = abs(n - xmin[1] - 1)
print(max(a, b, c, d, e))


def far_distance(array, n):
	index_min = array.index(1)
	index_max = array.index(n)
	distances = [index_min, index_max, n - index_min - 1, n - index_max - 1]
	return max(distances)
n = int(input())
a = [int(x) for x in input().split()]
print(far_distance(a, n))


arr_size = int(input())
array = list(map(int, input().split()))
min_elem_index = array.index(min(array))
max_elem_index = array.index(max(array))
min_to_start = max_elem_index
min_to_end = arr_size - 1 - max_elem_index
max_to_start = min_elem_index
max_to_end = arr_size - 1 - min_elem_index
max_dis = max(min_to_start, min_to_end, max_to_start, max_to_end)
print(max_dis)


b = int(input())
a = input()
a = a.split(' ')
a = [int(i) for i in a]
c = a.index(1)
d = a.index(b)
e = 0
b = b - 1
if abs(c - d) == b:
	print(b)
elif c < d:
	if abs(b - c) >= abs(d):
		print(abs(b - c))
	else:
		print(abs(d))
elif c > d:
	if abs(b - d) >= abs(c):
		print(abs(b - d))
	else:
		print(abs(c))


n = input()
a = [int(i) for i in input().split()]
max1 = max(a)
min1 = min(a)
ans1 = a.index(max1)
ans2 = len(a) - a.index(max1) - 1
ans3 = a.index(min1)
ans4 = len(a) - a.index(min1) - 1
print(max(ans1, ans2, ans3, ans4))


n = int(input())
a = [int(item) for item in input().split()]
index_max = a.index(max(a))
index_min = a.index(min(a))
if abs(index_max - index_min) == n - 1:
	print(n - 1)
elif index_min < index_max:
	result = max(index_max, n - 1 - index_min)
	print(result)
else:
	result = max(index_min, n - 1 - index_max)
	print(result)


number = int(input())
array = input().split()
nArray = []
for i in array:
	nArray.append(int(i))
distance = abs(nArray.index(1) - nArray.index(number))
dis1 = number - 1 - max(nArray.index(1), nArray.index(number))
dis2 = min(nArray.index(1), nArray.index(number))
distance = distance + max(dis1, dis2)
print(distance)


n = int(input())
a = list(map(int, input().split()))
ans = 0
l = a.index(n)
r = a.index(1)
for i in range(n):
	b = a.copy()
	(b[i], b[l]) = (b[l], b[i])
	ans = max(abs(b.index(1) - b.index(n)), ans)
	b = a.copy()
	(b[i], b[r]) = (b[r], b[i])
	ans = max(abs(b.index(1) - b.index(n)), ans)
print(ans)


n = int(input())
a = list(map(int, input().split()))
mi = a.index(1)
mx = a.index(n)
print(max(max(n - 1 - mi, n - 1 - mx), max(mi, mx)))


n = int(input())
inps = list(map(int, input().split(' ')))

def dist_of_higher_index_from_ri(max_ind):
	dist = n - 1 - max_ind
	return dist

def dist_of_lower_from_li(min_ind):
	dist = min_ind - 0
	return dist
indices = []
max_ind = inps.index(max(inps))
indices.append(max_ind)
min_ind = inps.index(min(inps))
indices.append(min_ind)
indices.sort()
diffs = []
maxr = dist_of_higher_index_from_ri(indices[1])
diffs.append(maxr)
minl = dist_of_lower_from_li(indices[0])
diffs.append(minl)
if minl == 0 and maxr == 0:
	print(abs(min_ind - max_ind))
elif minl == maxr:
	print(abs(n - 1 - indices[0]))
elif maxr > minl:
	print(abs(n - 1 - indices[0]))
else:
	print(indices[1])


n = int(input())
a = list(map(int, input().split()))
pos1 = a.index(1)
posn = a.index(n)
vmax = abs(posn - pos1)
if vmax < abs(posn - 0):
	vmax = abs(posn - 0)
if vmax < abs(n - 1 - posn):
	vmax = abs(n - 1 - posn)
if vmax < abs(pos1 - 0):
	vmax = abs(pos1 - 0)
if vmax < abs(n - 1 - pos1):
	vmax = abs(n - 1 - pos1)
print(vmax)


n = int(input())
a = (*map(int, input().split()),)
(x, y) = sorted([a.index(1), a.index(n)])
print(max(y, n - 1 - x))


n = int(input())
l = [int(x) for x in input().split()]
print(max(l.index(n), l.index(1), n - l.index(n) - 1, n - l.index(1) - 1))


n = int(input())
l = list(map(int, input().split()))
mini = l.index(1)
maxi = l.index(n)
print(abs(mini - maxi) + max(abs(max(mini, maxi) - (n - 1)), min(mini, maxi)))


n = int(input())
a = list(map(int, input().split()))
minInd = a.index(1)
maxInd = a.index(n)
m = abs(minInd - maxInd)
if minInd < maxInd:
	if minInd > 0 and m < maxInd:
		m = maxInd
	if maxInd < n - 1 and m < n - 1 - minInd:
		m = n - 1 - minInd
else:
	if maxInd > 0 and m < minInd:
		m = minInd
	if minInd < n - 1 and m < n - 1 - maxInd:
		m = n - 1 - maxInd
print(m)


n = int(input())
a = list(map(int, input().split()))
first = 0
end = 0
for (index, i) in enumerate(a):
	if i == 1:
		first = index
	if i == n:
		end = index
print(max(abs(end - first), max(end, max(first, max(abs(n - 1 - first), abs(n - 1 - end))))))


n = int(input())
a = [int(i) for i in input().split()]
ninp = -1
maxp = -1
for i in range(n):
	if a[i] == 1:
		minp = i
	if a[i] == n:
		maxp = i
print(max(abs(maxp), abs(n - 1 - maxp), abs(minp), abs(n - 1 - minp)))


def main():
	N = int(input())
	arr = list(map(int, input().split()))
	(mic, mac) = (0, 0)
	for i in range(len(arr)):
		if arr[i] == 1:
			mic = i
		if arr[i] == N:
			mac = i
	temp = min(mac, mic)
	temp2 = max(mic, mac)
	if temp < N - temp2:
		print(N - (temp + 1))
	else:
		print(temp2)
main()


def main():
	n = int(input())
	a = tuple(map(int, input().split()))
	(b, c) = (a.index(1), a.index(n))
	(b, c) = (min(b, c), n - max(b, c) - 1)
	print(n - min(b, c) - 1)
main()


readInts = lambda : list(map(int, input().split()))
n = int(input())
a = readInts()
p1 = a.index(1)
pn = a.index(n)
print(max(p1, pn, n - 1 - p1, n - 1 - pn))


n = int(input())
lst = list(map(int, input().strip().split(' ')))
maxN = minN = lst[0]
indexMax = indexMin = 0
for b in range(n):
	if lst[b] > maxN:
		maxN = lst[b]
		indexMax = b
	if lst[b] < minN:
		minN = lst[b]
		indexMin = b
disMax_0 = indexMax
disMax_n = n - indexMax - 1
disMin_0 = indexMin
disMin_n = n - indexMin - 1
ans = disMax_0
if ans < disMax_n:
	ans = disMax_n
if ans < disMin_0:
	ans = disMin_0
if ans < disMin_n:
	ans = disMin_n
print(ans)


n = input()
z = input()
z = z.split()
a = []
a.append(1)
a.append(int(n))
b = []
b.append(z.index('1') + 1)
b.append(z.index(n) + 1)
ans = 0
for i in b:
	for j in a:
		p = i - j
		if p < 0:
			p = -p
		if p > ans:
			ans = p
print(ans)


n = int(input())
a = list(map(int, input().split()))
_max = -1
_min = 101
for i in range(n):
	if a[i] > _max:
		_max = a[i]
		idx1 = i
	if a[i] < _min:
		_min = a[i]
		idx2 = i
if idx1 > idx2:
	(idx1, idx2) = (idx2, idx1)
print(max(n - 1 - idx1, idx2))


n = int(input())
a = list(map(int, input().split()))[:n]
mino = a[0]
maxo = a[0]
maxi = 0
mini = 0
for i in range(1, n):
	if a[i] < mino:
		mino = a[i]
		mini = i
	if a[i] > maxo:
		maxo = a[i]
		maxi = i
x = [maxi, mini, n - maxi - 1, n - mini - 1]
x.sort()
print(max(n - x[0] - 1, x[3]))


def main_function():
	n = int(input())
	p = [int(i) for i in input().split(' ')]
	counter_one = 0
	counter_two = 0
	firts_item_found = False
	second_item_found = False
	ind_one = -1000
	ind_two = -1000
	for i in range(len(p)):
		if (p[i] == 1 or p[i] == n) and (not firts_item_found):
			firts_item_found = True
			ind_one = i + 1
		elif not firts_item_found:
			counter_one += 1
		elif firts_item_found and (p[i] == 1 or p[i] == n):
			second_item_found = True
			ind_two = i + 1
		elif second_item_found:
			counter_two += 1
	if counter_one > counter_two:
		ind_one = 1
	else:
		ind_two = n
	return ind_two - ind_one
print(main_function())


t = int(input())
l = list(map(int, input().split()))
k = l.index(max(l))
r = l.index(min(l))
l1 = max(k, r, t - k - 1, t - r - 1)
if l1 == t:
	print(t - 1)
else:
	print(l1)


n = int(input())
A = list(map(int, input().split()))
pmin = 0
pmax = 0
for i in range(n):
	if A[i] == 1:
		pmin = i
	if A[i] == n:
		pmax = i
if pmin > pmax:
	tam = pmin
	pmin = pmax
	pmax = tam
if pmax <= n / 2:
	print(n - 1 - pmin)
elif pmin <= n / 2:
	if n - 1 - pmin > pmax:
		print(n - 1 - pmin)
	else:
		print(pmax)
else:
	print(pmax)


n = int(input())
arr = list(map(int, input().split()))
_min = arr[0]
_max = arr[0]
for i in range(n):
	if _min > arr[i]:
		_min = arr[i]
	if _max < arr[i]:
		_max = arr[i]
v1 = arr.index(_min) - 0
v2 = n - 1 - arr.index(_min)
v3 = arr.index(_max) - 0
v4 = n - 1 - arr.index(_max)
print(max(v1, v2, v3, v4))


n = int(input())
L = [int(e) for e in input().split(' ')]
print(max([n - L.index(n) - 1, L.index(n), n - L.index(1) - 1, L.index(1)]))


size = int(input(''))
original_list = list(map(int, input('').split()))
max_value = max(original_list)
max_index = original_list.index(max_value)
min_value = min(original_list)
min_index = original_list.index(min_value)
left = 0
right = len(original_list) - 1
if max_index > min_index:
	delta_right = right - max_index
	delta_left = min_index
else:
	delta_right = right - min_index
	delta_left = max_index
if delta_right == delta_left:
	print(abs(max_index - min_index) + delta_right)
elif delta_right > delta_left:
	print(abs(max_index - min_index) + delta_right)
else:
	print(abs(max_index - min_index) + delta_left)


import math
(n, x) = (int(input()), [int(i) for i in input().split()])
(min_index, max_index) = (x.index(min(x)), x.index(max(x)))
print(max([min_index, max_index, n - 1 - min_index, n - 1 - max_index]))


n = int(input())
l = list(map(int, input().rstrip().split()))
b = l.index(n)
a = l.index(1)
m = []
if a == 0 or b == 0 or a == n - 1 or (b == n - 1):
	m.append(n - 1)
p = a
q = n - 1 - a
x = b
y = n - 1 - b
m.append(max(max(p, q), max(x, y)))
print(m[0])


x = input()
x = int(x)
a = list(map(int, input().split()))
for i in range(x):
	if a[i] == 1:
		a1 = i
	elif a[i] == x:
		a2 = i
print(max(abs(x - 1 - a2), abs(x - 1 - a1), abs(a1), abs(a2)))


n = int(input())
li = [int(x) for x in input().split()]
mi = 1
ma = n
ind_ma = li.index(ma)
ind_mi = li.index(mi)
if ind_ma == n - 1 or ind_mi == 0:
	print(n - 1)
else:
	dma = n - 1 - ind_ma
	dmi = n - 1 - ind_mi
	print(max([dma, dmi, ind_ma, ind_mi]))


n = int(input())
a = list(map(int, input().split()))
b = a * 1
b.sort()
low = a.index(b[0]) + 1
high = a.index(b[-1]) + 1
if low > high:
	(low, high) = (high, low)
print(max(n - low, high - 1))


import math, sys, re, itertools
(rs, ri, rai) = (input, lambda : int(input()), lambda : list(map(int, input().split())))
(n, a, m) = (ri(), rai(), -1)
for (i, j) in itertools.product(range(n), range(n)):
	(a[i], a[j]) = (a[j], a[i])
	m = max(m, abs(a.index(1) - a.index(n)))
	(a[i], a[j]) = (a[j], a[i])
print(m)


n = input()
p = list(input().split())
s = max(p.index(n), int(n) - p.index(n) - 1)
t = max(p.index('1'), int(n) - p.index('1') - 1)
print(max(s, t))


n = int(input())
a = list(map(int, input().split()))
i1 = a.index(1)
i2 = a.index(n)
if i1 > i2:
	(i1, i2) = (i2, i1)
res = max(i2, n - i1 - 1)
print(res)


n = int(input())
a = list(map(int, input().split()))
x = a.index(min(a))
y = a.index(max(a))
if x > y:
	x1 = n - x - 1
	y1 = y
	if x1 > y1:
		print(n - 1 - y1)
	else:
		print(x)
else:
	y1 = n - y - 1
	x1 = x
	if y1 > x1:
		print(n - 1 - x1)
	else:
		print(y)


n = int(input())
a = list(map(int, input().split()))
x = a.index(1)
y = a.index(n)
if x > y:
	(x, y) = (y, x)
ans = max(x, n - 1 - y) + y - x
print(ans)


n = int(input())
lista = [int(x) for x in input().split()]
indmin = lista.index(min(lista))
indmax = lista.index(max(lista))
total = indmin - indmax
for i in range(2):
	if n - 1 - indmin > total:
		total = n - 1 - indmin
	if n - 1 - indmax > total:
		total = n - 1 - indmax
	if indmin > total:
		total = indmin
	if indmax > total:
		total = indmax
print(total)


n = int(input())
arr = [int(i) for i in list(input().split())]
mn = float('inf')
mx = -float('inf')
mn_i = 0
mx_i = 0
for i in range(n):
	if mx < arr[i]:
		mx = arr[i]
		mx_i = i
	if mn > arr[i]:
		mn = arr[i]
		mn_i = i
print(max(n - 1 - min(mn_i, mx_i), max(mn_i, mx_i)))


n = int(input())
a = list(map(int, input().split()))
b = a.index(n)
c = a.index(1)
d = abs(b - c)
print(max(d + min(b, c), d + abs(max(b, c) - n + 1)))


n = int(input())
arr = list(map(int, input().split()))
(posMax, posMin) = (0, 0)
for i in range(n):
	if arr[i] == 1:
		posMin = i + 1
	elif arr[i] == n:
		posMax = i + 1
res = max(max(n - posMax, posMax - 1), max(n - posMin, posMin - 1))
print(res)


n = int(input())
a = [int(i) for i in input().split()]
k = h = 0
for i in range(n):
	if a[i] == 1 or a[i] == n:
		k = i
		break
for i in range(k + 1, n):
	if a[i] == 1 or a[i] == n:
		h = i
if k > n - h - 1:
	print(h)
else:
	print(n - k - 1)


n = int(input())
l_n = list(map(int, input().split()))
max_i = l_n.index(max(l_n))
min_i = l_n.index(min(l_n))
print(max(max_i, min_i, n - min_i - 1, n - max_i - 1))


n = int(input())
arr = [int(x) for x in input().split(' ')]
(a, b) = [min(arr.index(1), arr.index(n)), max(arr.index(1), arr.index(n))]
print(b - a + max(a, n - b - 1))


n = int(input().strip())
a = [int(i) for i in input().strip().split(' ')]
i = a.index(1)
j = a.index(n)
print(max(max(i, j), n - min(i, j) - 1))


import sys
input = sys.stdin.buffer.readline
n = int(input())
arr = list(map(int, input().split()))
a = min(arr)
b = max(arr)
pos = []
for i in range(n):
	if arr[i] == a or arr[i] == b:
		pos.append(i)
	if len(pos) == 2:
		break
print(max(n - 1 - min(pos), max(pos) - 0))


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


a = int(input())
(*b,) = map(int, input().split())
c = b.index(1)
d = b.index(a)
print(max(abs(a - c - 1), c, abs(a - d - 1), d))


n = int(input())
l = list(map(int, input().split()))
r = sorted(l)
p = l.index(r[0])
h = l.index(r[n - 1])
if p < h:
	o = p
	y = n - 1 - h
	if o > y:
		print(h)
	else:
		print(n - 1 - p)
else:
	o = h
	y = n - 1 - p
	if o > y:
		print(p)
	else:
		print(n - 1 - h)


n = int(input().rstrip())
a = list(map(int, input().split()))
p1 = 0
p2 = 0
for i in range(n):
	if a[i] == 1:
		p1 = i
	if a[i] == n:
		p2 = i
print(max(max(max(max(abs(n - 1 - p1), abs(n - 1 - p2)), p1), p2), abs(p2 - p1)))


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)


f = int(input())
m = 0
n = 0
a = list(map(int, input().split()))
x = min(a)
y = max(a)
if a.index(x) > a.index(y):
	m = x
	n = y
else:
	m = y
	n = x
print(max(abs(len(a) - 1 - a.index(n)), abs(0 - a.index(m))))


input()
data = list(map(int, input().split()))
first = -1
last = -1
for (index, value) in enumerate(data):
	if value == 1:
		first = index
	if value == len(data):
		last = index
if first > last:
	(first, last) = (last, first)
print(last - first + max(first, len(data) - 1 - last))


n = int(input())
l = list(map(int, input().split()))
i = -1
j = -1
for k in range(n):
	if l[k] == 1:
		i = k
for k in range(n):
	if l[k] == n:
		j = k
print(max([j, n - i - 1, n - j - 1, i]))


n = int(input())
b = input()
a = b.split()
for i in range(n):
	if int(a[i]) == 1:
		l = i + 1
	elif int(a[i]) == n:
		r = i + 1
ans = n - l
if ans < l - 1:
	ans = l - 1
if ans < n - r:
	ans = n - r
if ans < r - 1:
	ans = r - 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
min_elt = 105
max_elt = 0
max_ind = -1
min_ind = -1
for i in range(n):
	if a[i] > max_elt:
		max_elt = a[i]
		max_ind = i
	if a[i] < min_elt:
		min_elt = a[i]
		min_ind = i
if min_ind in [0, n - 1] or max_ind in [0, n - 1]:
	print(n - 1)
else:
	mn = min(min_ind, max_ind)
	mx = max(min_ind, max_ind)
	ans = max(mx, n - 1 - mn)
	print(ans)


n = int(input())
m = list(map(int, input().split()))
(ma, mi) = (m.index(n), m.index(1))
(ma, mi) = (max(ma, mi), min(ma, mi))
print(max(ma, n - ma - 1, n - 1 - mi, mi - 1))


n = int(input())
a = list(map(int, input().split()))
b = list(reversed(a))
mx = max(a)
mn = min(a)
if a.index(mn) <= b.index(mn):
	mi = a.index(mn)
else:
	mi = b.index(mn)
if a.index(mx) <= b.index(mx):
	ma = a.index(mx)
else:
	ma = b.index(mx)
if mi >= ma:
	print(n - 1 - ma)
else:
	print(n - 1 - mi)


n = int(input())
a = input()
ba = a.split(' ')
ba = [int(i) for i in ba]
iz = min(ba.index(max(ba)), ba.index(min(ba)))
de = max(ba.index(max(ba)), ba.index(min(ba)))
d_iz = iz
d_de = n - 1 - de
if d_iz > d_de:
	print(de)
else:
	print(n - 1 - iz)


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	if a[i] == 1:
		posMin = i
	if a[i] == n:
		posMax = i
ans = max(posMin, n - 1 - posMin, posMax, n - 1 - posMax)
print(ans)


n = int(input())
l = list(map(int, input().split()))
a = min(l)
b = max(l)
if a == l[0] or b == l[0] or a == l[n - 1] or (b == l[n - 1]):
	print(n - 1)
else:
	a1 = abs(n - 1 - l.index(a))
	a2 = abs(l.index(a))
	b1 = abs(n - 1 - l.index(b))
	b2 = abs(l.index(b))
	print(max(a1, a2, b1, b2))


n = int(input())
a = list(map(int, input().split()))
mini = 0
maxi = 0
i = 0
c = 0
while i < n:
	if a[i] == 1:
		mini = i
		c += 1
	if a[i] == n:
		maxi = i
		c += 1
	if c == 2:
		break
	i = i + 1
if mini < maxi:
	k1 = mini - 0
	k2 = n - 1 - maxi
	if k1 > k2:
		mini = 0
	else:
		maxi = n - 1
	print(abs(maxi - mini))
else:
	k1 = n - 1 - mini
	k2 = maxi
	if k1 > k2:
		mini = n - 1
	else:
		maxi = 0
	print(abs(mini - maxi))


n = int(input())
a = list(map(int, input().split()))
minIdx = 0
maxIdx = 0
for i in range(n):
	if a[i] < a[minIdx]:
		minIdx = i
	if a[i] > a[maxIdx]:
		maxIdx = i
ans = abs(maxIdx - minIdx)
if ans != n:
	if minIdx < maxIdx:
		ans = max(abs(maxIdx - 0), abs(n - 1 - minIdx))
	else:
		ans = max(abs(minIdx - 0), abs(n - 1 - maxIdx))
print(ans)


n = int(input())
a = [int(c) for c in input().split()]
(pos1, pos2) = (a.index(1), a.index(n))
_min = min(pos1, pos2)
_max = max(pos1, pos2)
if _min <= n // 2 and _max <= n // 2:
	print(n - _min - 1)
elif _min >= n // 2 and _max >= n // 2:
	print(_max)
elif _min < n - _max - 1:
	print(n - _min - 1)
else:
	print(_max)


n = int(input())
a = list(map(int, input().split()))
maxa = a[0]
mini = a[0]
maxapo = 0
minipo = 0
for i in range(n):
	if a[i] > maxa:
		maxa = a[i]
		maxapo = i
	if a[i] < mini:
		mini = a[i]
		minipo = i
ans = abs(minipo - maxapo)
yo = min(minipo, maxapo) + 1
ro = max(minipo, maxapo) + 1
roro = n - ro + 1
if roro > yo:
	ans = ans + roro - 1
else:
	ans = ans + yo - 1
print(ans)


n = int(input())
x = list(map(int, input().split()))
(p, q) = (x.index(1) + 1, x.index(n) + 1)
(a, b) = (min(p, q), max(p, q))
if a - 1 > n - b:
	print(b - 1)
else:
	print(n - a)


n = int(input())
a = list(map(int, input().split(' ')))
pos_1 = a.index(1)
pos_n = a.index(n)
max_d = abs(pos_n - pos_1)
for swap in ((0, pos_1), (0, pos_n), (n - 1, pos_1), (n - 1, pos_n)):
	(a[swap[0]], a[swap[1]]) = (a[swap[1]], a[swap[0]])
	max_d = max(max_d, abs(a.index(1) - a.index(n)))
	(a[swap[0]], a[swap[1]]) = (a[swap[1]], a[swap[0]])
print(max_d)


n = int(input())
l = list(map(int, input().split()))
z1 = l.index(min(l))
z2 = len(l) - 1 - l.index(min(l))
z3 = l.index(max(l))
z4 = len(l) - 1 - l.index(max(l))
print(max(z1, z2, z3, z4))


n = int(input())
val = list(map(int, input().split()))
(po, pn) = (-1, -1)
for i in range(n):
	if val[i] == 1:
		po = i
	if val[i] == n:
		pn = i
print(max(abs(pn - po), abs(max(pn, po) - 0), abs(n - 1 - min(po, pn))))


n = int(input())
a = list(map(int, input().split()))
m0 = max(a)
m1 = min(a)
for i in range(n):
	if a[i] == m0:
		ma = i + 1
	elif a[i] == m1:
		mi = i + 1
d = abs(mi - ma)
if ma < mi:
	d0 = ma - 1
	d1 = n - mi
	if d1 > d0:
		d += d1
	else:
		d += d0
else:
	d0 = mi - 1
	d1 = n - ma
	if d1 > d0:
		d += d1
	else:
		d += d0
print(d)


n = int(input())
a = list(map(int, input().split()))
print(max(len(a) - 1 - a.index(n), len(a) - 1 - a.index(1), a.index(n), a.index(1)))


n = int(input())
S = list(map(int, input().split()))
p1 = S.index(min(S))
p2 = S.index(max(S))
s1 = n - p1 - 1
s2 = n - p2 - 1
ans = max([s1, s2, p1, p2])
print(ans)


n = int(input())
arr = list(map(int, input().split()))
one = arr.index(1)
last = arr.index(n)
answer = 0
for i in range(n):
	answer = max(abs(one - i), abs(last - i), answer)
print(answer)


a = int(input())
b = list(map(int, input().split()))
z = b.index(a)
z1 = b.index(1)
print(max(z, z1, a - z - 1, a - z1 - 1))


n = int(input())
a = list(map(int, input().split()))
m = min(a)
M = max(a)
midx = a.index(m)
Midx = a.index(M)
if midx > Midx:
	print(max(n - 1 - Midx, midx))
else:
	print(max(n - 1 - midx, Midx))


n = int(input())
arr = list(map(int, input().split()))
i_max = 0
i_min = 0
for i in range(n):
	if arr[i_max] < arr[i]:
		i_max = i
	if arr[i_min] > arr[i]:
		i_min = i
if i_max > i_min:
	(l, r) = (i_min, i_max)
else:
	(l, r) = (i_max, i_min)
if r > n - l - 1:
	print(r)
else:
	print(n - l - 1)


n = int(input())
L = [int(x) for x in input().split()]
p1 = L.index(1)
p2 = L.index(n)
rezwan = max(p1, p2, n - p1 - 1, n - p2 - 1)
print(rezwan)


n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
	if a[i] == 1:
		pos1 = i
	if a[i] == n:
		posn = i
print(max(posn, pos1, n - pos1 - 1, n - posn - 1))


from itertools import combinations

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	val = 0
	for (x, y) in combinations(range(n), 2):
		(arr[x], arr[y]) = (arr[y], arr[x])
		val = max(val, abs(arr.index(1) - arr.index(n)))
		(arr[x], arr[y]) = (arr[y], arr[x])
	print(val)
main()


n = int(input())
l = list(map(int, input().split()))
minimum = min(l)
maximum = max(l)
indexMax = 0
indexMin = 0
for i in range(0, len(l)):
	if l[i] == maximum:
		indexMax = i
	if l[i] == minimum:
		indexMin = i
count = 0
if indexMin == 0 or indexMax == 0 or indexMin == n - 1 or (indexMax == n - 1):
	count = n - 1
elif indexMin < indexMax and indexMin < n - indexMax:
	count = n - 1 - indexMin
elif indexMin < indexMax and indexMin >= n - indexMax:
	count = indexMax
elif indexMax < indexMin and indexMax < n - indexMin:
	count = n - 1 - indexMax
elif indexMax < indexMin and indexMax >= n - indexMin:
	count = indexMin
print(count)


n = int(input())
(p, p2) = (0, 0)
mas = list(map(int, input().split()))
for i in range(n):
	if mas[i] == 1:
		p = i + 1
	if mas[i] == n:
		p2 = i + 1
print(max(p - 1, p2 - 1, n - p, n - p2))


n = int(input())
arr = list(map(int, input().split()))
minA = arr.index(1)
maxA = arr.index(n)
print(max(maxA, n - 1 - maxA, minA, n - 1 - minA))


n = int(input())
lst = [int(x) for x in input().split()]
mi = lst.index(1)
ma = lst.index(n)
print(max(abs(ma - mi), abs(n - mi - 1), abs(n - ma - 1), ma, mi))


n = int(input())
a = [int(i) for i in input().split()]
one = a.index(1) + 1
last = a.index(n) + 1
print(max(n - one, n - last, one - 1, last - 1))


n = int(input())
a = list(map(int, input().split()))
minpos = a.index(min(a))
maxpos = a.index(max(a))
print(max(minpos, maxpos, n - minpos - 1, n - maxpos - 1))


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())
al = list(map(int, input().split()))
(a, b) = (al.index(min(al)), al.index(max(al)))
if a > b:
	(a, b) = (b, a)
if n > 3:
	if a - 0 > n - 1 - b:
		a = 0
	else:
		b = n - 1
elif n == 3:
	a = 0
	b = 2
print(b - a)


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


(n, a) = (input(), input().split())
(i, j) = (a.index('1'), a.index(n))
print(max(max(i, j), int(n) - 1 - min(i, j)))


def main():
	n = input()
	a = input().split(' ') * 1
	num_1 = a.index('1') + 1
	num_max = a.index(str(n)) + 1
	max_len = 0
	if max_len < num_max - 1:
		max_len = num_max - 1
	if max_len < num_1 - 1:
		max_len = num_1 - 1
	if max_len < len(a) - num_max:
		max_len = len(a) - num_max
	if max_len < len(a) - num_1:
		max_len = len(a) - num_1
	print(max_len)
main()


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

def swap_max(x, y):
	global arr_list
	(arr_list[x], arr_list[y]) = (arr_list[y], arr_list[x])
	min_pos = 0
	max_pos = n
	for (index, ele) in enumerate(arr_list):
		if ele == 1:
			min_pos = index
		if ele == n:
			max_pos = index
	(arr_list[x], arr_list[y]) = (arr_list[y], arr_list[x])
	ret = max_pos - min_pos
	if ret < 0:
		ret = -ret
	return ret
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		ans = max(ans, swap_max(i, j))
print(ans)


__author__ = 'artyom'

def main():
	n = read()
	a = read(3)
	i = 0
	while a[i] != 1 and a[i] != n:
		i += 1
	j = 1
	while a[-j] != 1 and a[-j] != n:
		j += 1
	return n - min(i + 1, j)

def read(mode=1, size=None):
	if mode == 0:
		return input().strip()
	if mode == 1:
		return int(input().strip())
	if mode == 2:
		return input().strip().split()
	if mode == 3:
		return list(map(int, input().strip().split()))
	a = []
	for _ in range(size):
		a.append(read(3))
	return a

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, tuple) or isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='\n')
write(main())


import sys
import math
n = [int(i) for i in input().split()][0]
ar = [int(i) for i in input().split()]
print(max(abs(ar.index(n)), abs(ar.index(n) - n + 1), abs(ar.index(1)), abs(ar.index(1) - n + 1)))
sys.stdout.close()


num = int(input())
arr = list(map(int, input().split()))
ans = []
for (i, n) in enumerate(arr, start=1):
	if n == 1 or n == num:
		ans.append(abs(num - i))
		ans.append(i - 1)
print(max(ans))


n = int(input())
s = [int(i) for i in input().split()]
x = s.index(1)
y = s.index(n)
if y > x:
	print(max(y, n - x - 1))
else:
	print(max(x, n - y - 1))


def calc_max_dist(_a, _n):
	(pos_min, pos_max) = (0, 0)
	for i in range(_n):
		if _a[i] == n:
			pos_max = i
		if _a[i] == 1:
			pos_min = i
	return max(n - 1 - pos_max, n - 1 - pos_min, pos_max, pos_min)
n = int(input())
a = list(map(int, input().split()))
print(calc_max_dist(a, n))


def maxDistance(arr):
	a = []
	for (idx, val) in enumerate(arr):
		if val == 1 or val == len(arr):
			a.append(idx)
	return max(a[1], len(arr) - a[0] - 1)
n = int(input())
arr = list(map(int, input().split()))
print(maxDistance(arr))


n = int(input())
a = [int(x) for x in input().split()]
ans = 0
for i in range(n):
	for j in range(n):
		(a[i], a[j]) = (a[j], a[i])
		for k in range(n):
			if a[k] == n:
				r = k
			if a[k] == 1:
				l = k
		ans = max(ans, abs(r - l))
		(a[i], a[j]) = (a[j], a[i])
print(ans)


n = int(input())
arr = list(map(int, input().split()))
one_index = arr.index(1)
n_index = arr.index(n)
if one_index < n_index:
	if one_index >= n - 1 - n_index:
		print(n_index)
	else:
		print(n - 1 - one_index)
elif n_index >= n - 1 - one_index:
	print(one_index)
else:
	print(n - 1 - n_index)


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())
ch = input().split()
ch = [int(x) for x in ch]
a = ch.index(min(ch))
b = ch.index(max(ch))
if a > b:
	print(max(a, n - 1 - b))
else:
	print(max(b, n - 1 - a))


n = int(input())
s = [int(z) for z in input().split()]
d = 0
for i in range(n):
	if s[i] == 1 or s[i] == n:
		d = max(d, i, n - 1 - i)
print(d)


def max_index(xs):
	return max(enumerate(xs), key=lambda x: x[1])[0]

def min_index(xs):
	return min(enumerate(xs), key=lambda x: x[1])[0]

def main():
	input()
	xs = [int(x) for x in input().split()]
	i_max = max_index(xs)
	i_min = min_index(xs)
	max_first = xs[:]
	max_last = xs[:]
	min_first = xs[:]
	min_last = xs[:]
	(max_first[0], max_first[i_max]) = (max_first[i_max], max_first[0])
	(min_first[0], min_first[i_min]) = (min_first[i_min], min_first[0])
	(max_last[-1], max_last[i_max]) = (max_last[i_max], max_last[-1])
	(min_last[-1], min_last[i_min]) = (min_last[i_min], min_last[-1])
	b = abs(max_index(xs) - min_index(xs))
	b = max(abs(max_index(max_first) - min_index(max_first)), b)
	b = max(abs(max_index(min_first) - min_index(min_first)), b)
	b = max(abs(max_index(max_last) - min_index(max_last)), b)
	b = max(abs(max_index(min_last) - min_index(min_last)), b)
	print(b)
main()


n = int(input())
a = list(map(int, input().split()))
a1 = a.index(max(a))
a2 = a.index(min(a))
if a1 > a2:
	(a1, a2) = (a2, a1)
if abs(a2 > n - a1 - 1):
	print(a2)
else:
	print(n - a1 - 1)


n = int(input())
a = list(map(int, input().split(' ')))
maxIndex = 0
minIndex = 0
for i in range(0, n):
	if a[i] > a[maxIndex]:
		maxIndex = i
	if a[i] < a[minIndex]:
		minIndex = i
print(max(maxIndex, minIndex, n - maxIndex - 1, n - minIndex - 1))


def main():
	m = int(input())
	vals = [int(v) for v in input().split()]
	(mx, mn) = (0, 0)
	for (i, v) in enumerate(vals):
		if v == m:
			mx = i
		elif v == 1:
			mn = i
	if max(mx, mn) != m - 1 and min(mx, mn) != 0:
		print(max(m - min(mn, mx) - 1, max(mn, mx)))
	else:
		print(m - 1)
main()


n = int(input())
lst = list(map(int, input().split()))
min_index = lst.index(min(lst))
max_index = lst.index(max(lst))
delta_left = min(min_index, max_index)
delta_right = min(len(lst) - 1 - min_index, len(lst) - 1 - max_index)
result = 0
if delta_left < delta_right:
	result = delta_right + abs(max_index - min_index)
elif delta_left > delta_right:
	result = delta_left + abs(max_index - min_index)
else:
	result = delta_left + abs(max_index - min_index)
print(result)


def maxmax(numbers):
	maxn = len(numbers)
	m1 = 0
	m2 = 0
	for (i, n) in enumerate(numbers):
		if n == 1:
			m1 = i
		elif n == maxn:
			m2 = i
	m1 = max(m1, maxn - m1 - 1)
	m2 = max(m2, maxn - m2 - 1)
	return max(m1, m2)

def solve(instr):
	return maxmax(list(map(int, instr.split(' '))))
_ = input()
print(solve(input()))


num = int(input())
arr = list(map(int, input().split()))
mx = 0
for (i, n) in enumerate(arr, start=1):
	if n == 1 or n == num:
		mx = max(mx, num - i)
		mx = max(mx, i - 1)
print(mx)


n = int(input())
ind1 = 0
indn = 0
a = input().split()
for i in range(0, n):
	x = int(a[i])
	if x == 1:
		ind1 = i
	elif x == n:
		indn = i
print(max(n - 1 - ind1, ind1, n - 1 - indn, indn))


n = int(input())
arr = list(map(int, input().split()))
imax = 0
imin = 0
mx = 0
mn = 101
for (i, k) in enumerate(arr):
	if k > mx:
		mx = k
		imax = i
	if k < mn:
		mn = k
		imin = i
print(max(imax, len(arr) - 1 - imax, imin, len(arr) - 1 - imin))


n = int(input())
tp = []
p = list(map(int, input().split()))
ta = p.index(1)
sa = p.index(n)
tp.append(abs(ta - (n - 1)))
tp.append(ta)
tp.append(abs(sa - (n - 1)))
tp.append(sa)
print(max(tp))


n = int(input())
elements = list(map(int, input().split()))
if len(elements) != n:
	raise ValueError('wrong element number')
indices = []
for (i, element) in enumerate(elements):
	if element in (1, n):
		indices.append(i)
print(indices[1] - indices[0] + max(indices[0], n - 1 - indices[1]))


number = int(input()) - 1
index = 0
positions = []
for element in input().split():
	if int(element) == number + 1:
		positions.append(index)
	elif int(element) == 1:
		positions.append(index)
	index += 1
	if len(positions) == 2:
		break
positions.sort()
answer = max(positions[0], number - positions[1]) + abs(positions[0] - positions[1])
print(answer)


n = int(input())
a = list(map(int, input().split()))
if n == 2:
	print(1)
else:
	maxa = 0
	mina = 101
	maxap = 0
	minap = 0
	for i in range(n):
		if a[i] < mina:
			mina = a[i]
			minap = i
		if a[i] > maxa:
			maxa = a[i]
			maxap = i
	if abs(minap - maxap) == n - 1:
		print(n - 1)
	else:
		print(max([minap, maxap, abs(n - 1 - maxap), abs(n - 1 - minap)]))


n = input('')
n = int(n)
arr = input('').split()
element1 = 0
element2 = 0
for i in range(0, n):
	x = int(arr[i])
	if x is 1:
		element1 = i
	if x is n:
		element2 = i
	if element1 != 0 and element2 != 0:
		break
if element2 < element1:
	m = element1
	element1 = element2
	element2 = m
if element1 is 0 or element2 is n - 1:
	print(n - 1)
else:
	d1 = element1
	d2 = n - 1 - element2
	if d1 > d2:
		print(element2)
	else:
		print(n - 1 - element1)


n = int(input())
data = list(map(int, input().split()))
firstindex = -1
lastindex = -1
for i in range(0, len(data)):
	if data[i] == 1:
		firstindex = i
	if data[i] == n:
		lastindex = i
if firstindex < lastindex:
	diff1 = lastindex
	diff2 = n - firstindex - 1
else:
	diff1 = firstindex
	diff2 = n - lastindex - 1
print(max(diff1, diff2))


n = int(input())
a = [int(x) for x in input().split()]
l = oi = a.index(1)
r = ni = a.index(n)
if l > r:
	(l, r) = (r, l)
dr = n - 1 - r
if l > dr:
	dr = l
print(r - l + dr)


n = int(input())
i1 = i2 = -1
i = 0
for x in map(int, input().split()):
	i += 1
	if x == 1 or x == n:
		if i1 < 0:
			i1 = i
		else:
			i2 = i
if i1 - 1 <= n - i2:
	print(n - i1)
else:
	print(i2 - 1)


t = 1
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	mini = 101
	maxi = 0
	mini_i = 0
	maxi_i = 0
	for i in range(0, n):
		if l[i] < mini:
			mini = l[i]
			mini_i = i + 1
		if l[i] > maxi:
			maxi = l[i]
			maxi_i = i + 1
	ans = max(abs(n - maxi_i), abs(n - mini_i))
	ans = max(ans, abs(1 - mini_i))
	ans = max(ans, abs(1 - maxi_i))
	print(ans)


p = int(input())
n = list(map(int, input().split()))
f = n.index(p)
s = p - 1 - f
t = n.index(1)
c = p - 1 - t
print(max(f, s, t, c))


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()))
mina = 1000
maxa = 0
i_min = 0
i_max = 0
N = n - 1
for i in range(n):
	if a[i] > maxa:
		i_max = i
		maxa = a[i]
	if a[i] < mina:
		i_min = i
		mina = a[i]
if abs(i_max - i_min) == n - 1:
	print(n - 1)
else:
	print(max(i_min, N - i_min, i_max, N - i_max))


n = int(input())
lst = list(map(int, input().split()))
maxPos = lst.index(n)
minPos = lst.index(1)
rangeMax = [maxPos, n - 1 - maxPos]
rangeMin = [minPos, n - 1 - minPos]
ans = max(max(rangeMax), max(rangeMin))
print(ans)


n = int(input())
line = str(input()).split()
line = [int(it) for it in line]
max_ptr = line.index(max(line))
min_ptr = line.index(min(line))
print(n - 1 - min(min(min_ptr, max_ptr), n - 1 - max(min_ptr, max_ptr)))


n = int(input())
array = [i for i in map(int, input().split())]
if array[0] == 1 or array[0] == n or array[n - 1] == 1 or (array[n - 1] == n):
	print(n - 1)
else:
	result = 0
	for i in range(n):
		if array[i] == 1 or array[i] == n:
			result = max(result, i, n - 1 - i)
	print(result)


n = int(input())
l = list(map(int, input().split()))
a = min(l)
b = max(l)
list1 = []
for i in l:
	if i == a or i == b:
		list1.append(l.index(i))
x = list1[0] - 0
y = n - 1 - list1[1]
if x > y:
	print(list1[1] - 0)
else:
	print(n - 1 - list1[0])


n = int(input())
check = [int(x) for x in input().split()]
x = min(check)
y = max(check)
pos_x = check.index(x) + 1
pos_y = check.index(y) + 1
temp = pos_y
maxdistance = 0
while temp <= n:
	temp += 1
	maxdistance = max(maxdistance, abs(pos_x - temp))
temp = pos_y
while temp >= 1:
	temp -= 1
	maxdistance = max(maxdistance, abs(pos_x - temp))
temp = pos_x
while temp <= n:
	temp += 1
	maxdistance = max(maxdistance, abs(pos_y - temp))
temp = pos_x
while temp >= 1:
	temp -= 1
	maxdistance = max(maxdistance, abs(pos_y - temp))
print(maxdistance - 1)


n = int(input())
p = list(map(int, input().split()))
posmin = p.index(min(p))
posmax = p.index(max(p))
if posmin == n - 1 or posmax == n - 1:
	print(n - 1)
else:
	print(max(n - 1 - posmin, n - 1 - posmax, posmin, posmax))


def arr_inp():
	return [int(x) for x in input().split()]
n = int(input())
a = arr_inp()
(ix_max, ix_min) = (a.index(max(a)) + 1, a.index(min(a)) + 1)
sum = abs(ix_max - ix_min)
(ixs_max, ixs_min) = (max(ix_max, ix_min), min(ix_max, ix_min))
if sum < n - 1:
	sum += max(n - ixs_max, ixs_min - 1)
print(sum)


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


def main():
	n = int(input())
	permu = list(map(int, input().split()))
	max_index = permu.index(max(permu))
	min_index = permu.index(min(permu))
	dist = abs(max_index - min_index)
	if dist == n - 1:
		print(n - 1)
	else:
		print(max(max_index, min_index, n - 1 - max_index, n - 1 - min_index))
main()


n = int(input())
a = list(map(int, input().split()))
max_a = a.index(max(a))
min_a = a.index(min(a))
ans = max(max_a, n - max_a - 1, min_a, n - min_a - 1)
print(ans)


n = int(input())
nums = [int(x) for x in input().split()]
pos = []
for i in range(0, n):
	if nums[i] == 1 or nums[i] == n:
		pos.append(i)
a = max(pos) + 1
b = min(pos) + 1
if n - b >= a - 1:
	print(n - b)
else:
	print(a - 1)


import sys
n = int(input())
input_str = sys.stdin.readline()
ar = input_str.split()
for i in range(len(ar)):
	ar[i] = int(ar[i])
for i in range(n):
	if ar[i] == 1:
		minind = i
	if ar[i] == n:
		maxind = i
print(abs(maxind - minind) + max(n - max(maxind, minind) - 1, min(minind, maxind)))


n = int(input())
t = n - 1
l = list(map(int, input().split()))
mx = max(l)
mn = min(l)
idx = l.index(mx)
idn = l.index(mn)
print(max(t - idn, idn, t - idx, idx))


n = int(input())
inp = list(map(int, input().split()))
one = -1
last = -1
for i in range(0, len(inp)):
	if inp[i] == 1:
		one = i
	if inp[i] == n:
		last = i
	if one != -1 and last != -1:
		break
l = [abs(len(inp) - 1 - last), abs(last), abs(one), abs(len(inp) - 1 - one)]
print(max(l))


__author__ = 'zihaozhu'
from sys import stdin
cases = int(stdin.readline())
numbers = list(map(int, stdin.readline().split()))
int1 = 0
intn = 0
for i in range(0, len(numbers)):
	if numbers[i] == 1:
		int1 = i + 1
	if numbers[i] == cases:
		intn = i + 1
maxDist = abs(intn - int1)
if maxDist == cases - 1:
	print(maxDist)
	exit(0)
if abs(int1 - 1) > maxDist:
	maxDist = abs(int1 - 1)
if abs(int1 - cases) > maxDist:
	maxDist = abs(int1 - cases)
if abs(intn - 1) > maxDist:
	maxDist = abs(intn - 1)
if abs(intn - cases) > maxDist:
	maxDist = abs(intn - cases)
print(maxDist)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = LI()
	m1 = a.index(min(a))
	m2 = a.index(max(a))
	m = sorted([m1, m2])
	r = 0
	for c in m:
		k = min(c, n - c - 1)
		t = n - k - 1
		if r < t:
			r = t
	return r
print(main())


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)


def answer():
	a = int(input())
	b = input().split()
	b = [int(x) for x in b]
	up = max(b)
	down = min(b)
	print(max(len(b) - b.index(up) - 1, len(b) - b.index(down) - 1, b.index(up), b.index(down)))
answer()


n = int(input())
input1 = input()
Lis = input1.split(' ', n)
List = []
for ele in Lis:
	List.append(int(ele))
maxValue = max(List)
minValue = min(List)
minIndex = List.index(minValue)
maxIndex = List.index(maxValue)
Distance = abs(maxIndex - minIndex)
Distance1 = []
Distance2 = []
if maxIndex - minIndex == n - 1:
	print(n - 1)
else:
	for i in range(0, n):
		Distance1.append(abs(i - maxIndex))
		Distance2.append(abs(i - minIndex))
	if max(Distance1) >= max(Distance2):
		if max(Distance1) >= Distance:
			print(max(Distance1))
		else:
			print(Distance)
	elif max(Distance1) < max(Distance2):
		if max(Distance2) >= Distance:
			print(max(Distance2))
		else:
			print(Distance)


import sys
n = int(input())
an = list(map(int, sys.stdin.readline().split()))
mmin = an[0]
imin = 0
mmax = an[0]
imax = 0
for i in range(1, n):
	if an[i] > mmax:
		(mmax, imax) = (an[i], i)
	elif an[i] < mmin:
		(mmin, imin) = (an[i], i)
big = max(imin, imax)
small = min(imin, imax)
print(max(big - 0, n - 1 - small))


n = int(input())
lst = list(map(int, input().split()))
mx = lst.index(max(lst))
mn = lst.index(min(lst))
if mx < mn:
	(mx, mn) = (mn, mx)
a = max(mx, n - 1 - mn)
print(a)


n = int(input())
a = list(map(int, input().split()))
max_distance = 0
index_max = a.index(max(a))
index_min = a.index(min(a))
if index_min < index_max:
	if index_min + 1 > n - index_max - 1:
		(a[0], a[index_min]) = (a[index_min], a[0])
	else:
		(a[-1], a[index_max]) = (a[index_max], a[-1])
elif index_max + 1 > n - index_min - 1:
	(a[0], a[index_max]) = (a[index_max], a[0])
else:
	(a[-1], a[index_min]) = (a[index_min], a[-1])
index_max = a.index(max(a))
index_min = a.index(min(a))
print(max(index_max, index_min) - min(index_max, index_min))


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


x = int(input())
p = list(map(int, input().split()))
(k, m) = (p.index(1) + 1, p.index(x) + 1)
print(max(abs(k - 1), abs(m - 1), abs(k - x), abs(m - x)))


def nicolas_swap():
	lenght = int(input())
	array = input().split()
	array = [int(i) for i in array]
	un_swap = False
	if int(min(array)) == int(array[-1]):
		if int(max(array)) == int(array[0]):
			un_swap = True
	elif int(min(array)) == int(array[0]):
		if int(max(array)) == int(array[-1]):
			un_swap = True
	if un_swap:
		print(abs(int(len(array) - 1) - int(0)))
	elif int(min(array)) == int(array[0]) or int(min(array)) == int(array[-1]):
		print(abs(int(len(array) - 1) - int(0)))
	elif int(max(array)) == int(array[0]) or int(max(array)) == int(array[-1]):
		print(abs(int(len(array) - 1) - int(0)))
	else:
		dic = {}
		dic[int(max(array))] = 0
		dic[int(min(array))] = 0
		o = 0
		for x in range(len(array)):
			if int(array[x]) in dic:
				dic[int(array[x])] = x
				o += 1
			if o == 2:
				break
		maximum = abs(dic[min(dic)] - 0)
		if abs(dic[min(dic)] - int(len(array) - 1)) > maximum:
			maximum = abs(dic[min(dic)] - int(len(array) - 1))
		if abs(dic[max(dic)] - 0) > maximum:
			maximum = abs(dic[max(dic)] - 0)
		if abs(dic[max(dic)] - int(len(array) - 1)) > maximum:
			maximum = abs(dic[max(dic)] - int(len(array) - 1))
		print(maximum)
nicolas_swap()


n = int(input())
a = [int(i) for i in input().split()]
mind = a.index(1)
maxd = a.index(n)
print(max(mind, maxd, n - 1 - mind, n - 1 - maxd))


n = int(input())
a = input().split()
b = 0
c = 0
for i in range(n):
	if a[i] == '1':
		b = i
	if a[i] == str(n):
		c = i
if c < b:
	(b, c) = (c, b)
print(max(c, n - b - 1))


n = int(input())
per = list(map(int, input().split()))
print(max(per.index(1), per.index(n), n - per.index(1) - 1, n - per.index(n) - 1))


n = int(input())
for i in range(1):
	t = [int(x) for x in input().split()]
x = t.index(1) + 1
y = t.index(n) + 1
print(max(n - x, n - y, x - 1, y - 1))


n = int(input())
List = [int(x) for x in input().split()]
Min = List.index(1)
Max = List.index(n)
print(max(abs(n - 1 - Min), abs(n - 1 - Max), Min, Max))


e = int(input())
t = list(map(int, input().split()))
p = t.index(min(t)) + 1
q = t.index(max(t)) + 1
s = []
for k in range(1, len(t) + 1):
	s.append(abs(k - p))
	s.append(abs(k - q))
print(max(s))


n = int(input())
a = n
a = list(map(int, input().split()))
a1 = a.index(1)
an = a.index(n)
k = 0
b = a1 - 0
c = n - 1 - a1
d = an - 0
e = n - 1 - an
if len(a) == 3:
	if a.index(1) != 1 and a.index(3) != 1:
		a = a
	elif a.index(1) == 1:
		if a.index(3) == 2:
			a.remove(1)
			a = [1] + a
		else:
			a.remove(1)
			a.append(1)
	elif a.index(1) == 0:
		a.remove(3)
		a.append(3)
	else:
		a.remove(3)
		a = [3] + a
elif len(a) == 2:
	print(1)
elif len(a) > 3:
	if a.index(1) != 0 and a.index(1) != n - 1 and (a.index(n) != 0) and (a.index(n) != n - 1):
		if b > c and b > d and (b > e):
			a.remove(n)
			a = [n] + a
		elif c > b and c > d and (c > e):
			a.remove(n)
			a.append(n)
		elif d > c and d > b and (d > e):
			a.remove(1)
			a = [1] + a
		elif e > c and e > d and (e > b):
			a.remove(1)
			a.append(1)
		elif c == d and c > e and (c > b) and (d > e) and (d > b):
			a.remove(n)
			a.append(n)
		elif b == e and b > c and (b > d) and (e > c) and (e > d):
			a.remove(1)
			a.append(1)
	elif a.index(1) == 0:
		a.remove(n)
		a.append(n)
	elif a.index(1) == n - 1:
		a.remove(n)
		a = [n] + a
	elif a.index(n) == 0:
		a.remove(1)
		a.append(1)
	elif a.index(n) == n - 1:
		a.remove(1)
		a = [1] + a
q = a.index(1)
w = a.index(n)
if len(a) != 2:
	if q > w:
		print(q - w)
	else:
		print(w - q)


n = int(input())
a = list(map(int, input().split(' ')))
(amax, amin) = (a.index(max(a)), a.index(min(a)))
print(max(amax, amin, n - 1 - amin, n - 1 - amax))


n = int(input())
s = input().split()
a = []
for i in range(n):
	a.append(int(s[i]))
(q, w) = (a.index(1) + 1, a.index(n) + 1)
print(max(abs(q - n), abs(q - 1), abs(w - n), abs(w - 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))


n = int(input())
arr = list(map(int, input().split()))
(l, r) = (arr.index(min(arr)) + 1, arr.index(max(arr)) + 1)
print(max(l - 1, r - 1, n - l, n - r))


n = int(input())
l = list(map(int, input().split()))
min_element = 1
max_element = n
min_index = l.index(min_element)
max_index = l.index(max_element)
if min_index < max_index:
	if min_index > n - max_index - 1:
		print(max_index)
	else:
		print(n - min_index - 1)
elif max_index > n - min_index - 1:
	print(min_index)
else:
	print(n - max_index - 1)


n = int(input())
numbers = input().split()
index_1 = numbers.index('1')
index_n = numbers.index(str(n))
result = abs(index_n - index_1)
if result != n - 1:
	(left, right) = (index_1, index_n) if index_1 < index_n else (index_n, index_1)
	result += max(left, n - right - 1)
print(result)


n = int(input())
mas = list(map(int, input().split()))
for i in range(n):
	if mas[i] == 1:
		n_min = i
	if mas[i] == n:
		n_max = i
print(max(n_max - n_min, n_max, n_min, n - 1 - n_min, n - 1 - n_max, n_min - n_max))


import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
i = 0
while a[i] != 1:
	i += 1
j = 0
while a[j] != n:
	j += 1
if a[n - 1] == n or a[n - 1] == 1 or a[0] == n or (a[0] == 1):
	print(n - 1)
else:
	print(max(max(n - j - 1, j), max(n - i - 1, i)))


n = int(input())
arr = list(map(int, input().split()))
(x, y) = (min(arr), max(arr))
if arr.index(x) == 0 or arr.index(y) == 0 or arr.index(x) == n - 1 or (arr.index(y) == n - 1):
	print(n - 1)
elif arr.index(x) < arr.index(y):
	print(max(n - 1 - arr.index(x), arr.index(y)))
elif arr.index(x) > arr.index(y):
	print(max(n - 1 - arr.index(y), arr.index(x)))


n = int(input())
l = list(map(int, input().split()))
if l[0] == 1 and l[-1] == n or (l[0] == n and l[-1] == 1):
	print(n - 1)
else:
	a = l.index(1)
	b = l.index(n)
	print(max(a, b, abs(n - 1 - b), abs(n - 1 - a)))


N = int(input())
A = list(map(int, input().split()))
mini = A.index(1)
maxi = A.index(N)
ans = -1
ans = max(ans, abs(mini - 0))
ans = max(ans, abs(mini - N + 1))
ans = max(ans, abs(maxi - 0))
ans = max(ans, abs(maxi - N + 1))
print(ans)


c = []
z = int(input())
x = list(map(int, input().split()))
c.append(x.index(max(x)) + 1)
c.append(x.index(min(x)) + 1)
c.sort()
print(['%d' % (c[1] - 1), '%d' % (z - c[0])][z - c[0] >= c[1] - 1])


n = int(input())
arr = [int(i) for i in input().split(' ')]
idx1 = arr.index(1)
idx2 = arr.index(n)
print(max(idx1, n - 1 - idx1, idx2, n - 1 - idx2))


n = int(input())
theperm = list((int(x) for x in input().split()))
firstpos = theperm.index(1) + 1
lastpos = theperm.index(n) + 1
print(max(n - firstpos, n - lastpos, firstpos - 1, lastpos - 1))


n = int(input())
a = list(map(int, input().split(' ')))
m = max(a)
mi = min(a)
i = a.index(m)
j = a.index(mi)
r = 0
if i < j:
	c = n - i - 1
	s = j
	r = max(c, s)
else:
	c = n - j - 1
	s = i
	r = max(c, s)
print(r)


n = int(input()) - 1
s = [int(i) for i in input().split()]
ind1 = s.index(1)
indn = s.index(n + 1)
printe = [abs(ind1 - indn), n - ind1, n - indn, ind1, indn]
if (ind1 or indn) == (0 or n):
	print(n)
else:
	print(max(printe))


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	if a[i] == 1:
		pos1 = i + 1
	if a[i] == n:
		posn = i + 1
res = max(posn - 1, n - posn, pos1 - 1, n - pos1)
print(res)


n = int(input())
arr = list(map(int, input().split()))
minimum = n + 1
maximum = 1 - 1
indexMax = -1
indexMin = -1
k = n // 2
for i in range(k):
	if arr[i] > maximum:
		maximum = arr[i]
		indexMax = i
	if arr[i] < minimum:
		minimum = arr[i]
		indexMin = i
	if arr[n - 1 - i] > maximum:
		maximum = arr[n - 1 - i]
		indexMax = n - 1 - i
	if arr[n - 1 - i] < minimum:
		minimum = arr[n - 1 - i]
		indexMin = n - 1 - i
if n % 2 != 0:
	if arr[k] > maximum:
		maximum = arr[k]
		indexMax = k
	if arr[k] < minimum:
		minimum = arr[k]
		indexMin = k
left = min(indexMin, indexMax)
right = max(indexMin, indexMax)
if n - 1 - left > right:
	print(n - 1 - left)
else:
	print(right)


n = int(input())
a = list(map(int, input().split()))
l = a.index(1)
r = a.index(n)
if l > r:
	print(max(n - 1 - r, l - 0))
else:
	print(max(n - 1 - l, r - 0))


n = int(input())
l = list(map(int, input().split()))
(k, h) = (l.index(max(l)), l.index(min(l)))
print([k - h + max(n - k - 1, h), h - k + max(n - h - 1, k)][k < h])


n = int(input())
l = list(map(int, input().split()))
(i, j) = (l.index(1), l.index(n))
print(max(i, j, n - i - 1, n - j - 1))


n = int(input())
a = list(map(int, input().split()))
(i, j) = (a.index(1) + 1, a.index(n) + 1)
if abs(i - j) == n - 1:
	print(n - 1)
else:
	print(max(n - i, i - 1, n - j, j - 1))


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


arr_size = int(input())
array = list(map(int, input().split()))
min_index = array.index(min(array))
max_index = array.index(max(array))
last = arr_size - 1
min_to_start = abs(max_index - 0)
min_to_end = abs(last - max_index)
max_to_start = abs(min_index - 0)
max_to_end = abs(last - min_index)
max_dis = max(min_to_start, min_to_end, max_to_start, max_to_end)
print(max_dis)


n = int(input())
a = [int(i) for i in input().split()]
pos_min = a.index(min(a))
pos_max = a.index(max(a))
print(max(pos_min, pos_max, n - 1 - pos_min, n - 1 - pos_max))


n = int(input())
a = [int(_) for _ in input().split()]
i1 = a.index(1)
i2 = a.index(n)
print(max(abs(n - i1 - 1), abs(i1), abs(i2), abs(n - i2 - 1)))


n = int(input())
l = list(map(int, input().split()))
p1 = l.index(1)
p2 = l.index(n)
d1 = abs(p1 - p2)
p2 = n - 1
d2 = abs(p1 - p2)
p2 = 0
d3 = abs(p1 - p2)
p2 = l.index(n)
p1 = n - 1
d4 = abs(p1 - p2)
p1 = 0
d5 = abs(p1 - p2)
print(max(d1, d2, d3, d4, d5))


n = int(input())
l = list(map(int, input().split()))
x = l.index(1)
y = l.index(n)
if abs(x - y) == n - 1:
	print(n - 1)
else:
	if x < y:
		p = x
		q = n - y - 1
	else:
		p = n - x - 1
		q = y
	z = max(p, q)
	print(z + abs(y - x))


(n, a) = (int(input()), list(map(int, input().split())))
(*b,) = reversed(a)
print(max(len(a) - min(a.index(n), a.index(1)) - 1, len(b) - min(b.index(n), b.index(1)) - 1))


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


n = int(input())
ls = list(map(int, input().split()))
minin = ls.index(min(ls))
maxin = ls.index(max(ls))
ls2 = ls[:]
if maxin > minin:
	temp = ls[-1]
	ls[-1] = max(ls)
	ls[maxin] = temp
else:
	temp = ls[-1]
	ls[-1] = min(ls)
	ls[minin] = temp
minin = ls.index(min(ls))
maxin = ls.index(max(ls))
result1 = abs(maxin - minin)
if maxin < minin:
	temp = ls2[0]
	ls2[0] = max(ls2)
	ls2[maxin] = temp
else:
	temp = ls2[0]
	ls2[0] = min(ls2)
	ls2[minin] = temp
minin = ls2.index(min(ls2))
maxin = ls2.index(max(ls2))
result2 = abs(maxin - minin)
if result1 > result2:
	print(result1)
else:
	print(result2)


n = int(input())
a = list(map(int, input().split()))
p1 = a.index(1)
p2 = a.index(n)
print(max(abs(n - 1 - p1), abs(n - 1 - p2), abs(p1), abs(p2)))


import math
from operator import itemgetter

def get_primes(prime_supr):
	is_prime = [0] * 2 + [1] * prime_supr
	for i in range(2, int(math.sqrt(prime_supr)) + 1):
		if is_prime[i]:
			for j in range(i * i, prime_supr + 1, i):
				is_prime[j] = 0
	return is_prime
get_int = lambda : map(int, input().split())
n = int(input())
a = list(get_int())
print(n - 1 - min(min(a.index(1), n - 1 - a.index(1)), min(a.index(n), n - 1 - a.index(n))))


n = int(input())
lst = list(map(int, input().split()))
x = lst.index(max(lst))
y = lst.index(min(lst))
a = x
b = n - 1 - x
c = y
d = n - 1 - y
print(max(a, b, c, d))


n = int(input())
lst = list(map(lambda s: int(s), input().split(' ')))

def solve1(n, lst):
	for (i, elm) in enumerate(lst):
		if elm == 1:
			pos_min = i
		if elm == n:
			pos_max = i
	pos_min = min(n - 1 - pos_min, pos_min)
	pos_max = min(n - 1 - pos_max, pos_max)
	return n - 1 - min(pos_min, pos_max)
print(solve1(n, lst))


n = int(input())
l = list(map(int, input().split()))
ma = max(l)
mi = min(l)
(x, y) = (-1, -1)
for i in range(n):
	if l[i] == ma:
		x = i + 1
	if l[i] == mi:
		y = i + 1
(x, y) = (max(x, y), min(x, y))
a = max(x - 1, n - y)
print(max(a, x - y))


n = int(input())
a = list(map(int, input().split()))
maxLocate = a.index(n)
minLocate = a.index(1)
distanceMax = len(a) - 1 - a.index(n)
distanceMin = len(a) - 1 - a.index(1)
print(max(maxLocate, minLocate, distanceMax, distanceMin))


n = int(input().strip())
a = [int(x) for x in input().strip().split()]
if n == 2:
	print(1)
elif n == 3:
	print(2)
else:
	m = a.index(min(a))
	M = a.index(max(a))
	d1 = min(m, M)
	d2 = n - max(m, M) - 1
	print(max(n - d2 - 1, n - d1 - 1))


def f(n):
	z = n.index(max(n))
	zz = n.index(min(n))
	return abs(z - zz)
n = int(input())
a = [int(i) for i in input().split()]
b = a[:]
c = a[:]
d = a[:]
zzz = a.index(max(a))
zzzz = a.index(min(a))
(a[0], a[zzz]) = (a[zzz], a[0])
(b[0], b[zzzz]) = (b[zzzz], b[0])
(c[-1], c[zzzz]) = (c[zzzz], c[-1])
(d[-1], d[zzz]) = (d[zzz], d[-1])
print(max([f(a), f(b), f(c), f(d)]))