There are $$$n$$$ students in a university. The number of students is even. The $$$i$$$-th student has programming skill equal to $$$a_i$$$. The coach wants to form $$$\frac{n}{2}$$$ teams. Each team should consist of exactly two students, and each student should belong to exactly one team. Two students can form a team only if their skills are equal (otherwise they cannot understand each other and cannot form a team).Students can solve problems to increase their skill. One solved problem increases the skill by one.The coach wants to know the minimum total number of problems students should solve to form exactly $$$\frac{n}{2}$$$ teams (i.e. each pair of students should form a team). Your task is to find this number.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of students. It is guaranteed that $$$n$$$ is even. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student.

Print one number — the minimum total number of problems students should solve to form exactly $$$\frac{n}{2}$$$ teams.

NoteIn the first example the optimal teams will be: $$$(3, 4)$$$, $$$(1, 6)$$$ and $$$(2, 5)$$$, where numbers in brackets are indices of students. Then, to form the first team the third student should solve $$$1$$$ problem, to form the second team nobody needs to solve problems and to form the third team the second student should solve $$$4$$$ problems so the answer is $$$1 + 4 = 5$$$.In the second example the first student should solve $$$99$$$ problems to form a team with the second one.

#include<iostream>
#include<algorithm>
using namespace std;
#include<vector>

int main() {
	int n;
	cin >> n;
    vector<int> a;
    int t;
    for(int i=0;i<n;++i)
    {
        cin >> t;
        a.push_back(t);
    }
    t=0;
    sort(a.begin(),a.end());
    for(int i=0;i<n/2;++i)
        t+=a[2*i+1]-a[2*i];
    cout << t;
	return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>

size_t solve(std::vector<size_t>& a)
{
	const size_t n = a.size();

	std::sort(a.begin(), a.end());

	size_t count = 0;
	for (size_t i = 0; i < n; i += 2) {
		count += a[i+1] - a[i];
	}
	return count;
}

int main()
{
	size_t n;
	std::cin >> n;

	std::vector<size_t> a(n);
	for (size_t i = 0; i < n; ++i)
		std::cin >> a[i];

	std::cout << solve(a) << '\n';

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector <int> habilidad;
	for(int i=0; i<n; i++){
		int temp;
		cin>>temp;
		habilidad.push_back(temp);
	}
	//formar parejas
	sort(habilidad.begin(), habilidad.end());
	int cont=0;
	for(int i=0; i<n; i+=2){
		int more=abs(habilidad[i]-habilidad[i+1]);
		cont=cont+more;
	}

	cout<<cont;
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main() {
    int n,c=0;
    cin>>n;
    int ar[n];
    for(int i=0;i<n;i++) {
        cin>>ar[i];
    }
    sort(ar,ar+n);
    for(int i=1;i<n;i+=2) {
        c+=(ar[i]-ar[i-1]);
    }
    cout<<c;
    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,sum=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n-1;i+=2){
        sum+=abs(a[i]-a[i+1]);
    }
    cout<<sum;
    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int a[1000];
int ans1,ans2;
int main() {
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0;i < n;i+=2) {
		ans1 = abs(a[i] - a[i+1]);
		ans2 = ans2 + ans1;
	}
	cout << ans2;
	return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int n, *a, s = 0;
	cin >> n;
	a = new int[n];
	for (int c = 0; c < n; c++)
		cin >> a[c];
	for (int c = 0; c < n; c++)
	for (int j = 0; j < n - 1; j++)
	if (a[j]>a[j + 1])
		a[j] ^= a[j + 1] ^= a[j] ^= a[j + 1];
	for (int c = 0; c < n; c += 2)
		s += a[c + 1] - a[c];
	cout << s ;
}

#include<bits/stdc++.h>
using namespace std;

int32_t main()
{
	// freopen("inf.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);

	#define int long long
   	int n;
   	cin>>n;
   	vector<int> a(n);
   	for(auto &x: a) cin>>x;
   	sort(a.begin(),a.end());
   	int ans=0;
   	for(int i=0;i<n;i+=2)
   	{
   		ans+=(a[i+1]-a[i]);
   	}
   	cout<<ans;
}

#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(const long long&a,long long&b)
{
	return a<b;
}
int main()
{
	int n,a[200];
	while(cin>>n)
	{
		for(int i=0;i<n;i++)
			cin>>a[i];
		sort(a,a+n);

		int s=0;
		for(int i=0;i<n;i+=2)
		{
			s+=a[i+1]-a[i];

		}
		cout<<s<<endl;

	}

}

#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(rng(a));
    reverse(rng(a));
    int ans = 0;
    for(int i = 1;i<n;i+=2){
        ans+=a[i-1]-a[i];
    }
    cout << ans;
}

#include<iostream>
#include<cmath>
using namespace std;
int num[10000000]={0};
int temp,le,ri,mid;
void fsort(int l,int r)
{
    le=l;
    ri=r;
    mid=num[(le+ri)/2];
    while(le<=ri)
    {
        while(num[le]<mid)le++;
        while(num[ri]>mid)ri--;
        if(le<=ri)
        {
            temp=num[ri];
            num[ri]=num[le];
            num[le]=temp;
            le++;
            ri--;
        }
    }
    if(le<r)fsort(le,r);
    if(l<ri)fsort(l,ri);
}
/*int solve(int l,int r)
{
	int sum=0;
	for(int i=l;i<=r;i++)
	{
		sum+=num[i];
	}
	int avg=sum/(r-l+1);
	int ans=0;
	for(int i=l;i<=r;i++)
	{
		ans+=abs(num[i]-avg);
	}
	return ans;
}*/
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>num[i];
	}
	fsort(0,n-1);
	//for(int i=0;i<n;i++)cout<<num[i]<<' ';
	//cout<<endl;
	int a=0;
	for(int i=0;i<n/2;i++)
	{
		//cout<<num[i<<1]<<' '<<num[i<<1|1]<<' ';
		a+=num[i<<1|1]-num[i<<1];
	}
	cout<<a;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,a[110],num;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n/2;i++)
	{
		num+=a[2*i]-a[2*i-1];
	}
	cout<<num;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n;
    cin>>n;
    vector<int>a(n);

    for(int i=0;i<n;i++)
    {
        cin>>a[i];

    }
    sort(a.begin(),a.end());
    int sum=0;
    for(int i=0;i<n;i+=2)
    {
        sum+=a[i+1]-a[i];
    }
    cout<<sum<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int ans=0;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort (a,a+n);
    int v=n/2;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=a[i+1] &&v>=0)
           {
               ans+=a[i+1]-a[i];
               i++;
               v--;

           }
           else

           {
             i++;
             v--;
           }

    }
    return cout<<ans<<endl,0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <random>
#include <iomanip>

#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#include <deque>
#include <array>
#include <iterator>
#include <bitset>
#include <initializer_list>

using namespace std;

#include <ext/rope>

using namespace __gnu_cxx;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define int long long

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;

#define add push_back
#define rem pop_back
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define SZ(x) int((x).size())
#define F first
#define S second
#define DEBUG(x) cout << #x << " " << x << endl;
#define forn(i, a, b) for(int i = a; i <= b; i++)

const double EPS = 1e-9;
const double PI = acos ( -1. );
const int MOD = 1e9 + 7;
const int MAXN = 500001;
int INF = __INT64_MAX__;
int MAX = -1e18;
int MIN = 1e18;
string YN[] = {"NO", "YES"};

#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))

inline int GCD_E ( int a, int b, int & x, int & y )
{
        if ( !a ) {
                x = 0;
                y = 1;
                return b;
        }
        int x1, y1;
        int d = GCD_E ( b % a, a, x1, y1 );
        x = y1 - ( b / a ) * x1;
        y = x1;
        return d;
}

inline int divMOD ( int a, int b, int m = MOD )
{
        int x, y;
        int g = GCD_E ( b, m, x, y );
        x = ( x % m + m ) % m;
        return ( a * x ) % m;
}

int px[] = { 1, 1, -1, -1 };
int py[] = { -1, 1, -1, 1};
int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
int fx[] = {-2, -2, -1, -1,  1,  1,  2,  2};
int fy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

template<typename T1, typename T2> auto max ( T1 a, T2 b ) { auto max = a > b ? a : b; return max; }
template<typename T1, typename T2> auto min ( T1 a, T2 b ) { auto min = a < b ? a : b; return min; }

int POW ( int a, int n, int m = MOD )
{
        int res = 1;
        while ( n ) {
                if ( n & 1 )
                        res = ( res * a ) % m;
                a = ( a * a ) % m;
                n >>= 1;
        }
        return res;
}

//tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> tr;

vector<int> vc;

string s, t;

set<int> st;

map<int, int> mp;

static const int N = 1 << 20;
static const int M = 123456;

static int n, m, k, res, cnt;
static int A[N], B[N];

void solution()
{
        cin >> n;
        forn ( i, 1, n ){
                cin >> A[i];
        }
        sort( A + 1, A + 1 + n );
        for ( int i = 1; i <= n; i += 2 ){
                cnt += A[i + 1] - A[i];
        }
        cout << cnt;

}

__INT16_C() main ( __int32 argc, char * argv[] )
{

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio ( false ); cin.tie ( nullptr ); cout.tie ( nullptr );
        //cout.precision(15);

        int query = 1;
        // cin >> query;

        while ( query-- ) solution();

}

/*
Problem:
	Given the array and the integer k as input
	Selecting the kth smallest element in an n-element array
QuickSelect(one-armed quicksort) Algorithm:
	Step1: Choose a pivot element from the array
	Step2: Partition the array into three subarrays containing the elements smaller than the pivot,
		   the pivot element itself, and the elements larger than the pivot.
	Step3: Recursively quickSelect the first or last subarrays.

	Partition(A[1 .. n], p)  :  return r - the idex of p in rearanged A[1 .. n] such that A[i..r-1] < A[r]=pivot <= A[r+1..n]
	QuickSelect(A[1 .. n], k):
		if n = 1
			return 1
		Choose pivot element A[p]
		r <- Partition(A[1..n], p)
		if(k > r)
			return QuickSelect(A[r+1..n], k-r)
		if(k < r)
			return QuickSelect(A[1..r], k)
		return r

----Quickselect was first described by Tony Hoare in 1961, literally on the same page where he first published quicksort

Complexity:
	Denpend on the value of pivot.
		pivot is median ("average case")						 : O(nlogn)
		2 subproblems are completely unbanlanced (worst case)    : O(n^2)
Specific problem: https://codeforces.com/problemset/problem/1092/B
*/

#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;

int Partition(int A[], int Left, int Right, int p) {
	int l = Left-1;
	swap(A[Right], A[p]);
	for(int i = Left; i < Right; i++) {
		if(A[i] < A[Right]) {
			l++;
			swap(A[i], A[l]);
		}
	}
	swap(A[Right], A[l+1]);
	return l+1;
}

int QuickSelect(int A[], int Left, int Right, int k) {
	if(Left == Right)
		return A[Left];
	int p = (Right + Left)/2;
	int r = Partition(A, Left, Right, p);
	if(k > (r - Left + 1))
		return QuickSelect(A, r+1, Right, k-(r - Left + 1));
	if(k < (r - Left + 1))
		return QuickSelect(A, Left, r-1, k);
	return A[r];
}

const int MAXN = 1e3+1;
int A[MAXN];
void Application() {
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", A+i);

	int ans = 0;
	for(int i = 0; i < n; i+=2)
		ans += (QuickSelect(A, 0, n-1, i+2) - QuickSelect(A, 0, n-1, i+1));
	printf("%d\n", ans);
}
int main() {
	int n;
	Application();
	return 0;
}

/*
Problem:
	Sort array of integer (A)
QuickSort Algorithm:
	Step1: Choose a pivot element from the array
	Step2: Partition the array into three subarrays containing the elements smaller than the pivot,
		   the pivot element itself, and the elements larger than the pivot.
	Step3: Recursively QuickSort the first and last subarrays.

	Partition(A[1 .. n], p)  :  return r - the idex of p in rearanged A[1 .. n] such that A[i..r-1] < A[r]=pivot <= A[r+1..n]
	QuickSort(A[1 .. n]):	{correct=>doNothing} 			, if n = 1
							{choose pivot element A[p]
							 r <- Partition(A[1..n], p)
							 QuickSort(A[1 .. r])			, if n > 1
							 QuiclSort(A[r+1 .. n]}

----The algorithm was discovered by Tony Hoare in 1959 and first published in 1961.

Complexity:
	Denpend on the value of pivot.
		pivot is median ("average case")						 : O(nlogn)
		2 subproblems are completely unbanlanced (worst case)    : O(n^2)
Specific problem: https://codeforces.com/problemset/problem/1092/B
*/

#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;

int Partition(int A[], int Left, int Right, int p) {
	int l = Left-1;
	swap(A[p], A[Right]);
	for(int i = Left; i < Right; i++)
		if(A[i] < A[Right]) {
			l++;
			swap(A[i], A[l]);
		}
	swap(A[Right], A[l+1]);
	return l+1;
}

void QuickSort(int A[], int Left, int Right) {
	if(Left >= Right)
		return;
	int p = Right;
	int r = Partition(A, Left, Right, p);
	QuickSort(A, Left, r-1);
	QuickSort(A, r+1, Right);
}

const int MAXN = 1e3+1;
int A[MAXN];
void Application() {
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", A+i);
	QuickSort(A, 0, n-1);
	int ans = 0;

	for(int i = 0; i < n; i+=2)
		ans += (A[i+1] - A[i]);
	printf("%d\n", ans);
}

int main(){
	Application();
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a[101];
int n;
int ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n-1;i+=2){
		ans+=(a[i+1]-a[i]);
	}cout<<ans;
	return 0;
}

// ConsoleApplication8.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
#include <map>
#include<string>
using namespace std;

map<int, int>MyMap;
int main()
{
	int Size, n;
	cin >> Size;
	for (int i = 0; i < Size; i++)
	{
		cin >> n;
		MyMap[n]++;
	}

	int Sum = 0;
	for (map<int, int>::iterator it = MyMap.begin(); it != MyMap.end(); it++)
	{
		if (it->second % 2 != 0)
		{
			map<int, int>::iterator it1 = it;
			it1++;
			for (; it1 != MyMap.end(); it1++)
			{
				if (it1->second % 2 != 0)
				{
					Sum += abs(it->first - it1->first);
					it1->second = 2;
					it = it1;
					break;
				}
			}
		}
	}
	cout << Sum;
	//system("pause");
	return 0;
}

//author:Darshik Hirapara
//DDU-Nadiad
#include<bits/stdc++.h>
using namespace std;
#define rip(a,b,c) for(a=b; a<c; a++)
int main()
{
	int t;
	cin>>t;
	int i, j, sum=0, sm_index, no[t];
	for(i=0; i<t; i++)
	{
		cin>>no[i];
		//cout<<sum;
	}
	//cout<<sum;
	rip(i, 0, t)
	{
		sm_index=i;
		rip(j, i+1, t)
		{
			if(no[j]>no[sm_index])
			{
				sm_index=j;
			}
		}
		if(sm_index>i)
		{
			no[sm_index]=no[sm_index] + no[i];
			no[i]=no[sm_index]-no[i];
			no[sm_index]=no[sm_index]-no[i];
		}
		//cout<<sum;
	}
	/*rip(i, 0, t)
	{
		cout<<no[i]<<endl;
	}*/
	rip(i, 0, t-1)
	{
		sum+=(no[i]-no[i+1]);
		i++;
	}
	cout<<sum;
	return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int n,ans,s[11111];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&s[i]);
	sort(s+1,s+1+n);
	for(int i=1;i<=n;i+=2) ans+=s[i+1]-s[i];
	printf("%d\n",ans);
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[101];
    for(int i=0 ;i<n ; i++)
        cin>>a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0 ; i<n ; i+=2)
        ans+=a[i+1]-a[i];
    cout<<ans<<endl;
}

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n=0, result=0;
    int arr[102];
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    sort(arr, arr+n);
    for(int i=n-1; i>0; i-=2)
    {
        result+=arr[i]-arr[i-1];
    }
    cout<<result;
    return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int a[100001];
int n,sum=0;
int main(){
	int i,j,k;
	cin>>n;
	for(i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	for(i=1;i<=n;i+=2)
	sum+=(a[i+1]-a[i]);
	cout<<sum<<endl;
	return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int c=0;
	sort(a,a+n);
	for(int i=0;i<n;i++){
		c+=a[i+1]-a[i];

		i++;
	}
	cout<<c;

	// your code goes here
	return 0;
}

#include <iostream>
#include <vector>
using namespace std;

typedef vector<int> vi;

void Merge(vi& left, vi& right, vi& fin)
{
	int i = 0, j = 0, k = 0;
	int nL = left.size();
	int nR = right.size();
	while (i < nL && j < nR)
	{
		if (left[i] <= right[j])
		{
			fin[k] = left[i];
			i++;
		}
		else
		{
			fin[k] = right[j];
			j++;
		}
		k++;
	}
	while (i < nL)
	{
		fin[k] = left[i];
		i++;
		k++;
	}
	while (j < nR)
	{
		fin[k] = right[j];
		j++;
		k++;
	}
}

void MergeSort(vector<int>& res)
{
	int n = res.size();
	if (n > 1)
	{
		int mid = n / 2;
		vector<int> left(mid);
		vector<int> right(n - mid);
		for (int i = 0; i < mid; i++)
		{
			left[i] = res[i];
		}
		for (int i = mid; i < n; i++)
		{
			right[i - mid] = res[i];
		}
		MergeSort(left);
		MergeSort(right);
		Merge(left, right, res);
	}
	return;
}

int main()
{
	std::ios::sync_with_stdio(false);
	int p;
	cin >> p;
	vector<int> x(p);
	int count = 0;
	for (int i = 0; i < p; i++)
	{
		int Ai;
		cin >> Ai;
		x[i] = Ai;

	}
	MergeSort(x);
	for (int i = 0; i < p - 1; i += 2)
	{
		count += x[i + 1] - x[i];
	}
	cout << count << endl;

	return 0;
}

#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

void answer(unsigned v)
{
    std::cout << v << '\n';
}

void solve(std::vector<unsigned>& a)
{
    const size_t n = a.size();

    std::sort(a.begin(), a.end());

    unsigned count = 0;
    for (size_t i = 0; i < n; i += 2)
        count += a[i+1] - a[i];

    answer(count);
}

int main()
{
    size_t n;
    std::cin >> n;

    std::vector<unsigned> a(n);
    std::copy_n(std::istream_iterator<unsigned>(std::cin), std::size(a), std::begin(a));

    solve(a);

    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  cin >> n;

  vector<int> vec;

  for (int i = 0; i < n; i++)
  {
    int temp;
    cin >> temp;
    vec.push_back(temp);
  }

  sort(vec.begin(), vec.end());
  // sort the vector*

  int sum = 0;
  for (int i = 0; i < n; i++)
  {
    sum += (vec[i+1] - vec[i]);
    i++;
  }

  cout << sum << endl;

}

    #include <bits/stdc++.h>
    using namespace std;

    #define SZ size()
    #define MIN LLONG_MIN
    #define MAX LLONG_MAX
    #define M 1000000007
    #define MP make_pair
    #define F first
    #define S second
    #define endl "\n"

    #define pb push_back
    #define N 100005

    typedef long long  ll;
    typedef unsigned long long ull;

    typedef vector<int> vi;
    typedef vector< vi > vvi;
    typedef vector<ll> vll;
    typedef vector<string> vs;
    typedef pair<int, int> pii;
    typedef map<int, int> mii;
    typedef map<char, int> mci;
    typedef map<string, int> msi;

    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    	// code part
    	int n; cin >>n; int a[N];int s=0;
    	for(int i =0; i <n; i++) cin >>a[i];
    	sort(a, a+n);
    	for(int i =0; i <n; i+=2) {
    	    s+=(a[i+1] - a[i]);
    	}
    	cout <<s;
    	return 0;
    }

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int A[n+3];
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
    }

    sort(A,A+n);
    int ans=0;

    for(int i=0; i<n-1; i=i+2)
    {
        ans+=A[i+1]-A[i];
    }

    cout<<ans<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int a[N], ans = 0;
template <class T> void cmax(T &x, T y) {x = x > y ? x : y;}
template <class T> void cmin(T &x, T y) {x = x < y ? x : y;}
template <class T> void rd(T &x) {
	char c = getchar(); int f = 1; x = 0;
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int main() {
	int i, n; rd(n);
	for (i = 1; i <= n; ++i) rd(a[i]);
	sort(a + 1, a + n + 1);
	for (i = 1; i <= n; i += 2) ans += a[i + 1] - a[i];
	cout << ans << '\n';
	return 0;
}

                        //Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
    int i,n,a,b,c,res,ans=0,in;
    vector<int>v;
    cin>>n;
    for(i=0; i<n; i++) {
        cin>>in;
        v.push_back(in);
    }
    sort(v.begin(),v.end());
    for(i=1; i<v.size(); i=i+2) {
        ans += v[i]-v[i-1];
    }
    cout<<ans<<endl;
}

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int* arr = new int[n];

    for(int i = 0; i < n; i++)
    {
       cin >> arr[i];
    }
    sort(arr, arr + n);

    int diff = 0;

    for(int i = 0; i < n; i += 2)
    {
        diff += abs(arr[i] - arr[i+1]);
    }

    cout << diff;

    return 0;
}

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

#include<bits/stdc++.h>
using namespace std;
const int maxn=100+5;
int n,a[maxn];
int read() {
    int x=0,f=1;
    char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int main() {
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+1+n);
	int ans=0;
	for(int i=1;i<=n;i+=2){
		ans+=abs(a[i]-a[i+1]);
	}
	printf("%d\n",ans);
    return 0;
}

#include <iostream>
using namespace std;

int main()
{
    int n,i,c=0,t;
    cin >> n;
    int a[n];
    for(i=0;i<n;i++)
        cin >> a[i];
    for(i=0;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(a[j]<a[i])
            {
                t=a[j];
                a[j]=a[i];
                a[i]=t;
            }
        }
    }
    for(i=0;i<n;i=i+2)
        c+=a[i+1]-a[i];
    cout << c;
    return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	long long n;
	cin >> n;
	vector<long long> v(n);
	for(long long i = 0; i < n; ++i){
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	long long res = 0;
	for(long long i = 0; i < n; i += 2){
		res += v[i + 1] - v[i];
	}
	cout << res << endl;
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int n, x[100005];
char s[100005];
int num;

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x[i];
    }
    sort(x, x+n);
    for(int i = 0; i < n; i+=2) {
        num += x[i+1]-x[i];
    }
    cout << num << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
	int ilestudentow, wynik;
	cin >> ilestudentow;
	int skills[ilestudentow+1];
	for(int i=0; i<ilestudentow; i++){
		cin >> skills[i];
	}
	sort(skills, skills + ilestudentow);
	for(int i = 0; i<ilestudentow;){
	if(skills[i]==skills[i+1]){
		 i=i+2;
	}
	else {
		wynik=wynik+(skills[i+1]-skills[i]);
		 i=i+2;
	}}
	cout << wynik;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[105],ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i+=2)
	{
		ans+=a[i+1]-a[i];
	}
	cout<<ans<<endl;
}

#include <iostream>
#include<algorithm>

using namespace std;
int main()
{
    int n, max=0, diff;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++) cin>>a[i];

    sort(a, a+n);

    for(int i=0; i<n;i+=2){
        diff=a[i+1]-a[i];
        max+=diff;
    }
    cout<<max<<endl;
    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;

/*void swap(int *a, int*b)
{
    int tmp=*a;
    *a=*b;
    *b=tmp;
}
int partition (int arr[], int low, int high)
{
    int pivot = arr[high]; // pivot
    int i = (low - 1); // Index of smaller element

    for (int j = low; j <= high - 1; j++)
    {
        // If current element is smaller than the pivot
        if (arr[j] < pivot)
        {
            i++; // increment index of smaller element
            swap(&arr[i], &arr[j]);
        }
    }
    swap(&arr[i + 1], &arr[high]);
    return (i + 1);
}
void quickSort(int arr[], int low, int high)
{
    if (low < high)
    {
        pi is partitioning index, arr[p] is now
        at right place
        int pi = partition(arr, low, high);

        // Separately sort elements before
        // partition and after partition
        quickSort(arr, low, pi - 1);
        quickSort(arr, pi + 1, high);
    }
}*/
void printArray(int arr[], int size)
{
    int i;
    for (i = 0; i < size; i++)
        cout << arr[i] << " ";
    cout << endl;
}

int main()
{
    int n,count=0;
    cin>>n;
    int *arr= new int[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }

    sort(arr,arr+n);
   //printArray(arr,n);
   // cout<<endl;
    for(int i=0;i<n-1;i+=2)
    {
      count+=arr[i+1]-arr[i];
    }
    cout<<count;
    return 0;
}

#include <cstdio>

int main()
{
   int N, t, ans;
   int a[200];
   scanf("%d",&N);
   for(int i = 0; i<N; ++i)scanf("%d", a+i);

   for(int i= 0; i<N;++i)
   for(int j =i+1;j<N;++j)
   if (a[i] > a[j]){
      t = a[i]; a[i] = a[j]; a[j] = t;
   }

   ans = 0;
   for(int i = 0; i < N; i +=2 ){
      ans += a[i+1] - a[i];
   }

   printf("%d\n", ans);

   return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {

	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	sort(a.begin(), a.end());
	int sum = 0;
	for (int i = 0; i < n; i += 2) {
		sum += a[i + 1] - a[i];
	}

	cout << sum << endl;

	return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    sort(a,a+n);
    int x,sum=0;
    for(int i=0;i<n;i+=2)
    {
        x=abs(a[i]-a[i+1]);
        sum+=x;
    }

    cout<<sum;
}

#include<bits/stdc++.h>
using namespace std;

void swap(int *a, int*b)
{
    int tmp=*a;
    *a=*b;
    *b=tmp;
}
int partition (int arr[], int low, int high)
{
    int pivot = arr[high]; // pivot
    int i = (low - 1); // Index of smaller element

    for (int j = low; j <= high - 1; j++)
    {
        // If current element is smaller than the pivot
        if (arr[j] < pivot)
        {
            i++; // increment index of smaller element
            swap(&arr[i], &arr[j]);
        }
    }
    swap(&arr[i + 1], &arr[high]);
    return (i + 1);
}
void quickSort(int arr[], int low, int high)
{
    if (low < high)
    {
        /* pi is partitioning index, arr[p] is now
        at right place */
        int pi = partition(arr, low, high);

        // Separately sort elements before
        // partition and after partition
        quickSort(arr, low, pi - 1);
        quickSort(arr, pi + 1, high);
    }
}
void printArray(int arr[], int size)
{
    int i;
    for (i = 0; i < size; i++)
        cout << arr[i] << " ";
    cout << endl;
}

int main()
{
    int n,count=0;
    cin>>n;
    int *arr= new int[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }

    quickSort(arr,0,n-1);
    //printArray(arr,n);
    for(int i=0;i<n-1;i+=2)
    {
      count+=arr[i+1]-arr[i];
    }
    cout<<count;
    return 0;
}

#include <iostream>
#include <stdlib.h>
using namespace std;

int*b;

void minisort(int * &a, int first1, int last1, int last2){
  int f1=first1, l1=last1, f2=last1+1, l2=last2, n=0;
  while (n<last2-first1+1){
    while ((a[f1]<=a[f2] || f2>l2)  && f1<=l1){
      b[n++]=a[f1++];
    }
    b[n++]=a[f2++];
  }
  for (int i=0;i<n;i++){
    a[i+first1]=b[i];
  }
}

void sort(int * &a, int first, int last){
  if (first >= last)
    return;
  int mid = first + (last - first) / 2;
  sort(a, mid+1, last);
  sort(a, first, mid);
  minisort(a, first, mid, last);
}

int main() {
  int n, res=0;
  cin >>n;
  int*a=(int*)calloc(n, sizeof(int));
  b=(int*)calloc(n, sizeof(int));
  for (int i=0;i<n;i++){
    cin >>a[i];
  }
  sort (a, 0, n-1);
  for (int i=1;i<n;i+=2){
    res+=(a[i]-a[i-1]);
  }
  cout <<res;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,i,p=0;
    cin>>n;
    int arr[n];
    for(i=0;i<n;i++)
      cin>>arr[i];
    sort(arr,arr+n);
    for(i=1;i<n;i+=2)
      p+=arr[i]-arr[i-1];
    cout<<p;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
int a[111];
int main(){
	int n; cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i];
	sort(a+1, a+n+1);
	int ans = 0;
	for(int i=1; i<=n; i++) {
		if(i % 2) ans -= a[i];
		else ans += a[i];
	}
	cout<<ans<<endl;
}

#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
int main(){
	int n,i,x,res=0;
	scanf("%d",&n);
	int v[101]{};
	vector<int> a;
	for(i=0;i<n;i++){
		scanf("%d",&x);
		v[x]++;
	}
	for(i=0;i<101;i++) if(v[i]%2==1) a.push_back(i);
	for(i=0;i<a.size();i+=2) res+=(a[i+1]-a[i]);
	printf("%d\n",res);
return 0;
}

#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
typedef _int64 ll;
int a[110];
int main()
{
	//freopen("in.txt","r",stdin);
	int n,i;
	while(cin>>n)
	{
		for( i = 0 ; i < n ; i++)
			cin>>a[i];
		sort(a,a+n);
		int ans=0;
		for( i = 1 ; i < n ; i+=2)
		{
			ans+=a[i]-a[i-1];
		}
		cout<<ans<<endl;
	}
	return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;

bool sap(int i,int j){
	return i>j;
}

int main(){
	int n,a[101];
	while(cin>>n){
		if(n%2==0) break;
	}
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n,sap);
	int sum=0;
	for(int i=0;i<n;i+=2){
		if(a[i]!=a[i+1]){
			sum+=a[i]-a[i+1];
		}
	}
	cout<<endl<<sum;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int ans = 0;
  for (int i = 0; i < n; i += 2) {
    ans += a[i + 1] - a[i];
  }
  cout << ans << "\n";
  return 0;
}

#include <iostream>
#include <algorithm>

int main() {
    int n; std::cin >> n;
    int s[n]; for(int i = 0; i < n; i++) std::cin >> s[i];
    std::sort(s, s+n);
    int output = 0;
    for(int i = 0; i < n-1; i += 2) {
        output += std::abs(s[i] - s[i+1]);
    }
    std::cout << output;
}

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
main()
{
    int a[105];
    int n;cin>>n;
    FOR(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);
    int res=0;
    for(int i=1;i<=n;i+=2)
    {
        res+=a[i+1]-a[i];
    }
    cout<<res;
}

#include <iostream>
using namespace std;
int main()
{
	const int a = 100;
	int n, i, A[a] = {0}, nmin, j, counter=0;
	cin >> n;
	for (i = 0; i < n; i++)
		cin >> A[i];
	for (i = 0; i < n - 1; i++)
	{
		nmin = i;
		for ( j = i + 1; j < n; j++)
			if (A[j] < A[nmin] && A[j] != 0 && A[nmin] != 0)
				nmin = j;
		if (nmin != i && A[nmin] != 0 && A[nmin] != 0)
		{
			int temp;
			temp = A[i];
			A[i] = A[nmin];
			A[nmin] = temp;
		}
	}
	for (i = n - 1; i >= 1;)
	{
		counter += A[i] - A[i - 1];
		i -= 2;
	}
	cout << counter;
		return 0;
}

#include<bits/stdc++.h>
using namespace std ;

int main(){
	int n , pri = 0 ;
	cin >> n ;
	int arr[n] ;
	for( int i = 0 ; i < n ; i++ ){
		cin >> arr[i] ;
	}
	sort( arr , arr + n ) ;
	for( int i = 1 ; i < n ; i += 2 ){
		pri += abs( arr[i] - arr[i-1] ) ;
	}
	cout << pri ;
}

// start : 77 ; 17:30
//https://atcoder.jp/contests/agc005/tasks
//120

#include<stdio.h>

void merge(int left, int mid, int right, int data[]){
	int sl = left;
	int sr = mid+1;
	int temp[1000];
	int st = 0;
	while(sl <= mid && sr <= right){
		if(data[sl]<data[sr]){
			temp[st++]=data[sl++];
		}else{
			temp[st++]=data[sr++];
		}
	}
	while(sl<=mid){
		temp[st++]=data[sl++];
	}
	while(sr<=right){
		temp[st++]=data[sr++];
	}
	for(int i = left,j=0;i<=right;i++,j++){
		data[i]=temp[j];
	}
}

void mergeSort(int left,int right, int data[]){
	if(left == right) return;
	int mid = (left+right)/2;
	mergeSort(left,mid,data);
	mergeSort(mid+1,right,data);
	merge(left,mid,right,data);
}
int abs(int a){
	if(a<0) return -a;
	return a;
}
int main(){
	int nc,temp[1000],hasil=0;
	scanf("%d",&nc);
	for(int i = 0;i<nc;i++){
		scanf("%d",&temp[i]);
	}
	mergeSort(0,nc-1,temp);
	for(int i = 0;i<nc-1;i+=2){
		hasil = hasil + abs(temp[i]-temp[i+1]);
	}
	printf("%d\n",hasil);
}

#include<bits/stdc++.h>
using namespace std;
#define NN 110
int a[NN],b[NN];
int main(){
	int n,s=0,t;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<n;i+=2){
		s+=abs(a[i+1]-a[i]);
	}
	printf("%d",s);
}

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    long long n,a,sum=0,x;
    vector<int> que;
    cin>>n;
    while(n--){
        cin>>x;
        que.push_back(x);
    }

    sort(que.begin(),que.end());

    for(int i=0;i<que.size();i=i+2){
        sum+=que[i+1]-que[i];
    }
    cout<<sum;
}

#include <bits/stdc++.h>
using namespace std;
int i,n,ans,a[105];
int main(){
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
for(i=0;i<n-1; i+=2)
ans+=a[i+1]-a[i];
cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;

        int n,a[100],c;
      int main ()
        {
            cin>>n;

            for ( int i=0 ; i<n ; i++ )
               cin>>a[i];

            sort(a,a+n);

            for ( int i=0 ; i<n ; i+=2 )
            {
                   if ( i==99 )
                    break;

            else   if ( (a[i]==a[i+1])  )
                    continue;
            else
                        c+=(a[i+1]-a[i]);
            }

               cout<<c<<endl;

        return 0;

        }

#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int n, sum = 0;;
	cin >> n;
	int*num = new int[n];
	for (int i = 0; i < n; ++i)
		cin >> num[i];
	sort(num, num + n);
	for (int i = 0; i < n / 2; ++i)
		sum += (num[2 * i + 1] - num[2 * i]);
	cout << sum << endl;
	return 0;
}

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define pb push_back
#define y second
#define x first

using namespace std;
typedef long long INT;
typedef pair<int, int> pii;
template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}
typedef vector<int> VI;

#define NN 110

int a[NN];

int main() {
#ifndef	ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n; scanf("%d", &n);
	for(int i=0; i<n; i++) scanf("%d", a+i);
	sort(a, a+n);

	int ans=0;
	for(int i=0; i<n; i++) {
		if(i&1) ans+=a[i];
		else ans-=a[i];
	}
	printf("%d\n", ans);
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int>::iterator partitionx(vector<int>::iterator first, vector<int>::iterator last){
    int v = *(first + distance(first, last) / 2);
    last--;
    while (distance(first, last) >= 0){
        while (*first < v) first++;
        while (*last > v) last--;
        if (*first == v && *last == v){
            first ++;
        }
        if (distance(first, last) > 0) {
            swap(*first, *last);
        }
    }
    return last;
}

void Qsort(vector<int>::iterator first, vector<int>::iterator last){
    vector<pair<vector<int>::iterator, vector<int>::iterator>> Q;
    Q.push_back(make_pair(first, last));
    while (!Q.empty()){
        auto iters = Q[Q.size() - 1];
        Q.pop_back();
        auto mid = partitionx(iters.first, iters.second);
        if (distance(iters.first, mid) > 1) Q.push_back(make_pair(iters.first, mid));
        if (distance(mid, iters.second) > 1) Q.push_back(make_pair(mid, iters.second));
    }
}

int main(){
    int n, s = 0;
    cin >> n;
    vector <int> a (n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    //auto x = partitionx(a.begin(), a.end());
    Qsort(a.begin(), a.end());
    for (int i = 0; i < n; i+= 2) s += a[i + 1] - a[i];
    cout << s;
    //cout << endl << *x << ' ' << distance(a.begin(), x) + 1;
    return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n,s=0;
	cin >> n;
	int a[150];
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a + 1, a + n+1);
	for (int i = 1; i <= n - 1; i += 2)
	{
		s += a[i + 1] - a[i];
	}
	cout << s << endl;
}

#include<iostream>
using namespace std;
int main()
{

    long long int a , i , b = 0 , j = 0 , v = 0  , x = 0;
    cin>>a;
    long long int n[a + 2];
    n[a + 1] = 0;
    for(i = 0 ; i < a; i++)
    {
        n[i] = 0;
        cin>> n[i];
    }
    for(j = 0 ; j < a; j++)
    {
        for(i = 0 ; i < a; i++)
    {
        if(n[i] > n[i + 1])
        {
            b = n[i];
            n[i] = n[i + 1];
            n[i + 1] = b;
        }
    }
    }
    for(i = 0; i < a; i += 2)
    {
        v +=  n[i + 1] - n[i];
    }
    cout<<v;
    return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[n+1];
	for(int i = 0; i < n; i++){
        cin >> a[i];
	}
	int sum = 0, k = 0;
	sort(a, a+n);
	for(int i = 1; i < n; i++){
        if(a[i] == a[i-1]){
            a[i] = -1;
            a[i-1] = -1;
        }
	}
	for(int i = 0; i < n; i++){
        if(a[i] != -1){
            a[k++] = a[i];
        }
	}
	n = k;
	for(int i = 0; i < n; i += 2){
        sum += a[i+1]-a[i];
	}
	cout << sum;
	return 0;
}

#include<bits/stdc++.h>

typedef long long int ll;
typedef unsigned long long int ull;

#define dbg printf("in\n")
#define nl printf("\n")
#define N 100100

#define sf(n) scanf("%d", &n)
#define sff(n,m) scanf("%d%d",&n,&m)
#define sfl(n) scanf("%I64d", &n)
#define sffl(n,m) scanf("%I64d%I64d",&n,&m)

#define pf(n) printf("%d",n)
#define pff(n,m) printf("%d %d",n,m)
#define pffl(n,m) printf("%I64d %I64d",n,m)
#define pfl(n) printf("%I64d",n)
#define pfs(s) printf("%s",s)

#define pb push_back
#define pp pair<ll,char>

using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);

    int i,j,k;
    int n,m,t;

    sf(n);
    int a[n];

    for(i=0;i<n;i++){
        sf(a[i]);
    }

    sort(a,a+n);

    int cnt=0;
    for(i=0;i<n;i+=2)
        cnt+=(a[i+1]-a[i]);

    pf(cnt);

    return 0;
}

/*
Problem:
	Sort array of integer (A)
Algorithm:
	Step1: Divide the input array into two subarrays of roughly equal size.
	Step2: Recursively mergesort each of the subarrays.
	Step3: Merge the newly-sorted subarrays into a single sorted array

	MergeSort(A[1 .. n]):	{correct=>doNothing} 		, if n = 1
							{m = n/2
							 MergeSort(A[1 .. m]
							 MergeSort(A[m+1 .. n])	, if n > 1
							 Merge(A[1 .. n], m)}
Complexity:
	O(nlogn)
Specific problem: https://codeforces.com/problemset/problem/1092/B
*/

#include <iostream>
#include <array>

const int MAXN = 1e6+1;
int B[MAXN];
void Merge(int A[], int l, int r, int m) {
	int i = l, j = m+1;
	for(int k = l; k <= r; k++)
		if(i > m) {
			B[k] = A[j]; j++;
		}
		else if(j > r) {
			B[k] = A[i]; i++;
		}
		else if(A[i] > A[j]) {
			B[k] = A[j]; j++;
		}
		else {
			B[k] = A[i]; i++;
		}
	for(int k = l; k <= r; k++)
		A[k] = B[k];
}

void MergeSort(int A[], int l, int r) {
	if(l == r)
		return;
	int m = (r+l)/2;
	MergeSort(A, l, m);
	MergeSort(A, m+1, r);
	Merge(A, l, r, m);
}

int A[MAXN];
int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", A+i);
	MergeSort(A, 0, n-1);
	int ans = 0;
	for(int i = 0; i < n; i+=2)
		ans += (A[i+1] - A[i]);
	printf("%d\n", ans);
	return 0;
}

#include <iostream>
using namespace std;
int main()
{
	int n,*A,i=0,j=0,a,b=0;
	cin>>n;
	A=new int[n];
	for(i=0;i<n;i++)
		cin>>A[i];
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(A[i]<A[j])
			{
				a=A[i];
				A[i]=A[j];
				A[j]=a;
			}
		}
	}
	for(int k=0;k<n-1;)
	{
		a=A[k+1]-A[k];
		b+=a;
		k+=2;
	}
	cout<<b;
	return 0;
}

#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
     int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    for(int i=0;i<n;i=i+2)
    {
        sum+=arr[i+1]-arr[i];
    }
    cout<<sum;
}

#include <bits/stdc++.h>
#include <climits>
using namespace std;

#define endl        '\n'
//#define IOS       ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define c0(x)       cout<<(x)<<" "
#define c1(x)       cout<<(x)<<endl
#define rep         for(ll i = 0 ; i < n ; i++)
#define f(i,s,n)    for(ll i = s ; i < n ; i++)
#define fe(i,s,n)   for(ll i = s ; i <= n ; i++)
#define rfe(i,s,n)  for(ll i = s ; i >= n ; i--)
#define TCs(x)      ll x; cin>>x; while(x--)
#define TC(x)       ll x=1; while(x--)
#define f2(it,v)    for(it = v.begin(); it != v.end(); ++it)
#define auto(m)     for(auto &it:m)
#define ip(n,a)     ll n;cin>>n;ll a[n];rep{cin>>a[i];}
#define ip2(n,a,b)  ll n;cin>>n;ll a[n];ll b[n];rep{cin>>a[i];} rep{cin>>b[i];}
//#define ip(n,a)   ll n;cin>>n;ll a[n];rep{cin>>a[i];}
#define op(n,a)     f(i,0,n){cout<<a[i]<<" ";}
#define i2p(n,k,a)  ll n,k;cin>>n>>k;ll a[n];rep{cin>>a[i];}
//#define ll        long long
//#define ld        long double
//#define vl        vector<ll>
#define mll         map<ll, ll>
#define mcl         map<char, ll>
#define msl         map<string, ll>
#define mp          make_pair
#define pii         pair<ll, ll>
#define pb          push_back
#define ff          first
#define ss          second
#define all(v)      v.begin(), v.end()
#define vsort(v)    sort(all(v))
#define vrsort(v)   reverse(all(v))
#define Max(x,y,z)  max(x,max(y,z))
#define Min(x,y,z)  min(x,min(y,z))
#define F           first
#define S           second
//#define ps(x,y)     fixed<<setprecision(y)<<x
//#define ps(x)       std::cout << std::fixed; std::cout << std::setprecision(x);
#define clz(a)      __builtin_clz(a) // count leading zeroes (geeksforgeeks.org/builtin-functions-gcc-compiler/)
#define ctz(a)      __builtin_ctz(a) // count trailing zeroes
//#define ctz(a)      __builtin_ctzll(a)
#define popc(a)     __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define GCD(A,B)    __gcd(A,B)
//#define LCM(A,B)    boost::math::lcm(A,B)
//#define COUNT(v,x)    count(all(v),x)
//#define COUNT(v,x)    count(all(s),'x')

//Typedefs:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pairs;
//typedef vector<pair<ll, pair<ll, ll>>> vppl;

const int N = 1e5 + 5;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
//Functions:----------------------------------------------------------------------------------------------------------------------------------------------------------------------
inline string IntToString(ll a)
{
    char x[100];
    sprintf(x, "%lld", a);
    string s = x;
    return s;
}
//....................................................................................//
inline ll StringToInt(string a)
{
    char x[100];
    ll res;
    strcpy(x, a.c_str());
    sscanf(x, "%lld", &res);
    return res;
}
//....................................................................................//
inline string GetString(void)
{
    char x[1000005];
    scanf("%s", x);
    string s = x;
    return s;
}
//....................................................................................//
inline string uppercase(string s)
{
    int n = s.size();
    f(i,0, n)
    if (s[i] >= 'a' && s[i] <= 'z')
        s[i] = s[i] - 'a' + 'A';
    return s;
}
//....................................................................................//
inline string lowercase(string s)
{
    int n = s.size();
    f(i,0,n)
    if (s[i] >= 'A' && s[i] <= 'Z')
        s[i] = s[i] - 'A' + 'a';
    return s;
}
//....................................................................................//
inline void OPEN(string s)
{
#ifndef TESTING
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
#endif
}
//....................................................................................//

template<typename T, typename U>            // Same as max_val = max (max_val, val)
static inline void amin(T &x, U y)          // Same as min_val = min (min_val,val)
{
    if (y < x)                              //maximum = amax(max_val, val);
        x = y;                              //minimum = amin (min_val, val);
}
//....................................................................................//
template<typename T, typename U>
static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
//....................................................................................//
ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
//....................................................................................//
int lcm(ll a, ll b)
{
    ll lar = max(a, b);
    ll small = min(a, b);
    for (ll i = lar; ; i += lar) {
        if (i % small == 0)
            return i;
    }
}
//....................................................................................//
int bsearch(ll arr[],ll l,ll r,ll x)
{
    while (l <= r)
    {
        ll m = l + (r - l) / 2;
        if (arr[m] == x){
            return m;
        }
        if (arr[m] < x){
            l = m + 1;
        }
        else
            r = m - 1;
    }
    return -1;
}
//....................................................................................//
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
//int bsearch(ll arr[], ll l, ll r, ll x){while (l <= r){ll m = l + (r - l) / 2;if(arr[m] == x){return m;}if(arr[m] < x){l = m + 1;}else{r = m - 1;}}}
//Solve:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void solve()
{
        ip(n,a);
        sort(a,a+n);
        ll ans=0;
        f(i,0,n)
        {
                if(i%2 == 0)
                {
                        ans+= a[i+1]-a[i];
                }
        }
        cout<<ans<<endl;

}

int main ()
{
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);

#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
#endif

        TC(t)
        {
                solve();
        }
        return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{

	int n, key = 0;
	cin >> n;
	vector <int> vect(n);
	for (int i = 0; i < n; i++)
	{
		cin >> vect[i];
	}
	sort(vect.begin(), vect.end());
	for (int i = 0; i < n; i++)
	{
		if (i % 2 != 0)
		{
			key += vect[i] - vect[i - 1];
		}
	}
	cout << key;
	return 0;
}

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
#define IOS ios::sync_with_stdio(0)
#define ull unsigned ll
#define uint unsigned
#define pai pair<int,int>
#define pal pair<ll,ll>
#define IT iterator
#define pb push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);++i)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);--i)
#define endl '\n'
#define ll long long
const ll mod = 1e9+7;

signed main() {
	#ifndef ONLINE_JUDGE
		//freopen("in.txt", "r", stdin);
		//freopen("out.txt","w",stdout);
	#endif
	int a[110];
	int n;cin >> n;
	for(int i = 1;i <= n;++i)cin >> a[i];
	sort(a+1,a+1+n);
	int ans = 0;
	for(int i = 1;i <= n;i += 2)ans += a[i+1] - a[i];
	cout << ans<< endl;
	return 0;
}

#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{int n,a[105],ans=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
sort(a,a+n);
for(int i=0;i<n;i+=2)
	ans+=a[i+1]-a[i];
printf("%d",ans);}

#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(const long long&a,long long&b)
{
	return a<b;
}
int main()
{
	int n,a[200];
	while(cin>>n)
	{
		for(int i=0;i<n;i++)
			cin>>a[i];
		sort(a,a+n);

		int s=0;
		for(int i=0;i<n;i+=2)
		{
			s+=a[i+1]-a[i];

		}
		cout<<s<<endl;

	}

}

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
    int c=0;
        for(int i=0;i<n-1;i=i+2){
            c=c+abs(a[i]-a[i+1]);
        }
         cout<<c<<endl;
    return 0;
}

#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int t=0;
    int count=0;
    vector<int> v(n);
    for(int i=0;i<n;++i)
    {
        cin>>v[i];
    }

    for(int i=0;i<v.size();++i)
    {
        for(int j=i+1;j<v.size();++j)
        {
            if(v[j]<v[i])
            {
                swap(v[i],v[j]);
                }
        }
        }
        for(int i=0;i<v.size();i+=2)
         {
       if(v[i]<v[i+1])
       {
           t=v[i+1]-v[i];
           v[i]+=t;
           count+=t;
           }
         }
      cout<<"\n"<<count;
}

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
using namespace std;

int main() {
	int n, a[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int cnt = 0;
	for (int i = n - 1; i >= 0; i-=2) {
		cnt = cnt + (a[i] - a[i - 1]);
	}
	cout << cnt << endl;
	return 0;
}

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	// your code goes here
	int n;
	int ctr=0;
	int arr[100];
	cin>>n;
	for(int i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	sort(arr,arr+n);
	for(int j=0;j<n;)
	{
	    ctr=ctr+arr[j+1]-arr[j];
	    j=j+2;
	}
	cout<<ctr;
	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n;
	int t = 0;
	cin >> n;
	vector <int> v(n);
	for (int o = 0; o < n; o++)
	{
		cin >> v[o];
	}
	sort(v.begin(), v.end());
	for (int i = 1; i < n; i = i + 2) {

			if (v[i] == v[i - 1]) {}
			else { t = t + v[i] - v[i - 1]; }
		}

		cout << t;
	}

//6
//5 10 2 3 14 5

#include <bits/stdc++.h>
#define ll long long
#define str string
using namespace std;
int main(){
	ll n,cnt=0;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(ll i=0;i<n-1;i+=2){
		cnt+=a[i+1]-a[i];
 }
 	cout<<cnt;
}

#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n";
#define ll long long int;
#define MAX 1000000009

int main()
 {
	IOS;
	int n;
	cin >> n;
	int a[n];
	for(int i =0;i<n;i++)
	{
		cin >> a[i];
	}
	sort(a,a+n);
	int sum(0);
	for(int i = 1;i<n;i+=2)
	{
		sum+=abs(a[i]-a[i-1]);
	}
	cout << sum;
	return 0;
  }

#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
typedef _int64 ll;
int a[110];
int main()
{
	//freopen("in.txt","r",stdin);
	int n,i;
	while(cin>>n)
	{
		for( i = 0 ; i < n ; i++)
			cin>>a[i];
		sort(a,a+n);
		int ans=0;
		for( i = 1 ; i < n ; i+=2)
		{
			ans+=a[i]-a[i-1];
		}
		cout<<ans<<endl;
	}
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int temp=0,t,diff=0;
    vector<int> v;
    cin>>t;

    for (int i=0; i<t; i++) {
        cin>>temp;
        v.push_back(temp);

    }

    sort(v.begin(), v.end());
    for (int i=0; i<t; i=i+2) {
        diff+=v[i+1]-v[i];

    }
    cout<<diff<<endl;
    return 0;
}

#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
void sor(int a[], int n) {
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n - i; ++j)
			if (a[j] > a[j + 1])
				swap(a[j], a[j + 1]);
}
int main() {
	int n, a[100], ANS = 0;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	sor(a, n - 1);
	for (int i = 0; i < n; i += 2)
		ANS += a[i + 1] - a[i];
	cout << ANS;
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < n; i += 2) {
        ans += a[i + 1] - a[i];
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main(){

	int n; cin >> n;
	int a[n];

	for(int i = 0; i < n; i++) cin >> a[i];

	sort(a, a+n);

	int ans = 0;

	for(int i = 0; i < n-1; i+=2) ans += a[i+1]-a[i];

	cout << ans;

	return 0;
}

#include <iostream>
using namespace std;
int main()
{
    int nofstudents,temp, x,problems =0;
    cin >> nofstudents;
    int skills [nofstudents];
    bool change;

    for(int i = 0; i<nofstudents; ++i){
        cin >> x;
        skills[i] = x;
    }
    do{
        change = false;
        for(int i = 0; i<(nofstudents-1); i++){
        if(skills[i+1] < skills[i])
        {
            temp = skills[i+1];
            skills[i+1] = skills[i];
            skills[i] = temp;
            change = true;
        }
    }
}
     while(change);
     for(int i = 0; i<nofstudents; i=i+2){
        if(skills[i]!=skills[i+1])
            problems = problems + (skills[i+1]-skills[i]);
     }
    cout << problems;
    return 0;
}

#include<iostream>
#include <algorithm>
using namespace std;

int main()
{
    int num, sum = 0;
    int arr[101];
    cin >> num;
    int i = 0;
    for (; i < num; i++)
        cin >> arr[i];
    sort(arr, arr + num);
    for (int j = 0; j < i - 1; j += 2)
    {
        sum += arr[j + 1] - arr[j];
    }
    cout << sum;
    return 0;
    }

#include<stdio.h>

int main()
{
	int n,skill[100],count=0;
	scanf("%d",&n);
	for(int q=0;q<n;q++)
	{
		scanf("%d",&skill[q]);
	}

	int temp;
	for(int q=0;q<n-1;q++)
	{
		for(int w=0;w<n-1;w++)
		{
			if(skill[w]<skill[w+1])
			{
				temp=skill[w];
				skill[w]=skill[w+1];
				skill[w+1]=temp;
			}
		}
	}

	for(int q=0;q<n;q+=2)
	{
		count=count+(skill[q]-skill[q+1]);
	}
	printf("%d",count);
}

// codeForces_1092B.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{

	int size, sum = 0, i = 0;
	cin >> size;
	vector <int> array(size);
	for (; i < size; i++) {
		cin >> array[i];
	}
	i = 0;
	sort(array.begin(), array.end());
	while (i < size ) {
		if (array[i + 1] == array[i]) {
		}
		else if(array[i + 1] > array[i]){
			sum += array[i + 1] - array[i];
		}
		i += 2;
	}
	cout << sum;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,a[100000],i;
	int t,x[100000],k=0,sum=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(i=0;i<n/2;i++)
	{
		t=i*2;
		x[k]=a[t+1]-a[t];
		//cout<<"x:"<<x;
		sum=sum+x[k];
		k++;
	}
	cout<<sum<<endl;
return 0;
}

#include<bits/stdc++.h>

using namespace std;

int a[200];
int main()
{
    int n,x,j;
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>x;
        a[x]++;
    }
    int k=0;
    x=0;
    j=0;
    for (int i=1; i<=100; i++)
    {
        if (x==0 && a[i]%2==1)
        {
            x=a[i];
            j=i;
            continue;
        }
        if ((a[i]%2)==1)
        {
            k+=min(x,a[i])*(i-j);
            x=max(a[i],x)-min(a[i],x);
            j=i;
        }
    }
    cout<<k;
    return 0;
}

/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
#include <algorithm>
using namespace std;
 int a[100];
int main()
{
    int n,i,l;
  cin>>n;
   for(i=0;i<n;i++)
   cin>>a[i];
   sort(a,a+n);
      for(i=0;i<n;i=i+2)
      {
        l=l+a[i+1]-a[i];
      }
  cout<<l;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int a[N];

int main() {
	int n , cnt = 0;;
	cin >> n;
	for (int i = 0; i < n; ++i) {
        cin >> a[i];
	}
	sort(a , a + n);
	for (int i = 0; i < n; i += 2) {
        if (a[i + 1] - a[i] >= cnt) {
            cnt += a[i + 1] - a[i];
        }
	}
	cout << cnt;
}

#include <stdio.h>
#include <math.h>

int main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int sum=0;
    for(int i=0;i<n/2;i++){
        long long  int temp=10000000000;
        for(int j=0;j<n;j++){
            if(i==j){
                continue;
            }
            if(fabs(a[i]-a[j])<=temp){
                temp=fabs(a[i]-a[j]);
            }
        }
        sum=sum+temp;
    }
    printf("%d\n",sum);
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define r(i,n) for(ll i=0;i<n;i++)
#define rp(i,a,b) for(ll i=a;i<b;i++)
#define rt return
#define db double
#define vd void
#define p(x) cout<<(x)<<endl;
#define ce continue;
#define bl bool
#define r0 rt 0;
#define r1 rt 1;
#define elif else if
#define bk break;
#define A p("A")
#define B p("B")
#define C p("C")
#define D p("D")
#define E p("E")
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define kaigyo cout<<endl;
#define pb(x) push_back(x);
using namespace std;
void Cond(int g){if(g)p("YES")else p("NO")rt;}
void cond(int g){if(g)p("Yes")else p("No")rt;}
ll power(ll k){ll t=1;r(i,k+1)t*=2;rt t;}
ll comb(ll i,ll j){ll up=1;for(ll n=i;n>i-j;n--){up*=n;}ll down=1;for(ll r=j;r>=1;r--)down*=r;rt up/(down);}//nCr.
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)rt b;gcd(b,a%b);}
ll Digits(ll k){ll t=0;while(k){t+=k%10;k/=10;}rt t;}
char m1[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char m2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char m3[10]={'0','1','2','3','4','5','6','7','8','9'};
const ll INF=(ll)1e18;
const ll MAX=(ll)1e5+10;
const ll NIL=-1;
struct Node{ll p,l,r;};
typedef struct edge{ll to,cost;}EDGE;
typedef pair<ll,ll> P;
#define ldb long double
ll ans=0,ct=0,ct1=0,ct2=0,cnt=0,tmp=0,g=0,n=0,m=0;
ll tmp1=0,tmp2=0,tmp3=0,tmp4=0,sum=0,pos=0,k=0;
ll len=0,len1=0,len2=0,len3=0,len4=0,len5=0;
ll mx=-INF,mn=INF;ll x;
map<ll,ll>mp,mp1,mp2;
set<P>st,st1,st2;
const ll MOD=((ll)1e9+7);

int main(){
cin>>n;
vector<ll>a(n);
r(i,n)cin>>a[i];
ans=0;
r(i,n){mn=INF;
	r(j,n){
	if(i==j||mp[j]||mp[i])ce
	if(abs(a[i]-a[j])<=mn){mn=abs(a[i]-a[j]);g=j;}
	}
	ans+=(mn!=INF)?mn:0;mp[i]=mp[g]=1;
}
p(ans)

	r0

}//main

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,arr[103]={0},Max = INT_MIN;
    cin>>n;
    for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n);
    for(int i=0;i<n;i+=2){
        int diff = arr[i+1] - arr[i];
        if(diff>Max)
            Max = diff;
    }
    cout<<Max<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,sum=0;
    cin>>n;
    int arr[n];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    for(i=0;i<n-1;i++)
    {
        for(j=1;j<=arr[i+1];j++)
        {
            if(arr[i]!=arr[i+1])
            {
                arr[i]++;
                sum++;
            }
            else
                break;
        }
    }
    return 0;
}

// Example program
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
    int n,d,mkz=0,min=100;
    cin >> n;
    int a[n];
    for (int i=0;i<n;i++) {
        cin >> a[i];
    } for (int i=0;i<n/2;i++) {
        min=100;
       for (int j=0;j<n;j++) {
           if(i!=j) {
           d=abs(a[i]-a[j]);
           }
             if( d<min) {
                 min=d;
             }
       }
       mkz=mkz+min;
    }
    cout << mkz ;
    return 0;

}

#include<iostream>
using namespace std;
int main(){
	int n ; cin >> n;
	int mas[n];
	int sum1 = 0;
	int sum2 = 0;

	for(int i = 1;i <= n; i++){

		cin >> mas[i];

		if(i <= n / 2)sum1+=mas[i];
		if(i > n / 2 && i <= n)sum2+=mas[i];

	}

	cout<<max(sum1,sum2)-min(sum1,sum2);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n1 1000000
//#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
//fflush(stdout)
int main()
{
    //fast
ios_base::sync_with_stdio(false); cin.tie(NULL);
ll n;
cin>>n;
ll a[n1];
for(ll i=0;i<n;i++)
{
	cin>>a[i];
}
int ans=0;
for(int i=0;i<n;i++)
{
	if(a[i]==0)
	{
		continue;
	}
	int no=a[i];
	int index=0;
	int dif=INT_MAX;
	int k=i;
	for(int j=0;j<n;j++)
	{
		int c=abs(a[j]-no);
		if(j!=k && c<dif)
		{
			dif=c;
			index=j;
		}
	}
	a[i]=0;
	a[index]=0;
    ans+=dif;
}
cout<<ans<<endl;

return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, sum = 0;

    cin >> n;

    int x[n+2];

    for(int i = 0; i <  n; i++)
    {
        cin >> x[i];
    }

    sort(x, x + n);

    x[n++] = 0;

    for(int i = 0; i < n ; i += 2)
    {

        sum += x[i+1] - x[i];

    }

    cout << sum << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,arr[103]={0},Max = INT_MIN;
    cin>>n;
    for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n);
    for(int i=1;i<n;i++){
        int diff = arr[i] - arr[i-1];
        if(diff>Max)
            Max = diff;
    }
    cout<<Max<<endl;
    return 0;
}

#include <stdio.h>

struct kb{
    int dizi[256];
};

kb sdizi[1024];

int main(){}

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=105;
int data[N];
int n,sum;
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	for(int i=0;i<n;i++) scanf("%d",&data[i]);
	sort(data,data+n);
	for(int i=0;i<n;i+=2) sum+=data[i+1]-data[i];
	cout<<sum<<'\n';
	return 0;
}

#include <iostream>
#include <algorithm>

int main() {
    int n; std::cin >> n;
    int s[n]; for(int i = 0; i < n; i++) std::cin >> s[i];
    std::sort(s, s+n);
    for(int i : s) {
        std::cout << i << " ";
    }
    int output = 0;
    for(int i = 0; i < n-1; i += 2) {
        output += std::abs(s[i] - s[i+1]);
    }
    std::cout << output;
}

#include<bits/stdc++.h>
using namespace std;

int main(){
       int n,sum=0;
       cin>>n;
       int arr[n];
       for(int i=0; i<n;i++){
              cin>>arr[i];
       }
       sort(arr,arr+n);
       for(int i=1;i<n;i++){
              int x=abs(arr[i]-arr[i-1]);
              sum+=x;
       }
       cout<<sum<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vii;
typedef vector<string> vs;
typedef unordered_map<int, int> uii;
typedef unordered_map<char, int> uci;
typedef unordered_map<string, int> usi;

int skillsDeterminer(vi skills) {
    vector < pair<int, int> > studentTeams;
    for(int i = 0; i < skills.size(); i++) {
        int currentPerson = skills[i];
        int diff = 10000;
        int secondPerson = 0;
        for(int j = 0; j < skills.size(); j++) {
            if(j!=i && skills[j]!=-1 && skills[i]!= -1) {
                int newDiff = abs(skills[i]-skills[j]);
                if(newDiff < diff) {
                    diff = newDiff;
                    secondPerson = j;
                }
            }
        }
        studentTeams.push_back(make_pair(currentPerson,skills[secondPerson]));
        skills[i] = -1;
        skills[secondPerson] = -1;
    }
    int minQues = 0;
    for(int i = 0; i < studentTeams.size(); i++) {
        if(studentTeams[i].first == -1 && studentTeams[i].second == -1) {
            continue;
        }
        else {
            int diff = abs(studentTeams[i].first - studentTeams[i].second);
            minQues += diff;
        }
    }

    return minQues;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int students;
    cin>>students;
    vi skills(students);
    for(int i = 0; i < students; i++) {
        cin>>skills[i];
    }
    int minSkills = skillsDeterminer(skills);
    cout<<minSkills;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 1e2 + 7;
bool arr[N];
int n;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);

  cin >> n;
  for (int i = 0; i < n; ++i) {
    int act;
    cin >> act;
    arr[act] ^= 1;
  }
  int res = 0;
  for (int i = 0; i < 101; ++i) {
    res += !arr[i];
  }
  cout << res << "\n";

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define per(i,a,b) for (int i=a; i>=b; --i)
#define Z(a) (int)(a).size()
#define all(i) (i).begin(),(i).end()
#define pb push_back
#define I first
#define II second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
// head

int n,h; VI ipt;

int main() {
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",&h), ipt.pb(h);
	sort(all(ipt));

	int mx=0;
	rep(i,1,n) mx+=ipt[i]-ipt[i-1];
	printf("%d",mx);
}

#include<bits/stdc++.h>
using namespace std;

main()
{
    int n;
    cin>>n;
    int a[100];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a,a+n);
    int dem=0;
    for(int i=1;i<=n;i+=2)
        dem+=abs(a[i]-a[i+1]);
    cout<<dem;
}

#include <bits/stdc++.h>
using namespace std;

void swap(int a,int b)
{
    int temp=a;
    a=b;
    b=temp;
}

void bubblesort(int c[],int n1)
{
    for (int i=0;i!=n1-1;i++)
    {
        for (int j=0;j!=n1-i-1;j++)
        {
            if(c[j]<=c[j+1])
            {
                swap(c[j],c[j+1]);

            }
        }
    }

}

int main()
{
    int n;
    cin>>n;
    int a[n];
    for (int i=0 ;i!=n;i++)
    {
        cin>>a[i];

    }
    bubblesort(a,n);
    int sum=0;
    for (int i=1;i!=n;i+=2)
    {
        sum=sum+(a[i-1]-a[i]);
    }
    cout<<"sum";
}

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        vector<int> v(n,0);
        for(int i=0;i<n;i++)
        {
            cin >> v[i];
        }
        int sum=0;
        for(int i=0;i<n;i += 2)
        {
            sum += v[i+1] -v[i];
        }
        cout << sum << endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    int sum=0;
    vector<int>a(n);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        a.push_back(x);

    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;i+=2)
    {
        sum=a[i+1]-a[i];
    }
    cout<<sum;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 100000000000000000
#define pb push_back
#define mp make_pair
//#define MAXX 200000
//vector<ll> Primes; ll isprime[MAXX+2],Ar[MAXX+100];
//void sieve(){
//    Primes.push_back(2);isprime[2]=1;
//    for(ll i=2;i<=MAXX;i+=2) Ar[i]=1;
//    for(ll i=3;i<=MAXX;i+=2){ if(Ar[i]==0) { Primes.push_back(i); isprime[i]=1; for(ll j=i*i;j<=MAXX;j+= i*2) Ar[j]=1;}}
//}
//double mysqrt(ll N){
//    double high,low,mid; high=(double)N;low=0.0;for(ll i=1;i<=64;i++){ mid=(high+low)/2; if(mid*mid>N) high=mid; else low=mid;}
//    return mid;}
//ll mod(ll B,ll M){ll X=B%M; if(X>=0) return X; else return M+X;}
///cin.ignore();
ll max(ll a,ll b) {if(a>b) return a; else return b;} ll min(ll a,ll b) {if(a<b) return a; else return b;}
ll pow(ll B,ll P) { ll S=1; for(ll i=1;i<=P;i++) S=S*B; return S;} ll fx4[]={1,-1,0,0}; ll fy4[]={0,0,1,-1};

int A[20000],B[20000];

int main()
{
    ///use always ll instead of int
    //sieve();

    ll T,N,M,X,Y,W;

    cin>>N;

    for(int i=1;i<=N;i++) cin>>A[i];

    ll ans=0;

    ll loop=N/2;

    for(int i=1;i<=N;i++)
    {
        ll MIN=10000,pos=1;

        if(A[i]==-1) continue;

        for(int j=1;j<=N;j++)
        {
            if(i==j || A[j]==-1) continue;

            X=abs(A[i]-A[j]);

            if(X<MIN)
            {
                //cout<<i<<" "<<j<<" "<<X<<" "<<MIN<<endl;
                MIN=X;
                pos=j;
            }
        }

        //cout<<i<<" "<<pos<<endl;

        if(A[i]!=-1) ans+=(abs(A[i]-A[pos]));
        A[i]=-1;
        A[pos]=-1;
    }

    cout<<ans<<endl;

    //for(int i=1;i<=N;i++) cout<<A[i]<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int
main ()
{

    int n;
    cin >> n;

    vector < int > numbers;
    int v;
    for (int i = 0; i < n; i++)
    {
        cin >> v;
        numbers.push_back (v);
    }

    sort (numbers.begin (), numbers.end ());
    reverse (numbers.begin (), numbers.end ());

    int sum = 0;

    for (int j = 0; j <= n; j += 2)
    {
        sum = sum + (numbers[j] - numbers[j + 1]);
    }

    cout << sum;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int a[105];

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i <n; ++i){
        cin >> a[i];
    }
    int nmb = 0;
    for(int i = 0; i < 100; ++i){
        for(int j = 0; j < n; ++j){
            for(int k = 0; k < n; ++k){
                if(k == j){
                    continue;
                }
                if(a[k] - a[j] == i){
                    a[k] = -1;
                    a[j] = -1;
                    nmb += i;
                }
            }
        }
    }

    cout << nmb << "\n";
    return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int mas[3];
int main() {
    cin >> mas[0] >> mas[1] >> mas[2];
    sort(mas, mas + 3);
    cout << mas[2] - mas[0];
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int habilidad[n];
	for(int i=0; i<n; i++){
		int temp;
		cin>>temp;
		habilidad[i]=temp;
	}
	//formar parejas
	int parejas[n];
	int menor;
	int indices=-1;
	int cont=0;
	bool ban=false;
	for(int y=0; y<n; y++){
		menor=100;
		indices=-1;
		ban=false;
		for(int i=0; i<n; i++){
			if(i!=y){
				if(abs(habilidad[y]-habilidad[i])<menor && parejas[i]!=1){
					menor=abs(habilidad[y]-habilidad[i]);
					indices=i;
					ban=true;
				}
			}
		}
		if(ban==true){
	  cont+=menor;
	  parejas[indices]=1;
     }
	  parejas[y]=1;
	}
	cout<<cont;
	return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n,a[1000];
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    cout<<(a[n-1]-a[0]+1)-n<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
main()
{
    int n,i,k,x=0,p;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=0;i<n;i++)
    {
        k=a[i]-a[i-1];
        if(x<k)
        {
            p=k;
        }
        x=k;
    }
    cout<<p<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define per(i,a,b) for (int i=a; i>=b; --i)
#define Z(a) (int)(a).size()
#define all(i) (i).begin(),(i).end()
#define pb push_back
#define I first
#define II second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
// head

int n,h; VI ipt;

int main() {
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",&h), ipt.pb(h);
	sort(all(ipt));

	int mx=0;
	rep(i,1,n) mx=max(mx,ipt[i]-ipt[i-1]);
	printf("%d",mx);
}

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
main()
{
    int a[105];
    int n;cin>>n;
    FOR(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);
    int res;
    for(int i=1;i<=n;i++)
    {
        res+=a[i+1]-a[i];
    }
    cout<<res;
}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <cstring>
#include <string>
#include <set>
using namespace std;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz size
#define INFMAX 10000000000
#define INFMIN 10000000000

const int maxn = 100;

int n,a[maxn];
long ans=0;

void Input()
{
    cin >> n;
    for (int i=1; i<=n; i++) cin >> a[i];
}

void Solve()
{
    sort(a+1,a+n+1);
    for (int i=1; i<=n; i+=2)
        if (a[i] == a[i+1]) continue; else ans += abs(a[i]-a[i+1]);
}

void Output()
{
    cout << ans;
}

int main()
{
    Input();
    Solve();
    Output();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
int main()
{
int i,n;
cin>>n;
int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);int c;
for(i=0;i<n;i+=2)
{
c+=(a[i+1]-a[i]);
}
cout<<c;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int a[N];
int main ()
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];

    }
    sort (a,a+n);
    for (int i = 1; i < n; i++)
    {
        ans = ans + (a[i] - a[i-1]);
    }
    cout << ans << endl;

}

#include<iostream>
#include<math.h>
using namespace std;
int main(){
    int n,dif,diff,p=1000,sum=0,m;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=0;i<n;i++){
        p=1000;
        m=0;
        if(a[i]==0) continue;
        for(int j=0;j<n;j++){
            if(i!=j && a[j]!=1000000){
                dif=a[i]-a[j];
                diff=abs(dif);
                //cout<<diff<<endl;
                if(diff<=p){
                    p=diff;
                    m=j;
                }
                //cout<<"m:"<<m<<endl;
            }
        }
        a[m]=1000000;
        a[i]=1000000;
        if(p==1000) p=0;
        //cout<<"p:"<<p<<endl;
        sum+=p;
    }
    cout<<sum;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int habilidad[n];
	for(int i=0; i<n; i++){
		int temp;
		cin>>temp;
		habilidad[i]=temp;
	}
	//formar parejas
	int parejas[n];
	int menor;
	int indices=-1;
	int cont=0;
	bool ban=false;
	for(int y=0; y<n; y++){
		menor=100;
		indices=-1;
		ban=false;
		if(parejas[y]!=1){
		for(int i=0; i<n; i++){
			if(i!=y){
				if(abs(habilidad[y]-habilidad[i])<menor && parejas[i]!=1){
					menor=abs(habilidad[y]-habilidad[i]);
					indices=i;
					ban=true;
				}
			}
		}
	}
		if(ban==true){
	  cont+=menor;
	  parejas[indices]=1;
     }
	  parejas[y]=1;
	}
	cout<<cont;
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    long long int n,i,res1=0,res2=0;
    cin>>n;
    int arr[n];
    for(i=0;i<n;i++){
        cin>>arr[i];
        if((n/2)>i){
            res1=res1+arr[i];
        }else{
          res2=res2+arr[i];
        }
    }
    if(res1>res2){
        cout<<res1-res2<<endl;
    }else{
    cout<<res2-res1<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n , c;
	cin >> n;
	vector <int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
		sort (a.begin() , a. end());
	for (int i = 0; i < n; i += 2)
	{
		c += a[i + 1] - a[i];
	}
	cout << c << endl;
}

// C++ program for implementation of Bubble sort
#include <bits/stdc++.h>
using namespace std;

void swap(int *xp, int *yp)
{
	int temp = *xp;
	*xp = *yp;
	*yp = temp;
}

// A function to implement bubble sort
void bubbleSort(int arr[], int n)
{
	int i, j;
	for (i = 0; i < n-1; i++)

	// Last i elements are already in place
	for (j = 0; j < n-i-1; j++)
		if (arr[j] > arr[j+1])
			swap(&arr[j], &arr[j+1]);
}

/* Function to print an array */
void printArray(int arr[], int size)
{
	int i,s=0;
	for (i = 0; i < size; i++)
		cout << arr[i] << " ";
	cout << endl;
	for(int j=0;j<size;j++)
	{
		s+=arr[j+1]-arr[j];
		j++;
	}
	cout<<s;
}

// Driver code
int main()
{
	int arr[20],n;
	cout<<"enter size..\n";
	cin>>n;
	cout<<"array is...\n";
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	//int n = sizeof(arr)/sizeof(arr[0]);
	bubbleSort(arr, n);
	cout<<"Sorted array: \n";
	printArray(arr, n);
	return 0;
}

// This code is contributed by rathbhupendra

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,x,y,z,arr[102];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    a=0;
    for(int j=0;j<n-1;j=j+2)
   {
       a=a+(arr[j+1]-(arr[j]));

   }

    cout<<a<<endl;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
int main() {
    int n, m = 0;
    cin >> n;
    vector<int> mas(n);
    for (int i = 0; i < n; i++) {
        cin >> mas[i];
    }
    sort (mas.begin(), mas.end());
    for (int i = 0; i < n; i++) {
        cout << mas[i] << " ";
    }
    for (int i = 0; i < n - 1; i++) {
        if (mas[i] <= mas[i + 1]) {
            m = m + (mas[i + 1] - mas[i]);
            i++;
        }
    }
    cout << "\n" << m;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<int> v;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int in;
        cin>>n;
        v.push_back(in);
    }
    sort(v.begin(),v.end());
    int out;
    for(int i=0;i<n-1;i+=2)
    {
        out+=abs(v[i]+v[i+1]);
    }
    cout<<out;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
	int ilestudentow, wynik;
	cin >> ilestudentow;
	int skills[ilestudentow+2];
	for(int i=1; i<=ilestudentow; i++){
		cin >> skills[i];
	}
	sort(skills, (skills+1) + (ilestudentow+1));
	for(int i = 1; i<ilestudentow;){
	if(skills[i]==skills[i+1]){
		 i=i+2;
	}
	else {
		wynik=wynik+(skills[i+1]-skills[i]);
		 i=i+2;
	}}
	cout << wynik;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int ans=0;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort (a,a+n);
    int v=n/2;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=a[i+1] &&v>=0)
           {
               ans+=a[i+1]-a[i];
               i+=2;
               v--;

           }
           i++;

    }
    return cout<<ans<<endl,0;
}

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {

	int n = 0;
	cin >> n;
	int *m;
	m = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> m[i];
	}
	int d = 0, c = 0, k = 0, p = 0;
	int t = 0;

	for (int i = 0; i < n - 1; i++) {
		t = m[i];
		if (n == 2) {
			cout << abs(m[i] - m[i+1]);
			return 0;
		}
		for (int j = i + 1; j < n; j++) {
			if (m[j] == t) {
				m[j] = -100;
				m[i] = -100;
				continue;
			}
		}
		for (int j = i + 1; j < n; j++) {
			if ((m[i] == -100) || (m[j] == -100) || (m[j + 1] == -100)) {
				continue;
			}
			d = abs(m[i] - m[j]);
			k = abs(m[i] - m[j + 1]);
			if (d < k) {
				p = d;
			}
			else {
				p = k;
			}
		}
		c += p;
		p = 0;

	}
	cout << c;
	return 0;

}

#include <iostream>
#include<vector>
using namespace std;
int main() {
	// your code goes here
	int n,min,x,pair;
	pair=0;
	int arr[100];
	int ctr=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	for(int i=0;i<n;i++)
	{   min=100;
	    if(arr[i]!=0)
	        {
	    for(int j=0;j<n;j++)
	    {   if((j!=i)&&(arr[j]!=0))
	        {
	            x=abs(arr[j]-arr[i]);
	        if(x<min)
	        {
	            min=x;
	            pair=j;
	        }
	        }
	    }
	    arr[i]=0;
	    arr[pair]=0;
	    ctr=ctr+min;

	}
	}
	cout<<ctr;
	return 0;
}

#include <iostream>
#include<vector>
#include<string>
using namespace std;
int partition(vector<int> &values, int left, int right) {
    int pivotIndex = left + (right - left) / 2;
    int pivotValue = values[pivotIndex];
    int i = left, j = right;
    int temp;
    while(i <= j) {
        while(values[i] < pivotValue) {
            i++;
        }
        while(values[j] > pivotValue) {
            j--;
        }
        if(i <= j) {
            temp = values[i];
            values[i] = values[j];
            values[j] = temp;
            i++;
            j--;
        }
    }
    return i;
}

void quicksort(vector<int> &values, int left, int right) {
    if(left < right) {
        int pivotIndex = partition(values, left, right);
        quicksort(values, left, pivotIndex - 1);
        quicksort(values, pivotIndex, right);
    }
}

int main()
{
    int n;
    cin>>n;
    vector<int>t;
    for(int i=0;i<n;i++)
    {
        int temp;
        cin>>temp;
        t.push_back(temp);
    }

    int count=0;
    for(int i=0;i<t.size()-1;)
    {
        int temp=t[i+1]-t[i];
        count=count+temp;
        i=i+2;
    }
    cout<<count;
    return 0;
}

#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
    int n,d,min=10000,c=0;
    cin >> n;
    int a[n];
     for(int i=0;i<n;i++) {
         cin >> a[i];
     }
    for(int i=0;i<n;i++) {
        min=10000;
        for(int j=0;j<n;j++) {
            d=abs(a[i]-a[j]);
            if(d<min && i!=j) {
                min=d;
            }
        } c=c+min;
        }
        cout << c/2;
        return 0;

}

#include <stdio.h>
#include <math.h>

int main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int sum=0;
    for(int i=0;i<n/2;i++){
        long long  int temp=10000000000;
        for(int j=0;j<n;j++){
            if(i==j){
                continue;
            }
            if(fabs(a[i]-a[j])<=temp){
                temp=fabs(a[i]-a[j]);
            }
        }
        sum=sum+temp;
    }
    printf("%d\n",sum);
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()

{
    ll t , n ;
    cin>>t;
    while(t--)
    {
        cin>>n;
        vector<ll> arr(n,0);
        for(int i =0;i<n;i++)
        cin>>arr[i];
        ll ans = 0;
        sort(arr.begin(),arr.end());
        for(int i=1;i<n;i=i+2)
        {
            ans += arr[i]-arr[i-1];
        }
        cout<<ans<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a[105],i,sum=0,n,k,c,b;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n+1);
    for(i=1; i<=n; i++)
    {
        sum+=a[i+1]-a[i];
        i++;}
        cout<<sum<<' ';

}

#include<bits/stdc++.h>

using namespace std;
int main()
{
    int  n,s[100],i;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
    }
    sort (s,s+100);

    return 0;
}

//   ALLAH IS THE ALMIGHTY   //
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int n;
  cin >> n;
  int x, a(0), b(0), div = n / 2;;
  for (int i = 0; i < n; i++) {
    cin >> x;
    div > i ? a += x : b += x;
  }
  cout << b - a << '\n';
  return 0;
}
//           SOLVED!            //

#include <bits/stdc++.h>
using namespace std;

        int n,a[101],c;
      int main ()
        {
            cin>>n;

            for ( int i=0 ; i<n ; i++ )
               cin>>a[i];

            sort(a,a+n);

            for ( int i=0 ; i<n ; i+=2 )
            {
                if ( (a[i]==a[i+1]) || (a[i]==a[i-1]) )
                    continue;
            else
                        c+=(a[i+1]-a[i]);
            }

               cout<<c<<endl;

        return 0;

        }

#include <bits/stdc++.h>

using namespace std;

int a[105];

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i <n; ++i){
        cin >> a[i];
    }
    int nmb = 0;
    for(int i = 0; i < 100; ++i){
        for(int j = 0; j < n; ++j){
            for(int k = 0; k < n; ++k){
                if(k == j){
                    continue;
                }
                if(abs(a[j] - a[k]) == i){
                    a[k] = -1;
                    a[j] = -1;
                    nmb += i;
                }
            }
        }
    }

    cout << nmb << "\n";
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int a[105];

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i <n; ++i){
        cin >> a[i];
    }
    int nmb = 0;
    for(int i = 0; i < 100; ++i){
        for(int j = 0; j < n; ++j){
            for(int k = 0; k < n; ++k){
                if(k == j){
                    continue;
                }
                if(a[k] - a[j] == i){
                    a[k] = -1;
                    a[j] = -1;
                    nmb += i;
                }
            }
        }
    }

    cout << nmb << "\n";
    return 0;
}

#include <iostream>
#include<vector>
using namespace std;
int main() {
	// your code goes here
	int n,min,x,pair;
	pair=0;
	int arr[100];
	int ctr=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	for(int i=0;i<n;i++)
	{   min=abs(arr[i]-arr[i+1]);
	    for(int j=0;j<n;j++)
	    {   if((j!=i)&&(arr[j]!=0))
	        x=abs(arr[j]-arr[i]);
	        if(x<min)
	        {
	            min=x;
	            pair=j;
	        }
	    }
	    arr[i]=0;
	    arr[pair]=0;
	    ctr=ctr+min;

	}
	cout<<ctr;
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define r(i,n) for(ll i=0;i<n;i++)
#define rp(i,a,b) for(ll i=a;i<b;i++)
#define rt return
#define db double
#define vd void
#define p(x) cout<<(x)<<endl;
#define ce continue;
#define bl bool
#define r0 rt 0;
#define r1 rt 1;
#define elif else if
#define bk break;
#define A p("A")
#define B p("B")
#define C p("C")
#define D p("D")
#define E p("E")
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define kaigyo cout<<endl;
#define pb(x) push_back(x);
using namespace std;
void Cond(int g){if(g)p("YES")else p("NO")rt;}
void cond(int g){if(g)p("Yes")else p("No")rt;}
ll power(ll k){ll t=1;r(i,k+1)t*=2;rt t;}
ll comb(ll i,ll j){ll up=1;for(ll n=i;n>i-j;n--){up*=n;}ll down=1;for(ll r=j;r>=1;r--)down*=r;rt up/(down);}//nCr.
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)rt b;gcd(b,a%b);}
ll Digits(ll k){ll t=0;while(k){t+=k%10;k/=10;}rt t;}
char m1[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char m2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char m3[10]={'0','1','2','3','4','5','6','7','8','9'};
const ll INF=(ll)1e18;
const ll MAX=(ll)1e5+10;
const ll NIL=-1;
struct Node{ll p,l,r;};
typedef struct edge{ll to,cost;}EDGE;
typedef pair<ll,ll> P;
#define ldb long double
ll ans=0,ct=0,ct1=0,ct2=0,cnt=0,tmp=0,g=0,n=0,m=0;
ll tmp1=0,tmp2=0,tmp3=0,tmp4=0,sum=0,pos=0,k=0;
ll len=0,len1=0,len2=0,len3=0,len4=0,len5=0;
ll mx=-INF,mn=INF;ll x;
map<ll,ll>mp,mp1,mp2;
set<P>st,st1,st2;
const ll MOD=((ll)1e9+7);

int main(){
cin>>n;
vector<ll>a(n);
r(i,n)cin>>a[i];
ans=0;
Sort(a)
k=n;ll s,t;
while(k){mn=INF;
	r(i,n){
		r(j,n){
	if(i==j||mp[i]||mp[j])ce
		if(abs(a[i]-a[j])<=mn){mn=abs(a[i]-a[j]);s=i;t=j;}
		}
	}
	//if(mn==INF)cout<<s<<" "<<t<<endl;
//	else p(mn)
ans+=(mn==INF)?0:mn;mp[s]=mp[t]=1;
k--;
}

p(ans)
	r0

}//main

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,total;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int j=0;j<n;j=j+2)
		total+=a[j+1]-a[j];
	cout<<total<<endl;
	return 0;
 }

#include <bits/stdc++.h>
#define    fast       ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
inline int Int()
{
    int x;
    scanf("%d", &x);
    return x;
}
#define    Int        Int()
vector<int> v;
set<int> s;
int main()
{

    fast;
    int t=Int;
    int arr[t];
    for(int i = 0;i<t;i++)
        arr[i] = Int;

    sort(arr,arr+t);

    int cnt = 0;
    int sum = 0;
    for(int i = t/2 - 1;i>=0;--i){
        cnt += abs(arr[i] - arr[i+1]);
        sum +=  cnt;
    }
    cout << sum << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int s[n];
  int count=0;
  vector<int >v(101);
  for(int a=0;a<n;a++)
  {
    cin>>s[a];
    v[s[a]]++;
    if(v[s[a]]==2) count++;
  }
  //cout<<count;
  sort(s,s+n);
//  for(int a=0;a<n;a++) cout<<s[a]<<" ";
  int ans=0;
  if(count>=(n/2)) cout<<0<<endl;
  else
  {
    for(int a=1;a<n;a++)
    {
      if(s[a]==s[a-1])
       {
        s[a]=-1;
        s[a-1]=-1;
      }
      else if(s[a-1]!=-1)
      {
        ans+=abs(s[a]-s[a-1]);
      //  a=a+1;
        s[a]=-1;
        count++;
      }
      if(count>=(n/2)) break;
    }
    cout<<ans;
  }
  return 0;
}
/*#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll t;
  cin>>t;
  while(t--)
  {
    ll n,k;
    cin>>n>>k;
    string s="abcdefghijklmnopqrstuvwxyz";
    ll l=n/k;
    for(ll a=0;a<k;a++)
    {
      for(ll b=0;b<l;b++)
      {
        cout<<s[a];
      }
    }
    if(n%k!=0)
    {
      cout<<s[k-1];
    }
  }
  return 0;
}*/

#include <iostream>

using namespace std;

long long n,i,j,k,l,a[1000001],ans,ans1;

int main() {
    cin >> n;
    for(i = 1; i <= n; i++) cin >> a[i];
    for(i = 1; i <= n / 2; i++) ans += a[i];
    for(i = n / 2 + 1; i <= n; i++) ans1+= a[i];
    cout << max(ans,ans1) - min(ans,ans1);
    return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=105;
int data[N];
int n,sum;
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	for(int i=0;i<n;i++) scanf("%d",&data[i]);
	sort(data,data+n);
	for(int i=0;i<n;i+=2) sum+=data[i+1]-data[i];
	cout<<sum<<'\n';
	return 0;
}

#include<iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n,i,sum=0;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    for(i=0;i<n;i++)
    {
        sum=sum+a[i]-a[i+1];
        i++;
    }
    cout<<sum;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<int> v;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int in;
        cin>>in;
        v.push_back(in);
    }
    sort(v.begin(),v.end());
    int out;
    for(int i=0;i<n-1;i+=2)
    {
        out+=abs(v[i]-v[i+1]);
    }
    cout<<out;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vii;
typedef vector<string> vs;
typedef unordered_map<int, int> uii;
typedef unordered_map<char, int> uci;
typedef unordered_map<string, int> usi;

int skillsDeterminer(vi skills) {
    vector < pair<int, int> > studentTeams;
    for(int i = 0; i < skills.size(); i++) {
        int currentPerson = skills[i];
        int diff = 1000;
        int secondPerson = 0;
        for(int j = 0; j < skills.size(); j++) {
            if(j!=i && skills[j]!=-1 && skills[i]!= -1) {
                int newDiff = abs(skills[i]-skills[j]);
                if(newDiff < diff) {
                    diff = newDiff;
                    secondPerson = j;
                }
            }
        }
        studentTeams.push_back(make_pair(currentPerson,skills[secondPerson]));
        skills[i] = -1;
        skills[secondPerson] = -1;
    }
    int minQues = 0;
    for(int i = 0; i < studentTeams.size(); i++) {
        if(studentTeams[i].first == -1 && studentTeams[i].second == -1) {
            continue;
        }
        else {
            int diff = abs(studentTeams[i].first - studentTeams[i].second);
            minQues += diff;
        }
    }

    // for (int i = 0; i < studentTeams.size(); i++)
    // {
    //     cout<<studentTeams[i].first<<" : "<<studentTeams[i].second<<endl;
    // }
    return minQues;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //Insert your f**king code here
    int students;
    cin>>students;
    vi skills(students);
    for(int i = 0; i < students; i++) {
        cin>>skills[i];
    }
    int minSkills = skillsDeterminer(skills);
    cout<<minSkills;
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,sum=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    //bubblesort;
    for(int i=0;i<n-1;i++)
    {
        for(int j=i;j<n-i-1;j++)
        {
            int t;
            if(a[j]>=a[j+1])
            {
                t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
        }
    }
    for(int i=0;i<n;i+=2)
    {
        sum=sum+a[i+1]-a[i];
    }
    cout<<sum;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    int sum=0;
    vector<int>a(n);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        a.push_back(x);

    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;i+=2)
    {
        sum+=a[i+1]-a[i];
    }
    cout<<sum;
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,sum1=0,sum2=0,i,tem;
    cin>>n;
    int arr[n];
    for(i=0;i<n;i++){
        cin>>arr[i];
    }
    for(i=0;i<n;i=i+2){
        sum1=sum1+arr[i];
    }
    for(i=1;i<n;i=i+2){
        sum2=sum2+arr[i];
    }
    tem=(n/2)-1;
    if(sum1>sum2){
       cout<<(sum1-sum2)+tem<<endl;
    }else{
    cout<<(sum2-sum1)+tem<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,a,c=0;
    cin>>n;
    vector<int>v;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<=n-2;i++)
    {
        if(v[i]!=-1&&v[i]==v[i+1])
            {
                c++;
                v[i]=-1;
                v[i+1]=-1;
            }
    }
    if(c==n/2)
    {
        cout<<"0"<<endl;
        return 0;
    }
    int ans=0;
    for(int i=0;i<=n-2;i++)
    {
        if(v[i]!=-1&&v[i+1]!=-1)
        {
            ans+=abs(v[i+1]-v[i]);
            v[i]=-1;
            v[i+1]=-1;
        }
    }
cout<<ans<<endl;
return 0;
}

// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

#include<bits/stdc++.h>
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define memo(a,val) memset(a,val,sizeof(a))
#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

const int mxn = 110;
int a[mxn];
bool vis[mxn];

int32_t main(){
	NINJA;

	int n; cin >> n;
	for1(i,n) cin >> a[i];

	int cost = 0;

	for1(i,n){
		if(vis[i]) continue;
		int id = -1;
		int mn = inf;
		vis[i] = 1;
		for1(j,n){
			if(vis[j]) continue;
			if(mn > abs(a[i]-a[j])){
				mn = abs(a[i]-a[j]);
				id = j;
			}
		}
		// debug() << deb(mn) deb(id);
		vis[id] = 1;
		cost +=mn;
	}

	cout << cost << endl;

	return 0;
}

#include<bits/stdc++.h>
#define ll              long long
#define ull             unsigned long long
#define pb              push_back
#define fastread()      (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
    fastread();
    int t,n,k;
    while(t--){
        cin>>n>>k;
        char a[] = {"abcdefghijklmnopqrstuvwxyz"};
        int j = 0;
        for(int i=0; i<n; i++){
            cout<<a[j++];
            if(j == k){
                j = 0;
            }
        }cout<<endl;
    }

    return 0;
}

#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main ()
{
    int n;
    int value;
    int S=0;
    int minx =2147483647;
    cin>>n;
    vector<int>arr;
    for (int i =0 ;i<n ; i++)
    {
        cin>>value;
        arr.push_back(value);
    }
    int r;
    for (int i=0 ; i< arr.size() ;i++)
    {
        for (int j =i+1 ; j<arr.size(); j++)
        {
            //minx = min(minx,abs(arr[i]-arr[j]));
            if (minx > abs(arr[i] - arr[j]))
            {
                minx = abs(arr[i] - arr[j]);
                r = j;
            }
        }
        minx =2147483647;
        arr.erase(arr.begin() + r);
        S = S +abs(arr[i] - arr[r]);
    }
    cout<<S;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
    int n;  cin >> n;
    vector<int> v(n);
    vector<tuple<int, int, int>> d;
    for(int i = 0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end());
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            d.push_back(make_tuple(abs(v[j] - v[i]), i, j));
        }
    }
    sort(d.begin(), d.end());
    int fkd[10000];
    memset(fkd, 0, sizeof(fkd));
    int ans = 0;
    int k = 0;
    for(int i = 0; k < n/2; i++){
        if(!fkd[get<1>(d[i])] and !fkd[get<2>(d[i])]){
            ans += get<0>(d[i]);
            fkd[get<1>(d[i])] = 1;
            fkd[get<2>(d[i])] = 1;
            k++;
        }
    }

    cout << ans;
}

#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int m,n,i,j,k,sum;
int a[1000];
double pi[1000],f[100];
int main()
{
    freopen("input.txt","r",stdin);
    int n;
    scanf("%d",&n);
    for(i=1;n>=i;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=1,sum=0;n/2>=i;i++)
    {
        sum+=fabs(a[i]-a[n-i+1]);
    }
    printf("%d\n",sum);
    return 0;
}

#include<string.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int y[100000],z[2000000];
int main()
{
	int x;
	scanf("%d\n", &x);
	for (int i = 1; i <= x; i++)
    {
	scanf("%d", &y[i]);
	}
	sort(y, y + x + 1);
	for (int i = 1; i <= 2 * x; i++) {
		z[i] = y[i + 1] - y[i];
	}
	sort(z, z + 2 * x + 1); printf("%d\n", z[2 * x]);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int n,a[100];
void BS()
{
    for(int i=1;i<=n-1;i++)
        for(int j=i+1;j<=n;j++)
            if(a[j]<a[i]) swap(a[j],a[i]);
}

main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    BS();
    int dem=0;
    for(int i=1;i<=n;i++) cout<<a[i]<<" ";
    for(int i=1;i<=n;i+=2)
        dem+=abs(a[i]-a[i+1]);
    cout<<dem;
}

    #include <bits/stdc++.h>
    using namespace std;

    #define SZ size()
    #define MIN LLONG_MIN
    #define MAX LLONG_MAX
    #define M 1000000007
    #define MP make_pair
    #define F first
    #define S second
    #define endl "\n"

    #define pb push_back
    #define N 100005

    typedef long long  ll;
    typedef unsigned long long ull;

    typedef vector<int> vi;
    typedef vector< vi > vvi;
    typedef vector<ll> vll;
    typedef vector<string> vs;
    typedef pair<int, int> pii;
    typedef map<int, int> mii;
    typedef map<char, int> mci;
    typedef map<string, int> msi;

    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    	// code part
    	int n; cin >>n; int a[N];
    	for(int i =0; i <n; i++) cin >>a[i];
    	sort(a, a+n);int s;
    	for(int i =0; i <n; i+=2) s+=a[i+1] - a[i];
    	cout << s<<endl;
    	return 0;
    }

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()

{
    ll t , n ;
    cin>>t;
    while(t--)
    {
        cin>>n;
        vector<ll> arr(n,0);
        for(int i =0;i<n;i++)
        cin>>arr[i];
        ll ans = 0;
        sort(arr.begin(),arr.end());
        for(int i=1;i<n;i=i+2)
        {
            ans += arr[i]-arr[i-1];
        }
        cout<<ans<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int
main ()
{

    int n;
    cin >> n;

    vector < int > numbers;
    int v;
    for (int i = 0; i < n; i++)
    {
        cin >> v;
        numbers.push_back (v);
    }

    sort (numbers.begin (), numbers.end ());

    int sum = 0;
    int roznica = 0;

    for (int j = 0; j <= n; j += 2) {
        roznica = (numbers[j + 1] - numbers[j]);
        sum = sum + roznica;
    }

    cout << sum << " ";

    return 0;
}

#include<iostream>
#include<math.h>
using namespace std;
int main(){
    int n,dif,diff,p=1000,sum=0,m;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=0;i<n;i++){
        p=1000;
        m=0;
        for(int j=0;j<n;j++){
            if(i!=j && a[j]!=0){
                dif=a[i]-a[j];
                diff=abs(dif);
                //cout<<diff<<endl;
                if(diff<=p){
                    p=diff;
                    m=j;
                }
                //cout<<"m:"<<m<<endl;
            }
        }
        a[m]=0;
        a[i]=0;
        if(p==1000) p=0;
        //cout<<"p:"<<p<<endl;
        sum+=p;
    }
    cout<<sum;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n1 1000000
//#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
//fflush(stdout)
int main()
{
    //fast
ios_base::sync_with_stdio(false); cin.tie(NULL);
ll n;
cin>>n;
ll a[n1];
for(ll i=0;i<n;i++)
{
	cin>>a[i];
}
int ans=0;
for(int i=0;i<n;i++)
{
	//int n=a[i];
	for(int j=0;j<n;j++)
	{
		if(i!=j && a[i]==a[j])
		{
			a[i]=INT_MAX;
			a[j]=INT_MAX;
			break;
		}
	}
}
for(int i=0;i<n;i++)
{
	if(a[i]==INT_MAX)
	{
		continue;
	}
	int no=a[i];
	int index=0;
	int dif=INT_MAX;
	int k=i;
	for(int j=0;j<n;j++)
	{
		int c=abs(a[j]-no);
		if(j!=k &&  c<dif)
		{
			dif=c;
			index=j;
		}
	}
	a[i]=INT_MAX;
	a[index]=INT_MAX;
	//cout<<i<<" "<<index<<" "<<dif<<endl;
    ans+=dif;
}
cout<<ans<<endl;

return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int mas[3];
int main() {
    cin >> mas[0] >> mas[1] >> mas[2];
    sort(mas, mas + 3);
    cout << mas[2] - mas[0];
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    int count;
    for(auto it=v.begin();it<v.end();it=it+2)
    {
        count = count-(*it-*(it+1));
    }
    cout<<count;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {

	int n;
	scanf("%d", &n);
	vector<int> v;
	int cur;
	for(int i=0; i<n; i++) {
		scanf("%d", &cur);
		v.push_back(cur);
	}
	sort(v.begin(), v.end());
	ll s;
	for(int i=0; i<v.size()-1; i+=2) {
		s += (v[i+1] - v[i]);
	}
	cout << s;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		if(n%2==0) cout<<n/2<<endl;
		else cout<<(n-3)/2+1<<endl;
	}
	return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        vector<int> v(n,0);
        for(int i=0;i<n;i++)
        {
            cin >> v[i];
        }
        int sum=0;
        for(int i=0;i<n;i += 2)
        {
            sum += v[i+1] -v[i];
        }
        cout << sum << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#include<algorithm>
#include<functional>
using namespace std;
int n,a[100001];
long long s;
int main()
{
    cin>>n;
    s=0;
    for (int i=1;i<=n;i+=2)
    {
        cin>>a[i];
        sort(a+1,a+n+1);
        s+=abs(a[i]-a[i+1]);
    }
    cout<<s;
}

#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define st first
#define nd second
typedef long long ll;
using namespace std;
ll X,N,T;
map<ll,ll> M;
main()
{
	ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0);
	cin>>N;
	for(;N--;T+=X*(1-M[X]),M[X]=1) cin>>X;
	if(T%2) cout<<T-M.begin()->first;
	else cout<<T;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, teams, problems = 0;;
    cin >> n;
    vector<int> student(n);
    for(int i = 0; i < n; i++) {
        cin >> student[i];
    }
    sort(student.begin(), student.end());
    for(int i = 0; i < n; i = i + 2) {
        problems = student[i + 1] - student[i];
    }
    cout << problems;
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

	int x, y, sum = 0;
	vector <int> arr;

	cin >> x;

	while (x--) {

		cin >> y;
		arr.push_back(y);

	}

	sort(arr.begin(), arr.end(), greater<int>());

	for (int i = 0; i < arr.size(); i += 2) {

		cout << arr[i] << " " << arr[i + 1] << endl;

		sum += arr[i] - arr[i + 1];

	}

	cout << sum;

	return 0;
}