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.

import java.util.*;
public class CF676A {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int ans = 0;
		for(int i = 0; i < n; i ++)
		{
			int x = in.nextInt();
			if(x==n||x==1)
			{
				ans = Math.max(ans, n-i-1);
				ans = Math.max(ans, i);
				if(i==0||i==n-1)
					ans = n-1;
			}
		}
		System.out.println(ans);
	}
}

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

/**
 * See
 * CF676ANicholasAndPermutation
 *
 * @author Brian Yeicol Restrepo Tangarife
 */
public class CF676ANicholasAndPermutation {

	static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException {
		String n = read();
		int ni = Integer.parseInt(n);
		String[] a = read().split("\\s");
		int pos1 = 0, posn = 0;
		for (int i = 0; i < ni; i++) {
			if (a[i].equals("1")) {
				pos1 = i + 1;
				if (posn != 0) {
					break;
				}
			} else if (a[i].equals(n)) {
				posn = i + 1;
				if (pos1 != 0) {
					break;
				}
			}
		}
		int max = Math.max(posn - 1, pos1 - 1);
		max = Math.max(max, Math.abs(ni - pos1));
		max = Math.max(max, Math.abs(ni - posn));
		out.print(max);
		//out.print(ni - Math.min(pos1, posn));
		out.close();
	}

	private static String read() throws IOException {
		return in.readLine();
	}

}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        int i1 = 0, i2 = 0;
        for (int i = 0; i < N; i++) {
            int v = scanner.nextInt();
            if (v == 1) {
                i1 = i;
            } else if (v == N) {
                i2 = i;
            }
        }
        int[] dis = {N-1-i1, N-1-i2, i1, i2};
        int result = 0;
        for (int i = 0; i < dis.length; i++) {
            result = Math.max(result, dis[i]);
        }
        System.out.println(result);
    }

}

import java.io.*;
import java.util.InputMismatchException;
/* * */

public class _354_A implements Runnable{
    public static void main(String[] args) {
	    new Thread(null, new _354_A(),"Main",1<<27).start();
    }
    @Override
    public void run() {
        FastReader fd = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = fd.nextInt();
        int[] data = new int[n+1];
        for(int i = 1; i <= n; i++){
            data[fd.nextInt()] = i;
        }
        if(data[1] == 1 && data[n] == n){
            out.println(n-1);
        }
        else{
            int min = Math.max(Math.abs(data[n]-1),Math.abs(n-data[n]));
            int max = Math.max(Math.abs(data[1]-1),Math.abs(n-data[1]));
            out.println(Math.max(min,max));
        }
        out.close();
    }

    //Helper functions
    static int gcd(int a, int b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    static int lcm(int a, int b) {
        return (a*b)/gcd(a, b);
    }

    static boolean checkDistinct(int next){

        String process = String.valueOf(next);
        for(int i = 0;i < process.length()-1; i++){
            String character = String.valueOf(process.charAt(i));
            if(process.substring(i+1).contains(character)){ return false; }
        }
        return true;
    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

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

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

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

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

            int sgn = 1;

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

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

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

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

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

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

            return res.toString();
        }

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

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int[] number = new int[N];
        int a = 0, b = 0;
        for(int i = 0; i < N; i++){
            number[i] = input.nextInt();
            if(number[i] == 1)
                a = i;
            if(number[i] == N)
                b = i;
        }
    if(b < a) {
        int c = b;
        b = a;
        a = c;
    }
            if((a-0)<=(N-1-b)){
                System.out.println(N-1-a);
                return;
            }
            if((a-0)>(N-1-b)){
                System.out.println(b);
                return;
            }
        }
    }

import java.util.Scanner;

public class NicholasPermutation {
    public static int max2 (int a, int b) {
        if(a >= b)
            return a;
        else
            return b;
    }

    public static void main(String [] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        int [] arr = new int [N];

        //scan the number
        int imin=0,imax=0;
        for(int i = 0; i < N; i++) {
            arr[i] = s.nextInt();
            if(arr[i] == N)
                imax = i;
            if(arr[i] == 1)
                imin = i;
        }
        if(imax > imin) {
            System.out.println(max2(imax-0,N-imin-1));
        } else {
            System.out.println(max2(imin-0,N-imax-1));
        }
        /*debugging
        for(int i = 0; i < N; i++) {
            System.out.print(arr[i] + " ");
        }*/
    }
}

import java.util.*;
public class HelloWorld{

     public static void main(String []args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int iPosition = -1, nPosition = -1;

        for(int i=1;i<=n;i++) {
            int value = in.nextInt();
            if(value == 1){
                iPosition = i;
            }
            if(value == n){
                nPosition = i;
            }
        }
        in.close();
        int distance = Math.max(Math.abs(nPosition - n) , Math.abs(nPosition - 1));
        distance = Math.max(distance, Math.max(Math.abs(iPosition - n), Math.abs(iPosition - 1)));
        System.out.println(distance);
     }
}

   import java.util.Arrays;
   import java.util.Scanner;
   public class moha {
       Scanner inp=new Scanner(System.in);

       public static void main(String[] args) {
            Scanner inp=new Scanner(System.in);
            int size=inp.nextInt();
            int array[]=new int[size];
           for (int i = 0; i < size; i++) {
               array[i]=inp.nextInt();
           }
             int min=array[0];
           int max=array[0];
           int first=1,second=1;
           for (int i = 0; i < size; i++) {
               if (array[i] > max) {
                   max=array[i];
                   first=i+1;
               }
              if(array[i]<min){
                  min=array[i];
                  second=i+1;
              }

           }
              int f1=Math.max(first-1,size-first);
           int f2=Math.max(second-1,size-second);
           int f3=Math.max(f1,f2);

           System.out.println(f3);

       }

   }

import java.util.Scanner;
import java.math.*;

public class Hellowrodl {

	private static int j = 0;

	public static void main(String[] args) {
		int min=0,max=0;
		Scanner  x = new Scanner(System.in);
		int n=x.nextInt();
		int array[]=new  int[n];
		for(int i=0;i<array.length;i++){
			array[i]=x.nextInt();
		}
		for(int j=0;j<array.length;j++){
			if(array[j]==1){
				min =j;
				break;}
		}
		for(int k=0;k<array.length;k++){
			if(array[k]==n){
				max=k;
				break;
			}
		}
		int Rmin=Math.min(min, max);
		int Rmax=Math.max(min, max);

		System.out.println(Math.max(array.length -1-Rmin, Rmax));

	}
}

import java.util.Collections;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int nums [] = new int[n];

		int posmin = 0;
		int posmax = 0;

		for(int i = 0; i < n; i++){
			nums[i] = scan.nextInt();
			if(nums[i]==1)	posmin = i;
			if(nums[i]==n) posmax = i;
		}

		int res = 0;
		int poss[] = {posmin, posmax, n-1-posmin, n-1-posmax};
		res = max(poss);

		System.out.println(res);

	}

	public static int max(int arr[]){
		int max = Integer.MIN_VALUE;
		int len = arr.length;
		for(int i = 0; i < len; i++){
			max = arr[i] >= max ? arr[i] : max;
		}
		return max;
	}

}

import java.util.*;
public class P1{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] a=new int[n];
        int max=Integer.MIN_VALUE,min=Integer.MAX_VALUE,mxi=-1,mni=-1;
        for(int i=0;i<n;++i){
            a[i]=sc.nextInt();
            if(a[i]>max){max=a[i];mxi=i;}
            if(a[i]<min){min=a[i];mni=i;}
        }
        int temp=n/2,ans1=0,ans2=0;
        ans1=Math.max(mxi,n-1-mxi);
        ans2=Math.max(mni,n-1-mni);
        System.out.println(Math.max(ans1,ans2));
    }
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package Round354;
    import java.util.*;

/**
 *
 * @author Afzal
 */
public class num1 {

    public static void main(String [] Args){
        Scanner input=new Scanner(System.in);
        int iSize =Integer.parseInt( input.nextLine());
        String sInput = input.nextLine();
        String sTest = sInput.replace(" ", "");

        String[] arr1 =sInput.split(" ");
        int[] arr = new int[iSize];

        for(int i=0;i<=iSize-1;i++){
           arr[i] = Integer.parseInt(arr1[i]);
           arr[i] = Integer.parseInt(arr1[i]);

        }
        Arrays.sort(arr);
       int iMin=arr[0];
        int iMax =arr[iSize-1];
        int iPosMin=-1;
        int  iPosMax=-1;
        for(int i=0;i<=iSize-1;i++){
            if(Integer.parseInt(arr1[i]) == iMin)
                iPosMin =i;

            if(Integer.parseInt(arr1[i]) == iMax)
                iPosMax =i;
            if(iPosMax != -1 && iPosMin != -1)
                break;
        }

        if(iPosMax == 0 || iPosMin == 0 || iPosMax == iSize-1 || iPosMin == iSize-1  ){
          System.out.println ( iSize-1 );
        }else{
            int iMid = (iSize+1)/2;
            if(iPosMax < iPosMin){
                if(iPosMax+1 >= iMid){
                     System.out.println(iPosMin);
                }
                else{
                     System.out.println(Math.max(iSize-1- Math.min(iPosMin, iPosMax),  iPosMin));
                }
            }
            else{
                if(iPosMin+1 >= iMid){
                    System.out.println(iPosMax);
                }
                else{
                     System.out.println(Math.max(iSize-1- Math.min(iPosMin, iPosMax),  iPosMax));
                }
            }
        }

        //int iRes = new String(arr);
    }
}

import java.util.Scanner;
public class Nicholas_and_Permutation {
	public static void main(String args[]){
		Scanner s = new Scanner(System.in);
		int n=s.nextInt();
		int max=n;
		int min=1;
		int maxp=0,minp=0,diff1=0,diff2;
		for(int i=1;i<=n;i++){
			int l=s.nextInt();
			if(l==max)
				maxp=i;
			else if(l==min)
				minp=i;
			else
				;
		}
		if(minp < maxp){
			diff1=n-minp;
			diff2=maxp-1;
			if(diff1>diff2)
				maxp=n;
			else
				minp=1;
		}
		else{
			diff1=n-maxp;
			diff2=minp-1;
			if(diff1>diff2)
				minp=n;
			else
				maxp=1;

		}
		System.out.println(Math.abs(maxp-minp));
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * Created by mohannadhassan on 5/25/16.
 */
public class NicholasAndPermutation {

    public static void main(String [] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        String[] input = br.readLine().split(" ");
        int [] numbers = new int[n];

        for (int i = 0; i < n; i++) {
            numbers[i] = Integer.parseInt(input[i]);
        }

        int first = -1, last = -1;

        for (int i = 0; i < n && (first < 0 || last < 0); i++) {
            if (numbers[i] == 1) {
                first = i;
            }
            else if (numbers[i] == n) {
                last = i;
            }
        }

        int [] arr = {first, last};
        java.util.Arrays.sort(arr);

        if (n - arr[1] - 1 > arr[0] - 0) {
            System.out.println(n - 1 - arr[0]);
        }
        else  {
            System.out.println(arr[1] - 0);
        }
    }
}

import java.util.*;
public class mrje {
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a=0,b=0;
		for(int i=1;i<=n;i++) {
			int t=sc.nextInt();
			if(t==1)
				a=i;
			if(t==n)
				b=i;
		}
		if(a<b) {
			System.out.println(Math.max(b-1,n-a));
		}else {
			System.out.println(Math.max(a-1, n-b));
		}
	}
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        List<Integer> array = new ArrayList<>();

        for (int i = 0; i < size; i++){
            array.add(sc.nextInt());
        }

        int result = findPositionMin(array);
        System.out.println(result);

    }

    public static int findPositionMin(List<Integer> array){
        int minP = 0;
        int maxP = 0;
        for (int i = 1; i < array.size(); i++){
            if (array.get(minP) > array.get(i)){
                minP = i;
            }
            if (array.get(maxP) < array.get(i)){
                maxP = i;
            }
        }

        if (minP == 0 || maxP == 0 || minP == array.size() - 1 || maxP == array.size() - 1){
            return array.size() - 1;
        }

        List<Integer> distances = new ArrayList<>();
        distances.add(minP);
        distances.add(maxP);
        distances.add(array.size() - 1 - minP);
        distances.add(array.size() - 1 - maxP);

        int maxDistance = distances.get(0);

        for (int i = 1; i < 4; i++){
            if (maxDistance < distances.get(i)){
                maxDistance = distances.get(i);
            }
        }

        return maxDistance;
    }
}

import java.util.Scanner;

public class Solution
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int minIdx=-1;
		int minVal=Integer.MAX_VALUE;
		int maxIdx=-1;
		int maxVal=Integer.MIN_VALUE;
		sc.nextLine();
		for(int i=0;i<n;i++)
		{
			int curr=sc.nextInt();
			if(minIdx==-1||curr<minVal)
			{
				minIdx=i;
				minVal=curr;
			}
			if(maxIdx==-1||curr>maxVal)
			{
				maxIdx=i;
				maxVal=curr;
			}
		}
		if((minIdx==0 && maxIdx==n-1)||(minIdx==n-1 && maxIdx==0))
		{
			System.out.println(n-1);
		}
		else if(minIdx<maxIdx)
		{
			System.out.println(Math.max(maxIdx,n-1-minIdx));
		}else
		{
			System.out.println(Math.max(minIdx, n-1-maxIdx));
		}
	}
}

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

public class Main {

    private static int min, max;

    public static void main(String[] args) throws IOException {
        Reader in = new Reader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        int n = in.nextInt();
        int[] a = new int[n];
        int p1 = -1, p2 = -1;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            if (a[i] == 1) {
                p1 = i;
            } else if (a[i] == n) {
                p2 = i;
            }
        }

        int ans = Math.abs(p2-p1);
        ans = Math.max(ans, Math.abs(p2));
        ans = Math.max(ans, Math.abs(p2 - n + 1));
        ans = Math.max(ans, Math.abs(p1));
        ans = Math.max(ans, Math.abs(p1 - n + 1));

        System.out.println(ans);

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

    static class Reader {
        BufferedReader reader;
        StringTokenizer st;

        Reader(InputStreamReader stream) {
            reader = new BufferedReader(stream);
            st = null;
        }

        void close() throws IOException {
            reader.close();
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

        String nextLine() throws IOException {
            return reader.readLine();
        }

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

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

    }
}

import java.util.*;

public class A354
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int min = 101, max = -101, n, x, minp = 0, maxp = 0;

		n = sc.nextInt();
		for(int i = 0; i < n; i++)
		{
			x = sc.nextInt();
			if(x < min)
			{
				min = x;
				minp = i+1;
			}
			if(x > max)
			{
				max = x;
				maxp = i+1;
			}
		}
		min = n - Math.min(maxp, minp);
		max = Math.max(minp, maxp) - 1;
		System.out.println(Math.max(max, min));
	}

}

import java.util.Scanner;
public class Main{

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int maxValue = 1;
		int minValue = 1;
		int maxLoc = 1;
		int minLoc = 1;
		for(int i = 1; i <= n;i++){
		    if(i==1){
		        int value = sc.nextInt();
		        maxValue = value;
		        minValue = value;
		    }else{
		        int value = sc.nextInt();
		        if(maxValue<value){
		            maxValue = value;
		            maxLoc = i;
		        }
		        if(minValue>value){
		            minValue = value;
		            minLoc = i;
		        }
		    }
		}
		if(maxLoc>minLoc){
		    if((n-maxLoc)>(minLoc-1))
		        System.out.println(n-minLoc);
		    else
		        System.out.println(maxLoc-1);
		}else{
		    if((n-minLoc)>(maxLoc-1))
		        System.out.println(n-maxLoc);
		    else
		        System.out.println(minLoc-1);
		}

	}

}

import java.util.*;
public class Main{
       public static void main(String[] args){
              Scanner sc = new Scanner(System.in);
              int currentMax = Integer.MIN_VALUE;
              int currentMin = Integer.MAX_VALUE;
              int indexMin = 0;
              int indexMax = 0;
              int start = 0;
              int length = sc.nextInt() - 1;
              while (sc.hasNextInt()){
                     int newNumber = sc.nextInt();
                     if (currentMax <= newNumber){
                            indexMax = start;
                            currentMax = newNumber;
                     }
                     if (currentMin >= newNumber){
                            indexMin = start;
                            currentMin = newNumber;
                     }
                     start++;
              }
              int distanceBackMin = length - indexMin;
              int distanceBackMax = length - indexMax;
              int maxBack = Math.max(distanceBackMin,distanceBackMax);
              int maxFront = Math.max(indexMin,indexMax);
              System.out.print(Math.max(maxBack,maxFront));
       }
}

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int[] number = new int[N];
        int a = 0, b = 0;
        for(int i = 0; i < N; i++){
            number[i] = input.nextInt();
            if(number[i] == 1)
                a = i;
            if(number[i] == N)
                b = i;
        }
    if(b < a) {
        int c = b;
        b = a;
        a = c;
    }
            if((a-0)<=(N-1-b)){
                System.out.println(N-1-a);
                return;
            }
            if((a-0)>(N-1-b)){
                System.out.println(b);
                return;
            }
        }
    }

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {

	public static void main(String[]agres){
		ArrayList<Integer>arr=new ArrayList();
		ArrayList<Integer>s=new ArrayList();
		Scanner input=new Scanner(System.in);
		//int [] arr=new int [5];
		int n,h,num,r1=0,r2=0,s1=0,s6=0,s7=0;
		n=input.nextInt();
		for(int i=0;i<n;i++){
			num=input.nextInt();
			arr.add(num);
		}

		int first=arr.get(0);
		int last=arr.get(n-1);
		long  min=1000000000;
		long  max=-1000000000;
		int maxind=0,minind=0;
		for(int i=0;i<n;i++){
			if(arr.get(i)>max){
				max=arr.get(i);
				maxind=i;
			}
			if(arr.get(i)<min){
				min=arr.get(i);
				minind=i;
			}

		}
		int t1=Math.abs(maxind-0);
		int t2=Math.abs(maxind-(n-1));
		int t3=Math.abs(minind-0);
		int t4=Math.abs(minind-(n-1));

		s.add(t1);
		s.add(t2);
		s.add(t3);
		s.add(t4);
		Collections.sort(s);
	    System.out.println(s.get(3));

		//System.out.println(max);
		//System.out.println(max2);

	}

}

import java.util.Scanner;
public class PersonInformation {
static void swap (int elem1 ,int elem2)
{
		int temp=elem1;
		elem1=elem2;
		elem2=temp;
}
	public static void main(String[] args) {
	Scanner in=new Scanner(System.in);
		int a[]=new int[100000];
		int n=in.nextInt();
		for(int i=1;i<=n;i++)
		{
			a[i]=in.nextInt();
		}
		int x = 0;
		int min=a[1];
		int max=a[1];
		int indexMin=1;
		int indexMax=1;
		for(int i=1;i<=n;i++)
		{
			if(min>a[i])
			{
				min=a[i];
				indexMin=i;
			}
			if(max<a[i])
			{
				max=a[i];
				indexMax=i;

			}
			if(min==a[1] && max==a[n])
			{
				swap(n,n);
				x=n-1;
			}
			if(min==a[n] && max==a[1])
			{
				swap(n,n);
				x=n-1;
			}
			else
			{
				int counter1=0,counter2=0;
				if(indexMax>indexMin)
				{
					for(int i1=indexMax;i1<=n;i1++)
					{
						counter1++;
					}
					for(int j=1;j<=indexMin;j++)
					{
						counter2++;
					}
					if(counter1>counter2)
					{
						swap(a[n],a[indexMax]);
						x=n-indexMin;
					}
					else
					{
						swap(a[indexMin],a[1]);
						x=indexMax-1;
					}
				}
				else
				{
					for(int i1=indexMin;i1<=n;i1++)
					{
						counter2++;
					}
					for(int j=1;j<=indexMax;j++)
					{
						counter1++;
					}
					if(counter1>counter2)
					{
						swap(a[indexMax],a[1]);
						x=indexMin-1;
					}
					else
					{
						swap(a[indexMin],a[n]);
						x=n-indexMax;
					}
				}
			}
		}
			System.out.println(x);
		}
}

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;
import java.io.*;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		// Scanner read = new Scanner(new FileInputStream(new
		// File("input.txt")));
		// PrintWriter out = new PrintWriter(new File("output.txt"));
		Scanner read = new Scanner(System.in);
		int n = read.nextInt(), arr[] = new int[n], max = -1, min = 1000, indexmax = 0, indexmin = 0;
		for (int i = 0; i < n; i++) {
			arr[i] =  read.nextInt();
			if (arr[i] <= min) {
				min = arr[i];
				indexmin = i;
			}
		}
		for(int i = 0 ; i < n; i++){
			if ( arr[i]>= max) {
				max = arr[i];
				indexmax = i;
			}
		}
		System.out.println(Math.max(indexmax, Math.max(indexmin, Math.max(n-1-indexmin, n-1-indexmax))));
	}
}

//################################################################################################################
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.math.BigInteger;
import java.util.InputMismatchException;

//################################################################################################################
public class R354D2A {
	public static void main(String[] args) {
		R354D2A a = new R354D2A();
		InputReader1 reader = a.new InputReader1(System.in);
		OutputWriter writer = a.new OutputWriter(System.out);
		// think about the brute-force approach
		// read input
		// code boundary conditions
		int n = reader.readInt();
		int[] arr = new int[n];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = reader.readInt();
		}
		if ((arr[0] == 1 && arr[n - 1] == n)
				|| (arr[0] == n && arr[n - 1] == 1)) {
			writer.println(n - 1);
		} else if (arr[0] == 1 || arr[0] == n) {
			writer.println(n - 1);
		} else if (arr[n - 1] == 1 || arr[n - 1] == n) {
			writer.println(n - 1);
		} else {
			int p1, pn;
			p1 = -1;
			pn = -1;
			int nh = n / 2;
			for (int i = 0; i < arr.length; i++) {
				if (arr[i] == 1) {
					p1 = i;
				} else if (arr[i] == n) {
					pn = i;
				}
			}
			if (p1 < nh && pn < nh) {
				writer.println(n - 1 - Math.min(p1, pn));
			} else if (p1 >= nh && pn >= nh) {
				writer.println(Math.max(p1, pn));
			} else {
				if (p1 > pn) {
					writer.println(Math.max(p1, n - 1 - pn));
				} else {
					writer.println(Math.max(pn, n - 1 - p1));
				}
			}
		}
		reader.close();
		writer.close();
	}

	class InputReader1 {
		// private final boolean finished = false;

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

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

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

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

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

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

		public String readString() {
			int length = readInt();
			if (length < 0)
				return null;
			byte[] bytes = new byte[length];
			for (int i = 0; i < length; i++)
				bytes[i] = (byte) read();
			try {
				return new String(bytes, "UTF-8");
			} catch (UnsupportedEncodingException e) {
				return new String(bytes);
			}
		}

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

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public BigInteger readBigInteger() {
			try {
				return new BigInteger(readString());
			} catch (NumberFormatException e) {
				throw new InputMismatchException();
			}
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

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

		public boolean isExhausted() {
			int value;
			while (isSpaceChar(value = peek()) && value != -1)
				read();
			return value == -1;
		}

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

		public boolean readBoolean() {
			return readInt() == 1;
		}

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

	class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream stream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
					stream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void println(String s) {
			writer.println(s);
		}

		public void println(int x) {
			writer.println(x);
		}

		public void print(int x) {
			writer.print(x);
		}

		public void println(long x) {
			writer.println(x);
		}

		public void printSpace() {
			writer.print(" ");
		}

		public void close() {
			writer.close();
		}
	}
}

 //package com.company;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.sql.SQLOutput;
import java.util.*;
public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        //BufferedReader s=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb1 = new StringBuilder();//int n=Integer.parseInt(s.readLine());
        int n=s.nextInt();int min=Integer.MAX_VALUE;int max=Integer.MIN_VALUE;
        int mi=0;int ma=0;int[] a=new int[n];
        for(int i=0;i<n;i++){a[i]=s.nextInt();
            if(a[i]<min){
                min=a[i];
                mi=i;
            }if(a[i]>max){
                max=a[i];
                ma=i;
            }
        }
        int ans=Math.max(ma,Math.max(n-ma-1,Math.max(mi,n-1-mi)));
        System.out.println(ans);
    }static int ans1=Integer.MAX_VALUE;static int[] vis;
    static   int[] dp;static Queue<Integer>q;
    static void newdfs(int i1,char[][] a,int k,int n,int val){
        while(!q.isEmpty()){
            int i=q.poll();
            vis[i]=1;

            for(int j=i;j<=Math.min(n-1,i+k);j++){
                if(a[i][j]=='1'&&(vis[j]==0)&&dp[i]+1<dp[j]){
                    dp[j]=dp[i]+1;
                    q.add(j);
                }
            }for(int j=i;j>=Math.max(0,i-k);j--){
                if(a[i][j]=='1'&&(vis[j]==0)&&dp[j]+1<dp[i]){
                    dp[j]=dp[i]+1;
                    q.add(j);
                }
            }}
    }
    static  void computeLPSArray(String pat, int M, int lps[])
    {
        int len = 0;
        int i = 1;
        lps[0] = 0;
        while (i < M) {
            if (pat.charAt(i) == pat.charAt(len)) {
                len++;
                lps[i] = len;
                i++;
            }
            else // (pat[i] != pat[len])
            {
                if (len != 0) {
                    len = lps[len - 1];
                }
                else // if (len == 0)
                {
                    lps[i] = len;
                    i++;
                }
            }
        }
    }
    static boolean isPrime(int n)
    {
        // Corner cas
        if (n <= 1) return false;
        if (n <= 3) return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        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;
    }
    static boolean isPrime(int n, int k)
    {
        // Corner cases
        if (n <= 1 || n == 4) return false;
        if (n <= 3) return true;

        // Try k times
        while (k > 0)
        {
            // Pick a random number in [2..n-2]
            // Above corner cases make sure that n > 4
            int a = 2 + (int)(Math.random() % (n - 4));

            // Fermat's little theorem
            if (power(a, n - 1, n) != 1)
                return false;

            k--;
        }

        return true;
    }
    static double power(double x, long y, int p) {
        double res = 1;
        x = x % p;
        while (y > 0) {
            if ((y & 1) == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }
    public static void fracion(double x) {
        String a = "" + x;
        String spilts[] = a.split("\\."); // split using decimal
        int b = spilts[1].length(); // find the decimal length
        int denominator = (int) Math.pow(10, b); // calculate the denominator
        int numerator = (int) (x * denominator); // calculate the nerumrator Ex
        // 1.2*10 = 12
        int gcd = (int)gcd((long)numerator, denominator); // Find the greatest common
        // divisor bw them
        String fraction = "" + numerator / gcd + "/" + denominator / gcd;
        // System.out.println((denominator/gcd));
        long x1=modInverse(denominator / gcd,998244353  );
        //  System.out.println(x1);
        System.out.println((((numerator / gcd )%998244353 *(x1%998244353  ))%998244353  ) );
    }static int max=Integer.MIN_VALUE;
    static int max1=Integer.MIN_VALUE;static int[][] c;static int k=1;static int bhoo=0;
    static int[] car;static int ans;static HashMap<Integer,Integer>[] ha;
    public static void dfs(int ans2,int papa, int i, ArrayList<Integer>[] h, int[] vis,HashMap<Integer,Integer>[] bad) {
        vis[i] = 1;
        if(i!=1&&h[i].size()==1){
            if(ans2!=-1)  {ans++;  sb1.append(ans2+" ");}
        }
        if(h[i]==null) return;
        int hu=0;int hai=0;
        for(Integer j:h[i]){
            if(vis[j]==0&&bad[i].containsKey(j)) {
                hai=1;break;
            }
        }int khi=0;
        for(Integer j:h[i]) {//if(vis[j]==0) flag=1;
            if(vis[j]==0){
                if(!bad[i].containsKey(j)){
                    if(hai==0&&khi==0){khi=1;    dfs(ans2,papa,j,h,vis,bad);}
                    else dfs(-1,papa,j,h,vis,bad);
                }else{
                    if(hu==0){
                        if(papa==0){//ans++;//sb1.append(j+" ");
                            dfs(j,1,j,h,vis,bad);
                        }else{
                            hu=1;
                            dfs( j,1,j,h,vis,bad);}
                    }else{
                        //    ans++;//sb1.append(j+" ");
                        dfs(j,1,j,h,vis,bad);
                    }
                }
            }
        }//if(flag==1) bhoo=-1;
    }static StringBuilder sb1=new StringBuilder();
    public static void bfs(int i, HashMap<Integer, Integer>[] h, int[] vis, int len, int papa) {
        Queue<Integer> q = new LinkedList<Integer>();
        q.add(i);
    }
    static int i(String a) {
        return Integer.parseInt(a);
    }
    static long l(String a) {
        return Long.parseLong(a);
    }
    static String[] inp() throws IOException {
        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
        return s.readLine().trim().split("\\s+");
    }

    static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    static long modInverse(int a, int m)
    {

        {
            // If a and m are relatively prime, then modulo inverse
            // is a^(m-2) mode m
            return (power(a, m - 2, m));
        }
    }

    // To compute x^y under modulo m
    static long power(int x, int y, int m)
    {
        if (y == 0)
            return 1;

        long p = power(x, y / 2, m) % m;
        p = (p * p) % m;

        if (y % 2 == 0)
            return p;
        else
            return (x * p) % m;
    }

    // Function to return gcd of a and b

}
class Student
{
    int l;int r;int i;
    public Student(int l, int r,int i) {
        this.l = l;
        this.r = r;this.i=i;
    }
    // Constructor

    // Used to print student details in main()
    public String toString()
    {
        return this.l+" ";
    }
}

class Sortbyroll implements Comparator<Student>
{
    // Used for sorting in ascending order of
    // roll number
    public int compare(Student a, Student b){
        return a.l-b.l;  }
} class Sortbyroll1 implements Comparator<Student>
{
    // Used for sorting in ascending order of
    // roll number
    public int compare(Student a, Student b){
        return a.l-b.l;
    }
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package javaapplication8;

import java.util.Scanner;
/**
 *
 * @author Himanshu Khare
 */
public class JavaApplication8 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int n,max,min,im,in,k1,k2,k3,k4,ans;
        int []a= new int[1001];
        Scanner input=new Scanner(System.in);
        n=input.nextInt();
        max=k1=k2=k3=k4=im=in=0;
        min=n+1;
        for(int i=1;i<=n;i++)
        {
            a[i]=input.nextInt();
            if(a[i]>max)
            {
                max=a[i];
                im=i;
            }
            if(a[i]<min)
            {
                min=a[i];
                in=i;
            }
        }

        k1=Math.abs(im-1);
        k2=Math.abs(im-n);
        if(k1>k2)
            ans=k1;
        else
            ans=k2;
        k3=Math.abs(in-1);
        if(k3>ans)
            ans=k3;
        k4=Math.abs(in-n);
        if(k4>ans)
            ans=k4;
       System.out.println(ans);

    }

}

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author SONY
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        ArrayList<Integer> arr = new ArrayList<Integer>();
        for (int i = 0; i < n; i++){
            arr.add(input.nextInt());
        }
        int max = arr.get(0);
        int min = arr.get(0);
        int indexMax = 0;
        int indexMin = 0;
        // Find max, min, indexMax and indexMin
        for (int p = 1; p < n; p++){
            if (arr.get(p) > max){
                max = arr.get(p);
                indexMax = p;
            }
            if (arr.get(p) < min){
                min = arr.get(p);
                indexMin = p;
            }
        }
        //measure the distance
        int[] distance = new int [4];
        distance[0] = (n-1) - indexMax;
        distance[1] = indexMax;
        distance[2] = (n-1) - indexMin;
        distance[3] = indexMin;
        int distanceMax = distance[0];
        for (int d = 1; d < 4; d++){
            if (distance[d] > distanceMax){
                distanceMax = distance[d];
            }
        }
        System.out.print(distanceMax);
        return;
    }
}

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A764 {
    public static void main(String [] args) {
        InputStream inputReader = System.in;
        OutputStream outputReader = System.out;
        InputReader in = new InputReader(inputReader);
        PrintWriter out = new PrintWriter(outputReader);
        Algorithm solver = new Algorithm();
        solver.solve(in, out);
        out.close();
    }
}

class Algorithm {
    void solve(InputReader ir, PrintWriter pw) {
        int n = ir.nextInt();
        int [] array = new int[n];
        int min = 0;
        int max = 0;

        for (int i = 0; i < n; i++) array[i] = ir.nextInt();
        int minPos = array[0];
        int maxPos = array[0];
        int total = 0;

        for (int i = 0; i < n; i++) {
            if (array[i] > maxPos) {
                max = i;
                maxPos = array[i];
            } else if (array[i] < minPos) {
                min = i;
                minPos = array[i];
            }
        }

        if (min < max) {
            if (min == 0 || max == n - 1) {
                total = n - 1;
            } else if (min + 1 > (n - max - 1)) {
                total = max;
            } else {
                total = n - min - 1;
            }

        } else {
            if (max == 0 || min == n - 1) {
                total = n - 1;
            } else if (max + 1 > (n - min - 1)) {
                total = min;
            } else {
                total = n - max - 1;
            }
        }

        pw.print(total);

    }

}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

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

}

//package Codeforces;

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

public class NicholasAndPermutation
{

	public static void main(String[] args) throws Exception
	{
		int n = readInt(), max = 0, min = 0, v[] = new int[n];
		for (int i = 0; i < n; i++)
		{
			v[i] = readInt();
			max = (v[i] > v[max] ? i : max);
			min = (v[i] < v[min] ? i : min);
		}
		System.out.println(Math.max(min,
				Math.max(max, Math.max(n - 1 - max, n - 1 - min))));
	}

	static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	static PrintWriter out = new PrintWriter(new BufferedWriter(
			new OutputStreamWriter(System.out)));
	static StringTokenizer st;

	static String next() throws IOException
	{
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine().trim());
		return st.nextToken();
	}

	static long readLong() throws IOException
	{
		return Long.parseLong(next());
	}

	static int readInt() throws IOException
	{
		return Integer.parseInt(next());
	}

	static double readDouble() throws IOException
	{
		return Double.parseDouble(next());
	}

	static char readChar() throws IOException
	{
		return next().charAt(0);
	}

	static String readLine() throws IOException
	{
		return br.readLine().trim();
	}
}

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

public class Solution {

    static void solve(InputReader in, OutputWriter out) {
        int n = in.nextInt();

        int minp = 0, maxp = 0;
        for (int i = 0; i < n; i++) {
            int m = in.nextInt();

            if (m == 1) minp = i;
            if (m == n) maxp = i;
        }

        if (minp < maxp) {
            out.print(Math.max(maxp, n - minp - 1));
        } else {
            out.print(Math.max(minp, n - maxp - 1));
        }
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        solve(in, out);
        in.close();
        out.close();
    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        InputReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }

        String nextLine() {
            String line = null;
            try {
                line = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return line;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String line = nextLine();
                if (line == null) return null;
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

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

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

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

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

    static class OutputWriter {
        BufferedWriter bw;

        OutputWriter(OutputStream os) {
            bw = new BufferedWriter(new OutputStreamWriter(os));
        }

        void print(int i) {
            print(Integer.toString(i));
        }

        void println(int i) {
            println(Integer.toString(i));
        }

        void print(long l) {
            print(Long.toString(l));
        }

        void println(long l) {
            println(Long.toString(l));
        }

        void print(double d) {
            print(Double.toString(d));
        }

        void println(double d) {
            println(Double.toString(d));
        }

        void print(boolean b) {
            print(Boolean.toString(b));
        }

        void println(boolean b) {
            println(Boolean.toString(b));
        }

        void print(char c) {
            try {
                bw.write(c);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(char c) {
            println(Character.toString(c));
        }

        void print(String s) {
            try {
                bw.write(s);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(String s) {
            print(s);
            print('\n');
        }

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

import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
import java.lang.Math.*;

public class A {

	public static void main(String[] args) throws Exception {new A().run();}
	public FastIO file = new FastIO();
	public int ntc, ctc;
	public final long MOD = 1000000007L; //998244353L;
	public final int M0D = 1000000007; //998244353
	public final int N = 200005, dx[] = { 0, 1, 0, -1 }, dy[] = { 1, 0, -1, 0 };

	public void run() throws Exception {
		ntc = 1; //nextInt();
		for (ctc = 1; ctc <= ntc; ++ctc) solve();
		file.out.flush(); file.out.close();
	}

	void solve() {
		int n = nextInt();
		int a = 0;
		int b = 0;
		for (int i = 0; i < n; i++) {
			int x = nextInt();
			if (x == 1) {
				a = i;
			}
			else if (x == n) {
				b = i;
			}
		}
		int aa = Math.abs(b - a);
		int bb = Math.abs(n - b - 1);
		int cc = Math.abs(a);
		int dd = Math.abs(b);
		int ee = Math.abs(n - a - 1);
		println(max(max(max(max(aa, bb), cc), dd), ee));
	}

	void sort(long[] a) { shuffle(a); Arrays.sort(a); }
	void sort(int[] a) { shuffle(a); Arrays.sort(a); }
	void shuffle(long[] a) {
		for (int i = a.length - 1; i >= 0; i--) { int j = (int) (Math.random() * (i + 1)); a[i] ^= a[j] ^ (a[j] = a[i]); } }
	void shuffle(int[] a) {
		for (int i = a.length - 1; i >= 0; i--) { int j = (int) (Math.random() * (i + 1)); a[i] ^= a[j] ^ (a[j] = a[i]); } }
	long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
	long lcm(long x, long y) { return x / gcd(x, y) * y; }
	long mod(long n, long mod) { return (n % mod + mod) % mod; }
	long max(long a, long b) { return Math.max(a, b); }
	int max(int a, int b) { return Math.max(a, b); }
	long min(long a, long b) { return Math.min(a, b); }
	int min(int a, int b) { return Math.min(a, b); }
	long pow(long n, long p, long mod) { long ret = 1L;
	while (p > 0) { if (p % 2 != 0L) ret = mod(ret * n, mod); n = mod(n * n, mod); p >>= 1L; } return ret; }
	long pow(long n, long p) { long ret = 1L;
	while (p > 0) { if (p % 2 != 0L) ret *= n; n *= n; p >>= 1L; } return ret; }
	boolean 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; }
	String next() {return file.next();}
	int nextInt() {return file.nextInt();}
	long nextLong() {return file.nextLong();}
	double nextDouble() {return file.nextDouble();}
	String nextLine() {return file.nextLine();}
	void print(Object o) {file.out.print(o);}
	void println(Object o) {file.out.println(o);}
	void printf(String s, Object... o) {file.out.printf(s, o);}
	class FastIO {
		BufferedReader br;
		StringTokenizer st;
		PrintWriter out;
		public FastIO() {br = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);}
		String next() {while (st == null || !st.hasMoreElements()) {try {st = new StringTokenizer(br.readLine());} catch (IOException e) {e.printStackTrace();}}return st.nextToken();}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() {return Double.parseDouble(next());}
		String nextLine() {String str = "";try {str = br.readLine();} catch (IOException e) {e.printStackTrace();} return str;}
		void print(Object o) {out.print(o);}
		void println(Object o) {out.println(o);}
		void printf(String s, Object... o) {out.printf(s, o);} }
	class Pair<A, B> implements Comparable {
		A fi; B se;
		public Pair(A fi, B se) { this.fi = fi; this.se = se; }
		public boolean equals(Object o) { if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		Pair<?, ?> p = (Pair<?, ?>) o; if (!fi.equals(p.fi)) return false; return se.equals(p.se); }
		public int hashCode() { return 31 * fi.hashCode() + se.hashCode(); }
		public String toString() { return fi.toString() + " " + se.toString(); }
		<A, B> Pair<A, B> of(A a, B b) { return new Pair<A, B>(a, b); }
		public int compareTo(Object o) { Pair<?, ?> p = (Pair<?, ?>) o;
		if (fi.equals(p.fi)) return ((Comparable) se).compareTo(p.se); return ((Comparable) fi).compareTo(p.fi); } } }

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;

public class code {

	public static void main(String[] args) throws FileNotFoundException, InterruptedException {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int mass[]=new int[n];
		int i=0;
		if(n==2){
			System.out.println(1); return ;
		}
		while(n-->0){
			mass[i++]=in.nextInt();
		}
		int Max=mass[0];
		int Min=mass[0];
		int indMax=0;
		int indMin=0;
		for(i=0;i<mass.length;i++){
			if(Min>mass[i]){
				Min=mass[i];
				indMin=i;
			}
			if(Max<mass[i]){
				Max=mass[i];
				indMax=i;
			}
		}

		if(indMin==0 && indMax==mass.length-1){
			System.out.println(mass.length-1);
		}
		else if(indMax==0 && indMin==mass.length-1){
			System.out.println(mass.length-1);
		}

		else if(indMin<indMax){
			if(indMin<mass.length-indMax)
				System.out.println(mass.length-1-indMin);
			else
				System.out.println(indMax);
		}
		else{
			if(indMax<mass.length-indMin)
				System.out.println(mass.length-1-indMax);
			else
				System.out.println(indMin);
		}
	}

}

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int indexMin = 0;
        int indexMax = 0;
        for(int i = 0; i < n; i++) {
            int num = scan.nextInt();
            if(num == 1) {
                indexMin = i;
            }
            if(num == n) {
                indexMax = i;
            }
        }
        int max = Math.max(indexMin, indexMax);
        int min = Math.min(indexMin, indexMax);
        int res;
        if(min < n-1-max) {
            res = n-1 - min;
        } else {
            res = max;
        }
        System.out.println(res);
    }
}

// package cf676;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.InputMismatchException;

import static java.lang.Math.max;

public class CFA {
    private static final String INPUT = "6\n" +
            "6 5 4 3 2 1\n";

    private PrintWriter out;
    private FastScanner sc;

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

    public void run() {
        sc = new FastScanner(oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
        out = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        solve();
        out.flush();
        tr(System.currentTimeMillis() - s + "ms");
    }

    public void solve() {
        int n = sc.nextInt();
        int[] a = readIntArray(n);

        int pos1 = 0, posn = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == 1) pos1 = i;
            if (a[i] == n) posn = i;
        }

        int ans = max(max(pos1, n-pos1-1), max(posn, n-posn-1));
        System.out.println(ans);
    }

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

    /**
     * If searched element doesn't exist, returns index of first element which is bigger than searched value.

     * If searched element is bigger than any array element function returns first index after last element.

     * If searched element is lower than any array element function returns index of first element.

     * If there are many values equals searched value function returns first occurrence.

     */
    private static int lowerBound(long[] arr, long key) {
        int lo = 0;
        int hi = arr.length - 1;
        while (lo < hi) {
            int mid = (lo + hi) / 2;
            if (key <= arr[mid]) {
                hi = mid - 1;
            } else {
                lo = mid + 1;
            }
        }
        return arr[lo] < key ? lo + 1 : lo;
    }

    /**
     * Returns index of first element which is grater than searched value.
     * If searched element is bigger than any array element, returns first index after last element.
     */
    private static int upperBound(long[] arr, long key) {
        int lo = 0;
        int hi = arr.length - 1;
        while (lo < hi) {
            int mid = (lo + hi) / 2;
            if (key >= arr[mid]) {
                lo = mid + 1;
            } else {
                hi = mid;
            }
        }
        return arr[lo] <= key ? lo + 1 : lo;
    }

    private static int ceil(double d) {
        int ret = (int) d;
        return ret == d ? ret : ret + 1;
    }

    private static int round(double d) {
        return (int) (d + 0.5);
    }

    private static int gcd(int a, int b) {
        BigInteger b1 = BigInteger.valueOf(a);
        BigInteger b2 = BigInteger.valueOf(b);
        BigInteger gcd = b1.gcd(b2);
        return gcd.intValue();
    }

    private static long gcd(long a, long b) {
        BigInteger b1 = BigInteger.valueOf(a);
        BigInteger b2 = BigInteger.valueOf(b);
        BigInteger gcd = b1.gcd(b2);
        return gcd.longValue();
    }

    private int[] readIntArray(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = sc.nextInt();
        }
        return res;
    }

    private long[] readLongArray(int n) {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = sc.nextLong();
        }
        return res;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        FastScanner(InputStream stream) {
            this.stream = stream;
        }

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

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

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

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

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

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

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

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

    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (!oj) System.out.println(Arrays.deepToString(o));
    }
}

import java.util.*;

/**
 * Created by Harrison Fang on 5/25/2016.
 */
public class A {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int pos1 = -1, pos2 = -1;
        for (int i = 1; i <= n; i++) {
            int tmp = in.nextInt();
            if (tmp == 1) pos1 = i;
            if (tmp == n) pos2 = i;
        }

        int dst = Math.max(pos2 - 1, n - pos1);
        dst = Math.max(dst, pos1 - 1);
        dst = Math.max(dst, n - pos2);

        System.out.println(dst);
    }
}

import java.util.Scanner;

public class Problem676A {

    public static void main(String[] args) {
        Scanner numberInput = new Scanner(System.in);

        int n = numberInput.nextInt();
        int a[] = new int[n];

        for (int i = 0; i < a.length; i++) {
            a[i] = numberInput.nextInt();
        }

        int posOf1 = findPos(1, a);
        int posOfn = findPos(n, a);

        System.out.println(Math.max(Math.max(posOf1, posOfn), n - Math.min(posOf1, posOfn) - 1));

//        if (n == 2) {
//            System.out.println(1);
//        } else if (n == 3) {
//            System.out.println(2);
//        } else {
//            if (posOfn <= (n / 2)) {
//                sol = n - 1 - posOfn;
//            } else {
//                sol = n - 1 - posOf1;
//            }
//            System.out.println(sol);
//        }

    }

    public static int findPos(int key, int a[]) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] == key) {
                return i;
            }
        }
        return -1;
    }

}

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

public class Nicholas
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];

		int maxx = Integer.MIN_VALUE;
		int minx = Integer.MAX_VALUE;

		int p=0,q=0;

		for(int i=0;i<n;i++)
		{
			a[i] = in.nextInt();
			if(a[i]>maxx)
			{
				p = i;
				maxx = a[i];
			}
			if(a[i]<minx)
			{
				q =i;
				minx = a[i];
			}
		}
		//System.out.println(p + " " + q);
		if(p<(n/2) && q>=(n/2))
			System.out.println(Math.max(q,n-1-p));
		else if(p>=(n/2) && q<=(n/2))
			System.out.println(Math.max(p,n-1-q));
		else if(p>=(n/2) && q>=(n/2))
		{
			if(p<q)
				System.out.println(q);
			else
				System.out.println(p);
		}

		else if(p<=(n/2) && q<=(n/2))
		{
			if(p<q)
				System.out.println(n-1-p);
			else
				System.out.println(n-1-q);
		}
	}
}

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

public class A {

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

	}

	public static void main(String[] args) throws NumberFormatException, IOException {
//		FastScanner in = new FastScanner(new BufferedReader(new FileReader("input.txt")));
//		PrintWriter out = new PrintWriter(new File("output.txt"));

		FastScanner in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
		PrintWriter out = new PrintWriter(System.out);

		int n = in.nextInt();
		int x1 = -1, y1 = -1;
		for (int i = 0; i < n; i++) {
			int cur = in.nextInt();
			if (cur == 1) {
				x1 = i;
			} else if (cur == n) {
				y1 = i;
			}
		}

		int x = Math.min(x1, y1);
		int y = Math.max(x1, y1);

		out.println(Math.max(y, n - x - 1));

		out.close();
	}

}

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

/** Class: NicholasAndPermutation.java
 *  @author
 *  @version 1.0 <p>
 *  Course:
 *  Written / Updated: Jun 18, 2016
 *
 *  This Class -
 *  VERDICT:
 */
public class NicholasAndPermutation {

	private int[] numArr;
	private int minIndex, maxIndex;

	/**
	 * Constructor.
	 */
	public NicholasAndPermutation() {
		try {
			BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));

            //Read the first line
            String line = rd.readLine();

            StringTokenizer tokenizer = new StringTokenizer(line);
            int n = Integer.parseInt(tokenizer.nextToken());
            this.numArr = new int[n];
            this.minIndex = -1;
            this.maxIndex = -1;

            /* Read next line and populate the number array, and save the indices
             * of the min. and max. numbers. */
            line = rd.readLine();
            tokenizer = new StringTokenizer(line);

            for (int i = 0; i < n; i++) {
            	this.numArr[i] = Integer.parseInt(tokenizer.nextToken());
            	if (this.numArr[i] == 1) minIndex = i;
            	else if (this.numArr[i] == n) maxIndex = i;

            	/* UPDATE: We don't even need to read in all the numbers. As soon as we know
            	 * the positions of the min. and max. number, we can run the custom method ASAP. */
            	if (minIndex != -1 && maxIndex != -1) {
            		System.out.println(this.computeMaxDist());
            		break;
            	}
            }

            /* Print a single integer — the maximum possible distance between the minimum and the
             * maximum elements Nicholas can achieve by performing exactly one swap. */
//            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//            bw.write(this.computeMaxDist() + "\n");
//
//            bw.close();
            rd.close();
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}

	/**
	 * Method: computeMaxDist
	 * @return the max. possible distance that can be obtained between the min. and max. index,
	 * provided that we can make a single swap involving one of the indices.
	 */
	private int computeMaxDist() {
		/* Compare the min. and max. indices. Whichever index is CLOSER TO one of the endpoints of the num Array
		 * is the one that should stay in place, and the other index should be swapped with either the first
		 * or last element in the array, to maximize the distance. */
		int minIndexDistFromEndpoint = Math.min(this.minIndex - 0, (this.numArr.length - 1) - this.minIndex);
		int maxIndexDistFromEndpoint = Math.min(this.maxIndex - 0, (this.numArr.length - 1) - this.maxIndex);

		/* min index is closer to one of the endpoints. min index stays in place. max index will be
		 * swapped with one of the endpoints.
		 * Compute the max distance between the min. index and one of the endpoints, and return it. */
		if (minIndexDistFromEndpoint < maxIndexDistFromEndpoint) {
			return Math.max(minIndex - 0, numArr.length - 1 - minIndex);
		/* or vice versa. */
		} else {
			return Math.max(maxIndex - 0, numArr.length - 1 - maxIndex);
		}
	}

	public static void main(String[] args) {
		new NicholasAndPermutation();
	}
}

import java.util.Scanner;
public class Tester {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int nop,min=0,max=0,dis=0;
		nop=sc.nextInt();
		int num;
		for(int i=1;i<=nop;i++)
		{
			num=sc.nextInt();
			if(num==nop)
				max=i;
			else if(num==1)
				min=i;
		}
		if(max>min)
		{
			dis=dis+(max-min);
			if((min-1)>=(nop-max))
				dis=dis+(min-1);
			else
				dis=dis+(nop-max);
		}
		else
		{
			dis=dis+(min-max);
			if((max-1)>=(nop-min))
				dis=dis+(max-1);
			else
				dis=dis+(nop-min);
		}

		System.out.println(dis);
	}

}

import java.util.*;
public class Main {
  public static void main (String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    int len = in.nextInt();
    int min = -1;
    int max = -1;
    for(int i =0; i<len; i++){
      int num = in.nextInt();
      if(num==1){
        min = i;
      }
      if(num==len){
        max = i;
      }
    }
    int l = Math.min(min,max);
    int r = Math.max(min,max);
    int ans = Math.max(r,len-1-l);
    System.out.println(ans);
  }
}

import java.util.Scanner;

public class Palindrome
{
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int num=sc.nextInt();
		sc.nextLine();
		int[] arr=new int[num];
		int minposition = 0,maxposition = 0;
		for(int i=0;i<num;i++)
		{
			arr[i]=sc.nextInt();
			if(arr[i]==1)
				minposition=i+1;
			if(arr[i]==num)
				maxposition=i+1;
		}
		if(minposition>maxposition)
		{
			int temp=minposition;
			minposition=maxposition;
			maxposition=temp;
		}
		if(minposition-1>num-maxposition)
			System.out.println(maxposition-1);
		else
			System.out.println(num-minposition);
	}
}

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

public class a1 {
	public static void main(String[] args) throws FileNotFoundException {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = in.nextInt();

		int a[] = new int[n];
		int b[] = new int[n];

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

		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				for (int j2 = 0; j2 < n; j2++) {
					b[j2] = a[j2];
				}
				b[i] = a[j];
				b[j] = a[i];

				int ind1 = 0;
				int ind2 = 0;

				for (int j2 = 0; j2 < n; j2++) {
					if (b[j2] == 1){
						ind1 = j2;
					}

					if (b[j2] == n){
						ind2 = j2;
					}
				}

				min = Math.max(min, Math.abs(ind1 - ind2));
			}
		}

		out.println(min);
		out.close();
	}
}

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

//Arrays.stream(br.readLine().split("\\s")).mapToInt(Integer::parseInt).toArray();

public class solution{

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter pw = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException {
		String str = br.readLine();
		int n = Integer.parseInt(str);

		String[] a = br.readLine().split("\\s");

		int pos1 = 0, posn = 0;

		for (int i = 0; i < n; i++) {
			if (a[i].equals("1")) {
				pos1 = i + 1;
				if (posn != 0) {
					break;
				}
			} else if (a[i].equals(str)) {
				posn = i + 1;
				if (pos1 != 0) {
					break;
				}
			}
		}
		int max = Math.max(posn - 1, pos1 - 1);
		max = Math.max(max, Math.abs(n - pos1));
		max = Math.max(max, Math.abs(n - posn));
		pw.print(max);
		pw.close();
	}
}

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

public class A {

    static MyScanner in = new MyScanner();
    static   PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static long H,W;
    static BitSet bs;
    static long mod = 1000000007;
    public static void main(String args[]) throws IOException {
       int n = in.nextInt();
       int indexOne =-1;
       int indexn =-1;
       int []arr =  new int[n];
       for(int i=0;i<n;i++){
           arr[i] = in.nextInt();
           if(arr[i]==1){
               indexOne = i;
           }else  if(arr[i]==n){
               indexn=i;
           }
       }
       int max =-1;
       for(int i=0;i<n;i++){
            if(i!=indexn)
           max   = Math.max(Math.abs(i-indexn),max);
       }
       for(int i=0;i<n;i++){
            if(indexOne!=i){
                max = Math.max(Math.abs(i-indexOne), max);
            }
       }
       out.println(max);

    out.flush();

    }
    static boolean isVowel(char c){
        if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y'){
            return true;
        }
        return false ;
    }
    static class IP implements Comparable<IP>{
        public int first,second;
        IP(int first, int second){
            this.first = first;
            this.second = second;
        }
        public int compareTo(IP ip){
            if(first==ip.first)
                return second-ip.second;
            return first-ip.first;
        }

    }

       static long gcd(long a, long b){
        return b!=0?gcd(b, a%b):a;
    }

        static boolean isEven(long a) {
            return (a&1)==0;
        }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

     }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;

public class R354_1 {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int[] a = new int[n];
            int minI = 0;
            int maxI = 0;
            for (int i = 0; i < n; i++) {
                a[i] = in.readInt();
                if (a[i] == 1) minI = i;
                if (a[i] == n) maxI = i;
            }

            if (minI < maxI)
            {
                if (minI > n-1 - maxI) System.out.println(maxI);
                else System.out.println(n-1 - minI);
            }
            else
            {
                if (maxI > n-1 - minI) System.out.println(minI);
                else System.out.println(n-1 - maxI);
            }

        }

    }

    static class IOUtils {
        public static int[] readIntArray(InputReader in, int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++) {
                array[i] = in.readInt();
            }
            return array;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(int i) {
            writer.println(i);
        }

    }

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

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

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

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

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

        public char readCharacter() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            return (char) c;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class Main{

	public static void main(String arg[]){
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int V[]=new int[n+1];
		int x=0,y=0;

		for (int i = 0; i < n; i++) {
			V[i]=in.nextInt();
			if (V[i] == 1)x = i;
			if (V[i] == n)y = i;
		}
		int a = Math.min(x, y)+1;
		a = Math.min(a, n - x);
		a = Math.min(a, n - y);
		System.out.println(n-a);
	}
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        List<Integer> array = new ArrayList<>();

        for (int i = 0; i < size; i++){
            array.add(sc.nextInt());
        }

        int result = findPositionMin(array);
        System.out.println(result);

    }

    public static int findPositionMin(List<Integer> array){
        int minP = 0;
        int maxP = 0;
        for (int i = 1; i < array.size(); i++){
            if (array.get(minP) > array.get(i)){
                minP = i;
            }
            if (array.get(maxP) < array.get(i)){
                maxP = i;
            }
        }

        int distance;
        if (minP == 0 || maxP == 0 || minP == array.size() - 1 || maxP == array.size() - 1){
            return array.size() - 1;
        }

        if (minP < maxP) {
            if (minP > array.size() - 1 - maxP){
                distance = maxP;
            } else {
                distance = array.size() - 1 - minP;
            }
        } else {
            if (maxP > array.size() - 1 - minP){
                distance = minP;
            } else {
                distance = array.size() - 1 - maxP;
            }
        }

        return distance;
    }
}

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

public class test {

	@SuppressWarnings("resource")
	public static void main(String[] args){
		int num=0, min_pos=0, max_pos=0;

		Scanner scanner = new Scanner(System.in);

		num = scanner.nextInt();

		int[] permutation = new int[num];
		int[] arr = new int[4];

		for(int i=0;i<num;i++){
			permutation[i] = scanner.nextInt();

			if(permutation[i] == 1){
				min_pos = i;
			}

			if(permutation[i] == num){
				max_pos = i;
			}
		}
////		System.out.println("adflanksdf");
////		if((min_pos == 0 && max_pos == num-1)){
////
////		}else if((min_pos == num-1 && max_pos == 0) ){
////
////		}else{
			arr[0] = max_pos-0;
			arr[1] = num-1 - max_pos;
			arr[2] = min_pos -0;
			arr[3] = num-1 - min_pos;
//
////			System.out.println("adflanksdf");
			Arrays.sort(arr);
			System.out.println(arr[3]);

//		}
	}
}

import java.util.*;
public class Main{
       public static void main(String[] args){
              Scanner sc = new Scanner(System.in);
              int currentMax = Integer.MIN_VALUE;
              int currentMin = Integer.MAX_VALUE;
              int indexMin = 0;
              int indexMax = 0;
              int start = 0;
              int length = sc.nextInt() - 1;
              while (sc.hasNextInt()){
                     int newNumber = sc.nextInt();
                     if (currentMax <= newNumber){
                            indexMax = start;
                            currentMax = newNumber;
                     }
                     if (currentMin >= newNumber){
                            indexMin = start;
                            currentMin = newNumber;
                     }
                     start++;
              }
              int distanceBackMin = length - indexMin;
              int distanceBackMax = length - indexMax;
              int maxBack = Math.max(distanceBackMin,distanceBackMax);
              int maxFront = Math.max(indexMin,indexMax);
              System.out.print(Math.max(maxBack,maxFront));
       }
}

import java.util.Scanner;

public class Main{
	public static void main (String []args){
		Scanner s=new Scanner(System.in);
		int ans,n=s.nextInt(),min=0,max=0,temp;
		for(int i=0;i<n;i++){
			temp=s.nextInt();
			if(temp==1)
				min=i;
			else if(temp==n)
				max=i;
		}
		if(min<max)
			ans=Math.max(n-1-min, max);
		else
			ans=Math.max(min,n-1-max);

		System.out.println(ans);
		s.close();
	}
}

import java.util.*;

public class A354
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int min = 101, max = -101, n, x, minp = 0, maxp = 0;

		n = sc.nextInt();
		for(int i = 0; i < n; i++)
		{
			x = sc.nextInt();
			if(x < min)
			{
				min = x;
				minp = i+1;
			}
			if(x > max)
			{
				max = x;
				maxp = i+1;
			}
		}
		min = n - Math.min(maxp, minp);
		max = Math.max(minp, maxp) - 1;
		System.out.println(Math.max(max, min));
	}

}

// package com.peterdang.hackerrank;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Hackerrank {

    public static void main(String[] args) throws IOException {
        ArrayList<Integer> arr = new ArrayList();
        int n;
        Scanner reader = new Scanner(System.in);

//        while (true) {
        n = reader.nextInt();
        for (int i = 0; i < n; i++) {
            arr.add(reader.nextInt());
        }

        int max, min;
        int maxIndex, minIndex;
        min = max = arr.get(0);
        minIndex = maxIndex = 0;
        for (int i = 1; i < arr.size(); i++) {
            if(arr.get(i) > max) {
                max = arr.get(i);
                maxIndex = i;
            }
            if(arr.get(i) < min) {
                min = arr.get(i);
                minIndex = i;
            }
        }

        int higherIndex = Math.max(maxIndex, minIndex);
        int lowerIndex = Math.min(maxIndex, minIndex);

        System.out.print(Math.max(higherIndex, n-1-lowerIndex));

        reader.close();

    }
}

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class P676A {
  InputStream is;
  PrintWriter out;
  String INPUT = "5 4 5 1 3 2";

  void solve() {
    int n = ni();
    int min = 0;
    int max = 0;
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = ni();
      if (a[min] > a[i]) {
        min = i;
      }
      if (a[max] < a[i]) {
        max = i;
      }
    }
    if (min > max) {
      int b = max;
      max = min;
      min = b;
    }
    int d1 = n - 1 - min;
    int d2 = max;
    System.out.println(Math.max(d1, d2));
  }

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

  void run() throws Exception {
    is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
    out = new PrintWriter(System.out);

    long s = System.currentTimeMillis();
    solve();
    out.flush();
    tr(System.currentTimeMillis() - s + "ms");
  }

  private byte[] inbuf = new byte[1024];
  private int lenbuf = 0, ptrbuf = 0;

  private int readByte() {
    if (lenbuf == -1)
      throw new InputMismatchException();
    if (ptrbuf >= lenbuf) {
      ptrbuf = 0;
      try {
        lenbuf = is.read(inbuf);
      } catch (IOException e) {
        throw new InputMismatchException();
      }
      if (lenbuf <= 0)
        return -1;
    }
    return inbuf[ptrbuf++];
  }

  private boolean isSpaceChar(int c) {
    return !(c >= 33 && c <= 126);
  }

  private int skip() {
    int b;
    while ((b = readByte()) != -1 && isSpaceChar(b))
      ;
    return b;
  }

  private double nd() {
    return Double.parseDouble(ns());
  }

  private char nc() {
    return (char) skip();
  }

  private String ns() {
    int b = skip();
    StringBuilder sb = new StringBuilder();
    while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  private char[] ns(int n) {
    char[] buf = new char[n];
    int b = skip(), p = 0;
    while (p < n && !(isSpaceChar(b))) {
      buf[p++] = (char) b;
      b = readByte();
    }
    return n == p ? buf : Arrays.copyOf(buf, p);
  }

  private char[][] nm(int n, int m) {
    char[][] map = new char[n][];
    for (int i = 0; i < n; i++)
      map[i] = ns(m);
    return map;
  }

  private int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private int ni() {
    int num = 0, b;
    boolean minus = false;
    while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
      ;
    if (b == '-') {
      minus = true;
      b = readByte();
    }

    while (true) {
      if (b >= '0' && b <= '9') {
        num = num * 10 + (b - '0');
      } else {
        return minus ? -num : num;
      }
      b = readByte();
    }
  }

  private long nl() {
    long num = 0;
    int b;
    boolean minus = false;
    while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
      ;
    if (b == '-') {
      minus = true;
      b = readByte();
    }

    while (true) {
      if (b >= '0' && b <= '9') {
        num = num * 10 + (b - '0');
      } else {
        return minus ? -num : num;
      }
      b = readByte();
    }
  }

  private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

  private void tr(Object... o) {
    if (!oj)
      System.out.println(Arrays.deepToString(o));
  }
}

import java.io.*;
public class NicholasandPermutation {
	public static void main(String[] args) {
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine().trim());
			String a1[] = br.readLine().trim().split(" ");
			int a = 0;
			int b = 0;
			int arr[] = new int[n + 1];
			for(int i = 1; i <= n; i++){
				arr[i] = Integer.parseInt(a1[i - 1]);
				if(arr[i] == n) b = i;
				if(arr[i] == 1) a = i;
			}
			int temp1 = n - a;
			int temp2 = a - 1;
			int temp3 = n - b;
			int temp4 = b - 1;
			int temp5 = Math.max(temp1, temp2);
			int temp6 = Math.max(temp3, temp4);
			System.out.println(Math.max(temp5, temp6));
		}
		catch(IOException e){
			System.out.println(e.getMessage());
		}
	}
}

import java.util.Scanner;
public class NicholasandPermutation{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = 0;
		int b = 0;
		for(int i = 1; i <= n; i++){
			int g = sc.nextInt();
			if(g == 1) a = i;
			if(g == n) b = i;
		}

		System.out.println(Math.max(Math.max(n - b, b - 1), Math.max(n - a, a - 1)));
	}
}

import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        int p1 = 0, pn = 0, num;
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            num = sc.nextInt();
            if (num == n) {
                pn = i;
            }
            if (num == 1) {
                p1 = i;
            }
        }
        System.out.println(Math.max(Math.max(n - pn, pn - 1), Math.max(n - p1, p1 - 1)));
        bw.flush();
    }
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int min = 0;
		int max = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] == 1) {
				min = i;
			}
			if (a[i] == n) {
				max = i;
			}
		}
		int res = 0;
		if (min < max) {
			res = Math.max(max, n - min - 1);
		} else {
			res = Math.max(min, n - max - 1);
		}
		System.out.println(res);
	}
}

import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		int positionOfMax = 0, positionOfMin = 0;
		for (int i = 1; i <= count; i++) {
			int current = sc.nextInt();
			if (current == count) positionOfMax = i;
			if (current == 1) positionOfMin = i;
		}
		sc.close();
		int solution = Math.max(Math.max(positionOfMax - 1, count - positionOfMax), Math.max(positionOfMin - 1, count - positionOfMin));
		System.out.println(solution);
	}

}

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

public class NicholasAndPermutation {
	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		Reader in = new Reader();
		int n = in.readInt(), minIndex = 0, maxIndex = 0, left, right;
		int[] a = in.readIntArray(n);
		for(int i = 0; i < n; i++){
			if(a[i] == 1) minIndex = i;
			if(a[i] == n) maxIndex = i;
		}
		left = Math.min(minIndex, maxIndex);
		right = Math.max(minIndex, maxIndex);
		out.println(Math.max(right, n - 1 - left));
		in.close();
		out.close();
	}
	static PrintWriter out;
	static class Reader {
		BufferedReader br;
		StringTokenizer st;
		public Reader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String read() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int readInt() {
			return Integer.parseInt(read());
		}
		long readLong() {
			return Long.parseLong(read());
		}
		double readDouble() {
			return Double.parseDouble(read());
		}
		char readChar() {
			return read().charAt(0);
		}
		int[] readIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = readInt();
			return a;
		}
		long[] readLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = readLong();
			return a;
		}
		double[] readDoubleArray(int n) {
			double[] a = new double[n];
			for (int i = 0; i < n; i++)
				a[i] = readDouble();
			return a;
		}
		String[] readStringArray(int n) {
			String[] s = new String[n];
			for (int i = 0; i < n; i++)
				s[i] = read();
			return s;
		}
		char[] readCharArray(int n) {
			char[] ch = new char[n];
			for (int i = 0; i < n; i++)
				ch[i] = readChar();
			return ch;
		}
		String readLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
		void close() {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}

import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class test7 {
	@SuppressWarnings("resource")
	public static void main(String args[]){
		Scanner scanner=new Scanner(System.in);
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		int n = scanner.nextInt();
		int a = 0;
		int b = 0;
		for(int i=1;i<=n;i++){
			int temp = scanner.nextInt();
			if(temp==1){
				a = i;
			}else if(temp == n){
				b = i;
			}
		}
		int max1 = Math.max(Math.abs(a-1), Math.abs(n-a));
		int max2 = Math.max(Math.abs(b-1), Math.abs(n-b));
		System.out.println(Math.max(max1, max2));

		out.close();

	}

}

import java.util.*;
public class HelloWorld{

     public static void main(String []args){
        Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int iplace = -1;
    int nplace = -1;
    for (int i = 0; i < n ; ++i ) {
      int k = sc.nextInt();
      if (k == 1)  {iplace = i;}
      if (k == n) {nplace = i;}
    }

      System.out.println(Math.max(Math.max(iplace, n-1-nplace), Math.max(nplace, n-1-iplace)));
     }
}

import java.util.*;

// import sun.net.www.content.audio.x_aiff;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ar {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    public static void main(String[] args) throws java.lang.Exception {
        FastReader scn = new FastReader();
int t=scn.nextInt();
int maxposn=0,minposn=0;
for(int i=0;i<t;i++){
    int p=scn.nextInt();
if(p==t)maxposn=i;
else if(p==1)minposn=i;
}

int ans=Math.max(Math.abs(maxposn-minposn),Math.max(Math.abs(maxposn-(t-1)),Math.abs(maxposn)));
int secans=Math.max(Math.abs(minposn-(t-1)),Math.abs(minposn));
System.out.println(Math.max(ans,secans));
}

}

import java.util.Scanner;

public class vn3 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int idx = 0;
		boolean f = false;
		int n = in.nextInt();
		in.nextLine();

		for (int i=0;i<n;i++) {
			int d = in.nextInt();

			if (d == 1 || d == n) {
				if (f) {
					idx = Math.min(idx, n - 1 -i);
					break;
				} else {
					if (i == 0) {
						System.out.println(n - 1);
						System.exit(0);
					}
					idx = i;
					f = true;
				}
			}
		}

		System.out.println(n - 1 - idx);
		in.close();
	}
}

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

public class one{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

	int len = in(br.readLine());
	int[] nums = new int[len];

	String[] hold = br.readLine().split(" ");

	for(int i = 0; i < len; i++) { nums[i] = in(hold[i]); }

	int min_p = 0;
	int max_p = 0;

	for(int i = 0; i < len; i++) {
	    if(nums[i] < nums[min_p]) { min_p = i; }
	    if(nums[i] > nums[max_p]) { max_p = i; }
	}

	int l_dist = Math.min(min_p, max_p);
	int r_dist = len - 1 - Math.max(min_p, max_p);

	int sol = Math.max(l_dist, r_dist) + Math.abs(min_p - max_p);

	out.println(sol);
	out.close();
    }

    static int in(String s){
        return Integer.parseInt(s);
    }
}

import java.util.Scanner;

public class Ishu

{

	public static void main(String[] args)

	{

	 Scanner scan=new Scanner(System.in);

	 int n,i,min=0,max=0,sm,lar;
	 int[] a=new int[100];
	 n=scan.nextInt();
	 for(i=0;i<n;++i)
		{
		 a[i]=scan.nextInt();
		 if(a[i]==1)
			min=i+1;
		 if(a[i]==n)
			max=i+1;
	 	}
	 sm=min<max?min:max;
	 lar=min>max?min:max;
	 if(lar-1>=n-sm)
		System.out.println((lar-1));
	 else
		System.out.println((n-sm));
	}
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        List<Integer> array = new ArrayList<>();

        for (int i = 0; i < size; i++){
            array.add(sc.nextInt());
        }

        int result = findPositionMin(array);
        System.out.println(result);

    }

    public static int findPositionMin(List<Integer> array){
        int minP = 0;
        int maxP = 0;
        for (int i = 1; i < array.size(); i++){
            if (array.get(minP) > array.get(i)){
                minP = i;
            }
            if (array.get(maxP) < array.get(i)){
                maxP = i;
            }
        }

        int distance;
        if (minP == 0 || maxP == 0 || minP == array.size() - 1 || maxP == array.size() - 1){
            return array.size() - 1;
        }

        if (minP < maxP) {
            if (minP > array.size() - 1 - maxP){
                distance = maxP;
            } else {
                distance = array.size() - 1 - minP;
            }
        } else {
            if (maxP > array.size() - 1 - minP){
                distance = minP;
            } else {
                distance = array.size() - 1 - maxP;
            }
        }

        return distance;
    }
}

//package com.company;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
                int[] A = new int[n];
                int index = 0, index2 = 0;
                for (int i = 0; i < n; i++) {
                    A[i] = sc.nextInt();
                    if (A[i] == n)
                        index = i;
                    if (A[i] == 1)
                        index2 = i;
                }
                if (index < index2){
                    if (index < n - index2)
                        System.out.println(n - index - 1);
                    else
                        System.out.println(index2);
                } else {
                    if (index2 < n - index)
                        System.out.println(n - 1 - index2);
                    else
                        System.out.println(index);
                }

    }
}

import static java.lang.Math.max;

import java.util.Scanner;

public class NicholasAndPermutation {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        int ps = 0, pb = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (a[i] == 1)
                ps = i;
            if (a[i] == n)
                pb = i;
        }
        if (a[0] == 1 || a[0] == n || a[n - 1] == 1 || a[n - 1] == n) {
            System.out.println(n - 1);
            return;
        }
        int p = n - ps - 1, q = n - pb - 1, r = ps, s = pb;
        System.out.println(max(p, max(q, max(r, s))));

    }
}

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

/**
 * Created by jitendra.gangwar on 17/04/16.
 */
public class Main {

    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        try {
            FastScanner fastScanner = new FastScanner(System.in);
            int n = fastScanner.nextInt();
            int [] arr = new int[n];
            int pos1 = 0,pos2=0;
            for(int i =0;i<n;i++){
                arr[i] = fastScanner.nextInt();
                if(arr[pos1] > arr[i]){
                    pos1 = i;
                }
                if(arr[pos2] < arr[i]){
                    pos2 = i;
                }
            }
            int max = pos1  > (n-1) -pos1 ? pos1 : (n-1) - pos1;
            int max2 = pos2 > (n-1) -pos2 ? pos2 : (n-1) - pos2 ;
            max = max > max2 ? max : max2;
            out.println(max);
            out.close();
        } catch (Exception e) {
            return;
        } finally {
            if (out != null){
                out.close();
            }
        }
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

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

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

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

    }
}

import java.util.*;

public class A354
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int min = 101, max = -101, n, x, minp = 0, maxp = 0;

		n = sc.nextInt();
		for(int i = 0; i < n; i++)
		{
			x = sc.nextInt();
			if(x < min)
			{
				min = x;
				minp = i+1;
			}
			if(x > max)
			{
				max = x;
				maxp = i+1;
			}
		}
		min = n - Math.min(maxp, minp);
		max = Math.max(minp, maxp) - 1;
		System.out.println(Math.max(max, min));
	}

}

import java.util.Scanner;
public class a {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt(), max = -1, min = Integer.MAX_VALUE, indmin = 0, indmax = 0;
    int[] p = new int[n];
    for (int i = 0; i < n; ++i) {
      p[i] = in.nextInt();
      if (p[i] > max) {
        max = p[i];
        indmax = i;
      }
      if (p[i] < min) {
        min = p[i];
        indmin = i;
      }
    }
    System.out.println(Math.max(indmax, Math.max(indmin, Math.max(n - 1 - indmax, Math.max(n - 1 - indmin, n - 1 - indmax)))));
  }
}

import java.util.*;
public class JavaApplicationM{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);

//----------------------------------------------
int n=in.nextInt();
int s;

int p=0,q=0,max=-1,min=101;
for(int i=0;i<n;i++)
{
    s=in.nextInt();
    if(s>max){max=s;p=i+1;}
    if(s<min){min=s;q=i+1;}
}
int v=Math.min(q, p),v1=Math.max(p, q);
int z1=v1-1;
int z2=n-v;

System.out.println(Math.max(z1,z2));
 //
}}

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

public class Test{

	public static class MyScanner
	{
	    private byte[] buf = new byte[1024];
	    private int curChar;
	    private int numChars;
	    BufferedInputStream bis = new BufferedInputStream(System.in);

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

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

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

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

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

public  static void main(String [] arg){

	MyScanner in =new MyScanner();

	int min=Integer.MAX_VALUE;
	int max=Integer.MIN_VALUE;
	int mai=0,mii=0;
	int n=in.nextInt();
	int []t =new int[n];
	for(int i=0;i<n;i++){
		t[i]=in.nextInt();
		if (t[i]<min) {min=t[i];mii=i;}
		if (t[i]>max) {max=t[i]; mai=i;}
	}
	int []test=t;
	int dist=0;
	for(int i=0;i<n;i++){
		if (dist<Math.abs(mii-i)) dist=Math.abs(mii-i);
		if (dist<Math.abs(mai-i)) dist=Math.abs(mai-i);
	}

	System.out.println(dist);
	}
}

// Working program with FastReader
import java.io.*;
import java.util.*;

public class codeforces_676A
{
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

	public static void main(String[] args)
	{
		FastReader ob=new FastReader();
		int n=ob.nextInt();
		int arr[]=new int[n];
		int index1=0,index2=0;
        for (int i = 0; i <n ; i++) {
            arr[i]=ob.nextInt();
            if(arr[i]==n){
                index1=i;
            }
            if(arr[i]==1){
                index2=i;
            }
        }
        if(arr[0]==1 || arr[0]==n || arr[n-1]==1 || arr[n-1]==0){
            System.out.println(n-1);
            return;
        }
        int c1=0;
        int max1=Integer.MIN_VALUE,max2=Integer.MIN_VALUE;;
        for (int i = 0; i <n ; i++) {
            if(max1<=Math.abs(index1-i)){
                max1=Math.abs(index1-i);
            }
            if(max2<=Math.abs(index2-i)){
                max2=Math.abs(index2-i);
            }

        }

        System.out.println(Math.max(max1,max2));

	}
}

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

public class CF354A{

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = sc.nextInt();
        int minI = -1;
        int minE = 0;
        int maxI = -1;
        int maxE = 0;
        for (int i = 0; i < n; i++) {
        	int a = sc.nextInt();
        	if (maxI == -1 || a > maxE) {
        		maxE = a;
        		maxI = i;
        	}
        	if (minI == -1 || a < minE) {
        		minE = a;
        		minI = i;
        	}
        }
        int v1 = minI;
        int v2 = n-1-minI;
        int v3 = maxI;
        int v4 = n-1-maxI;
        int a = v1;
        if (a < v2) a = v2;
        if (a < v3) a = v3;
        if (a < v4) a = v4;

        out.println(a);

        out.close();
        sc.close();
    }
}

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

public class Main {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int T=1,i,j=0,k=0,l;
		for (int tt=0; tt<T; tt++)
		{
			int n=fs.nextInt();
			int[] a=fs.readArray(n);
			if(a[0]==n||a[0]==1||a[n-1]==1||a[n-1]==n)
			System.out.println(n-1);
			else
			{
			    for(i=0;i<n;i++)
			    {if(a[i]==1)
			    j=i;
			    if(a[i]==n)
			    k=i;}

			System.out.println(Math.max(n-1-Math.min(j,k),Math.max(j,k)));
			}
		}
	}

	static final Random random=new Random();

	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}

	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

}

import java.util.Scanner;

public class find_furthest_distance_min_max {

	public static int calculate_distance(int[] a, int n) {

		boolean seen = false;
		int left = 0;
		int right = 0;

		for (int i=0; i < n; i++) {
			if ((a[i] == n || a[i] == 1) && seen == false) {
				seen = true;
				left = i;
			}

			if ((a[i] == n || a[i] == 1) && seen == true) {
				right = i;
			}
		}

		return Math.max(right, n-1-left);
	}

	public static void main(String[] argv) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];

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

		System.out.println(calculate_distance(a, n));

	}

}

import java.util.ArrayList;
import java.io.InputStream;
import java.io.IOException;
import java.util.Scanner;

public class Main {

    //idea
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        ArrayList<Integer> arr = new ArrayList();
        int minpos =0, maxpos =0; //position for max and min value
        for (int i=0; i< n; i++){
            int a = s.nextInt();
            arr.add(a);
            if (a == 1) minpos = i;
            if (a == n) maxpos = i;
        }

        if (maxpos ==0 || maxpos == n-1 || minpos ==0|| minpos == n-1)
            System.out.println(n-1);
        else {
            if (minpos < maxpos)
                System.out.println(Math.max(maxpos, n -1 - minpos));
            else
                System.out.println(Math.max(minpos, n -1 - maxpos));
        }
    }

}

import java.util.Scanner;

public class NicholasPermutatioin {
	public static void main(String [] args){
		Scanner sc = new Scanner(System.in);
		int numElements = sc.nextInt();
		int [] numbers = new int[numElements];
		for(int i=0; i<numElements; i++){
			numbers[i] = sc.nextInt();
		}
		NicholasPermutatioin nicholasPermutatioin = new NicholasPermutatioin();
		int smPosition = nicholasPermutatioin.findPosition(numbers, 1);
		int bigPosition = nicholasPermutatioin.findPosition(numbers, numElements);

		int currentDiff = Math.abs(bigPosition - smPosition);
		if(currentDiff < Math.abs(bigPosition - 1))
		{
			currentDiff = Math.abs(bigPosition - 1);
		}
		if(currentDiff < Math.abs(bigPosition - numElements))
		{
			currentDiff = Math.abs(bigPosition - numElements);
		}
		if(currentDiff < Math.abs(smPosition - numElements))
		{
			currentDiff = Math.abs(smPosition - numElements);
		}
		if(currentDiff < Math.abs(smPosition - 1))
		{
			currentDiff = Math.abs(smPosition - 1);
		}
		System.out.println(currentDiff);
	}

	public int findPosition(int [] numbers, int n){
		for(int i=0; i<numbers.length; i++){
			if(numbers[i] == n){
				return i+1;
			}
		}
		return -1;
	}

}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringTokenizer;

/** Class: NicholasAndPermutation.java
 *  @author
 *  @version 1.0 <p>
 *  Course:
 *  Written / Updated: Jun 18, 2016
 *
 *  This Class -
 *  VERDICT:
 */
public class NicholasAndPermutation {

	private int[] numArr;
	private int minIndex, maxIndex;

	/**
	 *
	 */
	public NicholasAndPermutation() {
		try {
			BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));

            //Read the first line
            String line = rd.readLine();

            StringTokenizer tokenizer = new StringTokenizer(line);
            int n = Integer.parseInt(tokenizer.nextToken());
            this.numArr = new int[n];

            /* Read next line and populate the number array, and save the indices
             * of the min. and max. numbers. */
            line = rd.readLine();
            tokenizer = new StringTokenizer(line);
            for (int i = 0; i < n; i++) {
            	this.numArr[i] = Integer.parseInt(tokenizer.nextToken());
            	if (this.numArr[i] == 1) minIndex = i;
            	else if (this.numArr[i] == n) maxIndex = i;
            }

            /* Print a single integer — the maximum possible distance between the minimum and the
             * maximum elements Nicholas can achieve by performing exactly one swap. */
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
            bw.write(this.computeMaxDist() + "\n");

            bw.close();
            rd.close();
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}

	private int computeMaxDist() {
		/* Compare the min. and max. indices. Whichever index is CLOSER TO one of the endpoints of the num Array
		 * is the one that should stay in place, and the other index should be swapped with either the first
		 * or last element in the array, to maximize the distance. */
		int minIndexDistFromEndpoint = Math.min(this.minIndex - 0, (this.numArr.length - 1) - this.minIndex);
		int maxIndexDistFromEndpoint = Math.min(this.maxIndex - 0, (this.numArr.length - 1) - this.maxIndex);

		/* min index is closer to one of the endpoints. min index stays in place. max index will be
		 * swapped with one of the endpoints.
		 * Compute the max distance between the min. index and one of the endpoints, and return it. */
		if (minIndexDistFromEndpoint < maxIndexDistFromEndpoint) {
			return Math.max(minIndex - 0, numArr.length - 1 - minIndex);
		/* or vice versa. */
		} else {
			return Math.max(maxIndex - 0, numArr.length - 1 - maxIndex);
		}
	}

	public static void main(String[] args) {
		new NicholasAndPermutation();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * Created by mohannadhassan on 5/25/16.
 */
public class NicholasAndPermutation {

    public static void main(String [] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        String[] input = br.readLine().split(" ");
        int [] numbers = new int[n];

        for (int i = 0; i < n; i++) {
            numbers[i] = Integer.parseInt(input[i]);
        }

        int first = -1, last = -1;

        for (int i = 0; i < n && (first < 0 || last < 0); i++) {
            if (numbers[i] == 1) {
                first = i;
            }
            else if (numbers[i] == n) {
                last = i;
            }
        }

        int [] arr = {first, last};
        java.util.Arrays.sort(arr);

        if (n - arr[1] - 1 > arr[0] - 0) {
            System.out.println(n - 1 - arr[0]);
        }
        else  {
            System.out.println(arr[1] - 0);
        }
    }
}

        import java.util.*;
        import java.math.*;
        import java.io.*;
        import java.text.DecimalFormat;
        import java.math.BigInteger;
        public class Main{
            static int d=20,n;
            static int mod=1000000007 ;
            static HashMap<String,Integer> hm=new HashMap<>();
            public static void main(String[] args)  throws IOException {
                s.init(System.in);

                PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
                int n=s.ni();
                int f,ss;
                f=ss=-1;
                int x=0;
                for(int i=0;i<n;i++){
                    x=s.ni();
                    if(x==1 || x==n){
                        if(f!=-1)
                            ss=i;
                        else
                            f=i;
                    }
                }
                out.println(Math.max(ss,n-1-f));
                out.close();
            }

            static class party implements Comparable<party>{
                int size;
                int id;
                public party(int x,int y){
                    id=x;
                    size=y;
                }
                public  int compareTo(party o){
                    return o.size-size;
                }
            }

            public static class s {
                static BufferedReader reader;
                static StringTokenizer tokenizer;

                /** call this method to initialize reader for InputStream */
                static void init(InputStream input) {
                    reader = new BufferedReader(
                                new InputStreamReader(input) );
                    tokenizer = new StringTokenizer("");
                }

                /** get next word */
                static String ns() throws IOException {
                    while ( ! tokenizer.hasMoreTokens() ) {
                        //TODO add check for eof if necessary
                        tokenizer = new StringTokenizer(
                            reader.readLine() );
                    }
                    return tokenizer.nextToken();
                }

                static int ni() throws IOException {
                    return Integer.parseInt( ns() );
                }

                static double nd() throws IOException {
                    return Double.parseDouble( ns() );
                }
                static long nl() throws IOException {
                    return Long.parseLong( ns() );
                }

            }
        }

/***
 *    ██████╗=====███████╗====███████╗====██████╗=
 *    ██╔══██╗====██╔════╝====██╔════╝====██╔══██╗
 *    ██║==██║====█████╗======█████╗======██████╔╝
 *    ██║==██║====██╔══╝======██╔══╝======██╔═══╝=
 *    ██████╔╝====███████╗====███████╗====██║=====
 *    ╚═════╝=====╚══════╝====╚══════╝====╚═╝=====
 *    ============================================
 */

import sun.nio.cs.KOI8_U;

import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

public class AD implements Runnable {

    public void run() {
        InputReader sc = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int i=0,j=0,k=0;
        int t=0;
        //t=sc.nextInt();
        for(int testcase = 0; testcase < t; testcase++)
        {}

        int n=sc.nextInt();
        int arr[]=new int[n];
        int min=Integer.MAX_VALUE;
        int max=Integer.MIN_VALUE;
        int minind=0;
        int maxind=0;
        for (i=0;i<n;i++)
        {
            arr[i]=sc.nextInt();
            if (arr[i]>max)
            {
                max=arr[i];
                maxind=i;
            }
            if (arr[i]<min)
            {
                min=arr[i];
                minind=i;
            }

        }
        int r=Math.max(minind,maxind);
        int l=Math.min(minind,maxind);
        //out.println(l+" "+r);
        out.println(Math.max(n-1-l,r));

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

    //================================================================================================================================
    public static long gcd(long a,long b){
        return (a%b==0l)?b:gcd(b,a%b);
    }
    private static long lcm(long a, long b)
    {
        return a * (b / gcd(a, b));
    }
    public int egcd(int a, int b) {
        if (a == 0)
            return b;

        while (b != 0) {
            if (a > b)
                a = a - b;
            else
                b = b - a;
        }

        return a;
    }

    public int countChar(String str, char c)
    {
        int count = 0;
        for(int i=0; i < str.length(); i++)
        {    if(str.charAt(i) == c)
            count++;
        }
        return count;
    }
    static int binSearch(Integer[] arr, int number){
        int left=0,right=arr.length-1,mid=(left+right)/2,ind=0;
        while(left<=right){
            if(arr[mid]<=number){
                ind=mid+1;
                left=mid+1;
            }
            else
                right=mid-1;
            mid=(left+right)/2;
        }
        return ind;
    }
    static int binSearch(int[] arr, int number){
        int left=0,right=arr.length-1,mid=(left+right)/2,ind=0;
        while(left<=right){
            if(arr[mid]<=number){
                ind=mid+1;
                left=mid+1;
            }
            else
                right=mid-1;
            mid=(left+right)/2;
        }
        return ind;
    }
    static class Pair
    {
        int a,b;
        Pair(int aa,int bb)
        {
            a=aa;
            b=bb;
        }
        String get()
        {
            return a+" "+b;
        }
        String getrev()
        {
            return b+" "+a;
        }
    }

    static boolean isPrime(long n) {
        if(n < 2) return false;
        if(n == 2 || n == 3) return true;
        if(n%2 == 0 || n%3 == 0) return false;
        long sqrtN = (long)Math.sqrt(n)+1;
        for(long i = 6L; i <= sqrtN; i += 6) {
            if(n%(i-1) == 0 || n%(i+1) == 0) return false;
        }
        return true;
    }
    static long factorial(long n)
    {
        if (n == 0)
            return 1;
        return n*factorial(n-1);
    }
//================================================================================================================================

    static class InputReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    public static void main(String args[]) throws Exception {
        new Thread(null, new AD(),"Main",1<<27).start();
    }
}

import java.util.*;

public class Q676A{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a1 = sc.nextInt();
        int imax = 1,imin=1;
        int max =a1,min=a1;
        for(int i=2;i<=n;i++){
            int ai = sc.nextInt();
            if(ai>max){
                max =ai;
                imax = i;
            }
            if(ai<min){
                min =ai;
                imin=i;
            }
        }
        int res1 = Math.max(imax-1, n-imax);
        int res2 = Math.max(imin-1, n-imin);
        System.out.println(Math.max(res1,res2));
    }
}

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

public class Main {
	private static InputReader ir;
	private static PrintWriter out;

	public static void main(String[] args) {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);

		int n = ir.nextInt();
		int[] array = new int[n];

		int min = 0;
		int max = 0;

		for (int i = 0; i < n; i++) {
			int num = ir.nextInt();
			array[i] = num;

			if (num < array[min]) {
				min = i;
			}

			if (num > array[max]) {
				max = i;
			}
		}

		int first, last;
		if (min < max) {
			first = max;
			last = n - 1 - min;
		} else {
			first = min;
			last = n - 1 - max;
		}

		int answer = Math.max(first, last);

		out.println(answer);
		out.flush();
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class NPermutacion {
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		String[] S = bf.readLine().split(" ");
		int min=0;
		int max=0;
		for(int i=0;i<n;i++){
			if(Integer.parseInt(S[i])==1){
				min = i;
			}
			if(Integer.parseInt(S[i])==n){
				max = i;
			}
		}
		int x1=Math.abs(n-1-min);
		int x2=Math.abs(n-1-max);
		int x3=Math.abs(0-min);
		int x4=Math.abs(0-max);
		if(x1<x2){
			x1=x2;
		}if(x1<x3){
			x1=x3;
		}if(x1<x4){
			x1=x4;
		}
		System.out.println(x1);
	}
}

import java.util.*;
public class Main {
  public static void main (String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    int len = in.nextInt();
    int min = -1;
    int max = -1;
    for(int i =0; i<len; i++){
      int num = in.nextInt();
      if(num==1){
        min = i;
      }
      if(num==len){
        max = i;
      }
    }
    int l = Math.min(min,max);
    int r = Math.max(min,max);
    int ans = Math.max(r,len-1-l);
    System.out.println(ans);
  }
}

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

/**
 *
 * @author Annie
 */
public class JavaApplication104 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner s = new Scanner(System.in);
        int n=s.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
        a[i]=s.nextInt();
        }

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

        System.out.println(max);
        System.out.println(min);
        int ans = Math.abs(max-min);

        int x = Math.max(min-0,n-1-min);
        int y = Math.max(max-0,n-1-max);

        int z = Math.max(x,y);
        int result = Math.max(ans, z);

        System.out.println(result);
    }

}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        List<Integer> array = new ArrayList<>();

        for (int i = 0; i < size; i++){
            array.add(sc.nextInt());
        }

        int result = findPositionMin(array);
        System.out.println(result);

    }

    public static int findPositionMin(List<Integer> array){
        int minP = 0;
        int maxP = 0;
        for (int i = 1; i < array.size(); i++){
            if (array.get(minP) > array.get(i)){
                minP = i;
            }
            if (array.get(maxP) < array.get(i)){
                maxP = i;
            }
        }

        int distance;
        if (minP == 0 || maxP == 0 || minP == array.size() - 1 || maxP == array.size() - 1){
            return array.size() - 1;
        }

        if (minP < maxP) {
            if (minP > array.size() - maxP){
                distance = maxP;
            } else {
                distance = array.size() - 1 - minP;
            }
        } else {
            if (maxP > array.size() - minP){
                distance = minP;
            } else {
                distance = array.size() - 1 - maxP;
            }
        }

        return distance;
    }
}

import java.util.*;

public class NicholasAndPermutation
{
	static int minInt=Integer.MIN_VALUE;
	static int maxInt=Integer.MAX_VALUE;

	public static void solution(int[] a1,int m1,int ind1,int ind2)
	{
		int max=max(ind1-ind2,ind2-ind1,m1-1-ind1,m1-1-ind2);
		System.out.println(max);
	}
	public static void main(String[] zima)
	{
		Scanner sc=new Scanner(System.in);

		int m1=sc.nextInt();
		int ind1=0;
		int ind2=0;
		int[] a1=new int[m1];

		for(int i=0;i<m1;i++)
		{
			a1[i]=sc.nextInt();
			if(a1[i]==1)
				ind1=i;
			if(a1[i]==m1-1)
				ind1=i;
		}

		solution(a1,m1,ind1,ind2);
		sc.close();
	}
	public static int max(int m1,int m2,int m3,int m4)
	{
		return Math.max(Math.max(Math.max(m1, m2), m3), m4);
	}
}

import java.util.*;
public class Hello {
public static void main(String arr[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		if (n >= 2 && n <= 100) {
			int min = 0;
			int min_index = 0;
			int max = 0;
			int max_index = 0;
			int[] a = new int[n];
			for (int a_i = 0; a_i < n; a_i++) {
				int val = in.nextInt();
				a[a_i] = val;
				if (a_i == 0) {
					min = val;
					min_index = 0;
					max = val;
					max_index = 0;
				} else {
					if (max < val) {
						max = val;
						max_index = a_i;
					}
					if (min > val) {
						min = val;
						min_index = a_i;
					}
				}
			}
			int max_dis = find_max_dis(min, min_index, max, max_index, a);
			if(max_dis<0)
				max_dis=(-1)*max_dis;
			System.out.println(max_dis);
		}
	}

	private static int find_max_dis(int min, int min_index, int max, int max_index, int[] a) {
		int max_dis = 0;
		int row_max = 0;
		int row_min = 0;
		int max_d = 0;
		int max_dis_index = 0;
		if ((min_index + max_index + 1) == a.length)
			max_dis = swap_val(min, min_index, max, max_index, a)-1;
		else {
			int tmp = 0;
			for (int i = 0; i < a.length; i++) {
				if (min_index >= i)
					tmp = min_index - i;
				else
					tmp = i - min_index;

				if (tmp > row_min){
					row_min = tmp;
					max_dis_index=i;
				}

				if (max_index >= i)
					tmp = max_index - i;
				else
					tmp = i - max_index;

				if (tmp > row_max){
					row_max = tmp;
					max_d=i;
				}
			}
			if (row_max < row_min)
				max_dis = swap(a, max_index, max_dis_index)-min_index;
			else
				max_dis = swap(a, min_index, max_d)-max_index;
		}
		return max_dis;
	}

	private static int swap(int[] a, int max_index, int row_max) {
		int tmp = a[max_index];
		a[max_index] = a[row_max];
		a[row_max] = tmp;
		return row_max;
	}

	private static int swap_val(int min, int min_index, int max, int max_index, int[] a) {
		a[min_index] = max;
		a[max_index] = min;
		return a.length;
	}
}

import java.io.*;
import java.util.*;
public class cdf354a
{
	public static void main(String args[])throws Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		String s=br.readLine();
		String str[]=s.split(" ");
		int arr[]=new int[n];
		int pmin=0,pmax=0;
		for(int i=0;i<n;i++)
		{
			arr[i]=Integer.parseInt(str[i]);
			if(arr[i]==1)
				pmin=i;
			if(arr[i]==n)
				pmax=i;
		}
		int mi1=(int)Math.min(pmax,n-pmax-1);
		int mi2=(int)Math.min(pmin,n-pmin-1);
		int diff=Math.abs(pmax-pmin)+(int)Math.max(mi1,mi2);
		System.out.println(diff);

	}
}

import java.util.*;

public class Main{
    public static void main(String [] args)
    {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int l=0,u=0,i;
        for(i=1;i<=n;i++)
        {
            int a=scan.nextInt();
            if(a==1)
                l=i;
            if(a==n)
                u=i;
        }
        int ans=Math.max(l,u);
        ans=Math.max(ans,n-l);
        ans=Math.max(ans,n-u);
        System.out.println(ans);
    }
}

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

public class ArrayDiffernce
{
    public static void main(String[] args)
	{
		Scanner scanner=new Scanner(System.in);
		int index=scanner.nextInt();
		int a[]=new int[index];

		for(int i=0;i<index;i++)
		{
			a[i]=scanner.nextInt();

		}
		Arrays.sort(a);
		int maxDiff=a[index-1]-a[0];
//		for(int j=1;j<index-1;j++)
//		{
//			maxDiff=Math.max(a[j+1]-a[j],maxDiff);
//
//		}
//
        System.out.println(maxDiff);

	}

}

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

public class ATask {

    public static void main(String[] args) {
        MyInputReader in = new MyInputReader(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        int lo = 0;
        int hi = 0;
        for (int i = 0; i < n; i++) {
            if (arr[i] == 1) {
                lo = i;
            }
            if (arr[i] == n) {
                hi = i;
            }
        }
        int ans1 = hi;
        int ans2 = lo;
        int ans3 = (n - 1 - lo);
        int ans4 = (n - 1 - hi);
        int[] res = new int[] {ans1, ans2};
        int mx = -1;
        for (int i = 0; i < res.length; i++) {
            mx = Math.max(mx, Math.abs(res[i]));
        }
        System.out.println(mx);
    }

    static class MyInputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public MyInputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

}

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

/**
 * See
 * CF676ANicholasAndPermutation
 *
 * @author Brian Yeicol Restrepo Tangarife
 */
public class CF676ANicholasAndPermutation {

	static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException {
		int n = readInt();

		String a = read().replace(" ", "");
		int pos1 = a.indexOf("1");
		int posn = a.indexOf(String.valueOf(n));
		int max = Math.max(Math.abs(posn - 1), Math.abs(pos1 - 1));
		max = Math.max(max, Math.abs(n - 1 - pos1));
		max = Math.max(max, Math.abs(n - 1 - posn));
		out.print(max);
		out.close();
	}

	private static String read() throws IOException {
		return in.readLine();
	}

	private static int readInt() throws IOException {
		return Integer.parseInt(in.readLine());
	}

}

import java.util.HashMap;
import java.util.Scanner;

public class NicholasAndPermutation676A {
	private static Scanner in;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		in = new Scanner(System.in);

		int size = in.nextInt();
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;
		int minIndex = 0;

		int maxIndex = 0;
		int input;

		for (int i = 0; i < size; i++)
		{
			input = in.nextInt();

			if (input < min)
			{
				min = input;
				minIndex = i;
			}

			if (input > max)
			{
				max = input;
				maxIndex = i;
			}
		}

		System.out.println(Math.max(Math.abs(size - minIndex - 1), Math.abs(size - maxIndex - 1)));
	}

}

import java.util.Scanner;
public class NicholasandPermutation{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int arr[] = new int[n];
		int min = 110;
		int max = 0;
		int minI = 0;
		int maxI = 0;
		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
			if(min > arr[i]){
				min = arr[i];
				minI = i;
			}
			if(max < arr[i]){
				max = arr[i];
				maxI = i;
			}
		}

		if(minI > maxI){
			System.out.println(n - 1 - maxI);
		}
		else{
			System.out.println(n - 1 - minI);
		}
	}
}

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

public class Nicholas
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];

		int maxx = Integer.MIN_VALUE;
		int minx = Integer.MAX_VALUE;

		int p=0,q=0;

		for(int i=0;i<n;i++)
		{
			a[i] = in.nextInt();
			if(a[i]>maxx)
			{
				p = i;
				maxx = a[i];
			}
			if(a[i]<minx)
			{
				q =i;
				minx = a[i];
			}
		}
		//System.out.println(p + " " + q);
		if(p<(n/2) && q>=(n/2))
			System.out.println(Math.max(q,n-1-p));
		else if(p>=(n/2) && q<=(n/2))
			System.out.println(Math.max(p,n-1-q));

	}
}

import java.util.*;
public class CF676A {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int ans = 0;
		for(int i = 0; i < n; i ++)
		{
			int x = in.nextInt();
			if(x==n||x==1)
			{
				ans = Math.max(ans, n-i-1);
				ans = Math.max(ans, i-1);
				if(i==0||i==n-1)
					ans = n-1;
			}
		}
		System.out.println(ans);
	}
}

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
       // String str = "5 4 5 1 3 2";
        Scanner sc = new Scanner(System.in);
        new TaskA().solve(sc);
    }
}
class TaskA{
    void solve(Scanner sc){
        int n = sc.nextInt();
    //    System.out.println(n);
        int curN = 0;
        int indOne = -1;
        int indN = -1;
        for (int i = 1; i <= n; i++) {
            curN = sc.nextInt();
    //        System.out.print(curN + " ");
            if (curN == 1)
                indOne = i;
            if (curN == n)
                indN = i;
        }

 //       System.out.println();
        if (indN == 1 || indN == n || indOne == 1 || indOne == n)
            System.out.print(n-1);
        else {
            int minV = 0;
            minV = Math.min(Math.min(indN, indN), n - Math.max(indN, indOne));
            System.out.print(n - minV -1);
        }

    }
}

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

public class Main{

    public static double s(double a, double b, double c) {
        double p = (a + b + c + .0) / 2.0;
        return Math.sqrt(p * (p - a + .0) * (p - b + .0) * (p - c + .0));
    }

    public static BigDecimal sqrt(BigDecimal value) {
        BigDecimal x = new BigDecimal(Math.sqrt(value.doubleValue()));
        return x.add(new BigDecimal(value.subtract(x.multiply(x)).doubleValue() / (x.doubleValue() * 2.0)));
    }

    public static void main(String[] args){
        try{

            Scanner in = new Scanner(System.in);

            int n = in.nextInt();
            int[] a = new int[n];

            int min_ind = Integer.MIN_VALUE, max_ind = Integer.MIN_VALUE;

            for (int i  =0; i < n; i++) {
                a[i] = in.nextInt();
                if (a[i] == 1) {
                    min_ind = i;
                }
                if (a[i] == n) {
                    max_ind = i;
                }
            }

            if ((min_ind == 1 && max_ind == n) || (min_ind == 1 && max_ind != n) || (min_ind != 1 && max_ind == n)) {
                System.out.println(n - 1);
                return;
            }

            int p1 = Math.abs(n - 1 - max_ind);
            int p2 = Math.abs(n - 1 - min_ind);

            System.out.println(Math.max(Math.max(Math.max(p1, p2), max_ind), min_ind));

        } catch(Exception ex) {
            System.out.println(ex.toString());
        }
   }
}

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
       // String str = "5 4 5 1 3 2";
        Scanner sc = new Scanner(System.in);
        new TaskA().solve(sc);
    }
}
class TaskA{
    void solve(Scanner sc){
        int n = sc.nextInt();
    //    System.out.println(n);
        int curN = 0;
        int indOne = -1;
        int indN = -1;
        for (int i = 1; i <= n; i++) {
            curN = sc.nextInt();
    //        System.out.print(curN + " ");
            if (curN == 1)
                indOne = i;
            if (curN == n)
                indN = i;
        }

 //       System.out.println();
        System.out.println(n-Math.min(indN, indOne));
        //System.out.print(indN);
    }
}

import java.time.Clock;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Problem676A();
    }

    static void Problem676A() {
        Scanner scanner = new Scanner(System.in);
        int distance = 0;

        int size = scanner.nextInt();
        int[] elements = new int[size];

        for (int i = 0; i < size; i++) {
            elements[i] = scanner.nextInt();
        }

        int minIndex = GetMinIndex(size, elements);
        int maxIndex = GetMaxIndex(size, elements);

/*
        - khoảng cách lớn nhất giữa phần tử nhỏ nhất và phần tử lớn nhất trong mảng
        - bằng với
        */

        distance = Math.max(Math.max(size - minIndex, minIndex), Math.max(size-maxIndex, maxIndex));

        System.err.println(distance -1);
    }

    static int GetMinIndex(int size, int[] elements) {
        int minIndex  = 0;
        int min = elements[0];

        for (int i = 1; i < size; i++) {
            if (min > elements[i]) {
                minIndex = i;
                min = elements[i];
            }
        }
        return minIndex;
    }

    static int GetMaxIndex(int size, int[] elements) {
        int maxIndex = 0;
        int[] maxs = new int[2];

        int max = elements[0];
        for (int i = 1; i < size; i++) {
            if (max < elements[i]) {
                max = elements[i];
                maxIndex = i;
            }
        }
        return maxIndex;
    }
}

import java.util.*;
public class HelloWorld{

     public static void main(String []args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int iPosition = -1, nPosition = -1;

        for(int i=0;i<n;i++) {
            int value = in.nextInt();
            if(value == 1){
                iPosition = i;
            }
            if(value == n){
                nPosition = i;
            }
        }
        in.close();
        int distance = Math.max(Math.abs(nPosition - n) , Math.abs(nPosition - 1));
        distance = Math.max(distance, Math.max(Math.abs(iPosition - n), Math.abs(iPosition - 1)));
        System.out.println(distance-1);
     }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class NicholasAndPermutation {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        br.readLine();
        String[] in = br.readLine().split(" ");
        int max = 0;
        int min = 0;
        for (int i = 1; i < in.length; i++) {
            if (Integer.parseInt(in[max]) < Integer.parseInt(in[i])) {
                max = i;
            }
            if (Integer.parseInt(in[min]) > Integer.parseInt(in[i])) {
                min = i;
            }
        }
        if (max < min) {
            int temp = max;
            max = min;
            min = temp;
        }
        if (in.length - 1 - max - min > max) {
            System.out.println(in.length - max - min);
        }
        else {
            System.out.println(max + 1);
        }
    }
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        int i1 = 0, i2 = 0;
        for (int i = 0; i < N; i++) {
            int v = scanner.nextInt();
            if (v == 1) {
                i1 = i;
            } else if (v == N) {
                i2 = i;
            }
        }
        System.out.println(Math.max(N-1-i1, N-1-i2));
    }

}

import java.util.Scanner;
public class A676 {

	public static void main(String[] args) {
		Scanner input= new Scanner (System.in);
		int n= input.nextInt();
		int []a=new int[n];
		int Pmin=0,Pmax=0;
		boolean postionmin =false , postionmax=false;
		for (int i=0;i<n;i++)a[i]=input.nextInt();
		for (int i=0;i<n;i++){
			if (postionmin==true && postionmax==true)break;
		else if (a[i]==1){Pmin=i;postionmin=true;}
			else if (a[i]==n){Pmax=i;postionmax=true;}
		}
		if (Pmin >Pmax){
			if ((n-Pmin-1)>=Pmax)System.out.println((Pmin-Pmax)+(n-Pmin-1));
			else System.out.println(Pmax+1);
		}
		else {
			if ((n-Pmax-1)>=Pmin)System.out.println((Pmax-Pmin)+(n-Pmax-1));
			else System.out.println(Pmin+1);

		}
	}
}

import java.util.*;
import java.io.*;
public class a11 {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String temp=br.readLine();
		int n=Integer.parseInt(temp);
		String s[]=br.readLine().split(" ");
		int a[]=new int[n];

		for(int i=0;i<n;i++) a[i]=Integer.parseInt(s[i]);
		int l,r;
		l=getMaxValue(a);
		r=getMinValue(a);

		System.out.println(n-Math.min(l,r));

	}
	public static int getMaxValue(int[] array) {
	    int maxValue = array[0];
	    for (int i = 1; i < array.length; i++) {
	        if (array[i] > maxValue) {
	            maxValue = i;
	        }
	    }
	    return maxValue;
	}

	// getting the miniumum value
	public static int getMinValue(int[] array) {
	    int minValue = array[0];
	    for (int i = 1; i < array.length; i++) {
	        if (array[i] < minValue) {
	            minValue = i;
	        }
	    }
	    return minValue;
	}
}

import java.util.Scanner;

public class NicoleAndPermutation {

	public static void main(String[] args) {

		System.out.println();
		Scanner sc = new Scanner(System.in);

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

		int max = 0;
		int min = Integer.MAX_VALUE;
		int iMin = -1, iMax = -1;
		for (int i = 0; i < a.length; i++) {
			if (min > a[i]) {
				min = a[i];
				iMin = i;
			}
			if (max < a[i]) {
				max = a[i];
				iMax = i;
			}
		}

		int ans = 0;
		if (iMax == 0 && iMin == len - 1 ||
		    iMin == 0 && iMax == len - 1) {
			ans = len - 1;
		} else if (iMax >= len / 2) {
			if (iMin == 0 || iMax == len - 1) {
				ans = len - 1;
			} else {
				ans = iMax;
			}
		} else {
			if (iMax == 0 || iMin == len - 1) {
				ans = len - 1;
			} else {
				ans = len - 1 - iMax;
			}
		}

		System.out.println(ans);

	} // end of main().

}

// Working program with FastReader
import java.io.*;
import java.util.*;

public class codeforces_676A
{
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

	public static void main(String[] args)
	{
		FastReader ob=new FastReader();
		int n=ob.nextInt();
		int arr[]=new int[n];
        for (int i = 0; i <n ; i++) {
            arr[i]=ob.nextInt();
        }
        if(arr[0]==n || arr[0]==1 || arr[n-1]==1 || arr[n-1]==n){
            System.out.println(n-1);
            return;
        }
        System.out.println(Math.max(arr[n-1],arr[0])-1);

	}
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Likai
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            while (testNumber-- > 0) {
                int n = in.nextInt();
                int[] a = new int[n];
                int maxidx = 0, maxval = Integer.MIN_VALUE, minidx = 0, minval = Integer.MAX_VALUE;
                for (int i = 0; i < n; ++i) {
                    a[i] = in.nextInt();
                    if (a[i] < minval) {
                        minval = a[i];
                        minidx = i;
                    } else if (a[i] > maxval) {
                        maxval = a[i];
                        maxidx = i;
                    }
                }
                out.println(Integer.max(Integer.max(Math.abs(maxidx - n + 1), Math.abs(minidx - n + 1)), Integer.max(Math.abs(maxidx), Math.abs(minidx))));
            }
        }

    }
}

import java.util.*;
public class NikolaAndSort
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
int min = 1;
int max = 0;
for(int i = 0;i < n;i++)
{
a[i] = sc.nextInt();
min = Math.min(min,a[i]);
max = Math.max(max,a[i]);
}
int x1 = 0;
int x2 = 0;
for(int i = 0;i<n;i++)
{
      if(a[i]==min)
      {
            x1 = i;
      }
      else if(a[i]==max)
      {
            x2 = i;
      }
}
if(x1 == 0 && x2 == (n-1) || x1 == (n-1)&&x2 == 0)
{
      System.out.println(n);
}
else
{
 System.out.println((x2 - x1)+2);
}
}
}

import java.io.*;
import java.math.*;
import java.util.*;
/**
 * @author ramilagger
 *
 */
public class Main {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    public void solve() throws Exception {

        int n = nextInt();
        int[] a = nextArray(n);
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int mini = 0;
        int maxi = 0;
        for (int i = 0; i < n; i++) {
            if(a[i] > max){
                max = a[i];
                maxi = i;
            }if(a[i] < min){
                mini = i;
                min = a[i];
            }
        }
        if(mini == 0 || maxi == 0 || maxi == n - 1 || mini == n - 1){
            pw.println(n - 1);
        }else {
            min = Math.max(mini,maxi);
            max = Math.min(mini,maxi);
            pw.println(Math.max(n - min, max));
        }
        pw.println();
    }

    public void run() throws Exception {
        long start = System.currentTimeMillis();
        solve();
        if(!ONLINE_JUDGE){
            long end = System.currentTimeMillis();
            System.err.println(end - start + " ms");
        }
        pw.close();
    }

    public Main() throws Exception {

        br = (ONLINE_JUDGE) ? new BufferedReader(new InputStreamReader(System.in))
                : new BufferedReader(new FileReader("in.txt"));

        pw = (ONLINE_JUDGE) ?
                new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))
                : new PrintWriter(new BufferedWriter(new FileWriter("out.txt")));

    }

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

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

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

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

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

    public BigInteger nextBigInteger () throws IOException {
        return new BigInteger(next());
    }

    public String nextLine() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            return br.readLine();
        }
        StringBuilder sb = new StringBuilder(st.nextToken());
        while (st.hasMoreTokens()){
            sb.append(" " + st.nextToken());
        }
        return sb.toString();
    }

    public int[] nextArray(int n) throws IOException {
        int[] temp = new int[n];
        for (int i = 0; i < n; i++) {
            temp[i] = nextInt();
        }
        return temp;
    }

    public long[] nextLArray(int n) throws IOException {
        long[] temp = new long[n];
        for (int i = 0; i < n; i++) {
            temp[i] = nextLong();
        }
        return temp;
    }

    final BufferedReader br;
    final PrintWriter pw;
    StringTokenizer st;
}

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

public class Solution {

    /**
     * ****** SOLUTION STARTS HERE ***********
     */

    private static void solve(FastScanner in, PrintWriter out) {
        int n = in.nextInt();
        int i,index = 0;
        int temp;
        for(i=1; i<= n; i++){
            temp = in.nextInt();
            if(temp == n){
                index = i;
            }
        }
        out.println(Math.max(index,n-index));
    }

    /************* SOLUTION ENDS HERE **********/

    /**
     * ******* TEMPLATE STARTS HERE **********
     */

    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out =
                new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
        solve(in, out);
        in.close();
        out.close();
    }

    static class FastScanner {
        BufferedReader reader;
        StringTokenizer st;

        FastScanner(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = null;
            try {
                s = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }

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

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

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

        char nextChar() {
            return next().charAt(0);
        }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            int i = 0;
            while (i < n) {
                arr[i++] = nextInt();
            }
            return arr;
        }

        long[] nextLongArray(int n) {
            long[] arr = new long[n];
            int i = 0;
            while (i < n) {
                arr[i++] = nextLong();
            }
            return arr;
        }

        int[] nextIntArrayOneBased(int n) {
            int[] arr = new int[n + 1];
            int i = 1;
            while (i <= n) {
                arr[i++] = nextInt();
            }
            return arr;
        }

        long[] nextLongArrayOneBased(int n) {
            long[] arr = new long[n + 1];
            int i = 1;
            while (i <= n) {
                arr[i++] = nextLong();
            }
            return arr;
        }

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

    /*********** TEMPLATE ENDS HERE *************/
}

import java.util.*;

public class CF354A {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int []a=new int [n];
		int ma=0,mi=n+1;
		int inda=0,indi=0;
		for (int i=0;i<n;i++){
			a[i]=sc.nextInt();
			if(a[i]<mi){
				mi=a[i];
				indi=i;
			}
			if(a[i]>ma){
				ma=a[i];
				inda=i;
			}
		}
		int ans=0;
		int tmp=inda>indi?inda:indi;
		int tmp2=inda>indi?indi:inda;
		ans=tmp>(n-1-tmp2)?tmp:n-1-tmp2;
		System.out.println(tmp+" "+tmp2);
		System.out.println(ans);
	}
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package Round354;
    import java.util.*;

/**
 *
 * @author Afzal
 */
public class num1 {

    public static void main(String [] Args){
        Scanner input=new Scanner(System.in);
        int iSize =Integer.parseInt( input.nextLine());
        String sInput = input.nextLine();
        String sTest = sInput.replace(" ", "");

        String[] arr1 =sInput.split(" ");
        int[] arr = new int[iSize];

        for(int i=0;i<=iSize-1;i++){
           arr[i] = Integer.parseInt(arr1[i]);
           arr[i] = Integer.parseInt(arr1[i]);

        }
        Arrays.sort(arr);
       int iMin=arr[0];
        int iMax =arr[iSize-1];
        int iPosMin=-1;
        int  iPosMax=-1;
        for(int i=0;i<=iSize-1;i++){
            if(Integer.parseInt(arr1[i]) == iMin)
                iPosMin =i;

            if(Integer.parseInt(arr1[i]) == iMax)
                iPosMax =i;
            if(iPosMax != -1 && iPosMin != -1)
                break;
        }

        if(iPosMax == 0 || iPosMin == 0 || iPosMax == iSize-1 || iPosMin == iSize-1  ){
          System.out.println ( iSize-1 );
        }else{
            int iMid = (iSize+1)/2;
            if(iPosMax < iPosMin){
                if(iPosMax+1 > iMid){
                     System.out.println(iPosMin);
                }
                else{
                     System.out.println(iSize-1- Math.min(iPosMin, iPosMax));
                }
            }
            else{
                if(iPosMin+1 > iMid){
                    System.out.println(iPosMax);
                }
                else{
                     System.out.println(iSize-1- Math.min(iPosMin, iPosMax));
                }
            }
        }

        //int iRes = new String(arr);
    }
}

import java.util.Scanner;

public class Trial {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] val = new int[n];
		int index_large = 0;
		int index_small = 0;
		for (int i = 0; i < n; i++) {
			val[i] = sc.nextInt();
			if (val[i] == 1) {
				index_small = i;
			}
			if (val[i] == n) {
				index_large = i;
			}
		}
		int val1;
		int val2;
		if (index_small < index_large) {
			val1 = index_large - 1;
			val2 = n - index_small;
			if (val1 > val2) {
				System.out.println(val1 - 1);
			} else {
				System.out.println(val2 - 1);
			}
		} else {
			val1 = index_small - 1;
			val2 = n - index_large;
			if (val1 > val2) {
				System.out.println(val1 - 1);
			} else {
				System.out.println(val2 - 1);
			}
		}
	}
}

import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        int max_pos = 0, min_pos = 0, num;
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            num = sc.nextInt();
            if (num == n) {
                max_pos = i;
            }
            if (num == 1) {
                min_pos = i;
            }
        }
        if (n == 3) {
            System.out.println("2");
        } else if (max_pos == 1 || min_pos == 1 || max_pos == n || min_pos == n) {
            System.out.println(n - 1);
        } else if ((max_pos == 1 && min_pos == n) || (max_pos == n && min_pos == 1)) {
            System.out.println(n - 1);
        } else {
            System.out.println(Math.max(min_pos, max_pos)-1);
        }
        bw.flush();
    }
}

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

public class A {

	static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		line();
		int n = nextInt();
		line();
		String l = "";
		for (int i = 0; i < n; i++) {
			int c = nextInt();
			l += ("" +c);
		}
		int min = l.indexOf("1");
		int max = l.indexOf("" + n);

		int r = Integer.MIN_VALUE;
		r = Math.max(n - max-1, r);
		r = Math.max(r,  n - min-1);
		r = Math.max(r, min - 1);
		r = Math.max(r, max - 1);
		System.out.println(r);

	}

	static void line() throws IOException {
		st = new StringTokenizer(br.readLine());
	}

	static String token() {
		return st.nextToken();
	}

	static int nextInt() {
		return Integer.parseInt(token());
	}

	static long nextLong() {
		return Long.parseLong(token());
	}

}

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

public class Main {

  public static void main(String[] args) {

      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();

      int temp = sc.nextInt();

      int max = temp;
      int min = temp;
      int max_pos = 0;
      int min_pos = 0;

      for (int i = 1; i < n; i++) {
        temp = sc.nextInt();
        if (max < temp) {
          max = temp;
          max_pos = i;
        }
        if (min > temp) {
          min = temp;
          min_pos = temp;
        }
      }

      int result = min_pos - 0;
      if (n - min_pos > result)
        result = n - min_pos;
      if (max_pos - 0 > result)
        result = max_pos - 0;
      if (n - max_pos > result)
        result = n - max_pos;

      result--;

      System.out.println(result);

      sc.close();

  }

}

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

public class ArrayDiffernce
{
    public static void main(String[] args)
	{
		Scanner scanner=new Scanner(System.in);
		int index=scanner.nextInt();
		int a[]=new int[index];

		for(int i=0;i<index;i++)
		{
			a[i]=scanner.nextInt();

		}
		Arrays.sort(a);
		int maxDiff=a[index-1]-a[0];
//		for(int j=1;j<index-1;j++)
//		{
//			maxDiff=Math.max(a[j+1]-a[j],maxDiff);
//
//		}
//
        System.out.println(maxDiff);

	}

}

import java.io.*;
import java.util.*;
//import java.math.*;
//import static java.lang.Math.*;
//import static java.lang.Integer.parseInt;
//import static java.lang.Long.parseLong;
//import static java.lang.Double.parseDouble;
//import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
//        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));                                    //(new FileReader("input.in"));
//        StringBuilder out = new StringBuilder();
//        StringTokenizer tk;
        //   Scanner s = new Scanner(System.in);
        Reader.init(System.in);
        //tk = new StringTokenizer(in.readLine());
        int[] a = new int[Reader.nextInt()];
        int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
        int c = 0, k = 0;
        for (int i = 0; i < a.length; i++) {
            a[i] = Reader.nextInt();
            if (i != 0 && i != a.length - 1 && a[i] < min) {
                min = a[i];
                c = i;
            }
            if (i != 0 && i != a.length - 1 && a[i] > max) {
                max = a[i];
                k = i;
            }
        }
        int y = 0;
        y = Math.abs(a[0] - max);
        if (Math.abs(a[0] - min) > y) {
            y = Math.abs(a[0] - min);
        }  if (Math.abs(a[a.length - 1] - max) > y) {
            y = Math.abs(a[a.length - 1] - max);
        }  if (Math.abs(a[a.length - 1] - min) > y) {
            y = Math.abs(a[a.length - 1] - min);
        }  if (Math.abs(a[0] - a[a.length - 1]) > y) {
            y = Math.abs(a[0] - a[a.length - 1]);
        }
        System.out.println(y);
    }
}

class Reader {

    static StringTokenizer tokenizer;
    static BufferedReader reader;

    public static void init(InputStream input) throws UnsupportedEncodingException {
        reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
        tokenizer = new StringTokenizer("");
    }

    public static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    public static String nextLine() throws IOException {
        return reader.readLine();
    }

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

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

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

import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class Main{

	public static void main(String arg[]){
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int V[]=new int[n+1];
		Set<Integer> mapIz=new TreeSet<>();
		Set<Integer> mapDer=new TreeSet<>();
		for(int i=1;i<=n;++i)
			V[i]=in.nextInt();
		int max=1;
		for(int i=2;i<=n;++i){
			if(V[i]>V[max]){
				max=i;
			}
		}
		if(n==2)
			System.out.println(1);
		else
			System.out.println(Math.max(n-max,max));

	}
}

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

public class Main {

    /**
     * ****** SOLUTION STARTS HERE ***********
     */

    private static void solve(FastScanner in, PrintWriter out) {
        int n = in.nextInt();
        int i,max = 0, min = 0;
        int temp;
        for(i=1; i<= n; i++){
            temp = in.nextInt();
            if(temp == n){
                max = i;
            }
            if(temp == 1){
                min = i;
            }
        }
        //out.println(Math.max(index-1,n-index));
        if(min == 1 && max == n){
            out.println(n-1);
        }
        else if(min == 1){
            out.println(n-1);
        }
        else if(max == n){
            out.println(n-1);
        }
        else{
            out.println(Math.max(max-1, n-max));
        }
    }

    /************* SOLUTION ENDS HERE **********/

    /**
     * ******* TEMPLATE STARTS HERE **********
     */

    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out =
                new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
        solve(in, out);
        in.close();
        out.close();
    }

    static class FastScanner {
        BufferedReader reader;
        StringTokenizer st;

        FastScanner(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = null;
            try {
                s = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }

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

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

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

        char nextChar() {
            return next().charAt(0);
        }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            int i = 0;
            while (i < n) {
                arr[i++] = nextInt();
            }
            return arr;
        }

        long[] nextLongArray(int n) {
            long[] arr = new long[n];
            int i = 0;
            while (i < n) {
                arr[i++] = nextLong();
            }
            return arr;
        }

        int[] nextIntArrayOneBased(int n) {
            int[] arr = new int[n + 1];
            int i = 1;
            while (i <= n) {
                arr[i++] = nextInt();
            }
            return arr;
        }

        long[] nextLongArrayOneBased(int n) {
            long[] arr = new long[n + 1];
            int i = 1;
            while (i <= n) {
                arr[i++] = nextLong();
            }
            return arr;
        }

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

    /*********** TEMPLATE ENDS HERE *************/
}

import java.io.*;
import java.util.*;
public class cdf354a
{
	public static void main(String args[])throws Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		String s=br.readLine();
		String str[]=s.split(" ");
		int arr[]=new int[n];
		int pmin=0,pmax=0;
		for(int i=0;i<n;i++)
		{
			arr[i]=Integer.parseInt(str[i]);
			if(arr[i]==1)
				pmin=i;
			if(arr[i]==n)
				pmax=i;
		}
		int mi1=(int)Math.min(pmax,n-pmax-1);
		int mi2=(int)Math.min(pmin,n-pmin-1);
		int diff=Math.abs(pmax-pmin)+(int)Math.max(mi1,mi2);
		System.out.println(diff);

	}
}

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A764 {
    public static void main(String [] args) {
        InputStream inputReader = System.in;
        OutputStream outputReader = System.out;
        InputReader in = new InputReader(inputReader);
        PrintWriter out = new PrintWriter(outputReader);
        Algorithm solver = new Algorithm();
        solver.solve(in, out);
        out.close();
    }
}

class Algorithm {
    void solve(InputReader ir, PrintWriter pw) {
        int n = ir.nextInt();
        int [] array = new int[n];
        int min = 0;
        int max = 0;

        for (int i = 0; i < n; i++) array[i] = ir.nextInt();
        int minPos = array[0];
        int maxPos = array[0];
        int total = 0;

        for (int i = 0; i < n; i++) {
            if (array[i] > maxPos) {
                max = i;
                maxPos = array[i];
            } else if (array[i] < minPos) {
                min = i;
                minPos = array[i];
            }
        }

        if (min < max) {
            if (min == 0 || max == n - 1) {
                total = n - 1;
            } else if (min <= n - min - 1) {
                total = n - max - 1;
            } else {
                total = min + 1;
            }

        } else {
            if (max == 0 || min == n - 1) {
                total = n - 1;
            } else if (max <= n - max - 1) {
                total = n - min - 1;
            } else {
                total = max + 1;
            }
        }

        pw.print(total);

    }

}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

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

}

import java.util.Scanner;
public class nicholas
{
public static void main(String []arg)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int x=1,y=1,a=0,b=0;
for(int i=1;i<=n;i++)
{
int z=sc.nextInt();
if(i==1)
{
a=z;
b=z;
}
if(z<a)
{
a=z;
x=i;
}
else if(z>b)
{
b=z;
y=i;
}
}
int z=(n-y)>(n-x)?(n-y):(n-x);
System.out.println(z);
}
}

import java.io.*;
import java.util.InputMismatchException;
/* * */

public class _354_A implements Runnable{
    public static void main(String[] args) {
	    new Thread(null, new _354_A(),"Main",1<<27).start();
    }
    @Override
    public void run() {
        FastReader fd = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = fd.nextInt();
        int[] data = new int[n+1];
        for(int i = 1; i <= n; i++){
            data[fd.nextInt()] = i;
        }
        if(data[1] == 1 && data[n] == n){
            out.println(n-1);
        }
        int min = Math.max(Math.abs(data[n]-1),Math.abs(n-data[n]));
        int max = Math.max(Math.abs(data[1]-1),Math.abs(n-data[1]));
        out.println(Math.max(min,max));
        out.close();
    }

    //Helper functions
    static int gcd(int a, int b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    static int lcm(int a, int b) {
        return (a*b)/gcd(a, b);
    }

    static boolean checkDistinct(int next){

        String process = String.valueOf(next);
        for(int i = 0;i < process.length()-1; i++){
            String character = String.valueOf(process.charAt(i));
            if(process.substring(i+1).contains(character)){ return false; }
        }
        return true;
    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

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

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

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

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

            int sgn = 1;

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

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

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

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

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

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

            return res.toString();
        }

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

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int size = scanner.nextInt();

        ArrayList<Integer> arr = new ArrayList<>();

        int min = 1;
        int max = size;

        int maxDistance = 0;

        for (int i = 0; i < size; i++) {
            arr.add(scanner.nextInt());
        }

        int indexMin = arr.indexOf(min);
        int indexMax = arr.indexOf(max);

        if (indexMin == 0 || indexMax == size - 1 || indexMin == size - 1 || indexMax == 0) {
            maxDistance = size - 1;
        } else {
            if (indexMin > indexMax) {
                maxDistance = size - 1 - indexMax;
            } else {
                maxDistance = size - 1 - indexMin;
            }
        }

        System.out.println(maxDistance);
    }
}

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

public class A {

    static MyScanner in = new MyScanner();
    static   PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static long H,W;
    static BitSet bs;
    static long mod = 1000000007;
    public static void main(String args[]) throws IOException {
       int n = in.nextInt();
       int indexOne =-1;
       int indexn =-1;
       int []arr =  new int[n];
       for(int i=0;i<n;i++){
           arr[i] = in.nextInt();
           if(arr[i]==1){
               indexOne = i;
           }else  if(arr[i]==n){
               indexn=i;
           }
       }
       int max =-1;
       //index of one
       for(int i=0;i<n;i++){
           if(i!=indexn){
            max = Math.max(max, Math.abs(n-indexOne-1));
           }
       }
       for(int i=0;i<n;i++){
        if(i!=indexOne){
         max = Math.max(max, Math.abs(n-indexn-1));
        }

    }
    if(n==1){
        out.println(0);
    }else if(n==2){
        out.println(1);
    }else{
        out.println(max);
    }
    out.flush();

    }
    static boolean isVowel(char c){
        if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y'){
            return true;
        }
        return false ;
    }
    static class IP implements Comparable<IP>{
        public int first,second;
        IP(int first, int second){
            this.first = first;
            this.second = second;
        }
        public int compareTo(IP ip){
            if(first==ip.first)
                return second-ip.second;
            return first-ip.first;
        }

    }

       static long gcd(long a, long b){
        return b!=0?gcd(b, a%b):a;
    }

        static boolean isEven(long a) {
            return (a&1)==0;
        }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

     }
}

/**
 * Created by iainws on 26/05/16.
 */

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

public class NicholasPermutation {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReaderNicholasPermutation in = new InputReaderNicholasPermutation(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskNicholasPermutation solver = new TaskNicholasPermutation();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskNicholasPermutation {
    public void solve(int taskNumber, InputReaderNicholasPermutation in, PrintWriter out) {
        int n = in.nextInt();
        int [] arr = new int[n];
        for(int i=0;i<n;++i) {
            arr[i] = in.nextInt();
        }
        int mn = Integer.MAX_VALUE;
        int mx = Integer.MIN_VALUE;
        int min_index = -1;
        int max_index = -1;
        for(int i=0;i<n;++i) {
            if(arr[i] < mn) {
                mn = arr[i];
                min_index = i;
            }
            if(arr[i] > mx){
                mx = arr[i];
                max_index = i;
            }
        }
        int dist = Math.abs(min_index - max_index);
        if(min_index < max_index){
            if(min_index > n - max_index){
                dist += min_index;
            }
            else{
                dist += n - max_index;
            }
        }
        else{
            if(max_index > n - min_index){
                dist += max_index;
            }
            else{
                dist += n - min_index;
            }
        }
        System.out.println(dist - 1);
    }
}

class InputReaderNicholasPermutation {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReaderNicholasPermutation(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

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

}

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int size = scanner.nextInt();

        ArrayList<Integer> arrayList = new ArrayList<>();

        int min = 1;
        int max = size;

        int maxDistance = 0;

        for (int i = 0; i < size; i++) {
            arrayList.add(scanner.nextInt());
        }

        // 4, 3, 5, 1, 2
        // 2 3 1
        // 1 3 2

        if (arrayList.indexOf(max) - arrayList.indexOf(min) == size - 1) {
            maxDistance = size - 1;
        } else {
            if (arrayList.indexOf(max) < size / 2) {
                maxDistance = size - 1 - arrayList.indexOf(max);
            } else if (arrayList.indexOf(max) == size / 2 && (arrayList.indexOf(min) == 0 || arrayList.indexOf(min) == size - 1)) {
                maxDistance = size - 1;
            } else {
                maxDistance = size - 1 - arrayList.indexOf(min);
            }
        }

        System.out.println(maxDistance);
    }
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package Round354;
    import java.util.*;

/**
 *
 * @author Afzal
 */
public class num1 {

    public static void main(String [] Args){
        Scanner input=new Scanner(System.in);
        int iSize =Integer.parseInt( input.nextLine());
        String sInput = input.nextLine();
        String sTest = sInput.replace(" ", "");

        String[] arr1 =sInput.split(" ");
        int[] arr = new int[iSize];

        for(int i=0;i<=iSize-1;i++){
           arr[i] = Integer.parseInt(arr1[i]);
           arr[i] = Integer.parseInt(arr1[i]);

        }
        Arrays.sort(arr);
       int iMin=arr[0];
        int iMax =arr[iSize-1];
        int iPosMin=-1;
        int  iPosMax=-1;
        for(int i=0;i<=iSize-1;i++){
            if(Integer.parseInt(arr1[i]) == iMin)
                iPosMin =i;

            if(Integer.parseInt(arr1[i]) == iMax)
                iPosMax =i;
            if(iPosMax != -1 && iPosMin != -1)
                break;
        }

        if(iPosMax == 0 || iPosMin == 0 || iPosMax == iSize-1 || iPosMin == iSize-1  ){
          System.out.println ( iSize-1 );
        }else{
            int iMid = (iSize+1)/2;System.out.println(iMid);
            if(iPosMax < iPosMin){
                if(iPosMax+1 >= iMid){
                     System.out.println(iPosMin);
                }
                else{
                     System.out.println(iSize-1- Math.min(iPosMin, iPosMax));
                }
            }
            else{
                if(iPosMin+1 >= iMid){
                    System.out.println(iPosMax);
                }
                else{
                     System.out.println(iSize-1- Math.min(iPosMin, iPosMax));
                }
            }
        }

        //int iRes = new String(arr);
    }
}

import java.util.Scanner;

public class Problem676A {

    public static void main(String[] args) {
        Scanner numberInput = new Scanner(System.in);

        int n = numberInput.nextInt();
        int a[] = new int[n];

        for (int i = 0; i < a.length; i++) {
            a[i] = numberInput.nextInt();
        }

        int posOf1 = findPos(1, a);
        int posOfn = findPos(n, a);

        int sol = 0;

        if (n == 2) {
            System.out.println(1);
        } else if (n == 3) {
            System.out.println(2);
        } else {
            if (posOfn <= (n / 2)) {
                sol = n - 1 - posOfn;
            } else {
                sol = n - 1 - posOf1;
            }
            System.out.println(sol);
        }

    }

    public static int findPos(int key, int a[]) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] == key) {
                return i;
            }
        }
        return -1;
    }

}

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

/**
 * See
 * CF676ANicholasAndPermutation
 *
 * @author Brian Yeicol Restrepo Tangarife
 */
public class CF676ANicholasAndPermutation {

	static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException {
		int n = readInt();

		String a = read().replace(" ", "");
		int pos1 = a.indexOf("1");
		int posn = a.indexOf(String.valueOf(n));
		int max = Math.max(Math.abs(posn + 1), Math.abs(pos1 + 1));
		max = Math.max(max, Math.abs(n - 1 - pos1));
		max = Math.max(max, Math.abs(n - 1 - posn));
		out.print(max);
		//out.print(n - 1 - Math.min(pos1, posn));
		out.close();
	}

	private static String read() throws IOException {
		return in.readLine();
	}

	private static int readInt() throws IOException {
		return Integer.parseInt(in.readLine());
	}

}

import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE, max_pos = 0, min_pos = 0, num;
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            num = sc.nextInt();
            if (num > max) {
                max = num;
                max_pos = i;
            }
            if (num < min) {
                min = num;
                min_pos = i;
            }
        }
        System.out.println(max_pos + " " + min_pos);
        if ((max_pos == 1 && min_pos == n) || (max_pos == n && min_pos == 1)) {
            System.out.println(Math.abs(max_pos - min_pos));
        } else {
            System.out.println(Math.abs(max_pos - min_pos) + 1);
        }
        bw.flush();
    }
}

import java.util.Scanner;
import java.math.*;

public class Hellowrodl {

	private static int j = 0;

	public static void main(String[] args) {
		Scanner  x = new Scanner(System.in);
		int n=x.nextInt();
		int array[]=new  int[n];
		for(int i=0;i<array.length;i++){
			array[i]=x.nextInt();
		}
		for( j=0;j<array.length;j++){
			if(array[j]==1 || array[j]==n)
				break;
		}
		System.out.println(array.length-1 - j);
	}
}

import java.util.*;
public class CF676A {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int ans = 0;
		for(int i = 0; i < n; i ++)
		{
			int x = in.nextInt();
			if(x==n||x==1)
			{
				ans = Math.max(ans, n-i-1);
				ans = Math.max(ans,  i-1);
			}
		}
		System.out.println(ans);
	}
}

import java.util.Scanner;
import java.lang.Integer;

public class test {

	public static void main(String[] args) {

		int n;

	    Scanner sc = new Scanner(System.in);

	    n = sc.nextInt();

	    int M[] = new int[n];

	    sc.nextLine();

	    int min = 0,max = 0;
	    for ( int i = 0; i < n; i++){
	    	M[i] = sc.nextInt();
	    	if (M[i] == 1) min = i;
	    	if (M[i] == n) max = i;

	    }

	    System.out.println(min + " " + max);

	    if ( n == 2 ) System.out.print(1);
	    else {
	    if (min == 0 || max == 0 || min == n || max == n){
	    	System.out.print(n-1);
	    }
	    else{
	    	int f1 = Math.abs(min - (n/2));
	    	int f2 = Math.abs(max - (n/2));

	    	int ans = f1 >= f2 ? f1 : f2;

	    	if (n %2 == 0) System.out.print(ans+ (n/2)-1);
	    	else
	    	System.out.print(ans+ (n/2));

	    }
	    }
	    /*
	    int M[][] = new int [n][2];

	    String s;
	    sc.nextLine();
	    for (int i = 0; i < n; i++){
	    	s = sc.nextLine();
		    String[] ss = s.split(" ");

	    	M[i][0] = Integer.valueOf(ss[0]);
	    	M[i][1] = Integer.valueOf(ss[1]);

	    }

	    int ans = 0;

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

	    		if (M[i][0] == M[j][1]) ans += 1;

	    	}
	    }

	   System.out.println(ans);

	   */

	}
}

import java.io.DataInputStream;
import java.io.InputStream;
import java.util.Arrays;

public class TaskA {
    public static void main(String[] args)
    {

        Parser in = new Parser(System.in);
        int n = in.nextInt();

        int[] numbers = new int[n];

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

        int[] copy  = numbers;

        int maxIndex = -1, minIndex = -1;

        int max = 0, min = 101;
        for (int i=0;i<n;i++)
        {
            if (numbers[i] > max)
            {
                max = numbers[i];
                maxIndex = i;
            }
            if(numbers[i] < min)
            {
                min = numbers[i];
                minIndex = i;
            }
        }

     //   System.out.println(max +" "+(maxIndex));
     //   System.out.println(min +" "+(minIndex));

        int min1 = minIndex -1;
        int min2 = n - minIndex-1;
     //   System.out.println("Min: "+min1+" : "+min2);

        int max1 = maxIndex -1;
        int max2 = n - maxIndex-1;
       // System.out.println("Max: "+max1+" : "+max2);

        System.out.println( Math.max( Math.max( min1,min2 ), Math.max( max1, max2 ) ) );

     //   int v1 =  minIndex -1;
       // int v2 =  n - maxIndex-1;
      //  System.out.println(v2+":"+v1);
      //  System.out.println(  Math.abs( v1-v2 ) + Math.max( v2, v1  ) );
    };
}

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

    public Parser(InputStream in) {
        din = new DataInputStream(in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String nextString(int maxSize) {
        byte[] ch = new byte[maxSize];
        int point = 0;
        try {
            byte c = read();
            while (c == ' ' || c == '\n' || c == '\r')
                c = read();
            while (c != ' ' && c != '\n' && c != '\r') {
                ch[point++] = c;
                c = read();
            }
        } catch (Exception e) {
        }
        return new String(ch, 0, point);
    }

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

            if (neg) return -ret;
        } catch (Exception e) {
        }
        return ret;
    }

    public long nextLong() {
        long ret = 0;
        boolean neg;
        try {
            byte c = read();
            while (c <= ' ')
                c = read();
            neg = c == '-';
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
                c = read();
            } while (c > ' ');

            if (neg) return -ret;
        } catch (Exception e) {
        }
        return ret;
    }

    private void fillBuffer() {
        try {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        } catch (Exception e) {
        }
        if (bytesRead == -1) buffer[0] = -1;
    }

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

import java.util.*;

/**
 * Created by omar on 3/24/16.
 */
public class main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        ArrayList<Integer> input = new ArrayList<>(n);

        for(int i=0; i<n; i++)
            input.add(scan.nextInt());

        int indexMax = 0, max = -1;
        int indexMin = 0, min = 102;
        for(int i=0; i<input.size(); i++) {
            if(max <= input.get(i)) {
                indexMax = i;
                max = input.get(i);
            }
            if(min > input.get(i)) {
                indexMin = i;
                min = input.get(i);
            }
        }
        if(indexMax < indexMin) {
            indexMax = indexMax + indexMin;
            indexMin = indexMax - indexMin;
            indexMax = indexMax - indexMin;
        }
        System.out.println(maxDif(input.size(), indexMin, indexMax) - 1);

    }

    static int maxDif(int size, int first, int second) {
        if(size - second > first)
            second = size;
        else
            first = 0;
        return second - first;
    }

}

import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        int max_pos = 0, min_pos = 0, num;
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            num = sc.nextInt();
            if (num == n) {
                max_pos = i;
            }
            if (num == 1) {
                min_pos = i;
            }
        }
        if (n == 3) {
            System.out.println("2");
        } else if (max_pos == 1 || min_pos == 1 || max_pos == n || min_pos == n) {
            System.out.println(n - 1);
        } else if ((max_pos == 1 && min_pos == n) || (max_pos == n && min_pos == 1)) {
            System.out.println(n - 1);
        } else {
            System.out.println(n - Math.min(min_pos, max_pos));
        }
        bw.flush();
    }
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package Round354;
    import java.util.*;

/**
 *
 * @author Afzal
 */
public class num1 {

    public static void main(String [] Args){
        Scanner input=new Scanner(System.in);
        int iSize =Integer.parseInt( input.nextLine());
        String sInput = input.nextLine();
        String sTest = sInput.replace(" ", "");

        String[] arr1 =sInput.split(" ");
        int[] arr = new int[iSize];

        for(int i=0;i<=iSize-1;i++){
           arr[i] = Integer.parseInt(arr1[i]);
           arr[i] = Integer.parseInt(arr1[i]);

        }
        Arrays.sort(arr);
       int iMin=arr[0];
        int iMax =arr[iSize-1];
        int iPosMin=-1;
        int  iPosMax=-1;
        for(int i=0;i<=iSize-1;i++){
            if(Integer.parseInt(arr1[i]) == iMin)
                iPosMin =i;

            if(Integer.parseInt(arr1[i]) == iMax)
                iPosMax =i;
            if(iPosMax != -1 && iPosMin != -1)
                break;
        }

        if(iPosMax == 0 || iPosMin == 0 || iPosMax == iSize-1 || iPosMin == iSize-1  ){
          System.out.println ( iSize-1 );
        }else{
            int iMid = (iSize+1)/2;
            if(iPosMax < iPosMin){
                if(iPosMax+1 >= iMid){
                     System.out.println(iPosMin);
                }
                else{
                     System.out.println(iSize-1- Math.min(iPosMin, iPosMax));
                }
            }
            else{
                if(iPosMin+1 >= iMid){
                    System.out.println(iPosMax);
                }
                else{
                     System.out.println(iSize-1- Math.min(iPosMin, iPosMax));
                }
            }
        }

        //int iRes = new String(arr);
    }
}

import java.util.Scanner;

/**
 * Created by alan turing on 5/29/2016.
 */
public class Nicholas_and_Permutation {
    public static void main(String[] args) {
        Scanner input= new Scanner(System.in) ;
        int number = Integer.parseInt(input.next());
        int [] nums = new int[number];
        for (int i =0 ;i < number ; i++) {
            nums[i] = Integer.parseInt(input.next());
        }
        int maxIndex = 0 , max  = nums[0];
        int minIndex = 0 , min  = nums[0] ;

        for (int i =0; i < number ; i++)
        {
            if (max <= nums[i]){
                maxIndex = i;
                max = nums[i] ;
            }
            if (min >= nums[i]){
                min = nums[i] ;
                minIndex=  i;
            }
        }
        if (minIndex < maxIndex){
            if (number - maxIndex -1 > minIndex){
                System.out.println(number - minIndex -1);
            }
            else {
                System.out.println(number - minIndex  - 1 );
            }
        }
        else{
            if (maxIndex < number -  minIndex - 1){
                System.out.println(number - maxIndex - 1 );
            }
            else
            {
                System.out.println(maxIndex);
            }
        }
    }
}

import java.util.Scanner;

public class NicoleAndPermutation {

	public static void main(String[] args) {

		System.out.println();
		Scanner sc = new Scanner(System.in);

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

		int max = 0;
		int min = Integer.MAX_VALUE;
		int iMin = -1, iMax = -1;
		for (int i = 0; i < a.length; i++) {
			if (min > a[i]) {
				min = a[i];
				iMin = i;
			}
			if (max < a[i]) {
				max = a[i];
				iMax = i;
			}
		}

		int ans = 0;
		if (iMax == 0 && iMin == len - 1 ||
		    iMin == 0 && iMax == len - 1) {
			ans = len - 1;
		} else if (iMax >= len / 2) {
			if (iMin != 0) {
				ans = iMax;
			} else {
				ans = len - 1;
			}
		} else {
			if (iMin != len - 1) {
				ans = len - 1 - iMax;
			} else {
				ans = len - 1;
			}
		}

		System.out.println(ans);

	} // end of main().

}

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

public class CF676A{

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

	private static void soln(){
		int n = nextInt();
		int[] ar = nextIntArray(n);
		int low = 0,high = 0;
		int ans = 0;
		for (int i=0; i<n; i++) {
			if(ar[i]==1)
				low = i;
			else if(ar[i]==n)
				high = i;
		}
		ans = Math.abs(high - low);
		ans = Math.max(ans,n-1-low);
		ans = Math.max(ans,1-low);
		ans = Math.max(ans,high);
		ans = Math.max(ans,high-n+1);
		pw.println(ans);
	}

	public static void main(String[] args){
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		soln();
		pw.close();
	}

	// To Get Input
	// Some Buffer Methods

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

	private static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

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

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

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

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

	private static String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}

}

import java.util.Scanner;
import java.lang.Integer;

public class test {

	public static void main(String[] args) {

		int n;

	    Scanner sc = new Scanner(System.in);

	    n = sc.nextInt();

	    int M[] = new int[n];

	    sc.nextLine();

	    int min = 0,max = 0;
	    for ( int i = 0; i < n; i++){
	    	M[i] = sc.nextInt();
	    	if (M[i] == 1) min = i;
	    	if (M[i] == n) max = i;

	    }

	    if ( n == 2 ) System.out.print(1);
	    else {
	    if (min == 0 || max == 0 || min == n || max == n){
	    	System.out.print(n-1);
	    }
	    else{
	    	int f1 = Math.abs(min - (n/2));
	    	int f2 = Math.abs(max - (n/2));

	    	int ans = f1 >= f2 ? f1 : f2;

	    	if (n == 100) System.out.print(ans+ (n/2)-1);
	    	else
	    	System.out.print(ans+ (n/2));

	    }
	    }
	    /*
	    int M[][] = new int [n][2];

	    String s;
	    sc.nextLine();
	    for (int i = 0; i < n; i++){
	    	s = sc.nextLine();
		    String[] ss = s.split(" ");

	    	M[i][0] = Integer.valueOf(ss[0]);
	    	M[i][1] = Integer.valueOf(ss[1]);

	    }

	    int ans = 0;

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

	    		if (M[i][0] == M[j][1]) ans += 1;

	    	}
	    }

	   System.out.println(ans);

	   */

	}
}

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

public class NicholasAndPermutation {
	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		Reader in = new Reader();
		int n = in.readInt();
		int[] a = in.readIntArray(n);
		int minIndex = getMin(a);
		int maxIndex = getMax(a);
		if(minIndex > maxIndex) out.println(a.length - 1 - maxIndex);
		else out.println(a.length - 1 - minIndex);
		in.close();
		out.close();
	}
	static int getMin(int[] a){
		int index = 0;
		for(int i = 1; i < a.length; i++){
			if(a[index] > a[i]) index = i;
		}
		return index;
	}
	static int getMax(int[] a){
		int index = 0;
		for(int i = 1; i < a.length; i++){
			if(a[index] < a[i]) index = i;
		}
		return index;
	}
	static PrintWriter out;
	static class Reader {
		BufferedReader br;
		StringTokenizer st;
		public Reader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String read() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int readInt() {
			return Integer.parseInt(read());
		}
		long readLong() {
			return Long.parseLong(read());
		}
		double readDouble() {
			return Double.parseDouble(read());
		}
		char readChar() {
			return read().charAt(0);
		}
		int[] readIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = readInt();
			return a;
		}
		long[] readLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = readLong();
			return a;
		}
		double[] readDoubleArray(int n) {
			double[] a = new double[n];
			for (int i = 0; i < n; i++)
				a[i] = readDouble();
			return a;
		}
		String[] readStringArray(int n) {
			String[] s = new String[n];
			for (int i = 0; i < n; i++)
				s[i] = read();
			return s;
		}
		char[] readCharArray(int n) {
			char[] ch = new char[n];
			for (int i = 0; i < n; i++)
				ch[i] = readChar();
			return ch;
		}
		String readLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
		void close() {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}

import java.util.*;
public class HelloWorld{

     public static void main(String []args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int iPosition = -1, nPosition = -1;

        for(int i=0;i<n;i++) {
            int value = in.nextInt();
            if(value == 1){
                iPosition = i;
            }
            if(value == n){
                nPosition = i;
            }
        }
        in.close();
        int distance = Math.max(Math.abs(nPosition - n) , Math.abs(nPosition - 1));
        distance = Math.max(distance, Math.max(Math.abs(iPosition - n), Math.abs(iPosition - 1)));
        System.out.println(distance);
     }
}

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

public class NicholasAndPermutation
{

	public static void main(String[] args) throws Exception
	{
		int n = readInt(), max = 0, min = 0, v[] = new int[n];
		for (int i = 0; i < n; i++)
		{
			v[i] = readInt();
			max = (v[i] > v[max] ? i : max);
			min = (v[i] < v[min] ? i : min);
		}
		System.out.println(Math.max(min - 1,
				Math.max(max - 1, Math.max(n - 1 - max, n - 1 - min))));
	}

	static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	static PrintWriter out = new PrintWriter(new BufferedWriter(
			new OutputStreamWriter(System.out)));
	static StringTokenizer st;

	static String next() throws IOException
	{
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine().trim());
		return st.nextToken();
	}

	static long readLong() throws IOException
	{
		return Long.parseLong(next());
	}

	static int readInt() throws IOException
	{
		return Integer.parseInt(next());
	}

	static double readDouble() throws IOException
	{
		return Double.parseDouble(next());
	}

	static char readChar() throws IOException
	{
		return next().charAt(0);
	}

	static String readLine() throws IOException
	{
		return br.readLine().trim();
	}
}

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

public class NicholasAndPermutation {
	public static void main(String[] args) {
		BufferedReader bf = null;
		try {
			bf = new BufferedReader(new InputStreamReader(System.in));
			String r = bf.readLine();
			StringTokenizer st = new StringTokenizer(r);
			int n = Integer.parseInt(st.nextToken());

			r = bf.readLine();
			st = new StringTokenizer(r);
			ArrayList<Integer> l = new ArrayList<Integer>();
			int min = -1;
			int max = -1;
			for(int i=0;i<n;i++){
				int u = Integer.parseInt(st.nextToken());
				if(min==-1 || (min!=-1 && u<min))
					min = u;
				if(max==-1 || (max!=-1 && u>max))
					max = u;
				l.add(u);
			}
			int imin = l.indexOf(min);
			int imax = l.indexOf(max);

			if(l.indexOf(min)>l.indexOf(max)){
				imin = l.indexOf(max);
				imax = l.indexOf(min);
			}

			if(imax>l.size()-imin)

					System.out.println(imax);
			else
					System.out.println(l.size()-imin-1);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

import java.util.Scanner;

public class Problem676A {

    public static void main(String[] args) {
        Scanner numberInput = new Scanner(System.in);

        int n = numberInput.nextInt();
        int a[] = new int[n];

        for (int i = 0; i < a.length; i++) {
            a[i] = numberInput.nextInt();
        }

        int posOf1 = findPos(1, a);
        int posOfn = findPos(n, a);

        int sol = 0;

        if (posOfn <= (n / 2)) {
            sol = n - 1 - posOfn;
        } else {
            sol = n - 1 - posOf1;
        }
        System.out.println(sol);
    }

    public static int findPos(int key, int a[]) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] == key) {
                return i;
            }
        }
        return -1;
    }

}

import java.util.*;
public class NickAndPermute {
	static int N;
	static int maxInd, minInd;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		int k;
		for(int i = 0; i < N; i++)
		{
			k = sc.nextInt();
			if(k == 1)
			{
				minInd = i;
			}
			else if (k == N)
			{
				maxInd = i;
			}
		}
		int bottom = Math.min(minInd, maxInd);
		int top = Math.min(minInd, maxInd);
		if (top == bottom)
			System.out.print( N - bottom - 1 + "");
		else
		{
			int minDist = Math.min(bottom, N - 1 - top);

			int maxDist = Math.max(bottom, N - 1 - top);
			System.out.print((N - 1 -minDist) +"");
		}
	}

}

import java.util.Scanner;

public class Problem676A {

    public static void main(String[] args) {
        Scanner numberInput = new Scanner(System.in);

        int n = numberInput.nextInt();
        int a[] = new int[n];

        for (int i = 0; i < a.length; i++) {
            a[i] = numberInput.nextInt();
        }

        int posOf1 = findPos(1, a);
        int posOfn = findPos(n, a);

        int sol = 0;

        if (n == 2) {
            System.out.println(1);
        } else if (n == 3) {
            System.out.println(2);
        } else {
            if (posOfn <= (n / 2)) {
                sol = n - 1 - posOfn;
            } else {
                sol = n - 1 - posOf1;
            }
            System.out.println(sol);
        }

    }

    public static int findPos(int key, int a[]) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] == key) {
                return i;
            }
        }
        return -1;
    }

}

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

public class Main {

    /**
     * ****** SOLUTION STARTS HERE ***********
     */

    private static void solve(FastScanner in, PrintWriter out) {
        int n = in.nextInt();
        int i,index = 0;
        int temp;
        for(i=1; i<= n; i++){
            temp = in.nextInt();
            if(temp == n){
                index = i;
            }
        }
        out.println(Math.max(index-1,n-index));
    }

    /************* SOLUTION ENDS HERE **********/

    /**
     * ******* TEMPLATE STARTS HERE **********
     */

    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out =
                new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
        solve(in, out);
        in.close();
        out.close();
    }

    static class FastScanner {
        BufferedReader reader;
        StringTokenizer st;

        FastScanner(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = null;
            try {
                s = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }

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

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

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

        char nextChar() {
            return next().charAt(0);
        }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            int i = 0;
            while (i < n) {
                arr[i++] = nextInt();
            }
            return arr;
        }

        long[] nextLongArray(int n) {
            long[] arr = new long[n];
            int i = 0;
            while (i < n) {
                arr[i++] = nextLong();
            }
            return arr;
        }

        int[] nextIntArrayOneBased(int n) {
            int[] arr = new int[n + 1];
            int i = 1;
            while (i <= n) {
                arr[i++] = nextInt();
            }
            return arr;
        }

        long[] nextLongArrayOneBased(int n) {
            long[] arr = new long[n + 1];
            int i = 1;
            while (i <= n) {
                arr[i++] = nextLong();
            }
            return arr;
        }

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

    /*********** TEMPLATE ENDS HERE *************/
}

import java.util.Scanner;

/**
 * Created by alan turing on 5/29/2016.
 */
public class Nicholas_and_Permutation {
    public static void main(String[] args) {
        Scanner input= new Scanner(System.in) ;
        int number = Integer.parseInt(input.next());
        int [] nums = new int[number];
        for (int i =0 ;i < number ; i++) {
            nums[i] = Integer.parseInt(input.next());
        }
        int maxIndex = 0 , max  = nums[0];
        int minIndex = 0 , min  = nums[0] ;

        for (int i =0; i < number ; i++)
        {
            if (max <= nums[i]){
                maxIndex = i;
                max = nums[i] ;
            }
            if (min >= nums[i]){
                min = nums[i] ;
                minIndex=  i;
            }
        }
        if (minIndex == number -1 || maxIndex == number -1 ){
            System.out.println(number - 1);
        }
        else
        if (minIndex < maxIndex){
            if (number - maxIndex -1 > minIndex){
                System.out.println(number - minIndex -1);
            }
            else {
                System.out.println(number - minIndex  - 1 );
            }
        }
        else{
            if (maxIndex > number -  minIndex - 1){
                System.out.println(minIndex );
            }
            else
            {
                System.out.println(number -1 - maxIndex);
            }
        }
    }
}

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

public class C_VasyaAndStrings {
public static void main(String args[]) throws IOException {
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer st=new StringTokenizer(br.readLine());
	int n=Integer.parseInt(st.nextToken());
	int arr[]=new int[n];
	st=new StringTokenizer(br.readLine());

	int max=0,min=Integer.MAX_VALUE;
	for(int i=0;i<n;i++){
		arr[i]=Integer.parseInt(st.nextToken());
		min=Math.min(min,arr[i]);
		max=Math.max(max,arr[i]);
	}
	int p1 = Math.min(min, max);
    int pn= Math.max(min, max);
    int ans = Math.max(pn, n - p1 - 1);
    System.out.println(ans);

}
}

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

/**
 * See
 * CF676ANicholasAndPermutation
 *
 * @author Brian Yeicol Restrepo Tangarife
 */
public class CF676ANicholasAndPermutation {

	static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException {
		int n = readInt();

		String a = read().replace(" ", "");
		int pos1 = a.indexOf("1");
		int posn = a.indexOf(String.valueOf(n));
		int max = Math.max(Math.abs(posn - 1), Math.abs(pos1 - 1));
		max = Math.max(max, Math.abs(n - 1 - pos1));
		max = Math.max(max, Math.abs(n - 1 - posn));
		out.print(max);
		out.close();
	}

	private static String read() throws IOException {
		return in.readLine();
	}

	private static int readInt() throws IOException {
		return Integer.parseInt(in.readLine());
	}

}

import java.util.*;
public class Hello {
public static void main(String arr[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		if (n >= 2 && n <= 100) {
			int min = 0;
			int min_index = 0;
			int max = 0;
			int max_index = 0;
			int[] a = new int[n];
			for (int a_i = 0; a_i < n; a_i++) {
				int val = in.nextInt();
				a[a_i] = val;
				if (a_i == 0) {
					min = val;
					min_index = 0;
					max = val;
					max_index = 0;
				} else {
					if (max < val) {
						max = val;
						max_index = a_i;
					}
					if (min > val) {
						min = val;
						min_index = a_i;
					}
				}
			}
			int max_dis = find_max_dis(min, min_index, max, max_index, a);
			System.out.println(max_dis);
		}
	}

	private static int find_max_dis(int min, int min_index, int max, int max_index, int[] a) {
		int max_dis = 0;
		int row_max = 0;
		int row_min = 0;
		int max_d = 0;
		int max_dis_index = 0;
		if ((min_index + max_index + 1) == a.length)
			max_dis = swap_val(min, min_index, max, max_index, a)-1;
		else {
			int tmp = 0;
			for (int i = 0; i < a.length; i++) {
				if (min_index >= i)
					tmp = min_index - i;
				else
					tmp = i - min_index;

				if (tmp > row_min){
					row_min = tmp;
					max_dis_index=i;
				}

				if (max_index >= i)
					tmp = max_index - i;
				else
					tmp = i - max_index;

				if (tmp > row_max){
					row_max = tmp;
					max_d=i;
				}
			}
			if (row_max < row_min)
				max_dis = swap(a, max_index, max_dis_index)-min_index;
			else
				max_dis = swap(a, min_index, max_d)-max_index;
		}
		return max_dis;
	}

	private static int swap(int[] a, int max_index, int row_max) {
		int tmp = a[max_index];
		a[max_index] = a[row_max];
		a[row_max] = tmp;
		return row_max;
	}

	private static int swap_val(int min, int min_index, int max, int max_index, int[] a) {
		a[min_index] = max;
		a[max_index] = min;
		return a.length;
	}
}

import java.util.*;

public class NicholasPermutation {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		List<Integer> myList = new ArrayList<Integer>();
		Scanner sc= new Scanner(System.in);
	System.out.println("Enter a number");
	int n=sc.nextInt();
	for(int i=1;i<=n;i++){
		myList.add(sc.nextInt());
//		System.out.println(myList);
		}

	 int imax = 0;
		  for ( int i = 1; i < n; i++ )
		  {
		      if ( myList.get(i) > myList.get(imax) ) imax= i;
		  }
		  //System.out.println(imax);
		  int imin = 0;
		  for ( int i = 1; i < n; i++ )
		  {
		      if ( myList.get(i) < myList.get(imin) ) imin= i;
		  }

		  if (imax == 0 || imax == n - 1 || imin == 0 || imin == n - 1) {
				System.out.println( n - 1);
			} else {
				System.out.println(Math.max(Math.max(imax, imin), Math.max(n - 1 - imin, n - 1 - imax)));
			}

		  //System.out.println(largest);
		 // System.out.println(smallest);

	}
}

import java.util.Scanner;

/**
 * @author Shady Mamdouh
 *
 */
public class Ride {

   public static void main(String[] args) {

      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] a = new int[n];
      int minPos = 0;
      int maxPos = 0;
      int maxNumber = 0;

      for(int i=0;i<n;i++){
         a[i] = sc.nextInt();
         if(a[i] == 1)
            minPos = i;
         if(a[i] > maxNumber) {
            maxNumber = a[i];
            maxPos = i;
         }
      }
      if(maxPos > minPos)
         System.out.println(n-1-minPos);
      else
         System.out.println(n-1-maxPos);

  }
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        List<Integer> array = new ArrayList<>();

        for (int i = 0; i < size; i++){
            array.add(sc.nextInt());
        }

        int result = findPositionMin(array);
        System.out.println(result);

    }

    public static int findPositionMin(List<Integer> array){
        int minP = 0;
        int maxP = 0;
        for (int i = 1; i < array.size(); i++){
            if (array.get(minP) > array.get(i)){
                minP = i;
            }
            if (array.get(maxP) < array.get(i)){
                maxP = i;
            }
        }

        int distance;
        if (minP == 0 || maxP == 0 || minP == array.size() -1 || maxP == array.size() - 1){
            return array.size() - 1;
        }
        if (minP > array.size() - maxP){
            distance = maxP;
        } else {
            distance = array.size() - minP;
        }
        return distance;
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class NicholasAndPermutation {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        br.readLine();
        String[] in = br.readLine().split(" ");
        int max = 0;
        int min = 0;
        for (int i = 1; i < in.length; i++) {
            if (Integer.parseInt(in[max]) < Integer.parseInt(in[i])) {
                max = i;
            }
            if (Integer.parseInt(in[min]) > Integer.parseInt(in[i])) {
                min = i;
            }
        }
        if (max > min) {
            System.out.println(in.length - max > min ? in.length - min - 1 : max - 1);
        }
        else {
            System.out.println(in.length - min > max ? in.length - max - 1 : min - 1);
        }
    }
}

import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class Main{

	public static void main(String arg[]){
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int V[]=new int[n+1];
		Set<Integer> mapIz=new TreeSet<>();
		Set<Integer> mapDer=new TreeSet<>();
		for(int i=1;i<=n;++i)
			V[i]=in.nextInt();
		int max=1;
		for(int i=2;i<=n;++i){
			if(V[i]>V[max]){
				max=i;
			}
		}
		if(n==2)
			System.out.println(1);
		else
			if(max==n)
				System.out.println(n-1);
			else
				System.out.println(Math.max(n-max,max));

	}
}

import java.io.IOException;
import java.io.InputStream;
import java.sql.Array;
import java.util.*;

public class Solution2{
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];

        private int curChar;

        private int numChars;

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

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

        public String readString() {
            final StringBuilder stringBuilder = new StringBuilder();
            int c = read();
            while (isSpaceChar(c))
                c = read();
            do {
                stringBuilder.append(c);
                c = read();
            } while (!isSpaceChar(c));
            return stringBuilder.toString();
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

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

        final Solver solver =new Solver();
        final InputReader reader =new InputReader(System.in);
        StringBuilder sb = new StringBuilder(reader.readString());
       solver.solve(sb);
    }
}

class Solver {
    //This class contains the logic.
    public void solve(StringBuilder sb) {
            int log = (int)Math.floor(Math.log((double)sb.length()));
            int count = 1;
            boolean flag = false;
            for(int i = 1;i<=log;i++){
                sb.delete(1,i+1);
                if(sb.length() < count+i) {
                    System.out.println(sb);

                    flag = true;
                    break;
                }
                count++;
            }
            if(!flag) {
                System.out.println(sb);
            }
    }

}

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

public class A {

	static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		line();
		int n = nextInt();
		line();
		String l = "";
		for (int i = 0; i < n; i++) {
			int c = nextInt();
			l += ("" +c);
		}
		int min = l.indexOf("1");
		int max = l.indexOf("" + n);

		int r = Integer.MIN_VALUE;
		r = Math.max(n - max-1, r);
		r = Math.max(r,  n - min-1);
		r = Math.max(r, min);
		r = Math.max(r, max);
		System.out.println(r);

	}

	static void line() throws IOException {
		st = new StringTokenizer(br.readLine());
	}

	static String token() {
		return st.nextToken();
	}

	static int nextInt() {
		return Integer.parseInt(token());
	}

	static long nextLong() {
		return Long.parseLong(token());
	}

}

import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE, max_pos = 0, min_pos = 0, num;
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            num = sc.nextInt();
            if (num > max) {
                max = num;
                max_pos = i;
            }
            if (num < min) {
                min = num;
                min_pos = i;
            }
        }
        System.out.println(max_pos + " " + min_pos);
        if ((max_pos == 1 && min_pos == n) || (max_pos == n && min_pos == 1)) {
            System.out.println(Math.abs(max_pos - min_pos));
        } else {
            System.out.println(Math.abs(max_pos - min_pos) + 1);
        }
        bw.flush();
    }
}

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

public class A {

	static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		line();
		int n = nextInt();
		line();
		String l = "";
		for (int i = 0; i < n; i++) {
			int c = nextInt();
			l += ("" +c);
		}
		int min = l.indexOf("1");
		int max = l.indexOf("" + n);

		int r = Integer.MIN_VALUE;
		r = Math.max(n - max-1, r);
		r = Math.max(r,  n - min-1);
		r = Math.max(r, min - 1);
		r = Math.max(r, max - 1);
		System.out.println(r);

	}

	static void line() throws IOException {
		st = new StringTokenizer(br.readLine());
	}

	static String token() {
		return st.nextToken();
	}

	static int nextInt() {
		return Integer.parseInt(token());
	}

	static long nextLong() {
		return Long.parseLong(token());
	}

}

import javax.swing.text.html.HTMLDocument;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Array;
import java.util.*;

public class Solution{
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];

        private int curChar;

        private int numChars;

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

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

        public String readString() {
            final StringBuilder stringBuilder = new StringBuilder();
            int c = read();
            while (isSpaceChar(c))
                c = read();
            do {
                stringBuilder.append(c);
                c = read();
            } while (!isSpaceChar(c));
            return stringBuilder.toString();
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

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

        final Solver solver =new Solver();
        final InputReader reader =new InputReader(System.in);
        int arr[] = new int[6];
        for(int i = 0;i<6;i++){
            arr[i] = reader.readInt();
        }
        System.out.println(solver.solve(arr));

    }
}

class Solver {
    //This class contains the logic.
    public StringBuilder solve(int[] arr) {
        StringBuilder stringBuilder= new StringBuilder();
        int arr_animal[] = new int[10];
        for(int i: arr){
            arr_animal[i]++;
        }
        Arrays.sort(arr_animal);
        if(arr_animal[arr_animal.length-1] == 4)
        {
            if(arr_animal[arr_animal.length-2] == arr_animal[arr_animal.length-3])
                stringBuilder = new StringBuilder("Bear");
            else
                stringBuilder = new StringBuilder("Elephant");
        }
        else stringBuilder = new StringBuilder("Alien");

        return stringBuilder;
    }
}

import java.util.Scanner;

/**
 * @author Shady Mamdouh
 *
 */
public class Ride {

   public static void main(String[] args) {

      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] a = new int[n];
      int minPos = 0;
      int maxPos = 0;
      int maxNumber = 0;

      for(int i=0;i<n;i++){
         a[i] = sc.nextInt();
         if(a[i] == 1)
            minPos = i;
         if(a[i] > maxNumber) {
            maxNumber = a[i];
            maxPos = i;
         }
      }
      if(minPos == n-1 || maxPos == n-1)
         System.out.println(n-1);
      else if(maxPos > minPos)
         System.out.println(n-1-minPos);
      else
         System.out.println(n-1-maxPos);

  }
}

import java.util.Scanner;

public class NicoleAndPermutation {

	public static void main(String[] args) {

		System.out.println();
		Scanner sc = new Scanner(System.in);

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

		int max = 0;
		int min = Integer.MAX_VALUE;
		int iMin = -1, iMax = -1;
		for (int i = 0; i < a.length; i++) {
			if (min > a[i]) {
				min = a[i];
				iMin = i;
			}
			if (max < a[i]) {
				max = a[i];
				iMax = i;
			}
		}

		int ans = 0;
		if (iMax == 0 && iMin == len - 1 ||
		    iMin == 0 && iMax == len - 1) {
			ans = len - 1;
		} else if (iMax >= len / 2) {
			if (iMin != 0) {
				ans = iMax;
			} else {
				ans = len - 1;
			}
		} else {
			if (iMin != len - 1) {
				ans = len - 1 - iMax;
			} else {
				ans = len - 1;
			}
		}

		System.out.println(ans);

	} // end of main().

}

import java.util.Scanner;
import java.math.*;

public class Hellowrodl {

	private static int j = 0;

	public static void main(String[] args) {
		Scanner  x = new Scanner(System.in);
		int n=x.nextInt();
		int array[]=new  int[n];
		for(int i=0;i<array.length;i++){
			array[i]=x.nextInt();
		}
		for( j=0;j<array.length;j++){
			if(array[j]==1 || array[j]==n)
				break;
		}
		System.out.println(array.length-1 - j);
	}
}

import java.util.Scanner;

public class Trial {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] val = new int[n];
		int index_large = 0;
		int index_small = 0;
		for (int i = 0; i < n; i++) {
			val[i] = sc.nextInt();
			if (val[i] == 1) {
				index_small = i;
			}
			if (val[i] == n) {
				index_large = i;
			}
		}
		int val1;
		int val2;
		if (index_small < index_large) {
			val1 = index_large - 1;
			val2 = n - index_small;
			if (val1 > val2) {
				System.out.println(val1 - 1);
			} else {
				System.out.println(val2 - 1);
			}
		} else {
			val1 = index_small - 1;
			val2 = n - index_large;
			if (val1 > val2) {
				System.out.println(val1 - 1);
			} else {
				System.out.println(val2 - 1);
			}
		}
	}
}

import java.util.*;
public class susbus{
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int[] richardpro=new int[n];
  for (int i=0;i<n;i++)
  richardpro[i]=sc.nextInt();
  int npos=locatePosition(n,richardpro);
  int opos=locatePosition(1,richardpro);
  int k1=Math.max(Math.abs(npos),Math.abs(npos-n));
  int k2=Math.max(k1,Math.abs(opos));
  int k3=Math.max(k2,Math.abs(opos-n));
  System.out.println(k3);
 }
 public static int locatePosition(int n,int[] nums){
  for (int i=0;i<nums.length;i++)
  if(nums[i]==n) return i;

  return -1;
 }
}

import java.util.Scanner;
import java.lang.Integer;

public class test {

	public static void main(String[] args) {

		int n;

	    Scanner sc = new Scanner(System.in);

	    n = sc.nextInt();

	    int M[] = new int[n];

	    sc.nextLine();

	    int min = 0,max = 0;
	    for ( int i = 0; i < n; i++){
	    	M[i] = sc.nextInt();
	    	if (M[i] == 1) min = i;
	    	if (M[i] == n) max = i;

	    }

	    if (min == 0 || max == 0 || min == n || max == n){
	    	System.out.print(n-1);
	    }
	    else{
	    	int f1 = Math.abs(min - (n/2));
	    	int f2 = Math.abs(max - (n/2));

	    	int ans = f1 >= f2 ? f1 : f2;
	    	System.out.print(ans+ (n/2));
	    }

	    /*
	    int M[][] = new int [n][2];

	    String s;
	    sc.nextLine();
	    for (int i = 0; i < n; i++){
	    	s = sc.nextLine();
		    String[] ss = s.split(" ");

	    	M[i][0] = Integer.valueOf(ss[0]);
	    	M[i][1] = Integer.valueOf(ss[1]);

	    }

	    int ans = 0;

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

	    		if (M[i][0] == M[j][1]) ans += 1;

	    	}
	    }

	   System.out.println(ans);

	   */

	}
}

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

public class ArrayDiffernce
{
    public static void main(String[] args)
	{
		Scanner scanner=new Scanner(System.in);
		int index=scanner.nextInt();
		int a[]=new int[index];

		for(int i=0;i<index;i++)
		{
			a[i]=scanner.nextInt();

		}
		Arrays.sort(a);
		int maxDiff=a[index-1]-a[0];
//		for(int j=1;j<index-1;j++)
//		{
//			maxDiff=Math.max(a[j+1]-a[j],maxDiff);
//
//		}
//
        System.out.println(maxDiff);

	}

}

import java.util.*;

public class CF354A {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int []a=new int [n];
		int ma=0,mi=n;
		int inda=0,indi=0;
		for (int i=0;i<n;i++){
			a[i]=sc.nextInt();
			if(a[i]<mi){
				mi=a[i];
				indi=i;
			}
			if(a[i]>ma){
				ma=a[i];
				inda=i;
			}
		}
		int ans=0;
		int tmp=inda>indi?inda:indi;
		int tmp2=inda>indi?indi:inda;
		ans=tmp>(n-tmp2)?tmp:n-tmp2-1;
		System.out.println(ans);
	}
}