#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[1000];
  for (int i = 0; i < (n); i++) cin >> a[i];
  int ans = 1e7;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++) {
      vector<int> v;
      int s = a[i];
      int t = a[j];
      for (int k = 0; k < (n); k++) {
        if (k != i and k != j) {
          v.push_back(a[k]);
        }
      }
      int max_e = *max_element(v.begin(), v.end());
      int min_e = *min_element(v.begin(), v.end());
      if (s > t) swap(s, t);
      ans = min(ans, max_e - min_e + abs(s - min_e) + abs(t - max_e));
    }
  cout << ans << endl;
}
