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.util.concurrent.ArrayBlockingQueue;
import java.io.*;
public class A 
{
	public static void main(String[] args)
	{
		new A().solve();
	}

	FasterScanner in=new FasterScanner();
	PrintWriter out=new PrintWriter(System.out);

	long mod=(int)1e9+7;
	public void solve()
	{
		int n=in.nextInt();
		int ans=0;
		for(int i=0;i<n;i++)
		{
			int x=in.nextInt();
			if(x==1 || x==n)
			{
				ans=Math.max(ans,n-i-1);
				ans=Math.max(ans,i-0);
			}
			
		}
		out.println(ans);
		out.close();
	}



	int[][] arr;
	int[][] visit;
	int[] ans;
	int cur;

	void dfs(int x,int y)
	{
		try
		{
			if(x<0 || x>=arr.length || y<0 || y>=arr[0].length)
			{
				return;
			}
			if(arr[x][y]==0)
			{
				return;
			}
			if(visit[x][y]!=0)
			{
				return;
			}

			visit[x][y]=cur;
			ans[cur]++;

			dfs(x-1,y-1);
			dfs(x-1,y);
			dfs(x-1,y+1);
			dfs(x,y-1);
			dfs(x,y+1);
			dfs(x+1,y-1);
			dfs(x+1,y);
			dfs(x+1,y+1);
		}
		catch(Exception e)
		{
			return ;
		}
	}


	class Edge
	{
		int nextv;
		int r;
		int t;
		public Edge(int ver,int r,int t)
		{
			this.nextv=ver;
			this.r=r;
			this.t=t;
		}
	}

	class s implements Comparable<s>
	{
		int idx;
		int w;
		public s(int i)
		{
			this.idx=i;
			this.w=Integer.MAX_VALUE;
		}

		@Override
		public int compareTo(s o) {
			// TODO Auto-generated method stub
			if(this.w!=o.w)
				return Integer.compare(this.w, o.w);
			else
				return Integer.compare(this.idx, o.idx);
		}
	}

	public static class FasterScanner {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
		public 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 boolean isEndOfLine(int c) {
			return c=='\n' || c=='\r' || c==-1;
		}
		public String nextString() {
			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==-1 || c==' ' || c=='\t';
		}
		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 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 double nextDouble()
		{
			return Double.parseDouble(nextString());
		}
		public int[] nextIntArray(int n)
		{
			int[] arr=new int[n];
			for(int i=0;i<n;i++)
			{
				arr[i]=nextInt();
			}
			return arr;
		}
		public long[] nextLongArray(int n)
		{
			long[] arr=new long[n];
			for(int i=0;i<n;i++)
			{
				arr[i]=nextLong();
			}
			return arr;
		}
		public int[] nextIntArray10(int n)
		{
			int[] arr=new int[n+1];
			for(int i=1;i<=n;i++)
			{
				arr[i]=nextInt();
			}
			return arr;
		}
		public long[] nextLongArray10(int n)
		{
			long[] arr=new long[n+1];
			for(int i=1;i<=n;i++)
			{
				arr[i]=nextLong();
			}
			return arr;
		}
		public int[] nextIntArray11(int n)
		{
			int[] arr=new int[n+2];
			for(int i=1;i<=n;i++)
			{
				arr[i]=nextInt();
			}
			return arr;
		}
		public long[] nextLongArray11(int n)
		{
			long[] arr=new long[n+2];
			for(int i=1;i<=n;i++)
			{
				arr[i]=nextLong();
			}
			return arr;
		}
	}

}