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.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Scanner;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class _p000676A {
    static public void main(final String[] args) throws IOException {
        p000676A._main(args);
    }
//begin p000676A.java
static private class p000676A extends Solver{public p000676A(){nameIn="p000676A.in"
;singleTest=true;}int n;int[]a;@Override protected void solve(){List<int[]>aa=ArrayToListWithIndexes
.apply(a);aa.sort((x,y)->x[0]-y[0]);int res=Math.abs(aa.get(0)[1]-aa.get(n-1)[1]
)+Math.max(Math.min(aa.get(0)[1],aa.get(n-1)[1]),n-1-Math.max(aa.get(0)[1],aa.get
(n-1)[1]));pw.println(res);}@Override public void readInput()throws IOException{
n=sc.nextInt();if(sc.hasNextLine()){sc.nextLine();}a=Arrays.stream(sc.nextLine()
.trim().split("\\s+")).mapToInt(Integer::valueOf).toArray();}static public void _main
(String[]args)throws IOException{new p000676A().run();}}
//end p000676A.java
//begin net/leksi/cf/ArrayToListWithIndexes.java
static private class ArrayToListWithIndexes{public static List<int[]>apply(final
int[]a){return IntStream.range(0,a.length).mapToObj(i->new int[]{a[i],i}).collect
(Collectors.toList());}public static List<long[]>apply(final long[]a){return IntStream
.range(0,a.length).mapToObj(i->new long[]{a[i],i}).collect(Collectors.toList());
}static class ValueAndIndex<T>{T value;int index;ValueAndIndex(final T value,final
int index){this.value=value;this.index=index;}}public static<T>List<ValueAndIndex<T>>
apply(final T[]a){return IntStream.range(0,a.length).mapToObj(i->new ValueAndIndex<T>
(a[i],i)).collect(Collectors.toList());}}
//end net/leksi/cf/ArrayToListWithIndexes.java
//begin net/leksi/contest/Solver.java
static private abstract class Solver{protected String nameIn=null;protected String
nameOut=null;protected boolean singleTest=false;protected boolean preprocessDebug
=false;protected boolean doNotPreprocess=false;protected Scanner sc=null;protected
PrintWriter pw=null;private void process()throws IOException{if(!singleTest){int
t=lineToIntArray()[0];while(t-->0){readInput();solve();}}else{readInput();solve(
);}}abstract protected void readInput()throws IOException;abstract protected void
solve()throws IOException;protected int[]lineToIntArray()throws IOException{return
Arrays.stream(sc.nextLine().trim().split("\\s+")).mapToInt(Integer::valueOf).toArray
();}protected long[]lineToLongArray()throws IOException{return Arrays.stream(sc.nextLine
().trim().split("\\s+")).mapToLong(Long::valueOf).toArray();}protected String joinToString
(final int[]a){return Arrays.stream(a).mapToObj(Integer::toString).collect(Collectors
.joining(" "));}protected String joinToString(final long[]a){return Arrays.stream
(a).mapToObj(Long::toString).collect(Collectors.joining(" "));}protected<T>String
joinToString(final T[]a){return Arrays.stream(a).map(v->v.toString()).collect(Collectors
.joining(" "));}protected<T>String joinToString(final T[]a,final Function<T,String>
toString){return Arrays.stream(a).map(v->v.toString()).collect(Collectors.joining
(" "));}protected<T>String joinToString(final Collection<T>a){return a.stream().map
(v->v.toString()).collect(Collectors.joining(" "));}protected<T>String joinToString
(final Collection<T>a,final Function<T,String>toString){return a.stream().map(v->
toString.apply(v)).collect(Collectors.joining(" "));}protected List<Long>intArrayToLongList
(final int[]a){return Arrays.stream(a).mapToObj(Long::valueOf).collect(Collectors
.toList());}protected List<Integer>toList(final int[]a){return Arrays.stream(a).mapToObj
(Integer::valueOf).collect(Collectors.toList());}protected List<Long>toList(final
long[]a){return Arrays.stream(a).mapToObj(Long::valueOf).collect(Collectors.toList
());}protected void run()throws IOException{boolean done=false;if(nameIn !=null)
{try{try(FileInputStream fis=new FileInputStream(nameIn);PrintWriter pw0=select_output
();){done=true;sc=new Scanner(fis);pw=pw0;process();}}catch(IOException ex){}}if
(!done){try(PrintWriter pw0=select_output();){sc=new Scanner(System.in);pw=pw0;process
();}}}private PrintWriter select_output()throws FileNotFoundException{if(nameOut
!=null){return new PrintWriter(nameOut);}return new PrintWriter(System.out);}}
//end net/leksi/contest/Solver.java
}
