#include "bits/stdc++.h" using namespace std; typedef long long ll; const int INF = (1<<30); const ll INFLL = (1ll<<60); const ll MOD = (ll)(1e9+7); #define l_ength size void mul_mod(ll& a, ll b){ a *= b; a %= MOD; } void add_mod(ll& a, ll b){ a = (an){ return memo[i]; } memo[i] = min(memo[i],solve(i+2)+abs(a[i]-a[i+1])); if(i+3>n){ return memo[i]; } memo[i] = min(memo[i],solve(i+3)+abs(a[i]-a[i+1])+abs(a[i+1]-a[i+2])); return memo[i]; } int main(void){ int i; cin >> n; for(i=0; i> a[i]; } sort(a,a+n); cout << solve(0) << endl; return 0; }