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.InputStreamReader;
import java.util.Map;
import java.util.StringTokenizer;

public class SolutionA {

//    private final static String FILENAME = "";
//    private final static String PATH = System.getProperty("user.home") + "/contests/" + FILENAME;

    public static void main(String[] args) throws IOException {
        SolutionA solution = new SolutionA();
        solution.initInputReader();
        solution.solve();
        solution.cleanup();
    }

    private void solve() throws IOException {
        int n = nextInt();

        int minIdx = -1;
        int maxIdx = -1;

        for (int i = 0; i < n; i++) {
            int nxt = nextInt();
            if (nxt == 1)
                minIdx = i;
            else if (nxt == n)
                maxIdx = i;
        }
        System.out.print(
                Math.max(
                        Math.max(maxIdx, minIdx),
                        n - Math.min(maxIdx, minIdx) - 1
                )
        );

    }

    private final static int MOD = 1000000007;

    /*
     * Methods for reading input
     */

    private BufferedReader br;
    private StringTokenizer st;

    private void initInputReader() throws IOException {
//        if (FILENAME.isEmpty()) {
            br = new BufferedReader(new InputStreamReader(System.in));
//        } else {
//            br = new BufferedReader(new FileReader(new File(PATH)));
//        }
        st = new StringTokenizer(br.readLine());
    }

    private void cleanup() throws IOException {
        br.close();
    }

    private int nextInt() throws IOException {
        checkEmptyTokenizer();
        return Integer.parseInt(st.nextToken());
    }

    private long nextLong() throws IOException {
        checkEmptyTokenizer();
        return Long.parseLong(st.nextToken());
    }

    private double nextDouble() throws IOException {
        checkEmptyTokenizer();
        return Double.parseDouble(st.nextToken());
    }

    private String nextString() throws IOException {
        checkEmptyTokenizer();
        return st.nextToken();
    }

    private void checkEmptyTokenizer() throws IOException {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
    }

    /*
     * Convenience methods
     */

    // Provides a default value if map doesn't have the key
    private <K, V> V getFromMap(Map<K, V> map, K key, V def) {
        if (map.containsKey(key)) {
            return map.get(key);
        }
        return def;
    }

    private void print(String line, Object... args) {
        System.out.println(String.format(line, args));
    }
}
