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

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

Input

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

The second line of the input contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n), where ai is equal to the element at the i-th position.

Output

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

Examples

Input

5
4 5 1 3 2


Output

3


Input

7
1 6 5 3 4 7 2


Output

6


Input

6
6 5 4 3 2 1


Output

5

Note

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

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

In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
import java.util.*;
import java.io.*;
public class Main{
    
    //make it false if Multiple test case is not in the question
    static boolean multipleTC = false;
    
    //for pre processing if needed
    void pre() throws Exception
    {}
        public static void main(String[] args) throws Exception{
            
        new Main().run();
      }
      



    // input output handled here
    private String solve(int tc) throws Exception{
          //take input here

        int n=ni();
        int min=0,max=0;
        for(int i=0;i<n;i++){
            int x=ni();
            if(x==1)
            min=i;
            if(x==n)
            max=i;
        }
        if(Math.abs(min-max)==(n-1))
        return ""+(n-1);


        int maxswap=Math.max(min,n-min-1);
        int minswap=Math.max(max,n-max-1);
        int maxm=Math.max(maxswap,minswap);


        return ""+(maxm);

    }
    

    

    
    
    void run() throws Exception{
    //	long start_time=System.nanoTime();

     //   in = new FastReader("input.txt");  out = new PrintWriter("output.txt");
         in = new FastReader(); out = new PrintWriter(System.out);
        


        StringBuilder print=new StringBuilder("");
        pre();
        int T = (multipleTC)?ni():1;
        for(int t = 1; t<= T; t++){
        print.append(solve(t)).append("\n");
        }

        p(print);
        //long end_time=System.nanoTime();
        //System.out.println("Running Time in nano sec : "+(end_time-start_time));
        
        out.flush();
        out.close();
    }
    
    PrintWriter out;
        FastReader in;
        
            void p(Object o)
                {out.print(o);}
            void pln(Object o)
                {out.println(o);}
            void pnf(Object o)
                {out.println(o);
                out.flush();}
        
            String n()throws Exception
                {return in.next();}
        
            String nln()throws Exception
                {return in.nextLine();}
        
            int ni()throws Exception
                {return Integer.parseInt(in.next());}
        
            long nl()throws Exception
                {return Long.parseLong(in.next());}
        
            double nd()throws Exception
                {return Double.parseDouble(in.next());}
    
        class FastReader{
            BufferedReader br;
            StringTokenizer st;
            
            public FastReader(){
                br = new BufferedReader(new InputStreamReader(System.in));
            }
    
            public FastReader(String s) throws Exception{
                br = new BufferedReader(new FileReader(s));
            }
    
            String next() throws Exception{
                while (st == null || !st.hasMoreElements()){
                    try{
                        st = new StringTokenizer(br.readLine());
                    }catch (IOException  e){
                        throw new Exception(e.toString());
                    }
                }
                return st.nextToken();
            }
    
            String nextLine() throws Exception{
                String str = "";
                try{   
                    str = br.readLine();
                }catch (IOException e){
                    throw new Exception(e.toString());
                }  
                return str;
            }
        }
}