#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e3 + 10;
ll n, a[N], sum = LLONG_MAX;
int main() {
// 读取糖果的数量
cin >> n;
// 读取每个糖果距左边第一颗糖果的距离
for (int i = 2; i <= n; i++) cin >> a[i];
// 对糖果的距离进行排序
sort(a + 1, a + 1 + n);
// 枚举两个分割点,将糖果分成三段
for (int i = 2; i <= n - 4; i++) {
for (int j = i + 2; j <= n - 2; j++) {
// 计算三段的长度
ll length1 = a[i] - a[1];
ll length2 = a[j] - a[i + 1];
ll length3 = a[n] - a[j + 1];
// 更新总长度的最小值
sum = min(sum, length1 + length2 + length3);
}
}
// 输出最小总长度
cout << sum;
return 0;
}