#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y = -1, z = 1001;
  int a[101];
  cin >> x;
  for (int i = 0; i < x; i++) {
    cin >> a[i];
    if (a[i] >= x && a[i] > y) {
      y = a[i];
    } else if (a[i] <= x && a[i] < z) {
      z = a[i];
    }
  }
  cout << abs(a[x / 2] - y) + abs(a[x / 2] - z);
  return 0;
}
