#include <bits/stdc++.h>
using namespace std;
int findPosition(vector<int> intVector, int flag) {
  int pos = 0;
  int tmp = intVector[pos];
  if (1 == flag) {
    for (int i = 1; i < intVector.size(); i++) {
      if (tmp < intVector[i]) {
        pos = i;
        tmp = intVector[pos];
      }
    }
  } else {
    for (int i = 1; i < intVector.size(); i++) {
      if (tmp > intVector[i]) {
        pos = i;
        tmp = intVector[pos];
      }
    }
  }
  return pos;
}
int main() {
  int n, tmp;
  int pos_max, pos_min, dis_end, dis_start, distance;
  vector<int> A;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    A.push_back(tmp);
  }
  pos_max = findPosition(A, 1);
  pos_min = findPosition(A, 0);
  if (pos_max > pos_min) {
    dis_end = n - 1 - pos_max;
    dis_start = pos_min;
    distance = pos_max - pos_min;
  } else {
    dis_end = n - 1 - pos_min;
    dis_start = pos_max;
    distance = pos_min - pos_max;
  }
  if (dis_end > dis_start) {
    cout << dis_end + distance;
  } else {
    cout << dis_start + distance;
  }
  return 0;
}
