#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, w[101];
  cin >> n;
  for (int i = 0; i < 2 * n; i++) {
    cin >> w[i];
  }
  sort(w, w + (2 * n));
  int mn = w[1] - w[0], x = 0, y = 0;
  for (int i = 3; i < 2 * n; i += 2) {
    x = min(mn, w[i - 1] - w[i - 2] + x);
    y = min(x, w[i] - w[i - 1] + y);
    mn = w[i] - w[i - 1] + mn;
  }
  cout << y << endl;
  return 0;
}
