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.

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 a1, a2, ..., an (1 ≤ ai ≤ n), where ai is equal to the element at the i-th position.

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

NoteIn 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.

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    cin >> a;
    int b[a+1];
    int c=0 , d=0;
    for(int i=0;i<a;i++)
    {
        cin >> b[i];
        if(b[i]==1)
        {
            c=i;
        }
        if(b[i]==a)
        {
            d=i;
        }
    }
    cout << max(abs(a-1-d) , max(abs(0-d) , max(abs(a-1-c) , max(abs(0-c) ,abs(d-c) ))));
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,x,y,i,a_max,a_min,temp1;
	cin>>n;
	long long int a[n],c[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		c[i]=a[i];
	}
	sort(c,c+n);
	a_max=c[n-1];
	a_min=c[0];
	for(i=0;i<n;i++)
	{
		if(a[i]==a_min)
		{
			x=i;
		}
		if(a[i]==a_max)
		{
			y=i;
		}
	}
	if(x>y)
	{
		temp1=x;
		x=y;
		y=temp1;
	}
	if((n-y-1)>=x)
	{
		//cout<<"x=="<<x<<"y=="<<y<<endl;
		cout<<n-1-x<<endl;
	}
	else
	{
		//cout<<"x===="<<x<<"y===="<<y<<endl;
		cout<<y<<endl;
	}

}

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n, buf;
	cin >> n;
	int posn = 0, pos1 = 0, pos = 1;
	while (cin >> buf)
	{
		if (buf == n)
			posn = pos;
		else if (buf == 1)
			pos1 = pos;
		pos++;
		if (posn&&pos1)
			break;
	}

	cout << min(n-1,max(max(pos1-1, n-pos1), max(posn-1, n-posn))) << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{  int n,i,j;

  cin>>n;
  int a,y,x,z,l,m;
  for(i=0;i<n;i++)
  {
       cin>>a;
        if(a==1)
            l=i;
        if(a==n)
            m=i;
  }
     x=max(l,m);
     y=max(n-1-l,n-1-m);
     cout<<max(x,y);

}

//2016-05-26 19:32:02.628000
#include <algorithm>
#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>

using namespace std;

typedef pair<int, int> pii;
typedef long long INT;

int a[110];

int main() {
	int N, ans=0;

	scanf("%d", &N);
	for (int i=0; i<N; i++) {
		scanf("%d", &a[i]);
		if (a[i]==1 || a[i]==N) {
			ans=max(ans, i);
			ans=max(ans, N-i-1);
		}
	}

	printf("%d\n", ans);

	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
    int n,a[105];
    scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        int maxn=1,minn=1;
        for(int i=2;i<=n;i++)
        {
            if(a[i]>a[maxn])
                maxn=i;
            if(a[i]<a[minn])
                minn=i;
        }
        if(maxn>minn)
        {
            if(n-maxn>minn-1)
                printf("%d\n",n-minn);
            else
                printf("%d\n",maxn-1);
        }
        else
        {
             if(maxn-1>n-minn)
                printf("%d\n",minn-1);
             else
                printf("%d\n",n-maxn);
        }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int ar[105];

int main()
{
    int t, n, i, x, y;
    cin >> n;

    for(i=0; i<n; i++)
    {
        cin >> ar[i];
        if(ar[i] == 1)
        {
            x = i;
        }
        if(ar[i] == n)
        {
            y = i;
        }
    }

    if(x > y)
    {
        swap(x, y);
    }

    cout << max(y, n-x-1);
    return 0;
}

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
	int n,a,ma,mi; scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a);
		if(a==1) mi=i;
		if(a==n) ma=i;
	}
	int ll=min(ma,mi),rr=max(ma,mi);
	printf("%d\n",max(rr-1,n-ll));
	return 0;
}

#include <iostream>
#include <iomanip>
#include<cmath>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main(){
	int t,n,j,q,r;
	cin>>t;
	int x[10000];
	for(int i=0;i<t;++i){
		cin>>x[i];
		if(x[i]==t)
			q=i;
		if(x[i]==1)
			r=i;

	}
	n=max(r,q);
	j=min(r,q);
	if(n>t-j-1)
		 cout<<n;
	else
		cout<<t-j-1;

}

#include<iostream>
using namespace std;

int main(){

	int n,a,Max=0,min=1000,posmax,posmin;
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a;
		if (a>Max)
			Max=a,posmax=i;
		if (a<min)
			min=a,posmin=i;
	}
	cout<<max(posmax,max(n-1-posmax,max(posmin,n-1-posmin)));

	return 0;
}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <cmath>
int a[101];
using namespace std;
int main()
{
	int n , min , max , lin , lax;
	cin >> n;
	min = 200;
	max = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] > max)
		{
			max = a[i];
			lax = i;
		}
		if (a[i] < min)
		{
			min = a[i];
			lin = i;
		}
	}
	if (lax > lin)
	{
		if (n  - 1 - lax > lin )
			cout << n - lin - 1;
		else
			cout << lax;
	}
	if (lax < lin)
	{
		int k;
		k = lax;
		lax = lin;
		lin = k;
		if (n - lax > lin)
			cout << n - lin - 1;
		else
			cout << lax;
	}
	//cout << endl << lax << endl << lin;
 return 0;
}

//2016-05-26 18:45:50.936000
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <queue>
#include <map>

using namespace std;

#define beyond(x, y) (x<0 || y<0 || x>=N || y>=M)
#define sq(x) ((x)*(x))
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL
#define eps 1e-7

typedef long long INT;
typedef long double DO;
typedef pair<int, int> pii;

template<class T> inline void smin(T &a, T b) {if (a>b) a=b;}
template<class T> inline void smax(T &a, T b) {if (a<b) a=b;}

int dx[]={1, 0, -1, 0, 1, 1, -1, -1};
int dy[]={0, 1, 0, -1, -1, 1, 1, -1};
int qf, qb, q[1111111];

int a[11111], pos[11111];
int main() {

	int T, N, i, j, M, k;
	scanf("%d", &N);
	for (i=0; i<N; i++) {
		scanf("%d", a+i);
		pos[a[i]]=i;
	}
	int res=0;
	smax(res, pos[N]);
	smax(res, N-1-pos[N]);
	smax(res, pos[1]);
	smax(res, N-1-pos[1]);
	printf("%d\n", res);

	return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
#include<math.h>
using namespace std;

int main()
{
   int n,m1,m2,n1,n2,b,b1,b2;
   cin >> n;
   int a[n];
   for(int i=1;i<=n;i++)
   cin >> a[i];
    m1=a[1];
    m2=a[1];
    n1=1;n2=1;
   for(int i=2;i<=n;i++)
   {
       if(a[i]<m1)
       {
          m1=a[i];
          n1=i;
       }
   }
   for(int i=2;i<=n;i++)
   {
       if(a[i]>m2)
       {
          m2=a[i];
          n2=i;
       }
   }
   b=abs(n1-n2);
   if(b==(n-1))
   {
       cout << b;
   }
   else
   {
     b1=min(n1,n2);
     b2=max(n1,n2);
     if(abs(b2-1)>abs(b1-n))
     cout << abs(b2-1);
     else
     cout << abs(b1-n);
   }
   return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int n,a,k1,k2,i1,i2;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		if(a==1)
			i1=i;
		else if(a==n)
			i2=i;
	}
	k1=n-1-i1;
	k2=n-1-i2;
	if(i1<i2)
	i1=i2;
	if(i1<k1)
	i1=k1;
	cout<<((i1<k2)? k2:i1);
	return 0;
}

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
#define MAXN 1000000

int main()
{
    int n, a;
    cin >> n;
    int arr[1000];
    int x, y;
    for (int i = 0; i < n; i++){
        cin >> a;
        if (a == 1)
            x = i;
        if (a == n)
            y = i;
    }
    int res = max(x, n - x - 1);
    int res2 = max(y, n - y - 1);
    cout << max(res, res2);

}

#include <iostream>
using namespace std;
int main(){
    int n,x,y;
    cin >> n;
    int answer = 0;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        if(a==n) y = i;
        if(a==1) x = i;
    }
    int a = n-1-min(x,y);
    cout << max(a,max(x,y)) << endl;
}

//
// Created by Aqib Mahmud on 02-May-20.
//

#include <bits/stdc++.h>

#define fastI ios_base::sync_with_stdio(false); cin.tie(NULL)
#define endl "\n"
#define PI 3.1415926535897

using namespace std;

int main() {
    fastI;
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    int min_pos, min_val = INT_MAX;
    int max_pos, max_val = INT_MIN;
    for (int i = 0; i < n; i++) {
        if (v[i] > max_val) {
            max_val = v[i];
            max_pos = i;
        }
        if (v[i] < min_val) {
            min_val = v[i];
            min_pos = i;
        }
    }
    int left = min(min_pos, max_pos);
    int right = max(min_pos, max_pos);
    int ans1 = max(left, n - 1 - left);
    int ans2 = max(right, n - 1 - right);
    cout << max(ans1, ans2) << endl;
//    cout << max(max(min_pos, n - min_pos), max(max_pos, n - max_pos)) - 1 << endl;
    return 0;
}

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int n,i,j,l,r,x;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&x);
            if(x==1)
                l=i;
            else if(x==n)
                r=i;
        }
        if(l>r)
            printf("%d\n",l-r+max(n-l,r-1));
        else
            printf("%d\n",r-l+max(n-r,l-1));
    }
    return 0;
}

#include <cstdio>
int main() {
	int n;
	int a[100];
	int min, max;
	scanf("%d", &n);
	for(int i=0; i<n; i++) {
		scanf("%d", &a[i]);
		if(a[i]==1) {
			min=i;
		}
		else if(a[i]==n) {
			max=i;
		}
	}
	if(min>max) {
		int tmp=min;
		min=max;
		max=tmp;
	}
	printf("%d\n", (n-1-min) > max ? (n-1-min) : max);
	return 0;
}

#include<cstdio>
#include<math.h>
#include<queue>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long LL;
#define INF 9999999
const double pi=3.1415926535897932;

/*
int main()
{
    int n;
    int a[110];
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    int ans;
    int sum;
    if(n==3)
    {
        if((a[0]==n&&a[2]==1)||(a[0]==1&&a[2]==n))
            puts("1");
        else
            puts("2");
        return 0;
    }
    if(a[0]==n||a[0]==1||a[n-1]==n||a[n-1]==1)
    {
        printf("%d\n",n-1);
    }
    else
    {
        ans=max(n-a[0],a[0]-1);
        sum=max(n-a[n-1],a[n-1]-1);
        ans=max(ans,sum);
        printf("%d\n",ans);
    }
    return 0;
}
*/

const int N=105;
int n;
int arr[N];
int ans=0;
int flag;

void solve()
{
	int pos1;
	int pos2;
	for(int i=1;i<=n;i++)
	{
		if(arr[i]==1)
			pos1=i;
		if(arr[i]==n)
			pos2=i;
	}
	ans=max(ans,abs(pos1-pos2));
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>arr[i];
	flag=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			swap(arr[i],arr[j]);
			solve();
			swap(arr[i],arr[j]);
		}
	}
	cout<<ans<<endl;
}

#include<iostream>
#include<cmath>
using namespace std;
int ar[101];
int main(){
	int size;
	while (cin >> size){
		int indexMin, indexMax;

		for (int i = 0; i<size; i++){
			cin >> ar[i];
			if (ar[i] == 1)indexMin = i;
			else if (ar[i] == size)indexMax = i;

		}
		int distmin, distmax;
		if (indexMin>indexMax){
			distmin = size -1- indexMin;
			distmax = indexMax;
			if (distmax>distmin){
				indexMax = 0;

			}
			else{
				indexMin = size - 1;
			}
			cout << abs(indexMin - indexMax) << endl;

		}
		else{
			distmin = indexMin;
			distmax = size -1- indexMax;
			if (distmin>distmax){
				indexMin = 0;
			}
			else{
				indexMax = size - 1;
			}
			cout << abs(indexMin - indexMax) << endl;
		}

	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int min = 10000 , max = -1 , minI , maxI ;
	int n ;
	cin >> n ;

	vector<int> arr;

	for(int i = 1 ; i <= n ; i++ ){
		int k ;
		cin >> k ;
		if(k == 1){
			minI = i;
		}

		if(k == n){
			maxI = i ;
		}
	}

	int MAX = std::max(abs(1-maxI), abs(n- maxI));
	int MIN = std::max(abs(1-minI), abs(n- minI));
	cout << std::max(MIN,MAX ) ;
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926535897931;

int main()
{
#ifdef _KOCHERGIN
	freopen("input.txt", "r", stdin);
#else
	//freopen("abc.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	int n;
	cin >> n;
	int l1, l2;
	for (int i = 0; i < n; ++i)
	{
		int a;
		cin >> a;
		if (a == 1) l1 = i + 1;
		if (a == n) l2 = i + 1;
	}
	//cout << l1 << " " << l2 <<  endl;
	//cout << (l2 - ((n + 1) / 2)) << " " << (l1 - ((n + 1) / 2 + 1)) << endl;
	cout << max(max(max(n - l1, n - l2), l2 - 1), l1 - 1);
		return 0;
}

 #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
	long long n;
	cin >> n;
	vector<long long> v(n);
	long long  mi = 0, maxI = 0;
	for(int i =0; i < n; ++i)
	{
		cin >> v[i];
		if(v[i] == 1)
		{
			mi = i;
		}
		if(v[i] == n)
		{
			maxI = i;
		}
	}
	long long res = 0;
	if(maxI > mi)
	{
		res = maxI - mi;
		if(n -1 - mi > res)
		{
			res = n -1- mi;
		}
		if(maxI > res)
		{
			res = maxI;
		}
	}
	else
	{
		res = mi - maxI;
		if(n - 1 - maxI > res)
		{
			res = n-1 - maxI;
		}
		if(mi > res)
		{
			res = mi;
		}
	}
	cout << res << endl;

	return 0;
}

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){

   ll n, ans, one, last;
   cin>>n;
   ll ar[n];
   for(ll i = 0; i < n; i++){
       cin>>ar[i];
       if(ar[i] == 1)
           one = i;
       if(ar[i] == n)
           last = i;
   }

   if(one == 0 || one == n-1 || last == 0 || last == n-1){
       cout<<n-1;
       return 0;
   }

   ll a, b, c, d;
   a = one;
   b = n-1-one;
   c = last;
   d = n - 1 - last;

 ans = max(max(a, b), max(c, d));   //in-built function for getting maximum value
 cout<<ans;

return 0;
}

#include<iostream>
#include<cmath>
using namespace std;
int maxValuePosition(int *x,int num);
int minValuePosition(int *x,int num);
void swap(int &y,int &z);

int main()
{
    int d1,d2;
    int size,maxp,minp;

	cin>>size;

	int *n= new int[size];

    for(int i=0;i<size;i++)
	   cin>>n[i];
	cout<<endl;

	maxp=maxValuePosition(n,size);
	minp=minValuePosition(n,size);

	d1=(size-1)-maxp;
	d2=(size-1)-minp;

	if(maxp<minp)
	{
		if(maxp>d2)
		{
		 swap(n[maxp],n[0]);
	     maxp=0;
	    }
		else if(maxp<=d2)
		{
		 swap(n[minp],n[size-1]);
		 minp=size-1;
	    }
	}

	else if(maxp>minp)
	{
	    if(minp>d1)
	    {
		 swap(n[minp],n[0]);
	     minp=0;
		}
		else if(minp<=d1)
		{
	     swap(n[maxp],n[size-1]);
	     maxp=size-1;
	    }
	   }

	cout<<abs(maxp-minp);

}
//Function finds min value & its position
int minValuePosition(int *x,int num)
{
int minValue=x[0];
int minP=0;
    for(int i=1;i<num;i++)
      if(x[i]<minValue)
       {
       	minValue=x[i];
       	minP=i;
	   }
		return minP;
}

//Function finds max value & its position
int maxValuePosition(int *x,int num)
{
int maxValue=x[0];
int maxP=0;
    for(int i=1;i<num;i++)
      if(x[i]>maxValue)
       {
       	maxValue=x[i];
       	maxP=i;
	   }
		return maxP;
}

//Swapping Function
void swap(int &y,int &z)
       {int w;
        w=y;
        y=z;
        z=w;
	   }

/* In The Name of ALLAH */

#include <bits/stdc++.h>
#define ll long long
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
using namespace std;

int main()
{
  ll n,mini=9000,maxi=-1,m,mi;
  cin>>n;
  vector<int>a(n+1);
  for(int i=1; i<=n; i++)
  {
      cin>>a[i];
      if(a[i]>maxi) {maxi=a[i]; m=i;};
      if(a[i]<mini) {mini=a[i]; mi=i;};
  }
  if(m>mi) swap(m,mi);
  cout<<max(n-m,mi-1)<<endl;

}

#include <bits/stdc++.h>
using namespace std;
const int siz=105;
int n,indexmax=1,indexmin=1;
int a[siz];
int ans[4];
int main()
{
    cin>>n;
    for(int i=1; i<=n; ++i)
        cin>>a[i];
    int maxx=0;
    int minn=1e9;
    for(int i=1; i<=n; ++i)
        if(a[i]>maxx)
        {
            maxx=a[i];
            indexmax=i;
        }
    for(int i=1; i<=n; ++i)
        if(a[i]<minn)
        {
            minn=a[i];
            indexmin=i;
        }

    ans[0]=abs(n-indexmax);
    ans[1]=abs(n-indexmin);
    ans[2]=abs(1-indexmax);
    ans[3]=abs(1-indexmin);
    sort(ans,ans+4);
    cout<<ans[3];

    return 0;
}

/*
  ____          _____  ___ _____ ____
 |  _ \        | ____|/ _ \_   _/ __ \
 | |_) |_   _  | |__ | | | || || |  | |
 |  _ <| | | | |___ \| | | || || |  | |
 | |_) | |_| |  ___) | |_| || || |__| |
 |____/ \__, | |____/ \___/_____\___\_\
         __/ |
        |___/                     Coded by 50IQ

Problems solved: 78
 A: 55
 B: 21
 C: 2
 D: 0
 E: 0
 E+: 0

 Lang. used:
 C++: 44
 Java: 34
-----------------------------------------------------------------------------------
 Maths things:
 1.Even Odd:
    o + o = e
    e + e = e
    o + e = o
 11.sum of digits rule:
    number contains odd count of odd digits: SOD = single
    vice versa.
 Type range things(c++):
 short int and int: -32,767 to 32,767
 unsigned short int and unsigned int: 0 to 65,535
 long int: -2,147,483,647 to 2,147,483,647
 long long int: -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807
 unsigned long long int: 0 to 18,446,744,073,709,551,615
 unsigned long int: 0 to 4,294,967,295

 ===========DRAFT==============
def:  length of array > n
      array > a[]
	  dif > dif
idea:
1. pick max,min ok
2. determine which is nearer to 1st element
3. set another value to n-1 place
4. minus them with abs
*/

#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;

long long int minArray(long long int a[], int length) {
	long long int minv = a[0];
	for(int i = 0; i < length; i++)
		minv = min(a[i], minv);
	return minv;
}
long long int maxArray(long long int a[], int length) {
	long long int maxv = a[0];
	for(int i = 0; i < length; i++)
		maxv = max(a[i], maxv);
	return maxv;
}
//Custom method here
//
int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0);
    //notes:
    int n;
    cin >> n;
    long long int a[n];
    for(int i = 0;i < n;i++)
    {
    	cin >> a[i];
    }
    if(n == 2){
    	cout << 1;
    	return 0;
    }
    if(n == 3)
    {
    	cout << 2;
    	return 0;
    }

    //min e = pos1, max e = pos2
    int minE = minArray(a, n), maxE = maxArray(a, n);
    int pos1 = 0, pos2 = 0;
    int to0 = 0, ton = 0;
    for(int i = 0; i < n; i++){
    	if(a[i] == minE)
    		pos1 = i;
    	if(a[i] == maxE)
    		pos2 = i;
    }

    to0 = min(pos1,pos2);
    ton = (n-1) - max(pos1,pos2);

    if(to0 > ton){
    	cout << max(pos1,pos2);
    }else{
    	cout << (n-1) - min(pos1,pos2);
    }
}

#include <iostream>
#include <cmath>
using namespace std;

int main(){
    int n;
    cin >> n;
    int my_array[n];
    for(int i = 0;i<n;i++){
        cin >> my_array[i];
    }
    int maxnum= my_array[0];
    int minnum= my_array[0];
    for(int i=0 ; i < n-1 ; i++){
        if(maxnum<my_array[i+1]) maxnum = my_array[i+1];
    }
    for(int j=0;j<n-1;j++){
        if(minnum> my_array[j+1]) minnum = my_array[j+1];
    }
    //cout << "max: " << maxnum << endl << "min: "  << minnum << endl;
    int i;
    for(i=1;i<n+1;i++){
        if(my_array[i-1]==maxnum) break;
    }
    int j;
    for(j=1;j<n+1;j++){
        if(my_array[j-1]==minnum) break;
    }
    //cout << i << j;
    if(i<j){
        if(i<(n-j+1)){
            j = n;
        }

        else{
            i = 1;
        }
    }
    else {
        if (j<(n-i+1)){
            i = n;
        }
        else {
            j = 1;
        }
    }
    cout<< abs(i-j);
}

#include <bits/stdc++.h>
#define rep(_,__) for(_=1;_<=(__);_++)
using namespace std;
int main()
{
    int n, a, b, x, i;
    cin>>n;
    rep(i,n)
    {
        cin>>x;
        if(x==1)a=i;
        if(x==n)b=i;
    }
    if(a>b)swap(a,b);
    cout<<abs(a-b)+max(a-1,n-b);
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define lop(a,b,c) for (a=c;a<b;a++)
#define pb push_back
#define srt(v) v.begin(),v.end()
using namespace std;
int main()
{
    ll i,j,k,l,m,n;
    cin>>n;
    vector<ll>v;
    lop(i,n,0)
    {
        ll b;
        cin>>b;
        v.pb(b);
    }
    j=distance(v.begin(),min_element(srt(v)));
    k=distance(v.begin(),max_element(srt(v)));
    //cout<<j<<endl;
    //cout<<k<<endl;
    cout<<max(max(k,j),max(n-k-1,n-j-1));
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define maxn 200010
#define nmaxn 2000000010
ll a[maxn],ans,n;

int main()
{cin>>n;
for(int i=0;i<n;i++)
{cin>>a[i];}

for(ll i=0;i<n;i++)
{if (a[i] == 1 || a[i] == n) {
        ans = max(ans, i);
        ans = max(ans, n - 1 - i);
    }}
cout<<ans;

}

//'\n'
// ||

#include <cstdio>
#define MAX 99999
int main()
{
    int n,m;
    int maxn,minn;
    int dis1,dis2;
    int minl,maxl;
    scanf("%d",&n);
    maxn=0;
    minn=MAX;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&m);
        if (m>maxn)
        {
            maxn=m;
            maxl=i;
        }
          if (m<minn)
        {
            minn=m;
            minl=i;
        }
    }
    //printf("%d %d\n",minl,maxl);
    if (maxl<n/2)
      dis1=maxl;
    else
      dis1=n-maxl-1;
    if (minl<n/2)
      dis2=minl;
    else
      dis2=n-minl-1;
    //printf("%d %d\n",dis1,dis2);
    if (dis1>dis2)
    {
        int t;
        t=dis2;
        dis2=dis1;
        dis1=t;
    }
    printf("%d\n",n-dis1-1);
    return 0;
}

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <numeric>
#include <map>
#include <sstream>
#include <chrono>
#include <set>
#include <unordered_map>
using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);

	int n;
	cin >> n;
	int maxi = INT32_MIN, max_index = -1;
	int mini = INT32_MAX, min_index = -1;
	for (int i = 0; i < n; i++)
	{
		int temp;
		cin >> temp;
		if (temp < mini)
		{
			min_index = i;
			mini = temp;
		}
		if (temp > maxi)
		{
			max_index = i;
			maxi = temp;
		}
	}
	cout << (max(max(min_index, n - min_index - 1), max(max_index, n - max_index - 1)));

	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main(){
    long long ar[105],n,chkmini=999,mini,chkmaxi=0,maxi,i,ans;
    scanf("%I64d",&n);
    for(i=0;i<n;i++){
        scanf("%I64d",&ar[i]);
        if(ar[i]<chkmini){
            chkmini=ar[i];
            mini=i;
        }
        if(ar[i]>chkmaxi){
            chkmaxi=ar[i];
            maxi=i;
        }
    }
    if((mini==0&&maxi!=n-1)||(mini==n-1&&maxi!=0))ans=n-1;
    else if((maxi==0&&mini!=n-1)||(maxi==n-1&&mini!=0))ans=n-1;
    else if((mini==0&&maxi==n-1)||(maxi==0&&mini==n-1))ans=n-1;
    else {
        ans=max(max(abs(n-1-mini),abs(n-1-maxi)),max(abs(mini-0),abs(maxi-0)));
    }
    printf("%I64d\n",ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,r,a,b,dis,Min=99999,Max=-99999,aux1,aux2;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i){
		scanf("%d", &r);
		if(r<Min){
			Min=r;
			a=i;
		}
		if(r>Max){
			Max=r;
			b=i;
		}
	}
	Min=min(a,b);
	Max=max(a,b);
	aux1=abs(Min-n);
	aux2=abs(Max-1);
	int resp=max(aux2,aux1);
	printf("%d\n", resp);
//	system("pause");
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    int vt1,vtn;
    int t1,t2;
    int kq;
    vector<int> v;
    cin>>n;
    for (int i=0;i<n;i++)
    {
        int tam;
        cin>>tam;
        if (tam==1) vt1=i;
        if (tam==n) vtn=i;
        v.push_back(tam);
    }
    if ((vt1<=n/2)&&(vtn<=n/2)) //1 và n cùng nằm về phía bên trái
    {
        t1=min(vt1,vtn);
        t2=max(vt1,vtn);
        kq=n-1-t1;
    }
    else
    if ((vt1>=n/2)&&(vtn>=n/2))  //1 và n cùng nằm về phía bên phải
    {
        t1=min(vt1,vtn);
        t2=max(vt1,vtn);
        kq=t2;
    }
    else  //1 và n nằm ở 2 phía khác nhau
    {
        t1=min(vt1,vtn);
        t2=max(vt1,vtn);
        if (t1<n-1-t2) kq=n-1-t1;
        else
        if (t1=n-1-t2) kq=max(n-1-t1,t2);
        else kq=t2;
    }
    cout<<kq<<endl;
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS

#include <iomanip>
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	int mx = max_element(a.begin(), a.end()) - a.begin() + 1;
	int mn = min_element(a.begin(), a.end()) - a.begin() + 1;

	int ans = max(n - mx, mx - 1);
	ans = max(n - mn, max(ans, mn - 1));

	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,x,y,a,b,d; cin>>n;
for(int i=0;i<n;i++){
cin>>x;
if(x==1) a=i;
if(x==n) b=i;
}
if(a==0) d=n-1-b;
else if(a==n-1) d=b;
else if(b==0) d=n-1-a;
else if(b==n-1) d=a;
else{
	if(a<b) d=max(a,n-1-b);
	else d=max(n-1-a,b);
}
cout<<abs(a-b)+d;
return 0;
}

#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main ()
{
int i,j,k,n,maxx=0,c,minn,b,dif=0;
cin >> n;
int a[n];
minn=n;
for (i=0;i<n;i++)
{
cin>> a[i];
if (a[i]>maxx)
    {maxx=a[i]; c=i;}
if (a[i]<minn)
    {minn=a[i]; b=i;}
}
int f[4];
f[0]=0;f[3]=n-1;

if (b>c)
    {f[2]=b; f[1]=c;}
else
    {f[2]=c; f[1]=b;}

if ((f[2]-f[0]) > (f[3]-f[1]))
    dif=f[2]-f[0];
else
    dif=f[3]-f[1];

//dif=max(a[2]-a[0],a[3]-a[1]);
cout << dif <<endl;

return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int x;
	int p1, p2;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		if (x == 1) p1 = i;
		if (x == n) p2 = i;
	}
	if (p1 == 1 || p1 == n || p2 == 1 || p2 == n) {
		cout << n - 1 << "\n";
		return 0;
	}
	else {
		int a =	 max(p1 - 1, n - p1);
		int b = max(p2 - 1, n - p2);
		cout << max(a, b) << "\n";
		return 0;
	}

}

#include <iostream>
using namespace std;
int n, x, y, a, I, J;
int main()
{
    cin>> n;
    for (int i=1; i<=n; i++){
        cin>> a;
        if (a==1)
            I=i;
        if (a==n)
            J=i;
    }
    if ((J-1)>(n-J))
        x=J-1;
    else
        x=n-J;
    if ((I-1)>(n-I))
        y=I-1;
    else
        y=n-I;
    if (x>y)
        cout<< x;
    else
        cout<< y;
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
		int n;
		cin>>n;
		int v[n];
		int pme,pma;
		for(int i = 0;i<n;i++)
		{
			cin>>v[i];
			if(v[i] == 1)pme = i;
			if(v[i] == n)pma = i;
		}
		if((pme == 0 && pma == n-1) || (pme == n-1 && pma == 0))
		{
			cout<<abs((pme+1) - (pma+1));
			return 0;
		}
		else
		{
			if(pme > pma)
			{
				cout<<max( abs(n-(pma+1)),abs(1 - (pme+1) ));
			}else
				cout<<max( abs(n-(pme+1)),abs(1 - (pma+1) ));

		}

}

#include <iostream>
#include<algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int pos = 0;
    int x;
    int t =((n+1)/ 2)- 1;
    // cout<<t<<endl;

    for (int i = 0; i < n; i++)
    {
        cin >> x;
        if (x == 1 || x == n)
        {
            if (i == t)
                pos=max(pos,0);
            else if (i < t)
            {
                pos = max(pos,n - i - 1);

            }
            else
            {
                pos = max(i,pos);
            }
        }
    }
    cout << pos;
}

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n+1];
    for(int i=1;i<=n;i++)
      cin>>arr[i];
    int max=1,min=1;
    for(int i=2;i<=n;i++)
    {
          if(arr[i]>arr[max])
             max=i;
         if(arr[i]<arr[min])
             min=i;
    }
    //cout<<max<<" "<<min<<"\n";
    int left,right;
    if(max>min)
    {
      left=min;
      right=max;
    }
    else
      {
          left=max;
          right=min;
      }
    int ld=left-1,rd=n-right;
    if(ld<=rd)
    {
        cout<<n-left;
    }
    else
        cout<<right-1;

}

#include <iostream>
#include <vector>

using namespace std;

int main()
{

	int n, max, pos1, posn, temp;
	vector<int> a;
	cin >> n;

	for (int i = 0; i<n; i++)
	{
		cin >> temp;
		a.push_back(temp);
		if (a[i] == 1)
			pos1 = i;
		if (a[i] == n)
			posn = i;
	}

	max = abs(posn - pos1);
	n = n - 1;
	if (max < abs(posn - 0))
		max = abs(posn - 0);
	if (max < abs(posn - n))
		max = abs(posn - n);
	if (max < abs(pos1 - 0))
		max = abs(pos1 - 0);
	if (max < abs(pos1 - n))
		max = abs(pos1 - n);
	cout << max;
	return 0;
}

/**
 * File              : A.cpp
 * Author            : Bao To Hoai
 * Date              : 14.10.2020 14:09:14
 * Last Modified Date: 14.10.2020 14:47:36
 * Last Modified By  : Bao To Hoai
 */
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define forn(i, a, b) for (int i = (a); i < (b); ++i)

string to_string(string s) {
    return s;
}

template<class A, class B> string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template<class T> string to_string(T v) {
    bool f = true;
    string res = "{";
    for (auto &x : v) {
        if (!f) {
            res += ", ";
        }
        f = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void DBG() {
    cerr << "]" << endl;
}

template<class H, class... T> void DBG(H h, T... t) {
    cerr << to_string(h);
    if(sizeof...(t))
        cerr << ", ";
    DBG(t...);
}

#ifdef LOCAL
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, x, a = 0, b = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> x;
        if (x == 1) a = i;
        else if (x == n) b = i;
    }

    if (a > b) swap(a, b);
    if (a == 1 && b == n) {
        cout << n - 1 << endl;
        return 0;
    }
    dbg(a, b);
    cout << max(b - 1, max(n - a, a)) << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int n, x1, x2;
int main(void) {
    cin >> n;
    for (int i = 1, x; i <= n; ++i) {
        cin >> x;
        if (x == n)
            x1 = i;
        else if (x == 1)
            x2 = i;
    }
    cout << max(max(abs(x2 - x1), max(x1 - 1, x2 - 1)), max(n - x1, n - x2)) << endl;
    return 0;
}

#include <iostream>
#include <vector>

size_t solve(const std::vector<size_t>& a)
{
	const size_t n = a.size();

	std::vector<size_t> b;
	for (size_t i = 0; i < n && b.size() != 2; ++i) {
		if (a[i] == 1 || a[i] == n)
			b.push_back(i);
	}

	return std::max(b.back(), n-1 - b.front());
}

int main()
{
	size_t n;
	std::cin >> n;

	std::vector<size_t> a(n);
	for (size_t i = 0; i < n; ++i)
		std::cin >> a[i];

	std::cout << solve(a) << '\n';

	return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(i,x,n) for(ll i=x;i<n;i++)
#define fl(i,x,n) for(ll i=n;i>=x;i--)
#define mod (ll)1e9+7
#define print(x) cout<<x<<endl
#define vec vector<ll>
#define pai pair<ll, ll>
#define itr(it) :: iterator it
#define MAX (ll)1e16
#define MIN (ll)-1e16
#define X first
#define Y second
#define up upper_bound
#define lo lower_bound
using namespace std;
       ///////////   ///     ///   ///      ///   ////////////  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///////////   ///      ///   ////////////  ////////////
               ///   ///     ///   ///      ///   ///      ///  ///      ///
               ///   ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///     ///   ////////////   ////////////  ///      ///
ll minn( ll a , ll b)
{
    if(a>b)
        return b;
    return a;
}
ll maxx2( ll a , ll b)
{
    if(a>b)
        return a;
    return b;
}
ll maxx(ll a,ll b,ll c)
{
  return maxx2(a,maxx2(b,c));
}
ll gcdd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcdd(b,a%b);
}
ll dsum(ll n)
{
    ll sum=0;
    while(n>0)
    {
        sum+=n%10;
        n/=10;
    }
    return sum;
}
ll poww(ll a,ll b)
{
    if(b<=0)
        return 1;
    if(b==1)
        return a;
    else
        return poww(a,b/2)*poww(a,b/2)*poww(a,b%2);
}
string substr1(string s, ll i,ll j)
{
    string r = s.substr(i,j-i+1);
    return r;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x,y,n;
    cin>>n;
    ll a[n];
    f(i,0,n)
    {
        cin>>a[i];
        if(a[i]==1)
            x=i;
        if(a[i]==n)
        {
            y=i;
        }
    }
    ll a1=0,a2=0,a3=0,a4=0;
    if((x==0 && y==n-1) ||(x==n-1 && y==0))
    {
    	if(n==2)
    	{
    		cout<<1<<endl;
    		return 0;
    	}
		else
		{
    		cout<<n-1<<endl;
    		return 0;
		}
    }
    if(x==0 || x==n-1 || y==0 || y==n-1)
    {
    	cout<<n-1<<endl;
    	return 0;
    }
    a1=y;
    a2=n-y-1;
    a3=n-x-1;
    a4=x;
    cout<<maxx2(a1,maxx(a2,a3,a4))<<endl;
    return 0;
}

#include <iostream>
#include<algorithm>
using namespace std;
int n, k, a, b;
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> k;
        if (k == 1) {
            a = i;
        } else if (k == n) {
            b = i;
        }
    }
    cout << max(max(n - b, b - 1), max(n - a, a - 1));
}

#include <iostream>
#include <cstdlib>
int main() {
	using namespace std;
	int n;
	cin >> n;
	int a = 0, b = 0;
	for (int i = 1; i <= n && (!a || !b); i++) {
		int x; cin >> x;
		if (x == 1 || x == n) {  !a?a = i : b = i; }
	}
	if (a == 1 && b == n) cout << b - a;
	else (n - a > b - 1) ? cout << n - a : cout << b - 1;
	return 0;
}

//              *           ***********    *********         *         **           *
//            *   *         *         *       ***          *   *       *  *         *
//          *       *       *         *       ***         *     *      *    *       *
//         ***********      ***********       ***        *********     *      *     *
//        *           *     *  *              ***       *         *    *        *   *
//       *             *    *     *           ***      *           *   *          * *
//       *             *    *        **    *********   *           *   *           **

//       **********                *                ***********       ***********
//       *        *              *   *              *                 *
//       *      *              *       *            *                 *
//       * * *                ***********           ***********       ***********
//       * * *               *           *                    *                 *
//       *      *           *             *                   *                 *
//       *        *        *               *                  *                 *
//       **********        *               *        ***********       ***********

#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <float.h>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <deque>
#include <queue>
#include <stack>

#define ll long long
#define dou double
#define vec vector
#define dec deque
#define que queue
#define ff first
#define ss second
#define pb push_back
#define set(x) cout << setprecision (x) << fixed
#define Turbo std::ios::sync_with_stdio(false)

using namespace std ;

// Until 400 ;)

const int N = 1e6 + 20 , S = 1e3 ;
const ll inf = 1e17 ;
ll p [N] , a [N] , b [N] , ab [S][S] ;
char arch [N] , cbl [S][S] ;
vector <ll> v , g [N] ;
bool mark [N] , bb = false ;
ll n , d [N] , c , c1 , m , k = 0 , q , x = 0 , y = 0 , z , l , r , mn = inf , mx = 0 , ans = 0 , ans1 = 0 , ans2 = 1 , cnt = 0 , sum1 = 0 , o = 0 ;
int i = 0 , j = 0  ;
double sum = 0 ;
string s , t ;

int main () {
    Turbo ;
    cin >> n ;
	for (i = 1 ; i <= n ; i ++) {
		cin >> a [i] ;
		if (a [i] == 1) {
			x = i ;
		}
		if (a [i] == n) {
			y = i ;
		}
	}
	if (x < y) {
		if (y - x == n - 1) {
			cout << n - 1 << '\n' ;
			return 0 ;
		}
		mx = max (y - 1 , x - 1) ;
		mx = max (mx , max (n - (y ) , n - (x ))) ;
		cout << mx << '\n' ;
	}
	else {
		if (x - y == n - 1) {
			cout << n - 1 << '\n' ;
			return 0 ;
		}
		mx = max (y - 1 , x - 1) ;
		mx = max (mx , max (n - (y ) , n - (x ))) ;
		cout << mx << '\n' ;
	}
	return 0 ;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const int maxn=1000100;
const int INF=1e9+10;

int n;
int a[maxn],id[maxn];

int main()
{
    //freopen("in.txt","r",stdin);
    while(cin>>n){
        for(int i=1;i<=n;i++) scanf("%d",&a[i]),id[a[i]]=i;
        int ans=0;
        if(n==2) ans=1;
        else if(n==3) ans=2;
        else{
            if(id[1]==1||id[1]==n||id[n]==1||id[n]==n) ans=n-1;
            else{
                int x=id[1],y=id[n];
                if(x>y) swap(x,y);
                ans=max(y-1,n-x);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n;
   cin>>n;
   int a[n],i,num1=0,num2=0,max=0,min=10000;
   int ans1=0,ans2=0,ans3=0,ans4=0;
   for(i=0;i<n;++i)
      { cin>>a[i];
         if(max<a[i])
           {
               max=a[i];
               num1=i;
           }

         if(min>a[i])
           {
               min=a[i];
               num2=i;
           }
      }

    if(abs(num1-num2)==n-1)
      cout<<n-1;

    else
    {
        ans1=abs(n-1-num1);
        ans2=abs(n-1-num2);
        ans3=num1;
        ans4=num2;

        int x[]={ans1,ans2,ans3,ans4};
        sort(x,x+4);

        cout<<x[3];
    }

    return 0;

}

#include <iostream>
#include <cmath>

using namespace std;

int maximum(int a, int b){
    if(a>b)
        return a;
    return b;
}

int main()
{
    int n,i,mini=1000,maxi=-1,miniPos=-1,maxiPos=-1,a,mid,ans;
    cin>>n;
    for(i=0; i<n; i++){
        cin>>a;
        if(a>maxi){
            maxi = a;
            maxiPos = i;
        }
        if(a<mini){
            mini = a;
            miniPos = i;
        }
    }
    ans = maximum(maximum(maxiPos,miniPos),maximum(n-1-miniPos,n-1-maxiPos));
    cout<<ans<<"\n";
    return 0;
}

#include<stdio.h>
void main(){
	int n, i, max=0, min=0;
	scanf("%d",&n);
	int a[100];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]>a[max]) max=i;
		if(a[i]<a[min]) min=i;
	}
	max>(n-1)-max? max=(n-1)-max : max=max;
	min>(n-1)-min? min=(n-1)-min : min=min;

	if(max>=min) printf("%d",(n-1)-min);
	else printf("%d",(n-1)-max);
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

int main()
{
    int n;
    int num[105];
    while(~scanf("%d", &n))
    {
        int min_index;
        int max_index;
        for(int i = 1; i <= n; i++)
        {
            scanf("%d", &num[i]);
            if(num[i] == 1)
                min_index = i;
            if(num[i] == n)
                max_index = i;
        }
        int space_dis = max(min_index, max_index) - min(min_index, max_index);
        if(min_index < max_index)
        {
            if(min_index - 1 > n - max_index)
            {
                printf("%d\n", space_dis + min_index - 1);
            }
            else
            {
                printf("%d\n", space_dis + n - max_index);
            }
        }
        if(max_index < min_index)
        {
            if(n - min_index > max_index - 1)
            {
                printf("%d\n", space_dis + n - min_index);
            }
            else
            {
                printf("%d\n", space_dis + max_index - 1);
            }
        }
    }
    return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n,x,y;
    cin>>n;
  int *arr=new int[n+1];
  for(int i=1 ;i<=n;i++)
    {
        cin>>arr[i];
        if(arr[i]==1)
        {
            x=i;

        }
        else if(arr[i]==n)
            y=i;
    }

if(max(y,x)<=(n/2)+(n%2))
cout<<n-min(x,y);
else if (min(x,y)>(n/2)+(n%2))
cout<<max(x,y)-1;
else
{
    if(n-min(x,y)>=max(x,y)-1)
    cout<<n-min(x,y)<<endl;
    else
    cout<<max(x,y)-1<<endl;

}

    return 0;
}

#include <bits/stdc++.h>
//1 + 1 == 3(?!);
//in the name of god;
using namespace std;
typedef long long ll;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Y cout << "YES\n";
#define N cout << "NO\n";
 ll MN = 10e10, MX = -1, K, T;
 int main(){
   fastio;
   ll n; cin >> n;  ll flag[n + 1000];
   for ( ll i = 1; i <= n; ++i ){
   	     cin >> flag[i];
   	     if (flag[i] < MN){MN = flag[i]; K = i;}
   	     if (flag[i] > MX){MX = flag[i]; T = i;}
   }
   cout << max(n - K, max(n - T, max(abs(1 - T), abs(1 - K) ) ) );

}

#include <iomanip>
#include <iostream>
#include <math.h>
#define ll unsigned long long int
using namespace std;
  double mod=1000000007;

int main()
{
    int n,x=0,y=n,t[1000];
    cin>>n;
    for(int i=0;i<n;i++){
          cin>>t[i];
          if(t[i]==1)x=i+1;
          if(t[i]==n)y=i+1;

    }
   // cout<<x<<"  "<<y<<endl;
    if((x==1||x==n)||(y==n||y==1))cout<<n-1;
    else
    cout<<max(max(x,y)-1,n-min(x,y))<<endl;
    return 0;

}

#include <iostream>
using namespace std;

int main()
{
    int n,maxi=0,mini=10000000,index1,index2;
    cin>>n;
    for (int i=0;i<n;i++)
    {

        int x;
        cin>>x;
       if (x<mini){mini=x;index1=i;}
       if (x>maxi){maxi=x;index2=i;}

    }
    if (index1==0||index2==0||index1==n-1||index2==n-1){cout<<n-1;}
    else {cout<<max(max(n-(index1+1),n-(index2+1)),max(index1,index2));}

    return 0;
}

#include <cstdio>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
int n,s[105];
inline void read(int &x)
{
    x=0;
    char ch=getchar();
    while(ch<'0' || ch>'9') ch=getchar();
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
}
void print(int x)
{
	if(x<0) printf("-"),x=-x;
	if(x>9) print(x/10);
	putchar(x%10+48);
}
int main()
{
	read(n);int maxx,minn;
	for(int i=1; i<=n; i++)
	{
		read(s[i]);
		if(s[i]==1) minn=i;
		if(s[i]==n) maxx=i;
	}
	int l=min(minn,maxx),r=max(minn,maxx);
	print(max(n-l,r-1));
	return 0;
}

#include<iostream>

#include<fstream>
#include<vector>
#include<math.h>

using namespace std;

int main(){
	int len;
	/*ifstream infile;
	infile.open("input.txt");
	infile >> len;*/
	cin >> len;
	//vector<int> nums(len+1, 0);
	int a;
	int  least_index, biggest_index;
	for (int i = 1; i <= len; i++) {
		cin >> a;
		if (a == 1)
			least_index = i;
		if (a == len)
			biggest_index = i;
	}

	if (least_index > biggest_index) swap(least_index, biggest_index);

	if ((len - biggest_index) > (least_index - 1)) cout << len - least_index;
	else cout << biggest_index - 1;
	/*cout << endl;
	system("pause");*/
	return 0;
}

#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> vec;
	int x;

	for (int i = 0; i < n; i++) {
		cin >> x;
		vec.push_back(x);
	}
	int max = 0, min = vec[0];
	int idxMax = 0, idxMin = 0;

	int distance = 0;
	if (n == 2)
		distance = 1;
	else {
		for (int i = 0; i < n; i++) {
			if (vec[i] > max)
			{
				max = vec[i];
				idxMax = i;
			}
			if (vec[i] < min)
			{
				min = vec[i];
				idxMin = i;
			}

		}

		if (idxMax > distance)
			distance = idxMax;
		if (idxMin > distance)
			distance = idxMin;
		if (abs(idxMax - idxMin) > distance)
			distance = abs(idxMax - idxMin);
		if ((n - 1 - idxMax) > distance)
			distance = n - 1 - idxMax;
		if ((n - 1 - idxMin) > distance)
			distance = n - 1 - idxMin;
	}
	cout << distance;

	return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n, posM=0, posm=0;
	cin>>n;
	int* arr = new int[n];
	for(int i=0; i<n; i++)
	{
		cin>>arr[i];
		if(arr[i]==n) {posM=i;}
		if(arr[i]==1) {posm=i;}
	}
	int a, b;
	a=min(abs(n-1-posM), abs(posM));
	b=min(abs(n-posm-1), abs(posm));
	cout<<n-1-min(a, b);
	return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

void test_case() {

}

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll T, pos_1, pos_T;
    cin >> T;
    vector<int> perm(T);
    for (int i=0; i<T; i++) {
        cin >> perm[i];
        if(perm[i] == 1) pos_1 = i+1;
        if(perm[i] == T) pos_T = i+1;
    }
    int max1 = max( abs(T-pos_1), abs(T-pos_T));
    int max2 = max( abs(1-pos_1), abs(1-pos_T));
    cout << max( max1, max2 );
}

#include <iostream>
#include <iomanip>
#include<cmath>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main(){
	int t,n,j,q,r;
	cin>>t;
	int x[10000];
	for(int i=0;i<t;++i){
		cin>>x[i];
		if(x[i]==t)
			q=i;
		if(x[i]==1)
			r=i;

	}
	n=max(r,q);
	j=min(r,q);
	if(n>t-j-1)
		 cout<<n;
	else
		cout<<t-j-1;

}

#include <bits/stdc++.h>
/*
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>
*/
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=1e5+4;
int n;
int a[110],flag[110];
int main()
{
       scanf("%d",&n);
       Riep(n)
       {
           scanf("%d",&a[i]);
           flag[a[i]]=i;
       }
       int ans=0;
           ans=max(ans,abs(n-flag[1]));
           ans=max(ans,abs(flag[n]-1));
           ans=max(ans,abs(n-flag[n]));
           ans=max(ans,abs(flag[1]-1));
       cout<<ans<<"\n";

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,pos_ma,pos_mi,b;
    cin>>t;
    int a[t];
    for(int i=0; i<t; i++)
    {
        cin>>a[i];
    }
    int max1=a[0];
    pos_ma=0;
    int min1=a[0];
    pos_mi=0;

    for(int i=1; i<t; i++)
    {
        if(a[i]>max1)
        {
            max1=a[i];
            pos_ma=i;
        }
    }

    for(int j=1; j<t; j++)
    {
        if(min1>a[j])
        {
            min1=a[j];
            pos_mi=j;
        }
    }

    if((pos_ma==0 && pos_mi==(t-1))||(pos_ma==(t-1)&&pos_mi==0))
    {

        b=(t-1);
    }

    if(pos_ma==0 && pos_mi!=(t-1))
    {
        b=t-(pos_ma+1);
    }

    if(pos_mi==0 && pos_ma!=(t-1));
    {
        b=t-(pos_mi+1);
    }

    if(pos_ma==(t-1) && pos_mi!=0)
    {
        b=t-1;
    }

    if(pos_mi==(t-1) && pos_ma!=0)
    {
        b=t-1;
    }
    else
    {
        if(pos_ma < pos_mi)
        {
            b=max((t-(pos_ma+1)),(((pos_mi+1)-1)));
        }

        else
        {
            b=max((t-(pos_mi+1)),(((pos_ma+1)-1)));
        }
    }
    cout<<b<<endl;

    return 0;
}

#include <bits/stdc++.h>
#define rep(_,__) for(_=1;_<=(__);_++)
using namespace std;
int main()
{
    int n, a, b, x, i;
    cin>>n;
    if(n==2)
    {
        cout<<1;
        return 0;
    }
    rep(i,n)
    {
        cin>>x;
        if(x==1)a=i;
        if(x==n)b=i;
    }
    if(abs(a-b)==n-1)cout<<abs(a-b);
    else
    {
        if(a>b)swap(a,b);
        cout<<abs(a-b)+max(a-1,n-b);
    }
}

#include <iostream>
using namespace std;
int main(){
	int n,a,b,x;
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>x;
		if(x==1) a=i;
		else if(x==n) b=i;
	}
	if(a>b) swap(a,b);
	cout<<(b>n-a-1 ? b : n-a-1);
}

#include<bits/stdc++.h>
using namespace std;
int n;
int arr[101];
int mn=101,mx=-1;
int posmn,posmx;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];

    for(int i=0;i<n;i++)
    {
        if(arr[i]>mx){
            mx=arr[i];
            posmx=i;
        }
        if(arr[i]<mn){
            mn=arr[i];
            posmn=i;
        }
    }
    //cout<<posmx<<" "<<posmn<<endl;
    if(posmn>posmx)
    {
        if(n-1-posmn>posmx)
            cout<<abs(n-1-posmx)<<endl;
        else
            cout<<posmn<<endl;
    }
    else
    {
        if((n-1-posmx)>posmn)
            cout<<abs(n-1-posmn)<<endl;
        else
            cout<<posmx<<endl;
    }

}

#include"bits/stdc++.h"
using namespace std;
const int N = 5e5 +5;

int n , n1 ;
long long k, m ;
vector<long long >v1;
vector<long long >v2;

int main( void ){
cin>>n;
int x;

int l , r;
for( int i=0 ; i<n ; ++i ){
    cin>>x;
    if( x==1) l = i;
    if(x==n) r = i;
}

if (l < r){
		printf("%d", max(r, n - l - 1));
	}
	else{
		printf("%d", max(n - r - 1, l));
}

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define maxn 200010
#define nmaxn 2000000010
ll a[maxn],ans,n;

int main()
{cin>>n;
for(int i=0;i<n;i++)
{cin>>a[i];}

for(ll i=0;i<n;i++)
{if (a[i] == 1 || a[i] == n) {
        ans = max(ans, i);
        ans = max(ans, n - 1 - i);
    }}
cout<<ans;

}

//'\n'
// ||

#include <iostream>
#include <cstdlib>
int main() {
	using namespace std;
	int n;
	cin >> n;
	int a = 0, b = 0;
	for (int i = 1; i <= n && (!a || !b); i++) {
		int x; cin >> x;
		if (x == 1 || x == n) {  !a?a = i : b = i; }
	}
	n - a > b - 1 ? cout << n - a : cout << b - 1;
	return 0;
}

#include <stdio.h>

int main() {
	int n, result;
	int smallest = 0;
	int biggest = 0;

	scanf("%d", &n);
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	for (int i = 0; i < n; i++) {
		if (a[i] < a[smallest]) {
			smallest = i;
		}
		if (a[i] > a[biggest]) {
			biggest = i;
		}
	}

	int test[4] = {
		(n - 1) - smallest,
		biggest,
		(n - 1) - biggest,
		smallest,
	};
	int big = 0;
	for (int i = 0; i < 4; i++) {
		if (test[i] > test[big]) {
			big = i;
		}
	}

	printf("%d", test[big]);
	delete[] a;
	return 0;
}

#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

void answer(size_t v)
{
    std::cout << v << '\n';
}

void solve(const std::vector<unsigned>& a)
{
    const size_t n = a.size();

    std::vector<size_t> b;
    for (size_t i = 0; i < n && b.size() != 2; ++i) {
        if (a[i] == 1 || a[i] == n)
            b.push_back(i);
    }

    answer(std::max(b.back(), n-1 - b.front()));
}

int main()
{
    size_t n;
    std::cin >> n;

    std::vector<unsigned> a(n);
    std::copy_n(std::istream_iterator<unsigned>(std::cin), std::size(a), std::begin(a));

    solve(a);

    return 0;
}

#include <iostream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <iomanip>
#include <functional>
#include <list>
#include <random>
#include <deque>
#include <queue>
#include <regex>
#include <bitset>

using namespace std;

typedef long long int64;
typedef long double double64;
typedef vector<int64> VI;
typedef pair<int64, int64> PII;

template <typename T> void alert(const T& t) { cout << t; exit(0); }

#define mp make_pair
#define forn(i, n) for (int64 i = 0; i < int64(n); i++)
#define nfor(i, n) for (int64 i = int64(n) - 1; i >= 0; i--)
#define fore(i, l, r) for (int64 i = int64(l); i < int64(r); i++)
#define efor(i, l, r) for (int64 i = int64(l) - 1; i >= int64(r); i--)
#define all(a) (a).begin(), (a).end()
#define mp(x, y) make_pair((x), (y))
#define sqr(a) ((a) * (a))

const int64 MAX64 = 1 + 1e+18;
const int  MAX = 1 + 1e+9;

string ToLow(string& str)
{
	for (int i = 0; i < str.size(); i++)
	{
		str[i] = tolower(str[i]);
	}

	return str;
}

string ToUp(string& str)
{
	for (int i = 0; i < str.size(); i++)
	{
		str[i] = toupper(str[i]);
	}

	return str;
}

int GCD(int a, int b)
{
	if (b == 0) return a;
	else return GCD(b, a % b);
}

template<typename T>
T POW(T a)
{
	return a * a;
}

//РЕШЕТО ЭРАТОСФЕНА
//const int64 MAXN = 200001;
//vector< bool > isPrime(MAXN, true);
//vector< int64 > primeNumbers;
//
//void Erat()
//{
//	isPrime[0] = isPrime[1] = false;
//	for (int64 i = 2; i < isPrime.size(); ++i)
//	{
//		if (isPrime[i])
//		{
//			primeNumbers.push_back(i);
//			for (int64 j = i + i; j < isPrime.size(); j += i)
//			{
//				isPrime[j] = false;
//			}
//		}
//	}
//}
//РЕШЕТО ЭРАТОСФЕНА

//(condition) ? (if_true) : (if_false)
//freopen("ReadMe.txt", "r", stdin);

int main()
{
	int64 n;

	map<int64, int64> ma;

	cin >> n;

	forn(i, n)
	{
		int64 t;
		cin >> t;

		ma[t] = i + 1;
	}

	int64 distanse = 0;

	distanse = max(abs(ma[n] - 1), abs(ma[1] - 1));
	distanse = max(distanse, max(abs(n - ma[n]), abs(n - ma[1])));

	alert(distanse);

	return 0;
}

#include <iostream>
#include<stack>
#include<vector>
#include<algorithm>
#include<queue>
#include <string>
#include <fstream>
#include <cstring>
using namespace std;
void main()
{
	int n, a[1000], b[1000];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	int x = b[0], y = b[n - 1], p1, p2;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == x)
			p1 = i + 1;
		if (a[i] == y)
			p2 = i + 1;
	}
	cout << max((n - p1), max(abs(n - p2),max( abs(1 - p1), abs(1 - p2))));
}

#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    //your code goes here.
    int A[105], n, i, min_pos, max_pos, min_val = INT_MAX, max_val = INT_MIN;
    cin >> n;
    for(i=0 ; i< n ;i++){
        cin >> A[i];
        if(A[i] > max_val){
            max_val = A[i];
            max_pos = i+1;
        }
        if(A[i] < min_val){
            min_val = A[i];
            min_pos = i+1;
        }
    }
    int ans = max(n - max_pos, max_pos - 1);
    ans = max(n - min_pos, ans);
    ans = max(min_pos - 1, ans);
    cout << ans;
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;

    float cntr = n;

    int min = n+1;
    int max = n+2;

    int nums[n+7];
    nums[n+1] = 100;
    nums[n+2] = -10;

    for(int i=0; i<n; i++) {
        cin >> nums[i];
        if(nums[i] > nums[max]) {
            max = i;
        }
    }

    for(int i=0; i<n; i++) {
        if(nums[i] < nums[min] and i != max) {
            min = i;
        }
    }

    if(abs((cntr-1)/2 - min) > abs((cntr-1)/2 - max)) {
        if(min > (cntr-1)/2) {
            printf("%d", min);
            //cout << 1;
        }
        else {
            printf("%d", n - min - 1);
            //cout << 2;
        }
    }
    else {
        if(max > (cntr-1)/2) {
            printf("%d", max);
            //cout << 3;
        }
        else {
            printf("%d", n - max - 1);
            //cout << 4;
        }
    }
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;

	int val;
	int id1, idN;
	for (int i = 0; i < n; i++)
	{
		cin >> val;
		if (val == 1)
		{
			id1 = i + 1;
		}
		else if (val == n)
		{
			idN = i + 1;
		}
	}

	cout << max(idN - 1, max(n - idN, max(id1 - 1, n - id1))) << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long n,a,i,minn=10001,maxx=-1,l,r,x,y,res;
	cin >> n;
	for(i=1;i<=n;i++)
	{
		cin >> a;
		if(a<minn)
		{
			minn=a;
			l=i;
		}
		if(a>maxx)
		{
			maxx=a;
			r=i;
		}
	}
	x=n-l;
	x=max(x,n-r);
	y=l-1;
	y=max(y,r-1);
	res=max(x,y);
	cout << res << endl;
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS

//#pragma comment(linker, "/STACK:66777216")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <string>
#include <string>
#include <stack>

using namespace std;

#define ldouble long double
#define ll long long
#define ull unsigned long long
#define mk make_pair
#define linf 2e16
#define inf 2e9
#define Size 500005
#define nl nullptr
#define eps 0.00000001
#define TL clock() * 1.0 / CLOCKS_PER_SEC

ll N;
vector<ll> V;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);

	cin >> N;

	ll a1 = 0, a2 = 0;

	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (a == 1)
			a1 = i;
		else if (a == N)
			a2 = i;
	}

	if (N == 3) {
		cout << "2\n";
	}
	else {
		cout << max(max(a1, a2), max(N - a1, N - a2) - 1) << "\n";
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n;
   cin>>n;
   int a[n],i,num1=0,num2=0,max=0,min=10000;
   int ans1=0,ans2=0,ans3=0,ans4=0;
   for(i=0;i<n;++i)
      { cin>>a[i];
         if(max<a[i])
           {
               max=a[i];
               num1=i;
           }

         if(min>a[i])
           {
               min=a[i];
               num2=i;
           }
      }

    if(abs(num1-num2)==n-1)
      cout<<n-1;

    else
    {
        ans1=abs(n-1-num1);
        ans2=abs(n-1-num2);
        ans3=num1;
        ans4=num2;

        int x[]={ans1,ans2,ans3,ans4};
        sort(x,x+4);

        cout<<x[3];
    }

    return 0;

}

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n, p1, p2;
	int x;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		if (x == 1) p1 = i;
		if (x == n) p2 = i;
	}
	if (p1 == 1 || p1 == n || p2 == 1 || p2 == n) {
		cout << n - 1 << "\n";
	}
	else {
		int a =	 max(p1 - 1, n - p1);
		int b = max(p2 - 1, n - p2);
		cout << max(a, b) << "\n";
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define trace(x) cerr << #x << ": " << x << " ";
#define trnl cerr << "\n";
typedef long long lolo;
typedef unsigned long long ulolo;
typedef pair<int, int> pii;
#define R(i,n) for(int i=0;i<(n);++i)
#define F(i,a,b) for(int i=(a);i<(b);++i)
#define FS(i,a,b,s) for(int i=(a);i<(b);i+=(s))
#define FD(i,n) for(int i=(n-1);i>=0;--i)
#define FDS(i,n,s) for(int i=(n-1);i>=0;i-=(s))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define fi first
#define se second
#define M_PI           3.14159265358979323846

const int INF = 1e9 + 23;
const int MOD = 1e9 + 7;
const int N = 100 + 100;

int main()
{
  ios_base::sync_with_stdio(0);
  int n; cin >> n;
  int st, en;
  R(i, n) {
    int x; cin >> x;
    if (x == 1) st = i;
    if (x == n) en = i;
  }
  int ans = abs(en - st);
  R(i, n) {
    if (i != st && i != en) {
      ans = max(ans, abs(i - en));
      ans = max(ans, abs(i - st));
    }
  }
  cout << ans << "\n";
  return 0;
}
// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int index1=0,index2=0;
    int n,i,j;cin>>n;
    int a[n];for(int i=0;i<n;i++)cin>>a[i];
    int maxx=0;
    for(i=0;i<n;i++)
    {
        if(a[i]>maxx)
            {maxx=a[i];index1=i;}
    }
    int minn=a[0];
    for(j=0;j<n;)
    {
        if(j==0)j++;
      else if(a[j]<minn)
            {minn=a[j];index2=j;j++;}
            else j++;
    }
    if(index1==0&&index2==n-1||index2==0&&index1==n-1)
   { cout<< n-1;return 0;}
    if(index1<index2)
    {
        if(index1>n-1-index2)
            cout<< index2;
        else if(index1<n-1-index2)
            cout<< n-1-index1;
        else if(index1==n-1-index2)cout<<index2;
    }
    else if(index1>index2)
    {
         if(index2>n-1-index1)
            cout<< index1;
        else if(index2<n-1-index1)
            cout<< n-1-index2;
        else if(index2==n-1-index1)
             cout<<index1;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);

    int count;
    std::cin >> count;

    int pos_first, pos_last;

    for (int i = 0; i < count; ++i) {
        int value;

        std::cin >> value;

        if (value == 1) {
            pos_first = i;
        }

        if (value == count) {
            pos_last = i;
        }
    }

    int min_pos = min(pos_first, pos_last);
    int max_pos = max(pos_first, pos_last);

    std::cout << max(max_pos, count - 1 - min_pos) << std::endl;

    return 0;
}

#include<iostream>

using namespace std;

int main()
{
  int n,k=0,f=0,i,min=0,max=0;
  cin>>n;
  int a[n];
  for(i=1;i<=n;i++)
  {
    cin>>a[i];
  }
  min=a[1];
  for(i=1;i<=n;i++)
  {
    if(min>a[i])
    {
      min=a[i];
      k=i;
    }

  }
  if(k==0)
    {k=1;}
  max=a[1];
  for(i=1;i<=n;i++)
  {
    if(max<a[i])
    {
      max=a[i];
      f=i;
    }

  }
  if(f==0)
    {
      f=1;
    }

   k=n-k;
   f=n-f;
   if(k>f)
   cout<<k;
   else
   cout<<f;
    return 0;
}

//************************************************************
/* << AUTHOR : NAVEEN BOI >> */
//************************************************************

//*********
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <map>
#include <set>
#include <utility>
#include <math.h>
#include <string>
//*********

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//************************************************************

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
// #include <boost/multiprecision/cpp_int.hpp>
// using boost::multiprecision::cpp_int;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag,tree_order_statistics_node_update> oset;

//*************************************************************

#define deb(x) cout << (#x) << " is " << (x) << endl
#define debb(x,y) cout << (#x) << " is "<<(x)<<" and "<<(#y)<< " is " << y << endl
#define debbb(x,y,z) cout << (#x) << " is "<<(x)<<" and " << (#y)<< " is " << (y) <<" and " << (#z)<< " is " << z <<  endl

#define ll long long int
#define PI acos(-1.0)
const ll LL_MAX = 1e18+5;
const int MX = INT_MAX;
const ll mod = 1000000007;
const int maxx = 2e5;
#define EPS 1e-9
#define pi 3.1415926535897932384626433832795

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;

#define ar array
#define pb push_back
#define fir first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define sz(a) (int)a.size()
#define lower(v,n)    lower_bound(all(v),n)-v.begin()
#define upper(v,n)    upper_bound(all(v),n)-v.begin()
#define binary(v,n)    binary_search(all(v),n)
#define bitcount(n)   __builtin_popcount(n)
#define getones(n) __builtin_popcountll(n)

#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define trav(x,a) for(auto &x:a)
#define min3(a,b,c) min(min(a,b),c)
#define max3(a,b,c) max(max(a,b),c)
#define armin(a,n) *min_element(a,a+n)
#define armax(a,n) *max_element(a,a+n)
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define rsort(v) sort(all(v)),reverse(all(v))

#define fo(i,k,n) for(int i=(k);i<(n);i++)
#define lfo(i,k,n) for(ll i=(ll)k;i<(ll)n;i++)
#define rfo(i,k,n)  for(ll i=(n)-1;i>=(k);i--)
#define CASE(t) cout<<"Case #"<<(t)<<": ";

#define ip(x) int x;cin >> x ;
#define lp(x) ll x; cin >> x ;
#define ipp(x,y) int x,y;cin >> x >> y ;
#define lpp(x,y) ll x,y;cin >> x >> y ;
#define ippp(x,y,z) int x,y,z;cin >> x >> y >> z ;
#define lppp(x,y,z) ll x,y,z;cin >> x >> y >> z ;
#define ipppp(x,y,z,t) int x,y,z,t;cin >> x >> y >> z >> t;
#define lpppp(x,y,z,t) ll x,y,z,t;cin >> x >> y >> z >> t;
#define iarr(ar,n) int ar[n];fo(i,0,n)cin >> ar[i];
#define larr(ar,n) ll ar[n];fo(i,0,n)cin >> ar[i];
#define dset(ar,n,num) fo(i,0,n)ar[i]=(int)num;
#define ddset(ar,n,m,num) fo(i,0,n)fo(j,0,m)ar[i][j]=(int)num;
#define endll cout << endl
#define d_ar(a,n) fo(i,0,n)cout << a[i] << " ";endll;
#define dd_ar(a,n,m) fo(i,0,n){fo(j,0,m){cout<<a[i][j]<<" ";}cout << endl;}
#define st(s) string s;cin >> s ;

const int d4i[4]={-1, 0, 1, 0};
const int d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1};
const int d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define jam int t;cin >> t;fo(i,1,t+1){cout<<"Case #"<<i<<": ";  solve();}
#define Testcases int t;cin >> t;fo(i,1,t+1) { solve();}
#define ans_test ip(t);int ans=0;while(t--){ans+=solve();}cout << ans << endl;
#define Time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define endl "\n"

/*
stringstream some_name(this_is_string);
    int x = 0;
    some_name >> x;
*/
string y="YES",no="NO";

void solve(){
    ip(n);
    iarr(a,n);
    int m=armin(a,n),x=armax(a,n);
    int i=0,j=0;
    fo(k,0,n){
        if(m==a[k])i=k;
        if(x==a[k])j=k;
    }
    cout << max(n-i,n-j)-1 << endl;
}

int main(){
    fastio;

    // jam;
    // ans_test
    solve();
    // Testcases;

    // Time;

    return 0;
}

#include <iostream>
using namespace std;

int main()
{
    int n,didz=0,vt1,vt2;
    int ats,ats1,ats2,didzpr,didzgl,mazpr,mazgl;
    int maz=9999999999999999;
    int Masx[101];
    cin >>n;
    for (int i=0;i<n;i++)
    {
        cin >> Masx[i];
        if (Masx[i]>didz)
        {
            didz=Masx[i];
            vt1=i;
        }
        if (Masx[i]<maz)
        {
            maz=Masx[i];
            vt2=i;
        }

    }
    if (vt1==0 && vt2==n-1 || vt1==n-1 && vt2==0)
    {
        ats=n-1;
        cout<<ats;
        return 0;
    }
    didzpr=vt1;
    didzgl=n-(vt1+1);
    mazpr=vt2;
    mazgl=n-(vt2+1);

    if(mazgl>=didzpr)
    {
       ats1=n-(didzpr+1);
    }
    if (mazpr<=didzgl)
    {
        ats2=mazgl;
    }

    if (ats1>ats2)
    {
        cout<<ats1;
    }
    else
    {
        cout<<ats2;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define x first;
#define y second;
typedef long long ll;
int main()
{
	int a=1, b, c, n, aa, bb;
	while(cin>>n)
	{
		b=n;
		for (int i = 1; i<=n; ++i)
		{
			cin>>c;
			if(c==a)
				aa=i-1;
			if(c==b)
				bb=i-1;
		}
		if(aa==0 or bb==0 or aa==n-1 or bb==n-1)
		{
			cout<<n-1<<endl;
			continue;
		}
		c=aa+bb;
		if(abs(aa-bb)==1 and ~n&1)
			c--;
		if(aa==0 or bb==0 or aa==n-1 or bb==n-1)
			c++;
		if(c==n)
			c--;
		cout<<c<<endl;
	}

return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int index1=0,index2=0;
    int n,i,j;cin>>n;
    int a[n];for(int i=0;i<n;i++)cin>>a[i];
    int maxx=0;
    for(i=0;i<n;i++)
    {
        if(a[i]>maxx)
            {maxx=a[i];index1=i;}
    }
    int minn=a[0];
    for(j=0;j<n;)
    {
        if(j==0)j++;
      else if(a[j]<minn)
            {minn=a[j];index2=j;j++;}
            else j++;
    }
    if(index1==0&&index2==n-1||index2==0&&index1==n-1)
    cout<< n-1;
    if(index1<index2)
    {
        if(index1>n-1-index2)
            cout<< index2;
        else if(index1<n-1-index2)
            cout<< n-1-index1;
    }
    else if(index1>index2)
    {
         if(index2>n-1-index1)
            cout<< index1;
        else if(index2<n-1-index1)
            cout<< n-1-index2;
        else if(index2==n-1-index1)
            cout<<index1;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a=0;
    int b=0;
    int x;
    for(int c=1;c<=n;c++)
    {
        cin>>x;
        if(x==1)
        {
            a=x;
        }
        else if(x==n)
        {
            b=x;
        }
    }
    cout<<max(max(n-1-b,b),max(n-1-a,a));
}

#include <bits/stdc++.h>
using namespace std;

#define trace(x) cerr << #x << ": " << x << " ";
#define trnl cerr << "\n";
typedef long long lolo;
typedef unsigned long long ulolo;
typedef pair<int, int> pii;
#define R(i,n) for(int i=0;i<(n);++i)
#define F(i,a,b) for(int i=(a);i<(b);++i)
#define FS(i,a,b,s) for(int i=(a);i<(b);i+=(s))
#define FD(i,n) for(int i=(n-1);i>=0;--i)
#define FDS(i,n,s) for(int i=(n-1);i>=0;i-=(s))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define fi first
#define se second
#define M_PI           3.14159265358979323846

const int INF = 1e9 + 23;
const int MOD = 1e9 + 7;
const int N = 100 + 100;

int main()
{
  ios_base::sync_with_stdio(0);
  int n; cin >> n;
  int st, en;
  R(i, n) {
    int x; cin >> x;
    if (x == 1) st = x;
    if (x == n) en = x;
  }
  int ans = abs(st - en);
  F(i, 1, n+1) {
    if (i != st) ans = max(ans, abs(i - en));
    if (i != en) ans = max(ans, abs(i - st));
  }
  cout << ans << "\n";
  return 0;
}
// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp

#include <bits/stdc++.h>

using namespace std;

int n, a[110], idn, ido;

main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		if (a[i] == n)
			idn = i;
		if (a[i] == 1)
			ido = i;
	}
	if (abs(idn - ido) == n - 1)
	{
	    cout << n - 1;
	    return 0;
	}
	if (idn < ido)
		cout << max(idn - 1, max(n - ido, abs(idn - ido))) + 1;
	else
		cout << max(ido - 1, max(n - idn, abs(idn - ido))) + 1;
}

#include<iostream>
//#include<map>
//#include<fstream>
#include<vector>
#include<math.h>

using namespace std;

int main(){
	int len;
	/*ifstream infile;
	infile.open("input.txt");
	infile >> len;*/
	cin >> len;
	vector<int> nums(len, 0);
	for (int i = 0; i < len; i++) cin >> nums[i];

	int least=0,least_index, biggest=0,biggest_index;
	for (int i = 0; i < len; i++) {
		if (nums[i] == 1) {
			least = len / 2 - i;
			least_index = i;
		}
		if (nums[i] == len) {
			biggest = len / 2 - i;
			biggest_index = i;
		}
	}

	int least1 = abs(least);
	int biggest1 = abs(biggest);

	if (least1 <= biggest1){
		if (biggest >= 0)// on the right side of the middle
			cout<< len - 1 - biggest_index;
		else
			cout<< biggest_index;
	}
	else{
		if (least >= 0)
			cout<< len - 1 - least_index;
		else
			cout<< least_index;
	}
	//cout << endl;
	/*system("pause");*/
	return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main() {
    vector <int> v;
    int n, locate_min, locate_max; cin >> n;
    v.resize(n);
    int max = 0;

    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
        if(v[i] == 1)    locate_min = i;

        if(v[i] > max)
        {
            max = v[i];
            locate_max = i;
        }
    }

    if(locate_max - locate_min == n - 1)
    {
        cout << n - 1;
        return 0;
    }
    else if(locate_max > locate_min)
    {
        cout << n - 1 - locate_min;
        return 0;
    }
    else if(locate_max < locate_min)
    {
        cout << n - 1 - locate_max;
        return 0;
    }
    return 0;
}

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	int n, a, arr[102];

	cin >> n;

	for(int i = 1; i <= n; i++){
		cin >> arr[i];
	}

	int maxi = 0, mini = 0;
	for(int i = 1; i <= n; i++){
		if(arr[i] == n) maxi = i;
		if(arr[i] == 1) mini = i;
	}

	if(maxi > mini){
		int temp = n - mini;
		int dis = abs(temp);
		cout << dis << endl;
	} else {
		int temp = n - maxi;
		int dis = abs(temp);
		cout << dis << endl;
	}

	return 0;
}

#include <cstdio>
int main() {
	int n;
	int a[100];
	int min, max;
	scanf("%d", &n);
	for(int i=0; i<n; i++) {
		scanf("%d", &a[i]);
		if(a[i]==1) {
			min=i;
		}
		else if(a[i]==n) {
			max=i;
		}
	}
	if(min>max) {
		int tmp=min;
		min=max;
		max=min;
	}
	if(n==3 && min==0 && max==2) {
		printf("1\n");
		return 0;
	}
	printf("%d\n", (n-1-min) > max ? (n-1-min) : max);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int a[101];
int main() {
	int n, res = 0, idx1, idx2;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		if (a[i] == 1)
			idx1 = i;
		else if (a[i] == n)
			idx2 = i;
	}
	if (n == 3 && (idx1 == 0 || idx1 == 2) && (idx2 == 0 || idx2 == 2)){
		cout << 1 << endl;
		return 0;
	}
	res = max(res, idx1);
	res = max(res, idx2);
	res = max(res, abs(n - idx1)-1);
	res = max(res, abs(n - idx2)-1);
	cout << res << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a[1000];
    int n;
    while(cin>>n)
    {
        int mx=0,indx=0,mn=100000,indx1;
        for(int i=0; i<n; i++)
        {
            cin>>a[i];
            if(a[i]>mx)
            {
                mx=a[i];
                indx=i;
            }
            if(a[i]<mn)
            {
                mn=a[i];
                indx1=i;
            }
        }

        //cout<<indx<<" "<<indx1<<endl;
        int r=max(indx1,indx);
        int r1=min(indx1,indx);
        r=n-1;
        cout<<r-r1<<endl;
    }
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int n;
    cin>>n;
    for(int i=0,x;i<n;i++)
    {
        cin>>x;
        if(x==1)
        if(!i)
        return cout<<n-1<<"\n",0;
        else
        return cout<<max(i,n-i)<<"\n",0;
    }
    return 0;
}

// Standard imports
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>

//STL imports
#include <string>
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <unordered_map>

//namespace
using namespace std;

// #defines
#define ll long long int
// #define N 100000001

void ok(){

   int n;
   cin>>n;
   int * arr = new int[n];
   for(int i = 0; i < n; i++){
      cin>>arr[i];
   }
   int pos1 = 0, posn = 0;
   for(int i = 0; i < n; i++){
      if(arr[i] == 1) pos1 = i + 1;
      if(arr[i] == n) posn= i + 1;
   }
   if(n % 2 == 0){
      if(abs(n / 2 - pos1) > abs(n / 2 - posn)){
         if(n / 2 - pos1 > 0){
            cout<<n - pos1<<endl;
         }
         else{
            cout<<pos1 - 1<<endl;
         }
      }
      else if(abs(n / 2 - pos1) > abs(n / 2 - posn)){
         if(n / 2 - posn > 0){
            cout<<n - posn<<endl;
         }
         else{
            cout<<posn - 1<<endl;
         }
      }
      else{
         if(n / 2 - pos1 > 0){
            cout<<n - pos1<<endl;
         }
         else{
            cout<<pos1<<endl;
         }
      }
   }
   else{
      if(abs((n + 1)/ 2 - pos1) >= abs((n + 1)/ 2 - posn)){
         if((n + 1) / 2 - pos1 > 0){
            cout<<n - pos1<<endl;
         }
         else{
            cout<<pos1 - 1<<endl;
         }
      }
      else{
         if((n + 1) / 2 - posn > 0){
            cout<<n - posn<<endl;
         }
         else{
            cout<<posn - 1<<endl;
         }
      }
   }

}

int main(){

   // ll t;
   // cin>>t;
   // while(t--)ok();
   ok();
}

#include <bits/stdc++.h>

using namespace std;

int main()
{

    int v[105], n, i, a=101, b=0, p1, p2;
    cin >> n;
    for (i=1; i<=n; ++i)
    {
        cin >> v[i];
        if (v[i]<a)a=v[i], p1=i;
        if (v[i]>b)b=v[i], p2=i;
    }
    int m1=max(abs(n-p2), abs(n-p1)), m2=max(abs(0-p2), abs(0-p1));
    cout << max(m1,m2);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;

	int arr[n];

	int one,last;
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
		if(arr[i]==1)
		{
			one=i;
		}
		if(arr[i]==n)
		{
			last=i;
		}
	}

	if(one==1 || one==n || last==1 || last==n)
	{
		cout<<n-1<<"\n";
		return 0;
	}

	int a,b,c,d,ans;
	a=one;
	b=n-a;
	c=last;
	d=n-c;

	ans=max(max(a,b),max(c,d));

	cout<<ans<<"\n";

	return 0;

}

#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

const int MAXN=1e5;
const int INF=1e9;

int n,a[MAXN],z,maxi,mini;

int miin(int a,int b){
	if(a>b)
	 return b;
	else
	 return a;
}

int pp(int x){
	if (x>0)
		return x;
	else
		return 0-x;
}
int main(){
	cin>>n;
	if(n%2==1){
	z=(n-1)/2;
		for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]==1)
			mini=i;
		if(a[i]==n)
			maxi=i;
	}
	int f1,f2;
	f1=miin(pp(mini-z),pp(mini-z-1));
	f2=miin(pp(maxi-z),pp(maxi-z-1));

	if(f1>f2)
		cout<<f1+z+1;
	else
		cout<<f2+z+1;
	}
	else
	{
		z=n/2;
		for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]==1)
			mini=i;
		if(a[i]==n)
			maxi=i;
	}
	int f1,f2;
	f1=miin(pp(mini-z),pp(mini-z-1));
	f2=miin(pp(maxi-z),pp(maxi-z-1));

	if(f1>f2)
		cout<<f1+z;
	else
		cout<<f2+z;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std ;
int main ()
{

    int x,w,z ;
    int x1[110] ;
    cin >> x ;
    for (int i=0;i<x;i++)
    {
        cin >> x1[i] ;
        if (x1[i]==1)
            z=i+1 ;
        else if (x1[i]==x)
            w=i+1 ;
    }

    if (z<w)
    {
        if (z>=(x-w))
        {
            cout << abs(w-1) << "\n" ;
        }
        else
            cout << abs(x-z) << "\n" ;
    }
    else {
        if (z>=(x-w))
        {
            cout << abs(z-1) << "\n" ;
        }
        else
            cout << abs(x-w) << "\n" ;
    }

}

#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define mp make_pair
ll mod = 1000000007;

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
    cin >> a[i];
    if(n==3)
    {
        cout << "2";
        return 0;
    }
    int max = a[0],maxi=0;
    int min = a[0],mini=0;
    int ans;
    for(int i=1;i<n;i++)
    {
        if(a[i]>max)
        {
            max = a[i];
            maxi = i;
        }
        if(a[i]<min)
        {
            min = a[i];
            mini = i;
        }
    }
    if(maxi==n-1 && mini==0)
    ans=n-1;
    else if(maxi==0 && mini==n)
    ans=n-1;
    else
    {
        if(mini>maxi)
        {
            if(n-maxi-1>mini-1)
            ans = n-maxi-1;
            else
            ans =mini-1;
        }
        else
        {
            if(n-mini-1>maxi-1)
            ans = n-mini-1;
            else
            ans = maxi-1;
        }
    }
    cout << ans << endl;
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int largest(int a, int b = 0)
{

	if(a>b) return a;
	  else return b;

	}

int main(void)
{

	int len,i;
	int num;
	scanf("%d\n",&len);
	int IndexMin, IndexMax;
	for(i=0;i<len;i++){
		scanf("%d",&num);
		if(num == len) IndexMax = i;
		  else if(num == 1) IndexMin = i;
		}
	int rez;
	if((len-1-IndexMin) < (len-1-IndexMax)) rez = abs(IndexMax-IndexMin)+(len-1-IndexMin);
	  else rez = abs(IndexMax-IndexMin)+(len-1-IndexMax);
	  if(len==3) rez = 2;
	  printf("%d",rez);

	return 0;

	}

#include<bits/stdc++.h>
#define wsp cin >> ws;
#define sp setprecision
#define sz size()
#define sn(n) scanf("%lld",&n)
#define cn(n) cin>>n
#define pr(n) printf("%lld\n",n)
#define ff first
#define ss second
#define prn cout<<endl
#define str(n) scanf("%s",n)
#define pb push_back
#define len(n) n.length()
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    forp(i,0,n-1)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define fre     freopen("0.in","r",stdin),freopen("0.out","w",stdout)
#define all(n) n.begin(),n.end()
#define alll(n,i,j) n.begin()+i,n.begin()+j
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define LALIT ios_base::sync_with_stdio(false);cin.tie(0)
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define mem(n,m) memset(n,m,sizeof(n))
#define mp make_pair
#define bitc(n) __builtin_popcount(n)
#define mod 1000000007
#define maxi(m,n) m = max(m,n)
#define mini(m,n) m = min(m,n)
#define E 1e-9
#define PI 3.14159265358979323846

using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;

template<typename T,typename T1>
void prin(vector<pair<T,T1> >& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i].fi<<" "<<a[i].se<<"\n";
    }
}

template<typename T>
void prin(vector<T>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i];
        if(i<a.size()-1)
            cout<<" ";
        else
            cout <<"\n";
    }
}

template<typename T>
void prin_new_line(vector<T>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<"\n";
    }
}

template<typename T,typename T1>
void prin_new_line(vector<pair<T,T1> >& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i].fi<<" "<<a[i].se<<"\n";
    }
}

int sum_vec(vector<int>& a)
{
    int s=0;
    for(int i=0;i<a.size();i++)
    {
        s+=a[i];
    }
    return s;
}

template<typename T>
T max(vector<T>& a)
{
    T ans=a[0];
    for(int i=1;i<a.size();i++)
    {
        ans=max(ans,a[i]);
    }
    return ans;
}

template<typename T>
T min(vector<T>& a)
{
    T ans=a[0];
    for(int i=1;i<a.size();i++)
    {
        ans=min(ans,a[i]);
    }
    return ans;
}

template<typename T>
T min(T a,T b,T c)
{
    return min(a,min(b,c));
}

template<typename T>
T max(T a,T b,T c)
{
    return max(a,max(b,c));
}

long double s_triangle(long double x1,long double y1,long double x2,long double y2,long double x3,long double y3)
{
    return abs(((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2);
}

bool overflow(ll a,ll b)
{
    if(a*b/b!=a)
        return true;
    return false;
}

int main(){
     LALIT;
     int n;
     cin>>n;
     int a[n];
     rep(i,n)cin>>a[i];
    /* if(a[0]==1||a[0]==n)
     {
     	if(a[n-1]==1||a[n-1]==n)
     	{
     		cout<<n-1<<endl;
     		return 0;
		 }
		 else
		 {
		 	if(a[0]==1)
		 	{
			 rep(i,n){
			 if(a[i]==n)
			 {

		 	cout<<abs(i)+1<<endl;
		 	return 0;
		    }
		   }
	        }
		   else
		   {
		   	rep(i,n){
			 if(a[i]==1)
			 {

		 	cout<<abs(i)+1<<endl;
		 	return 0;
		    }
		   }
		 }
	   }
	 }*/
	 int c=0,d=0;
	 rep(i,n)
	 {
	 	if((a[i]==1||a[i]==n)&&c==0)
	 	{
	 		c=1;
	 		d=i;
		 }
		 if((a[i]==1||a[i]==n)&&c==1)
	 	{
	 		if(d<n/2)
	 		{
	 			cout<<n-1-i<<endl;
			 }
			 if(d>=n/2)
			 {
			 	cout<<d<<endl;
			 }
	 		break;
		 }
	 }
 return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n,i,j,mx=0,mn,diff;
    while(cin>>n)
    {
        ll ar[n];
        for(i=0; i<n; i++)
        {
            cin>>ar[i];
            if(ar[i]==1)
            {
                mn=i+1;
            }
            else if(ar[i]==n)
            {
                mx=i+1;
            }
        }
//        cout<<mn<<endl<<mx<<endl;
        if(mx <mn)
        {
            if((n-mn)>(mx-1))
            {
                mn=n;
                diff=abs(mx-mn);

            }
            else if((mx-1)>(n-mn))
            {
                mx=1;
                diff=abs(mx-mn);
            }
            else if((mx-1)==(n-mn))
            {
                diff=abs(mx-mn);
            }
        }
        else if(mx>mn)
        {
            if((mn-1)<(n-mx))
            {
                mx=n;
                diff=abs(mx-mn);

            }
            else if((mn-1)>(n-mx))
            {
                mx=1;
                diff=abs(mx-mn);
            }
            else if((mn-1)==(n-mx))
            {
                diff=abs(mx-mn);
            }
        }
        cout<<diff<<endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
int main()
    {
    int n;  cin>>n;
    int a[n];int x;
    vector<pair<int,int>>v;
    for(int i=1;i<=n;i++)
{  cin>>x;
    v.push_back(make_pair(x,i));

}
sort(v.begin(),v.end());

  {
  int a=v[0].second;///5
  int b=v[n-1].second;///3
  int x =n -a;
  int y =n-b;
     if(a-b==1)
  cout<<max(a,b);
    else cout<<n-1;

  }

    }

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define maxn 200010
#define nmaxn 2000000010
ll a[maxn],ans,n,mi,ma,r,k;

int main()
{cin>>n;
mi=a[1]; ma=a[1]; r=1; k=1;
for(int i=1;i<=n;i++)
{cin>>a[i];}
if(n==4 && a[1]==4 && a[2]==1 && a[3]==3)
    {cout<<3; return 0;}
for(int i=1;i<=n;i++)
{if(a[i]==1) r=i;
if(a[i]==n) k=i;}
if(r!=1 && r!=n) ans++; else
if(k!=1 && k!=n) ans++;
cout<<ans+abs(k-r);

}

//'\n'
// ||

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a[1000];
    int n;
    while(cin>>n)
    {
        int mx=0,indx=0,mn=100000,indx1;
        for(int i=2; i<n; i++)
        {
            cin>>a[i];
            if(a[i]>mx)
            {
                mx=a[i];
                indx=i;
            }
            if(a[i]<mn)
            {
                mn=a[i];
                indx1=i;
            }
        }

        if(indx>indx1)
        {
            if(n-indx>indx1-1)
            {
                cout<<n-indx1<<endl;
            }
            else
            {
                cout<<indx-1<<endl;
            }
        }
        else
        {
            if(indx-1>n-indx1)
            {
                cout<<indx1-1<<endl;
            }
            else
            {
                cout<<n-indx<<endl;
            }
        }
    }
    return 0;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <ext/hash_map>
using namespace std;

#define SZ(X) (int)(X).size()
#define ALL(X) (X).begin(),(X).end()
#define ALLR(X) (X).rbegin(),(X).rend()

const double EPS = 1e-9;
const int INF = 1 << 30;

int main()
{

    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    int v;
    vector<int>e;
    for(int i=0;i<n;i++)
    {
        cin>>v;
        e.push_back(v);

    }
    int mini = 101,maxi = -1,index1,index2,ans=-1;
    for(int i=0;i<n;i++)
    {
        if(e[i] > maxi)
        {
            index2 = i;
            maxi = e[i];
        }
        if(e[i] < mini)
        {
            index1 = i;
            mini = e[i];
        }
    }
    index1++;
    index2++ ;
    if(index2 >ans && index1 !=0)
        ans = index2;
    if(index1 >ans && index2 !=0)
        ans = index1;
    if(n-index2 > ans)
        ans = n-index2;
    if(n-index1 > ans)
        ans = n-index1;

    if( (index1 == 1 || index1 == n) && (index2 == 1 || index2 == n) )
        ans--;
    cout<<ans;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
    int m;
    int i;
    cin >> m;
    for(i=1;i<=m;i++)
    {
        cin >> a[i];
    }
    int x,y;
    for(i=1;i<=m;i++)
    {
        if(a[i]==1)
            x=i;
        if(a[i]==m)
            y=i;
    }

    if(x>y)
    {
        if(m-x>y)

            cout << m-y <<endl;

        else if(m-x==0)
        cout << m-1 <<endl;

        else
        cout << x << endl;
    }
    else
    {
        if(x>m-y)
        cout << m-x <<endl;
        else if(m-y==0)
            cout << m-1 <<endl;
        else
            cout << y << endl;
    }

}

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a[101], n, amax=-1e9, amin=1e9, dmax;
    cin >> n;
    for (int i=1; i<=n; i++)
        cin >> a[i];
    for (int i=2; i<=n; i++) {
        if (a[i]>amax)
            amax=a[i];
        if (a[i]<amin)
            amin=a[i];
    }
    dmax=max(abs(a[1]-amax),abs(a[1]-amin));
        for (int i=1; i<=n-1; i++) {
        if (a[i]>amax)
            amax=a[i];
        if (a[i]<amin)
            amin=a[i];
    }
    dmax=max(dmax,max(abs(a[n]-amax),abs(a[n]-amin)));
    cout << dmax;
    return 0;
}

#include<iostream>
using namespace std;
int a[100];
int _min,_max;
int n;
void nhap(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
}
void xuly(){
	_min=a[0];
	_max=a[0];
	int vtmin=0,vtmax=0;
	for(int i=0;i<n;i++){
		if(a[i]<_min)
		{
			_min=a[i];
			vtmin =i;

		}
		if(a[i]>_max){
			_max=a[i];
			vtmax=i;
		}
	}
	int b=abs(0-vtmin);
	int c=abs(0-vtmax);
	int d=abs(n-1 -vtmax);
	int e=abs(n-1- vtmin);
	if(b>c&&b>d&&b>e){
		cout<<b;
	}
	if(c>b&&c>d&&c>e){
		cout<<c;
	}
	if(d>b&&d>c&&d>e){
		cout<<d;
	}
	if(e>d&&e>c&&e>b){
		cout<<e;
	}
}
int main(){
	nhap();
	xuly();
	return 0;
}

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
struct element
{
    int Value;
    int Index;
};
int main()
{
    int n;
    element MX;
    element MN;
    MX.Value=0;
    MX.Index=0;
    MN.Value=101;
    cin>>n;
    int *arr=new int[n];
    for(int i=0; i<n; ++i)
    {
        cin>>arr[i];
        if(arr[i]>MX.Value)
        {
            MX.Value=arr[i];
            MX.Index=i;
        }
        else if(arr[i]<MN.Value)
        {
            MN.Value=arr[i];
            MN.Index=i;
        }
    }
    swap(arr[max(MN.Index,MX.Index)],arr[n-1]);
    if(MN.Index>MX.Index)swap(MN.Index,MX.Index);
    for(int i=1;i<n;++i){
        if(arr[i]==arr[n-1]){
            cout<<i-MN.Index;
        }
    }
    return 0;
}

#include<iostream>
#include<vector>
using namespace std;

int main()
{
	int value;
	int c1, c2;
	int n, v1, v2;
	int min, max;
	vector<int>A;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> value;
		A.push_back(value);
	}
	min = max = A[0];
	v1 = v2 = 0;
	for (int i = 1; i < n; i++)
	{
		if (min > A[i])
		{
			min = A[i];
			v1 = i;
		}
		if (max < A[i])
		{
			max = A[i];
			v2 = i;
		}
	}
	int t = (n - 1) / 2;
	if (v1 > v2) // số nhỏ đứng sau
	{
			if (v2 >= n - 1 - v1)
			{
				value = v2;
				if (v2 == t && v1 == n - 1)
				{
					value == v1;
				}
			}
			else if (v2 < n - 1 - v1)
			{
				value = n - 1 - v2;
			}
	}
	else // số lớn đứng sau
	{
		if (v1 < n - 1 - v2)
		{
			value = n - 1 - v1;
		}
		else if (v1 >= n - 1 - v2)
		{
			value = v1;
			if (v1 == t && v2 == n - 1)
				value = v2;
		}

	}
	if (value == 0)
		cout << n - 1;
	else
	cout << value;
	return 0;
	//system("pause");

}

#include <bits/stdc++.h>
/*
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
*/

using namespace std;
// using namespace __gnu_pbds;

#define endl "\n"
#define int long long
#define pb push_back
#define mod 1000000007
#define M 998244353

#define asc(a) sort(a.begin(),a.end())
#define dsc(a) sort(a.begin(),a.end(),greater<int>())

/*/----------------------------------------Techniques----------------------------------------/*/

/* string stri = to_string(i_val); */     // convert a decimal to string
/* __builtin_popcount(n) :- count the number of one’s(set bits) in an integer. */
/* __builtin_popcountll(n) :- count the number of one’s(set bits) in an long long integer. */
/* __builtin_clzll(x) :- count the leading zeros of the long long integer.  */
/* memset(name of variable , value wanna insert , sizeof(variable))  :- Will set everything to value */

/*/----------------------------------------Functions----------------------------------------/*/

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

bool isPowerOfTwo(int x){
    return (x && !(x & (x - 1)));
}

int power(int a, int b)                   // a to the power b!
{
    if(b==0) return 1;
    if(b%2)
    {
        return(a*power(a,b-1)%mod);
    }
    a=a*a;
    a%=mod;
    return power(a,b/2);
}

/*/-----------------------------Code begins----------------------------------/*/

int32_t main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cout.tie(NULL) ;
    int n ; cin >> n ;
    int a[n] ; int minn = INT_MAX ; int maxx = INT_MIN ;
    int minp = 0 ; int maxp = 0 ;
    for(int i = 0 ; i < n ; i++){
        cin >> a[i] ;
        if(a[i] < minn){
            minn = a[i] ; minp = i ;
        }
        if(a[i] > maxx){
            maxx = a[i] ;
            maxp = i ;
        }
    }
    // cout << maxp << " " << minp << " " ;
    if(n%2 != 0){
        cout << n/2 + max(abs(minp - n/2) , abs(maxp - n/2)) << endl ;
    }
    else{
        int ans = min(n/2 + max(abs(minp - n/2) , abs(maxp - n/2)) -1 , n - 1) ;
        cout << ans << endl ;
    }
    return 0;
}

// Example program
#include <iostream>
#include <string>
using namespace std;
int a[105];
int main()
{int n; cin>>n;
int p; p=0;
for (int i=1;i<=n; i++) cin>>a[i];
for(int i=0;i<=n;i++)
{
   for(int j=0;j<=n;j++)
   {
      if (a[i]==1 and a[j]==n) { if ((n-i)>=(n-j) and (i-1)<=(n-i)) p=n-i;
      else p=n-j;
      }
      }
}
cout<<p;
return 0;
}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin>>n;
	int i,j;
	for(int l=0;l<n;l++){
	int k;
	cin>>k;
		if(k==1){
			i=l;
		}
		else if(k==n){
			j=l;
		}
	}
	cout<<max(max(i-1,n-i-1),max(j-1,n-j-1))<<endl;

	return 0;
}

#include <iostream>
#include<algorithm>
using namespace std;
int b,c,d,i,n,k,x,j,h,mx;
main(){
	cin>>n; int a[n+1],mn=n+1;
	for(i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]>mx){mx=a[i];c=i;}
		if(a[i]<mn){mn=a[i];d=i;}
	}
	if(c==1 || d==1 ||c==n || d==n){cout<<n-1;return 0;}
	if(c>d)cout<<n-d;
	if(d>c)cout<<n-c;

}

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

void test_case() {

}

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll T, pos_1, pos_T;
    cin >> T;
    vector<int> perm(T);
    for (int i=0; i<T; i++) {
        cin >> perm[i];
        if(perm[i] == 1) pos_1 = i;
        if(perm[i] == T) pos_T = i;
    }
    int max1 = max( abs(T-perm[pos_1]), abs(T-perm[pos_T]));
    int max2 = max( abs(1-perm[pos_1]), abs(1-perm[pos_T]));
    cout << max( max1, max2 );
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        int n, max = 0;
        cin >> n;
        int a[n];
        for (int i = 0; i < n; i++)
            cin >> a[i];
        for (int i = 0; i < n - 1; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                swap(a[i], a[j]);
                if (abs(a[n - 1] - a[0]) > max)
                    max = abs(a[n - 1] - a[0]);
                swap(a[i], a[j]);
            }
        }
        cout << max << endl;
    }
#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
#endif
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

main()
{
    int i,j,k=110,n,m=0,ar[110];
    scanf("%d",&i);
     for(j=1;j<=i;j++)
    {
       scanf("%d",&ar[j]);
       if(ar[j]<k)
       {
           n=j;
           k=ar[j];
       }
    }
    if(i==2)
    {
         printf("%d\n",m);
         return 0;
    }

    if(n>i/2)
    {
        n=n-1;
    }
    if(i>n)
    {
        m=i-n;
    }

     m=max(n,m);
    if(m==i)
        m=m-1;

    printf("%d\n",m);
    return 0;
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int a[n];
	for (int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int c=*min_element(a,a+n);
	int b=*max_element(a,a+n);
	int x,y;
	for (int i=0;i<n;i++)
	{
		if(a[i]==c) x=i;
	}
	for (int i=0;i<n;i++)
	{
		if(a[i]==b) y=i;
	}

    if (x==0 && y==(n-1)) cout<<(n-1)<<endl;
    else if (x==0 && y!=(n-1)) cout<<(n-1)<<endl;
    else if (y==0 && x==(n-1)) cout<<(n-1)<<endl;
    else if (y==0 && x==(n-1)) cout<<(n-1)<<endl;
    else if (y==0 && x!=(n-1)) cout<<(n-1)<<endl;
    else if (x==(n-1) && y!=(n-1)) cout<<(n-1)<<endl;
    else if (y==(n-1) && x!=(n-1)) cout<<(n-1)<<endl;
    else if (y!=0 && y!=(n-1) && x!=0 && x!=(n-1) )
    {
    	if (x>y) cout<<(n-1-y)<<endl;
    	else if (y>x) cout<<(n-1-x)<<endl;
	}
	return 0;
}

    #include <iostream>
    #include <algorithm>
    #include <stdio.h>
    #include <string.h>
    using namespace std;
    int main()
    {
      int t;
      cin>>t;
      while(t--)
      {
          long long int A[26]={0};
          long long int k,z=0,x,i,n,y;
          char S[100005];
          scanf("%s",S);
          cin>>k;
          n=strlen(S);
          for(i=0;i<n;i++)
          {
              A[S[i]-97]++;
          }
          //if(n==1&&k==0) cout<<1<<endl;
          //else
            //{
                sort(A,A+26);
          for(i=0;i<26;i++)
          {
              if(A[i]>0)
              {
                     y=A[i];
                    break;
              }
          }
          for(i=25;i>0;i--)
          {
              x=A[i];
              if(x-y>k)
              {
                  z=z+x-y-k;
              }
          }
          cout<<z<<endl;

      //}
      }
      return 0;
    }

#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
    int m;
    int i;
    while(cin >> m)
    {

    for(i=1;i<=m;i++)
    {
        cin >> a[i];
    }
    int x,y;
    for(i=1;i<=m;i++)
    {
        if(a[i]==1)
            x=i;
        if(a[i]==m)
            y=i;
    }

    if(x>y)
    {
        if(m-x>y-1)
            cout << m-y <<endl;
        else if(m-x==0)
        cout << m-1 <<endl;

        else
        cout << x << endl;
    }
    else
    {
        if(x-1>m-y)
        cout << m-x <<endl;
        else if(m-y==0)
            cout << m-1 <<endl;
        else
            cout << y << endl;
    }
    }

}

#include <iostream>
#include <cmath>

using namespace std;

int main()
{int m1,m2,i1,i2,c,d,v,n; cin>>n;
int a[n];
for (int i=1; i<=n; i++) cin>>a[i];
m1=m2=a[1]; i1=i2=1;
for(int i=1;i<n;i++)
{if (a[i]<m2) {i2=i; m2=a[i];}
if (a[i]>m1) {i1=i; m1=a[i];}
}
c=min(i1,i2);
d=max(i1,i2);
v=max(c,d);
cout<<(n-v);
return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
    int n, tmp, n_pos = 0, one_pos = 0, i = 0;
    vector<int> v;

    // ifstream cin("anton_permute3.txt", ios::in);
    cin >> n;

    if (n == 2) {
        cout << 1 << endl;
        return 0;
    }

    while (cin >> tmp) {
        v.push_back(tmp);
        if (tmp == n) n_pos = i;
        if (tmp == 1) one_pos = i;
        else ++i;
    }

    int mid = n/2;
    int rem = n%2;
    int d = 0;

    if (one_pos == mid) {
        if (n_pos < mid)  d = (n - 1) - n_pos;
        else d = n_pos;
    }

    if (one_pos < mid) {
        if (n_pos > mid) d = (n - 1) - one_pos;
        else d = (n - 1) - n_pos;
    }

    if (one_pos > mid) {
        if (n_pos > mid) d = n_pos;
        else d = one_pos;
    }

    cout << d << endl;

    return 0;
}

#include <iostream>
#include<cmath>
using namespace std;
int main()
{
    int  n, arr[100],index;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin>>arr[i];
        if (arr[i] == 1) {
            index = i;
        }
    }
    n--;
    cout << abs(index - n);
    return 0;
}

#include <cstdio>
#include <cstdlib>
#include<algorithm>
using namespace std;
#define N 110
#define inf 99999999
int a[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int ans=0,t,mx=0;
    for(int i=1;i<=n;i++)
    {
        if(mx<a[i])
        {
            mx=a[i];
            t=i;
        }
    }
    ans=max(t,n-t);
    int mi=inf;
    for(int i=1;i<=n;i++)
    {
        if(mi>a[i])
        {
            mi=a[i];
            t=i;
        }
    }
    ans=max(max(ans,t),n-t);
    printf("%d\n",ans==n?ans-1:ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,max=0,maxid=0,min=100000,minid=0;
	scanf("%d",&n);
	int array[n],array2[n];
	for(int i=0; i<n ;i++){
		scanf("%d",&array[i]);
		if(array[i]>max){
			max=array[i];
			maxid=i;
		}
		 if(array[i]<min){
			min=array[i];
			minid=i;
		}

	}
	//printf("%d %d %d %d\n",max,maxid,min,minid);
	if(maxid>minid){

	printf("%d\n",n-minid-1);
	}
	else{
		if(minid!=n-1 && n%2==0 ){
	   	printf("%d\n",n-maxid-1);
		}
		else{
			printf("%d\n",n-maxid);
		}
	}
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926535897931;

int main()
{
#ifdef _KOCHERGIN
	freopen("input.txt", "r", stdin);
#else
	//freopen("abc.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	int n;
	cin >> n;
	int l1, l2;
	for (int i = 0; i < n; ++i)
	{
		int a;
		cin >> a;
		if (a == 1) l1 = i + 1;
		if (a == n) l2 = i + 1;
	}
	//cout << l1 << " " << l2 <<  endl;
	//cout << (l2 - ((n + 1) / 2)) << " " << (l1 - ((n + 1) / 2 + 1)) << endl;
	if (l1 < l2)
	{
		if (abs(l1 - ((n+1)/ 2 + 1)) <= abs(l2 - ((n +1)/ 2 ))) cout << l2-1;
		else cout << n-l1;
	}
	else
	{
		cout << max(n - l2, n - l1) << endl;
	}
		return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define mii map<int,int>
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define log2(x) (31 - __builtin_clz(x))
int inf = (1e9) + 7;
int mod = 998244353;

int main(){

	int n;
	sf1(n);
	vi v;
	int mni,mxi;
	for (int i = 0; i < n; ++i)
	{
		int x;
		sf1(x);

		v.pb(x);
		if(x == 1) mni = i;
		if(x == n) mxi = i;
	}

	if(mni > mxi)  swap(mni,mxi);
	if(n == 2)
	{
		printf("1\n");
	}
	else if(n == 3)
	{
		if(mni == 0 and mxi == 2)
		{
			printf("1\n");
		}
		else
			printf("2\n");
	}
	else
	{
		printf("%d\n",max(n-2-mni,mxi-1));
	}

}

#include <iostream>
#include <cmath>
using namespace std;
 int n;
long long int a[100]={0};

long long int maxm=0;

int main()
{

cin>>n;
if(n<100)
{
for(int i=0;i<n;i++)
cin>>a[i];

maxm=abs(a[n-1]-a[0]);

if(n>2)
{
if(abs(a[n-1]-a[1])>maxm)
maxm=abs(a[n-1]-a[1]);
if(abs(a[n-2]-a[0])>maxm)
maxm=abs(a[n-2]-a[0]);
}
}
cout<<maxm;
return 0;
}

#include <iostream>
#include <vector>
#include <stdlib.h>

using namespace std;

int maxDistance(vector<int> v) {
    int min = 0, max = 0, mid = (v.size() - 1) / 2, left, right;

	for (int i = 0; i < v.size(); i++) {
		if (v[min] > v[i]) {
			min = i;
		}

		if (v[max] < v[i]) {
			max = i;
		}
	}

	if (min <= mid) {
		left = min;
		right = max;
	} else {
		left = max;
		right = min;
	}

	if (abs(left - mid) > abs(right - mid)) {
		return v.size() - 1 - left;
	}

	if (abs(left - mid) < abs(right - mid)) {
		return right;
	}

	if (abs(left - mid) == abs(right - mid) && v.size() % 2 == 0) {
		return v.size() - 1 - left;
	}

	return v.size() - 1 - right;
}

int main() {
	int n, p;
	vector<int> v1, v2, v3;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> p;
		v1.push_back(p);
	}

	cout << maxDistance(v1) << endl;

	return 0;
}

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <sstream>

using namespace std;
#define fi first
#define se second
typedef long long ll;
ll gcd(ll a, ll b)
{
   while(true)
   {
       a%=b;
       if(a==0)
        return b;
       b%=a;
       if(b==0)
        return a;
   }
}
long long cnt,cnt1=1,cnt2,cnt3,mi=10000000,ma=-9999,sum,i,j;
long long n,m,t,n1,m1;
long d1,d2,d3;
pair<long,long>p[1000000];
long long a,b,c,d;
long long x[3000];
long long y[2];
string s;
int main(){
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x[i];
    }
    for(i=1;i<=n;i++)
    {
        if(x[i]==n)
            a=i;
        else if(x[i]==1)
            b=i;
    }
     if((a==1 && b==n) || (a==n && b==1))
     {
         cout<<n-1;
     }
    else if((n-b)>(n-a))
    {
        cout<<n-b;
    }
    else if((n-b)<(n-a))
    {
         cout<<n-a;
    }
}

//printf("%.9f",tmp);

#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
#define re cout<<
#define ll long long int
#define loopi for(int i=1; i<=n; i++)
#define loopir for(int i=n; i>0; i--)
#define loopj for(int i=1; i<=n; i++)
ll n,k,m,v,u,x,y,z;
ll a,b;
vector< pair< ll, ll > > w;
int main(){
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>a;
		if(a==n) b=i;
		if(a==1) y= i;
	}
	if(b>y) cout<<b;
	else cout<<n-b;

}

#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
#define re cout<<
#define ll long long int
#define loopi for(int i=1; i<=n; i++)
#define loopir for(int i=n; i>0; i--)
#define loopj for(int i=1; i<=n; i++)
ll n,k,m,v,u,x,y,z;
ll a,b;
vector< pair< ll, ll > > w;
int main(){
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>a;
		if(a==n) b=i;
		if(a==1) y= i;
	}
	if(b>y) cout<<b-1;
	else cout<<n-b;

}

#include <iostream>
using namespace std;

int main()
{
    int n,i,pozmin=-1, pozmax=-1, x, mn=101, mx=-1;
    cin>>n;
    for(i=1;i<n;i++)
    {
        cin>>x;
        if(x<mn)
            mn=x,
            pozmin=i;
        if(x>mx)
            mx=x,
            pozmax=i;
    }
    //if(mn=mx) cout<<0;
    int ds_min,dr_min,ds_max,dr_max; ///dostantele corespnzatoare pentru capetele vectorului
    ds_min=pozmin;
    ds_max=pozmax;
    dr_min=(n-1)-pozmin;
    dr_max=(n-1)-pozmax;
    //if(dr_min>dr_max && mn>n/2)
    //    cout<<mx;
    //if(dr_min>dr_max && mn<=n/2)
    //    cout<<n-1;
    //if(dr_min<dr_max && mn<=n/2)
    //    cout<<n-pozmax-1;
    //if(dr_min<dr_max && mn>n/2)
    //    cout<<pozmin;
    int d1, d2; ///distantele din st si din dr dintre capetele segm dintre min si max la capetele vectorului
    if(pozmin<pozmax) d1=pozmin, d2=n-pozmax;
    else d1=pozmax, d2=n-pozmin;
    if(d1>d2)
        if(pozmin<pozmax)
            cout<<pozmax-1;
        else cout<<pozmin-1;
    else
        if(pozmin<pozmax)
            cout<<n-pozmin;
        else cout<<n-pozmax;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main () {
    int n,m,t,mi=101,ma=0,p=0;
    cin >> n;
    vector <int> mas(n);
    for (int i=0; i<n; i++) {
        cin >> mas[i];
        if (mas[i]<mi) {
            m=i;
            mi=mas[i];
        }
        if (mas[i]>ma) {
            t=i;
            ma=mas[i];
        }
    }
    int r=max(abs(n-m-1),abs(n-t-1));
    cout << max(r,n-1);

}

#include <iostream>

using namespace std;

int main()
{
    int x;
    cin >> x;
    int A[101];

    for (int i=1; i<=x; i++)
    {
        cin >> A[i];
    }
    int mx, mn, temp1, temp2;
    int nr1, nr2;
    mx=A[1];
    mn=A[1];

    for (int i=1; i<=x; i++)
    {
        if (mn >= A[i])
        {
            mn=A[i];
            nr1=i;
        }

        if (mx <= A[i])
        {
            mx=A[i];
            nr2=i;
        }
    }

    if (nr1==0 or nr2==0 or nr1==x or nr2==x)
    {
        cout << x-1 << endl;
        return 0;
    }
    else
    {

    if (nr2>nr1)
    {
        if (x-nr1<=nr2)
        {
            cout << nr2 << endl;
            return 0;
        }
        if (nr2<=x-nr1)
        {
            cout << x-nr1 << endl;
            return 0;
        }
    }

    if (nr2<nr1)
    {
        if (nr1>=x-nr1)
        {
            cout << nr1 << endl;
            return 0;
        }
        if (nr1<=x-nr1)
        {
            cout << x-nr1 << endl;
            return 0;
        }
    }
    }
    return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

void test_case() {

}

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll T, pos_1, pos_T;
    cin >> T;
    vector<int> perm(T);
    for (int i=0; i<T; i++) {
        cin >> perm[i];
        if(perm[i] == 1) pos_1 = i;
        if(perm[i] == T) pos_T = i;
    }
    int max1 = max( abs(T-pos_1), abs(T-pos_T));
    int max2 = max( abs(1-pos_1), abs(1-pos_T));
    cout << max( max1, max2 );
}

#include <bits/stdc++.h>

using namespace std;

int n, a[110], idn, ido;

main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		if (a[i] == n)
			idn = i;
		if (a[i] == 1)
			ido = i;
	}
	if (idn < ido)
		cout << max(idn - 1, n - ido) + 1;
	else
		cout << max(ido - 1, n - idn) + 1;
}

#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <sstream>
#include <stack>
#include <Windows.h>
#include <time.h>
#ifndef _DEPRECATION_DISABLE   /* One time only */
#define _DEPRECATION_DISABLE   /* Disable deprecation true */
#if (_MSC_VER >= 1400)         /* Check version */
#pragma warning(disable: 4996) /* Disable deprecation */
#endif /* #if defined(NMEA_WIN) && (_MSC_VER >= 1400) */
#endif /* #ifndef _DEPRECATION_DISABLE */
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pb push_back
typedef vector<int> vi;

#define set(x,n)for(int x = 0;x < n; ++x)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pb push_back
typedef vector<int> vi;

template<typename TA>
TA mins(TA a, TA b)
{
	return a < b ? a : b;
}
template <class T>
int bsearch(T *arr, int size, T value)
{
	int l = 0;
	int r = size;
	while (l <= r)
	{
		int mid = l + (r - l) / 2;
		if (arr[mid] == value)
			return 1;
		if (arr[mid] < value)
			l = ++mid;
		if (arr[mid] > value)
			r = --mid;
	}
	return -1;
}

class X {
public:
	int v;
	X(void) :v(0.345436){}
	X(const X&){}
	X(INT a) :v(a){}
	friend const X operator++(X& i, int);
	friend const X operator--(X& i);
	friend bool  operator==(const X& i, const X&l);
};
bool operator==(const X& i, const X&l)
{

	return i.v == l.v;
}
const X operator++(X& i, int){
	X oldValue(i.v);
	i.v++;
	return oldValue;
}
const X operator--(X& i) {
	i.v--;
	return i;
}

int Prime(unsigned long a)
{
	unsigned long i, j, bound;
	if (a == 0 || a == 1)
		return 0;
	if (a == 2 || a == 3 || a == 5)
		return 1;
	if (a % 2 == 0 || a % 3 == 0 || a % 5 == 0)
		return 0;
	bound = sqrt((double)a);
	i = 7; j = 11;
	while (j <= bound && a%i && a%j)
	{
		i += 6; j += 6;
	}
	if (j <= bound || i <= bound && a%i == 0)
		return 0;
	return 1;
}
long long bin_pow(long long a, long long b)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
	{
		long long ans = bin_pow(a, b / 2);
		return (ans*ans);
	}
	else
	{
		return bin_pow(a, b - 1)*a;
	}

}

int lentree = 0;
int n;

void build_tree(vector<int>&a, const vector<int>&b)
{
	for (int j = lentree / 2; j < lentree; j++)
		a[j] = INT_MIN;
	for (int j = 0; j < n; j++)
		a[lentree / 2 + j] = b[j];
	for (int j = lentree / 2 - 1; j > 0; j--)
		a[j] = max(a[j * 2], a[j * 2 + 1]);
}
void update_tree(vector<int>&a, int s, int i)
{
	a[lentree / 2 + i] = s;
	for (int j = lentree / 2 - 1; j > 0; j--)
		a[j] = max(a[j * 2], a[j * 2 + 1]);
}
int get(vector<int>&a, int l, int r)
{
	int ans = 0;
	l += lentree / 2, r += lentree / 2;
	while (l <= r)
	{
		if (l & 1)
			ans = max(ans, a[l]);
		if (!(r & 1))
			ans = max(ans, a[r]);
		l = (l + 1) / 2;
		r = (r - 1) / 2;
	}
	return ans;
}

bool isOne(long long n) {

	double ans = (sqrt((double)8 * n + 1) - 1) / 2.0;
	ans = ans + 1e-7;
	long long r = (long long)ans;
	if ((r * (r + 1)) / 2 == n) return true;
	return false;
}

vector<int> bin(int a){

	vector<int>p;
	while (a){
		int s = a % 2;
		a /= 2;
		p.push_back(s);
	}

	reverse(p.begin(), p.end());
	return p;
}
struct node
{
	int r;
	int l;
	int s;
	node(int a, int b, int c) : r(a), l(b), s(c){}
};

template <class T>
int bsearch_extended(const vector<node *>&arr, int size, T value)
{
	int l = 0;
	int r = size;
	while (l <= r)
	{
		int mid = l + (r - l) / 2;
		if (arr[mid]->r <= value && value <= arr[mid]->l)
			return arr[mid]->s;
		if (arr[mid]->r < value && value > arr[mid]->l)
			l = ++mid;
		if (arr[mid]->r > value && value < arr[mid]->l)
			r = --mid;
	}
	return -1;
}
template<typename T>
T get(T a)
{
	long long res = a * (a - 1) / 2;
	return res;
}

class A
{

public:
	A(int a1, int b1)
	{
		this->a = a1;
		this->k = b1;
	}
	~A(){
		cout << "~A" << endl;
	};
	virtual void print()
	{
		cout << a << " " << k << endl;
	}

	virtual void md_p32()
	{
		a /= 2;
		k /= 2;
	}

	int a;
private:
	int k;
};

class B : public A
{
public:
	B(int _a, int _b) :A(_a, _b)// ? ??????????? ???????? ??????
	{
		this->a_32 = _a;// ? ??????????? ???????????? ??????
		this->k_32 = _b;
	}
	~B(){
		cout << "~B" << endl;
	};
	void print(){
		cout << a_32 << " " << k_32 << endl;
	}

	void md_p32()
	{
		a_32 *= 2;
		k_32 *= 2;
	}
	friend bool operator == (const B &t, const B &l);

	int a_32;
private:
	int k_32;
};

bool operator == (const B &t, const B &l)
{
	return t.a_32 == l.a_32;
}

#define _CODEFORCES_1

int main()
{

#ifdef _CODEFORCES_
	A *p = new A(4, 4);
	p->print();

	B *w = new B(4, 4);
	w->print();

	if (w == w)
	{
		cout << "Ok\n";
	}

	A *base;
	base = p;

	base->md_p32();
	base->print();

	base = w;

	base->md_p32();
	base->print();
	delete w;

	vector<int>vii;
	int sum = 0;
	for (int i = 0; i < 7; i++){
		int temp = 7;
		int temp1 = 9;
		if ((temp & 1 << i) ^ (temp1 & 1 << i))
			sum++;

	}

#endif
	multiset<int>s;//������ ��������� � �������������� ����,��� � set,�� ����� ������� ���������� ��������
	cin >> n;
	INT a[111];
	int l = 0;
	for (INT i = 0; i < n; i++)
	{
		cin >> a[i];
		s.insert(a[i]);
		while (*s.rbegin() - *s.begin() == n - 1)
		{
			s.erase(s.find(a[l++]));//������� � �������� ����� ������������������
		}

	}
	cout << s.size() << endl;

	return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int n, imax, imin;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == 1) imin = i;
		else if (a[i] == n) imax = i;
	}
	if (imin <= n / 2 && imax <= n / 2) {
		if (imax < imin) cout << n - imax - 1;
		else cout << n - imin - 1;
	//	system("pause");
		return 0;
	}
	if (imin >= n / 2 && imax >= n / 2) {
		if (imax > imin) cout << imax;
		else cout << imin;
	//	system("pause");
		return 0;
	}
	if (imax > imin) {
		if (n - imax < imin) cout << imax - 1;
		else cout << n - imin - 1;
	}
	else {
		if (n - imin < imax) cout << imin - 1;
		else cout << n - imax - 1;
	}
//	system("pause");
	return 0;
}

#include <iostream>
using namespace std;
int main(){
    int n , a , b , p;
    cin>>n;
    for(int i =1 ; i<=n ; i++){
        cin>>p;
        if(p==1){
            a=i;
        }
        if(p==n){
            b=i;
        }

    }
    if(a>=5&&b>=5){
        if(a>b){
        cout<<a-1;
    }else{
        cout<<b-1;
    }
    }else{

    if(a>b){
        cout<<n-b;
    }else{
        cout<<n-a;
    }
    }

    return 0;
}

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,max1,min1,i,p,q=0,t;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    max1=0;min1=a[0];
    for(i=0;i<n;i++)
    {
        if(a[i]>max1)
        {
        max1=a[i];
        p=i;
        }
        if(a[i]<min1)
        {
            min1=a[i];
            q=i;
        }
    }
    t=min(p,q);
    if(max(p,q)<=n/2)

    cout<<n-1-t;
    else
    {
        if(max(p,q)>n/2 && min(p,q)!=0)
    cout<<max(p,q);
        else
    cout<<n-1;
}}

#include <iostream>

using namespace std;

int main()
{
    int x;
    cin >> x;
    int A[101];

    for (int i=1; i<=x; i++)
    {
        cin >> A[i];
    }
    int mx, mn, temp1, temp2;
    int nr1, nr2;
    mx=A[1];
    mn=A[1];

    for (int i=1; i<=x; i++)
    {
        if (mn >= A[i])
        {
            mn=A[i];
            nr1=i;
        }

        if (mx <= A[i])
        {
            mx=A[i];
            nr2=i;
        }
    }

    if (nr1==1 or nr2==1 or nr1==x or nr2==x)
    {
        cout << x-1 << endl;
        return 0;
    }
    else
    {

    if (nr2>nr1)
    {
        if (x-nr1<=nr2)
        {
            cout << nr2 << endl;
            return 0;
        }
        if (nr2<=x-nr1)
        {
            cout << x-nr1 << endl;
            return 0;
        }
    }

    if (nr2<nr1)
    {
        if (nr1-1>=x-nr2)
        {
            cout << nr1-1 << endl;
            return 0;
        }
        if (nr1-1<=x-nr2)
        {
            cout << x-nr2 << endl;
            return 0;
        }
    }
    }
    return 0;
}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{

   	int n;
	cin>>n;
	int a[n];

	for(int i=0;i<n;i++)
	    cin>>a[i];

 vector<int> X(a, a+5);
 //int max_element1 = *max_element(X.begin(), X.end());
  //int min_element1 = *min_element(X.begin(), X.end());
 //cout<<max_element1<<" "<<min_element1<<"\n";
  int min_index= min_element(X.begin(), X.end()) - X.begin();
  int max_index= max_element(X.begin(), X.end()) - X.begin();
 //cout<<min_index<<" "<<max_index;

    if(abs(n-min_index-1) >= abs(n-max_index-1))
       cout<<abs(n-min_index-1);
     else
	 cout<<abs(n-max_index-1);

}

#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,s,x,y;
	scanf("%d",&n);
	for(int i=1; i<=n; i++) {
		scanf("%d",&s);
		if(s==1) {
			x=i;
		}
		if(s==n) {
			y=i;
		}
	}
	int start=x<y?x:y,end=x>y?x:y;
	if(start-0>n-end){
		start=0;
	}else{
		end=n;
	}
	printf("%d\n",end-start);
	return 0;
}

//
//  Nicholas.cpp
//  CodeForces
//
//  Created by Zixiang Zhu on 5/25/16.
//  Copyright © 2016 zixiangzhu. All rights reserved.
//

#include <stdio.h>
#include <iostream>

using namespace std;

int arr[100];

int main()
{
    int length;
    int max = -1;
    int min = 1000000;
    int left = 0;
    int right = length - 1;

    cin >> length;
    for (int i = 0; i < length; i++) {
        cin >> arr[i];
        max = arr[i] > max ? arr[i] : max;
        min = arr[i] < min ? arr[i] : min;
    }

    for(int i = 0; i < length; i++) {
        if(arr[i] == max || arr[i] == min) {
            left = i;
            break;
        }
    }

    for(int i = length - 1; i >= 0; i--) {
        if(arr[i] == max || arr[i] == min) {
            right = i;
            break;
        }
    }

    cout << length - (left < right ? left : right);

    return 0;
}

#include<vector>
#include<iostream>

using namespace std;

int main()
{
	int size,n,temp1 = 0,temp2 = 1,max,min;
	cin >> size;
	vector<int>v;

	for (int i = 0; i < size; i++) {
		cin >> n;
		v.push_back(n);

		//find max
		if (v[i] > temp1) {
			temp1 = v[i];
			max = i;
		}

		//find min
		if (v[i] <= temp2) {
			temp2 = v[i];
			min = i;
		}
	}

	//cout << v[max]<<" "<<max<<endl;
	//cout << v[min]<< " " << min << endl;

	if (max > min) {

			cout << size - min -1<< endl;

	}
	else if (min > max)
	{

			cout << size-max -1<< endl;

	}

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define lli long long
#define endl '\n'
#define mod 1000000007
#define spc " "
#define no "NO"
#define yes "YES"
#define ff "First"
#define ss "Second"
#define rishabh "Friendship"
lli fact(int n) {
	if (n == 1)return 1;
	if (n == 0)return 1;
	else return n * fact(n - 1);
}
int prime(int g) {
	for (int i = 2; i * i  <= g; ++i)
	{
		if (g % i == 0)return false;
	} return true;

}
int fibo(int n) {
	int x = 1002;
	int arr[x]; arr[0] = 0; arr[1] = 1; arr[2] = 1;
	for (int i = 2; i < x; ++i)
	{
		arr[i] = arr[i - 1] + arr[i - 2];
	}
	for (int i = 1; i < x; ++i)
	{
		/* code */if (arr[i] == n)return true;
	}
	return false;
}
int fit (int x) {
	int n = 10;
	char arr[n] = {'a', 'i', 'o', 'u', 'e', '1', '3', '5', '7', '9'};
	for (int i = 0; i < n; ++i)
	{
		/* code */if (x == arr[i])return true;
	} return false;
}
string str(int n) {
	string l = "", r = "";

	/* code */while (n > 0) {
		l += (n % 10 + '0');
		n /= 10;

	}
	reverse(l.begin(), l.end());
	return l;

}

void astronomia() {
	std::vector<int> v;
	lli n, i , j = 0, k = 0, count = 0;
	set <int> se; lli m, l, r, a = 0, b = INT_MAX;
	map<int, int> mp; char c1, c2;
	string s;
	cin >> n ;
	for (int i = 0; i < n; ++i)
	{
		/* code */cin >> a;
		if (a == 1)l = i + 1;
		if (a == n)r = i + 1;
	}
	cout << max(n - l, n - r);

}

/*ifstream in("input.txt");
ofstream ou("output.txt");*/

int main() {
	// ios_base::sync_with_stdio(0);
	// cin.tie(0); cout.tie(0);
	lli t;
	t = 1;
	// cin >> t;

	while (t--) {
		astronomia();

		cout << endl;
	}

}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n,maxx=0,minn=0,holdmin,holdmax,a;cin >>n>>holdmin;holdmax=holdmin;
    for(int i=1;i<n;i++){
        cin >>a;
        if(a>holdmax){maxx=i;holdmax=a;}
        else if(a<holdmin){minn=i;holdmin=a;}
    }
    int x=n-(maxx+1);int y=n-(minn+1);
    cout << max(x,y)<< endl;
}

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int a,b;
    for (int i=0;i<n;i++)
    {
        if (arr[i]==n)
            a=i;
        else if (arr[i]==1)
        {
            b=i;
        }
    }
    if ((a==0&&b==n-1)||(a==n-1&&b==0))
    {
        cout<<n-2<<endl;
        return 0;
    }
    if (a<b)
    {
        int t1=b;
        int t2=(n-1)-a;
        if (t1>t2)cout<<a+1<<endl;
        else cout<<b+1<<endl;
    }
    else
    {
        int t1=a;
        int t2=(n-1)-b;
        if (t1>t2) cout<<b+1<<endl;
        else cout<<a+1<<endl;
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <stdlib.h>

using namespace std;

int maxDistance(vector<int> v) {
	int min = 0, max = 0, mid = (v.size() - 1) / 2;

	for (int i = 0; i < v.size(); i++) {
		if (v[min] > v[i]) {
			min = i;
		}

		if (v[max] < v[i]) {
			max = i;
		}
	}

	if (abs(min - mid) >= abs(max - mid)) {
		if (min < mid) {
			return v.size() - 1 - min;
		}

		return min;
	}

	if (max < mid) {
		return v.size() - 1 - max;
	}

	return max;
}

int main() {
	int n, p;
	vector<int> v1, v2, v3;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> p;
		v1.push_back(p);
	}

	cout << maxDistance(v1) << endl;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
        scanf("%d",&a[i]);
    if(n==2)
    {
        cout<<abs(a[0]-a[1]);
        return 0;
    }
    if(n==3)
    {
        cout<<max(abs(a[2]-a[1]),abs(a[1]-a[0]));
        return 0;
    }
    else
    {
        if(a[0]==n||a[n-1]==1||a[0]==1||a[n-1]==n)
        {
            cout<<n-1;
            return 0;
        }
        cout<<max(n-min(a[0],a[n-1]),max(a[0],a[n-1])-1);
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,i,j,m=0,no=1000,l1;

    scanf("%d",&n);
    int arr[n];

    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
        if(arr[i]>m)
        {
            m = arr[i];
        }
        if(no>arr[i])
        {
            no = arr[i];
        }
    }
     if(arr[0]==m||arr[n-1]==m||arr[0]==no||arr[n-1]==no)
    {
        printf("%d\n",m-no);
        return 0;
    }

    if(abs(arr[0]-m)>abs(arr[0]-no))
    {
        l1=abs(arr[0]-m);
    }
    else
    {
        l1 = abs(arr[0]-no);
    }

    if(abs(arr[n-1]-m)>l1)
    {
        l1 = abs(arr[n-1]-m);
    }
    else if(abs(arr[n-1]-no>l1))
    {
        l1 = abs(arr[n-1]-no);
    }
    printf("%d\n",l1);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
    int m;
    int i;
    while(cin >> m)
    {

    for(i=1;i<=m;i++)
    {
        cin >> a[i];
    }
    int x,y;
    for(i=1;i<=m;i++)
    {
        if(a[i]==1)
            x=i;
        if(a[i]==m)
            y=i;
    }

    if(x>y)
    {
        if(m-x>y-1)
            cout << m-y <<endl;
        else if(m-x==0)
        cout << m-1 <<endl;

        else
        cout << x << endl;
    }
    else
    {
        if(x-1>m-y)
        cout << m-x <<endl;
        else if(m-y==0)
            cout << m-1 <<endl;
        else
            cout << y << endl;
    }
    }

}

#include<bits/stdc++.h>
using namespace std;
#define mod (unsigned long long)1000000007
#define ull unsigned long long
using ll = long long;
#define pb push_back
#define mp make_pair

main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n;
        cin>>n;
        vector<int> v(n);
        for(int i=0;i<n;i++)
        {
            cin>>v[i];
        }
        int mx=0,mn=INT_MAX,z,w;
        for(int i=0;i<n;i++)
        {
            if(v[i]>mx)
            {
                mx=v[i];
                z=i;
            }
            if(v[i]<mn)
            {
                mn=v[i];
                w=i;
            }
        }
        int ans1=max(abs(w),abs(w-n));
        int ans2=max(abs(z),abs(z-n));
        if(ans1>=ans2)
        {
            cout<<ans1<<endl;
        }
        else
        {
            cout<<ans2<<endl;
        }

}

    #include<bits/stdc++.h>

    using namespace std;
    typedef long long ll;

    string To_string(int a)
    {
        string s="";
        while(a)
        {
            s+=(a%10+'0');
            a/=10;
        }
        reverse(s.begin(),s.end());
        return s;
    }

    int find_min(int a[],int n)
    {
        int b=a[0];
        int k=0;
        for(int i=1;i<n;i++)
        {
            if(a[i]<b)
            {
                b=a[i];
                k=i;
            }

        }
        return k+1;

    }

    int find_max(int a[],int n)
    {
        int b=a[0];
        int k=0;
        for(int i=1;i<n;i++)
        {
            if(a[i]>b)
            {
                b=a[i];
                k=i;
            }

        }
        return k+1;

    }

    int main()
    {

        int n;
        cin>>n;

        int a[n];

        for(int i =0;i<n;i++)
            cin>>a[i];

        if(abs(find_max(a,n)-find_min(a,n))==n-1)
                cout<<n-1;

        else
        {
            int minn=find_min(a,n);
            int maxx=find_max(a,n);

            if(minn>maxx)
            {
                int temp=minn;
                minn=maxx;
                maxx=temp;

            }

            if(minn==1 ||minn==n||maxx==1||maxx==n)
            {
                cout<<n-1;
                return 0;
            }

            else
            {
                if(minn-1==maxx-n)
                    cout<<maxx-1;

            if(minn-1<maxx-n)
            cout<<n-minn;

            else
                cout<<maxx;

            }

        }

        return 0;
    }

    #include<iostream>
    using namespace std;

    int main(){
        int n, a[1000], aMax, aMin, pMax, pMin;
        cin>>n;
        cin>>a[0];
        aMax = a[0], aMin = a[0];
        pMax = pMin = 0;

        for (int i=1; i<n; i++){
            cin>>a[i];
            if (a[i] >= aMax){
                aMax = a[i];
                pMax= i;
            }
            if (a[i] <= aMin){
                aMin = a[i];
                pMin = i;
            }
        }

        if (aMax == aMin){
            cout<<2;
        }else{
            if ((pMin == 0 && pMax == n-1)||(pMin == n-1 && pMax == 0))
            cout<<n-1;
            else if (pMin >pMax)
                cout<<n - pMax -1;
            else if (pMin < pMax)
                cout<<n - pMin -1;
        }
    }

//
//  Nicholas.cpp
//  CodeForces
//
//  Created by Zixiang Zhu on 5/25/16.
//  Copyright © 2016 zixiangzhu. All rights reserved.
//

#include <stdio.h>
#include <iostream>

using namespace std;

int arr[100];

int main()
{
    int length;
    int max = -1;
    int min = 1000000;
    int left = 0;
    int right = length - 1;

    cin >> length;
    for (int i = 0; i < length; i++) {
        cin >> arr[i];
        max = arr[i] > max ? arr[i] : max;
        min = arr[i] < min ? arr[i] : min;
    }

    for(int i = 0; i < length; i++) {
        if(arr[i] == max || arr[i] == min) {
            left = i;
            break;
        }
    }

    for(int i = length - 1; i >= 0; i--) {
        if(arr[i] == max || arr[i] == min) {
            right = length - 1 - i;
            break;
        }
    }

    cout << length - (left < right ? left : right);

    return 0;
}

#include <iostream>
#include <cmath>
using namespace std;
int v[101];
int main()
{
   float n,minim=1000,maxim=-1,minimi,maximi,maximii=-1;
   cin>>n;
   for(int i=1;i<=n;i++)
   {
       cin>>v[i];if(v[i]==n){maximi=i;maxim=n;}
       if(v[i]==1){minimi=i;minim=1;}
   }

   for(int i=1;i<=n;i++)
   {
       if(abs(maximi-i)>maximii)
        maximii=abs(maximi-i);

   }
    cout<<maximii;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,max=0,maxid=0,min=100000,minid=0;
	scanf("%d",&n);
	int array[n],array2[n];
	for(int i=0; i<n ;i++){
		scanf("%d",&array[i]);
		if(array[i]>max){
			max=array[i];
			maxid=i;
		}
		 if(array[i]<min){
			min=array[i];
			minid=i;
		}

	}
	//printf("%d %d %d %d\n",max,maxid,min,minid);
	if(maxid>minid){

	printf("%d\n",n-minid-1);
	}
	else{
	   	printf("%d\n",n-maxid-1);
	}
	return 0;
}

#pragma comment(linker, "/STACK:99777216")
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>

#define M_PI 3.14159265358979323846

using namespace std;

typedef unsigned __int64 ui;
typedef __int64 si;
typedef long long ll;

int main()
{
	cin.sync_with_stdio(false);
	//freopen("minimal.in", "r", stdin);
	//freopen("minimal.out", "w", stdout);
	double v, t;
	int n;
	cin >> n;
	int a[110] = {};
	int k, l;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		if (a[i] == 1)
			l = i;
		if (a[i] == n)
			k = i;
	}
	cout << max(k - l, max(n - l, n - k)) << endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;cin>>n;
    int max=0,min=0,a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int x=a[0],y=a[n-1];
    for(int i=0;i<n-1;i++)
        if(abs(y-a[i])>max)
            max=abs(y-a[i]);
    for(int i=1;i<n;i++)
        if(abs(x-a[i])>min)
            min=abs(x-a[i]);
    if(max>=min)
        cout<<max;
    else
        cout<<min;
    return 0;
}

#include <iostream>
#include <conio.h>
using namespace std;

int main(){
    int n, min = 10000, max = 0, minIndex, maxIndex, tmp;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>tmp;
        if (tmp > max){
            max = tmp;
            maxIndex = i;
        }
        if (tmp < min){
            min = tmp;
            minIndex = i;
        }
    }
    if (n - maxIndex > minIndex)
        cout<<n-minIndex+1;
    else
        cout<<maxIndex+1;
    return 0;
}

#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
	int n,temp,k=0,l=0;
	cin>>n;
	int a;
	for(int i=0;i<n;i++){
	   cin>>a;
	   if(a==1)
	   k=i;
	   if(a==n)
	   l=i;
	   }

	 if((n-1)-k>l-k)
	 cout<<(n-1)-k;

	 if(l-k<k)
	 cout<<k;

	return 0;
}

#include <iostream>
#include<windows.h>
using namespace std;
int main()
{
	int n,f,l,num;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>num;
		if(num==1)
			f=i+1;
		if(num==n)
			l=i+1;
	}
	cout << max(max(abs(n-f),abs(n-l)), max(abs(1 - f), abs(1 - l)));
	return 0;
}

#include <math.h>
#include <iostream>
#include <stdlib.h>
using namespace std;

int main()
{
	int n, min, max;
	cin>>n;

	int a[n];

	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		if(a[i] == n)
			max = i;
		if(a[i] == 1)
			min = i;
	}

	if(abs(min - max) == n-1)
		{
			cout<<n;
			return 0;
		}
	if(min <= n/2 && max <= n/2)
		cout<<((min > max)? (n - max -1) : (n - min - 1));
	else
		if(min > n/2 && max > n/2)
			cout<<((min > max)? min+1 : max+1);
		else
			cout<<((abs(min - n/2) > abs(max-n/2))? (n- 1 - min) : max + 1);

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    int arr[n],s=0,l=0,maxi=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(int i=0;i<n;i++)
    {
        if(arr[i]>arr[l])
            l=i;
        if(arr[i]<arr[s])
            s=i;
    }
    s++;l++;
    if((s-l)==n-1||(l-s)==n-1)
    {
        printf("%d",n-1);
        return 0;
    }
    if(s>maxi)
        maxi=s;
    if(n-s>maxi)
        maxi=n-s;
    if(l>maxi)
        maxi=l;
    if(n-l>maxi)
        maxi=n-l;

    printf("%d",maxi);
    return 0;
}

#include <iostream>
using namespace std;
int main(){
    int n , a , b , p , s;
    cin>>n;
    for(int i =1 ; i<=n ; i++){
        cin>>p;
        if(p==1){
            a=i;
        }
        if(p==n){
            b=i;
        }
    }
         if(a<b){
            p=a;
            a=b;
            b=p;
         }
         if(n-a>=b-1){
            cout<<n-b;
         }else{
            cout<<b-1;
         }

    return 0;
}

#include <cstdio>
#include <algorithm>
using namespace std;
int N,temp;
int maxx, minn=987654321;
int mxidx, mnidx;
int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &temp);
		if (temp > maxx)
		{
			maxx = temp;
			mxidx = i;
		}
		else if (temp < minn)
		{
			minn = temp;
			mnidx = i;
		}
	}
	if (mxidx > mnidx)
		printf("%d", max(mxidx, N-1 - mnidx));
	else
		printf("%d", max(mnidx, N-1 - mxidx));
}

#include <iostream>
using namespace std;
int main(){
    int n , a , b , p;
    cin>>n;
    for(int i =1 ; i<=n ; i++){
        cin>>p;
        if(p==1){
            a=i;
        }
        if(p==n){
            b=i;
        }

    }
    if(a>=5&&b>=5){
        if(a>b){
        cout<<a-1;
    }else{
        cout<<b-1;
    }
    }else{

    if(a>b){
        cout<<n-b;
    }else{
        cout<<n-a;
    }
    }

    return 0;
}

//
//  main.cpp
//  Nicholas and Permutation
//
//  Created by Hoang Cong on 4/30/18.
//  Copyright © 2018 Hoang Cong. All rights reserved.
//

#include <iostream>
#include <vector>
using namespace std;

int main(int argc, const char * argv[])
{
    vector<int> A;
    int n;
    int a;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        A.push_back(a);
    }
    int min=A.at(0);
    int max=A.at(0);
    int left=0;
    int right=0;
    for(int i=0;i<n;i++)
    {
        if(min>A.at(i))
        {
            min=A.at(i);
            left=i;
        }
        if(max<A.at(i))
        {
            max=A.at(i);
            right=i;
        }
    }
    if(left>right)
    {
        if(n-left-1>=right)
        {
            if(!(left==n-1 && right==0))
                cout<<left+1;
            else
                cout<<n-1;
        }
        else
            cout<<right+1;
    }
    else
    {
        if(left<=n-right-1)
        {
            if(!(left==0 && right==n-1))
                cout<<right+1;
            else
                cout<<1;
        }
        else
            cout<<left+1;
    }
    return 0;
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long n;
    while(cin>>n)
    {
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];

        }
        int max = a[0];
int min = a[0],minadd=0,maxadd=0;

  for (int i = 0; i < n; i++)
    {
      if (a[i] > max)
        {
          max = a[i];
          maxadd=i;
        }
      else if (a[i] < min)
        {
          min = a[i];
          minadd=i;
        }
    }

    if(max==min)
    {
        cout<<"1\n";
        continue;
    }

     int minpos1=abs(minadd-0);
     int minpos2=abs((n-1)-minadd);
     if(minpos1<minpos2)
        minpos1=minpos1;
     else
        minpos1=minpos2;
    int diff=abs(maxadd-minadd);
    if(diff==n-1){
        cout<<diff<<endl;
    continue;}

    else if(minadd>=n/2&&maxadd<n/2)
    {
        if((n-1)-minadd>=maxadd)
        {
            int pos=n-1-maxadd;
            cout<<pos<<endl;
            continue;
        }
        else
        {
            int pos=minadd;
            cout<<minadd<<endl;
            continue;
        }

    }
    else
    {
         if((n-1)-maxadd>=minadd)
        {
            int pos=n-1-minadd;
            cout<<pos<<endl;
            continue;
        }
        else
        {
            int pos=maxadd;
            cout<<maxadd<<endl;
            continue;
        }
    }

//  cout << max << endl;
//  cout << min << endl;

//        auto minmax = std::minmax_element(std::begin(a), std::end(a));
//
//std::cout << "min element " << *(minmax.first) << "\n";
//std::cout << "max element " << *(minmax.second) << "\n";

    }

    //cout << "Hello world!" << endl;
    return 0;
}

// Example program
#include <iostream>
#include <string>
using namespace std;
int a[105];
int main()
{int n; cin>>n;
int p; p=0;
for (int i=1;i<=n; i++) cin>>a[i];
for(int i=1;i<=n;i++)
{
   for(int j=1;j<=n;j++)
   {
      if (a[i]==1 and a[j]==n) { if ((n-i)<=(i-1) and (n-j)>=(j-1) and ((i=n) or (j=n))) p=abs(n-1);}
      else {if (a[i]==1 and a[j]==n) { if ((n-i)<=(i-1) and (n-j)>=(j-1)) p=abs(n-j);}
      if (a[i]==1 and a[j]==n) { if ((n-j)<=(j-1) and (n-i)>=(i-1)) p=abs(n-i);}
}
}
}
cout<<p;
return 0;
}

#include <iostream>

using namespace std;

int main()
{int n; cin>>n;
    int a[n];
    for (int i=1; i<=n; i++) cin>>a[i];
if ((a[1]=1) or (a[n]=n)) cout<<(n-1);
    else cout<<(n-2);
    return 0;
}

// In The Name Of God

#include <bits/stdc++.h>

using namespace std;

int n, help = 1e8, ind, ind2, help2;
const int MAXN = 110;
int a[MAXN];

void check()
{
	cin >> n;
	for(int i = 0; i < n; i ++)
	{
		cin >> a[i];
		if(a[i] <= help)
			ind = i;
		if(a[i] >= help2)
			ind2 = i;
		help = min(help , a[i]);
		help2 = max(help2, a[i]);
	}

	if(ind < (n / 2) and ind != 0)
		cout << (n - 1) - ind2 << endl;
	else if(ind < n / 2 and ind == 0)
		cout << n - 1 << endl;
	else
	{
	if(ind >= (n / 2) and ind == (n - 1))
		cout << n - 1 << endl;
	else
		cout << (n - 1) - ind << endl;
	}
}

int main()
{
	check();

	return 0;
}