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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;


import java.util.*;
public class random_num {
	public static void main(String args[]){
		InputReader s= new InputReader(System.in);
		OutputStream outputStream= System.out;
		PrintWriter out= new PrintWriter(outputStream);
		int n=s.nextInt();
		int a[]=new int[n];
		int max=Integer.MIN_VALUE;
		int min=Integer.MAX_VALUE;
		int min_pos=0;
		int max_pos=0;
		for(int i=0;i<n;i++){
			a[i]=s.nextInt();
			if(a[i]>max){
				max=a[i];
				max_pos=i;
			}
			if(a[i]<min){
				min=a[i];
				min_pos=i;
			}
		}
		if(min_pos<max_pos){
			if(min_pos<n-1-max_pos){
				out.println(n-1-min_pos);
			}
			else{
				out.println(max_pos);
			}
		}
		else{
			if(max_pos<n-1-min_pos){
				out.println(n-1-max_pos);
			}
			else{
				out.println(min_pos);
			}
		}
		//System.out.println(max_pos+" "+min_pos);
		out.close();
		
	}
	static class InputReader {
		
	    public BufferedReader reader;
	    public StringTokenizer tokenizer;
 
	    public InputReader(InputStream inputstream) {
	      reader = new BufferedReader(new InputStreamReader(inputstream));
	      tokenizer = null;
	    }
	    
	    public String nextLine(){
	    	String fullLine=null;
	    	while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	              fullLine=reader.readLine();
	            } catch (IOException e) {
	              throw new RuntimeException(e);
	            }
	            return fullLine;
	          }
	          return fullLine;
	    }
		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 long nextLong() {
		      return Long.parseLong(next());
		    }
	    public int nextInt() {
	      return Integer.parseInt(next());
	    }
	  }
	public static int gcd(int number1, int number2) {  
		if(number2 == 0){
			return number1;
		} 
		return gcd(number2, number1%number2); 
	}
	public static int combinations(int n,int r){
		if(n==r) return 1;
		if(r==1) return n;
		if(r==0) return 1;
		return combinations(n-1,r)+ combinations(n-1,r-1);
	}
	public static long binomialCoeff(int n, int k)
	{
	    long C[][]= new long[n+1][k+1];
	    int i, j;
	 
	    // Caculate value of Binomial Coefficient in bottom up manner
	    for (i = 0; i <= n; i++)
	    {
	        for (j = 0; j <= Math.min(i, k); j++)
	        {
	            // Base Cases
	            if (j == 0 || j == i)
	                C[i][j] = 1;
	 
	            // Calculate value using previosly stored values
	            else
	                C[i][j] = C[i-1][j-1] + C[i-1][j];
	        }
	    }
	 
	    return C[n][k];
	}
	public static int expo(int a, int b){
	    if (b==1)
	        return a;
	    if (b==2)
	        return a*a;

	    if (b%2==0){
	            return expo(expo(a,b/2),2);
	    }
	    else{
	        return a*expo(expo(a,(b-1)/2),2);
	    }
	}
	
	public static void sieve(int N){
		int arr[]= new int[N+1];
		for(int i=2;i<Math.sqrt(N);i++){
			if(arr[i]==0){
				for(int j= i*i;j<= N;j= j+i){
					arr[j]=1;
				}
			}
		}
		// All the i for which arr[i]==0 are prime numbers.
	}
	static class Pair implements Comparable<Pair>
    {
        int f,s;
        Pair(int ii, int cc)
        {
            f=ii;
            s=cc;
        }
        
        public int compareTo(Pair o) 
        {
            return Integer.compare(this.f, o.f);
        }
        
    }

}