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.

import java.util.Arrays;
import java.util.Scanner;

public class TeamsForming
{
    public static void main( String args [] )
    {
        Scanner input = new Scanner( System.in );

        int numberOfStudents = input.nextInt();

        int skills [] = new int [ numberOfStudents ];

        int teamCounter = 0;

        for( int i = 0; i < numberOfStudents; i++ )
            skills [ i ] = input.nextInt();

        Arrays.sort( skills );

        for( int i = 0; i < numberOfStudents; i += 2 )
        {
            teamCounter += ( skills [ i + 1] - skills [ i ] );
        }

        System.out.println( teamCounter );
    }
}

import java.util.*;
public class teams
{
 public static void main(String args[])
 {
   Scanner sc=new Scanner(System.in);
   int n=sc.nextInt();int c=0;
   int a[]=new int[n];
   for(int i=0;i<n;i++)
     a[i]=sc.nextInt();
   Arrays.sort(a);
   for(int j=0;j<n-1;j=j+2)
   {
    c=c+(a[j+1]-a[j]);
   }
   System.out.println(c);
 }
}

import java.util.*;
public class CF {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in= new Scanner(System.in);
		int t=in.nextInt();
		in.nextLine();
		int[] arr=new int[t];
		for(int i=0;i<t;i++) {
			arr[i]=in.nextInt();
		}
		Arrays.sort(arr);
		int count=0;
		for(int i=1;i<arr.length;i+=2) {
			count+=arr[i]-arr[i-1];
		}
		System.out.println(count);
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class B1092 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            ar[i] = input.nextInt();
        }
        Arrays.sort(ar);
        int sum = 0;
        for (int i = 0; i < n-1; i = i+2) {
            sum = sum + (ar[i+1] - ar[i]);
        }
        System.out.println(sum);
    }
}

import java.util.Scanner;

public class teamsForming {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
int numOfTeams=0;
Scanner k=new Scanner(System.in);
numOfTeams=k.nextInt();
int a[]=new int[numOfTeams];
for(int i=0;i<numOfTeams;i++) {
	a[i]=k.nextInt();
}
if(numOfTeams==2) {
	if(a[0]>a[1]) {
		System.out.println(a[0]-a[1]);
	}else {
		System.out.println(a[1]-a[0]);
	}
}else {
sort(a,0,a.length-1);
  int sum=0;
 int i=0;
 int j=1;

 while(j<numOfTeams) {
	 sum+=a[j]-a[i];
	 i+=2;
	 j+=2;
 }
  System.out.println(sum);
	}}static int partition(int arr[], int low, int high)
    {
        int pivot = arr[high];
        int i = (low-1);
        for (int j=low; j<high; j++)
        {
             if (arr[j] <= pivot)
            {
                i++;

                int temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }

        int temp = arr[i+1];
        arr[i+1] = arr[high];
        arr[high] = temp;

        return i+1;
    }

    public static void sort(int arr[], int low, int high)
    {
        if (low < high)
        {
            int pi = partition(arr, low, high);

           sort(arr, low, pi-1);
            sort(arr, pi+1, high);
        }
    }
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
    // Complete the maximumSum function below.
    public static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    public static  int gcd(int a,int b){
        if(b==0)
            return a;
        int r=a%b;
        return gcd(b,r);
    }

    // private static final FastReader scanner = new FastReader();

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader scanner = new InputReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);
        int n=scanner.nextInt();
        int arr[]=new int[n];
        for(int t=0;t<n;t++){
          arr[t]=scanner.nextInt();
        }
        Arrays.sort(arr);
        int sum=0;
        for(int i=n-1;i>=0;i--){
            sum+=arr[i]-arr[i-1];
            i--;
        }
        w.println(sum);
        w.close();
    }
}

import java.util.*;
public class sol{
    public static void main(String args[]){
        int n;
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        int ar[]=new int[n];
        for(int i=0;i<n;i++){
            ar[i]=sc.nextInt();
        }
        Arrays.sort(ar);
        int cnt=0;
        for(int i=0;i<n-1;i=i+2){
            cnt=cnt+(ar[i+1]-ar[i]);
        }
        System.out.println(cnt);
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class test {
      public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for(int i =0;i<n;i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int sum = 0;
        for(int i = 0;i<(a.length - 1);i = i+2){
            sum += Math.abs(a[i] - a[i+1]);

        }
          System.out.println(sum);

    }
}

/*==============================================
Name        : Shadman Shariar                 ||
Email       : shadman.shariar@northsouth.edu  ||
University  : North South University (NSU)    ||
Facebook    : shadman.shahriar.007            ||
==============================================*/

import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner (System.in);

		int t = input.nextInt();

		int []  arr  = new int [t];

		for (int i = 0; i < t; i++) {

			arr[i] = input.nextInt();

		}

		int max =0 ;
		Arrays.sort(arr);
		for (int i = 1; i < arr.length; i+=2) {
			int sum = Math.abs(arr[i]-arr[i-1]);
			max+= sum;
		}

		System.out.println(max);
		input.close();

	}
}

import java.util.Arrays;
import java.util.Scanner;
public class team {
    public static void main(String[] args){
        Scanner input=new Scanner(System.in);
        int n=input.nextInt();
        int [] arr=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=input.nextInt();
        }
        Arrays.sort(arr);
        int sum=0;
        for(int i=0;i<n;i+=2){
            sum+=arr[i+1]-arr[i];
        }
        System.out.println(sum);
    }
}

import java.io.*;
import java.lang.*;
import java.util.*;

public class MyClass {
    public static void main(String args[]) throws IOException{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      int n = Integer.parseInt(br.readLine());

      String str[] = br.readLine().trim().split(" ");

      int arr[] = new int[n];
      for(int i=0; i<n; i++)
      {
          arr[i] = Integer.parseInt(str[i]);
      }
      Arrays.sort(arr);

      int total = 0;

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

      System.out.println(total);
    }
}///

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;

public class SortCommand {
    // This class should not be instantiated.
    public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    public static Random random = new Random();

    private SortCommand() { }

    // stably merge a[lo .. mid] with a[mid+1 ..hi] using aux[lo .. hi]
    private static void merge(Comparable[] a, Comparable[] aux, int lo, int mid, int hi) {
        // precondition: a[lo .. mid] and a[mid+1 .. hi] are sorted subarrays
        assert isSorted(a, lo, mid);
        assert isSorted(a, mid+1, hi);

        // copy to aux[]
        for (int k = lo; k <= hi; k++) {
            aux[k] = a[k];
        }

        // merge back to a[]
        int i = lo, j = mid+1;
        for (int k = lo; k <= hi; k++) {
            if      (i > mid)              a[k] = aux[j++];
            else if (j > hi)               a[k] = aux[i++];
            else if (less(aux[j], aux[i])) a[k] = aux[j++];
            else                           a[k] = aux[i++];
        }

        // postcondition: a[lo .. hi] is sorted
        assert isSorted(a, lo, hi);
    }

    // mergesort a[lo..hi] using auxiliary array aux[lo..hi]
    private static void sort(Comparable[] a, Comparable[] aux, int lo, int hi) {
        if (hi <= lo) return;
        int mid = lo + (hi - lo) / 2;
        sort(a, aux, lo, mid);
        sort(a, aux, mid + 1, hi);
        merge(a, aux, lo, mid, hi);
    }

    /**
     * Rearranges the array in ascending order, using the natural order.
     * @param a the array to be sorted
     */
    public static void sort(Comparable[] a) {
        Comparable[] aux = new Comparable[a.length];
        sort(a, aux, 0, a.length-1);
        assert isSorted(a);
    }

    /***************************************************************************
     *  Helper sorting function.
     ***************************************************************************/

    // is v < w ?
    private static boolean less(Comparable v, Comparable w) {
        return v.compareTo(w) < 0;
    }

    /***************************************************************************
     *  Check if array is sorted - useful for debugging.
     ***************************************************************************/
    private static boolean isSorted(Comparable[] a) {
        return isSorted(a, 0, a.length - 1);
    }

    private static boolean isSorted(Comparable[] a, int lo, int hi) {
        for (int i = lo + 1; i <= hi; i++)
            if (less(a[i], a[i-1])) return false;
        return true;
    }

    /***************************************************************************
     *  Index mergesort.
     ***************************************************************************/
    // stably merge a[lo .. mid] with a[mid+1 .. hi] using aux[lo .. hi]
    public static void merge(Comparable[] a, int[] index, int[] aux, int lo, int mid, int hi) {

        // copy to aux[]
        for (int k = lo; k <= hi; k++) {
            aux[k] = index[k];
        }

        // merge back to a[]
        int i = lo, j = mid+1;
        for (int k = lo; k <= hi; k++) {
            if      (i > mid)                    index[k] = aux[j++];
            else if (j > hi)                     index[k] = aux[i++];
            else if (less(a[aux[j]], a[aux[i]])) index[k] = aux[j++];
            else                                 index[k] = aux[i++];
        }
    }

    /**
     * Returns a permutation that gives the elements in the array in ascending order.
     * @param a the array
     * @return a permutation {@code p[]} such that {@code a[p[0]]}, {@code a[p[1]]},
     *    ..., {@code a[p[N-1]]} are in ascending order
     */
    public static int[] indexSort(Comparable[] a) {
        int n = a.length;
        int[] index = new int[n];
        for (int i = 0; i < n; i++)
            index[i] = i;

        int[] aux = new int[n];
        sort(a, index, aux, 0, n-1);
        return index;
    }

    // mergesort a[lo..hi] using auxiliary array aux[lo..hi]
    private static void sort(Comparable[] a, int[] index, int[] aux, int lo, int hi) {
        if (hi <= lo) return;
        int mid = lo + (hi - lo) / 2;
        sort(a, index, aux, lo, mid);
        sort(a, index, aux, mid + 1, hi);
        merge(a, index, aux, lo, mid, hi);
    }

    // print array to standard output
    private static void show(Comparable[] a) {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println("\n");
    }

    public static int readInt() throws IOException{
        return Integer.parseInt(in.readLine());
    }

    public static Integer[] getIntArrayRead() throws IOException{

        int n = Integer.parseInt(in.readLine());
        String[] nValuesString = in.readLine().split(" ");
        Integer[] nValuesInteger = new Integer[n];
        for (int i = 0; i < n; i++ ) {
            nValuesInteger[i] = Integer.parseInt(nValuesString[i]);
        }
        return nValuesInteger;

    }

    public static void numberCommands(Integer[]nValues) {
        int aSize = nValues.length;
        SortCommand.sort(nValues);
        //show(nValues);
        int result = 0;
        for (int i = 1; i < aSize ; i++) {
            result += nValues[i] - nValues[i-1];
            //System.out.println(result);
            i++;
        }

        System.out.println(String.format("%d", result));

    }
    public static Integer[] getRandomArrayInt() {

        int n = random.nextInt(10) + 1;
        //System.out.println("Размер массива "+ n);
        Integer[] result = new Integer[n];
        for(int i = 0; i < n; i++) {
            result[i] = random.nextInt(10) + 1;
        }
        return result;
    }

    public static void main(String[] args) throws IOException {
        /*
        for (int i = 0; i < 5; i++) {
            Integer[] nValues = getRandomArrayInt();
            show(nValues);
            Integer[] mValues = getRandomArrayInt();
            show(mValues);
            findTwoNumber(nValues, mValues);
        }
        */

        Integer[] nValues = getIntArrayRead();
        numberCommands(nValues);
        in.close();

    }
}

import java.util.Scanner;
import java.util.Arrays;

public class Main {
    static void Do(){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i = 0 ; i<n ; i++){
            a[i] = in.nextInt();
        }
        int sum = 0;
        Arrays.sort(a);
        for(int i = 0 ; i< n-1 ; i+=2 )

            if(a[i] < a[i+1]){
                sum += a[i+1]- a[i];

            }
        System.out.println(sum);

    }

    public static void main(String[] args) {
        Do();

    }
}

import java.io.*;
import java.lang.*;
import java.util.*;

public class MyClass {
    public static void main(String args[]) throws IOException{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      int n = Integer.parseInt(br.readLine());

      String str[] = br.readLine().trim().split(" ");

      int arr[] = new int[n];
      for(int i=0; i<n; i++)
      {
          arr[i] = Integer.parseInt(str[i]);
      }
      Arrays.sort(arr);

      int total = 0;

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

      System.out.println(total);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class TeamBuildingExample {

    public static void main(String[] args) throws IOException {
        // This is unsorted array
        List<Integer> array = new ArrayList<Integer>();
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        String[] input = in.readLine().split(" ");
        for (String str : input) {
            array.add(Integer.parseInt(str));
        }
        int min = 0;
        Collections.sort(array);
        for (int i = 0; i < n - 1; i += 2) {
            int j = i + 1;
            int val = array.get(j) - array.get(i);
            min += val;
        }
        System.out.println(min);
    }
}

import java.util.*;
public class hello
{
    public static void main(String[] args)
    {
        int n;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int sum = 0;
        int arr[] = new int[n];
        for(int i=0;i<n;i++)
        {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        for(int i=0;i<n;i++)
        {
            sum+=arr[i+1]-arr[i];
            i++;
        }
        System.out.println(sum);
    }
}

import java.util.*;
public class div573{
	public static void main(String sp[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> al = new ArrayList<>();
		for(int i=0;i<n;i++)
			al.add(sc.nextInt());
		Collections.sort(al);
		long ans=0;

		for(int i=1;i<n;i+=2){
			ans+=(al.get(i)-al.get(i-1));
		}
		System.out.println(ans);

	}
}

import java.util.Arrays;
import java.util.Scanner;

public class TeamsForming {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        int min = 0;
        for (int i = 0; i < n; i+=2)
        {
            min += arr[i+1]-arr[i];
        }
        System.out.println(min);
    }
}

import java.io.*;
import java.math.*;
import java.util.*;

public class practice {
	static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[100001]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
	public static void debug(int[][] arr) {
		int r = arr.length;
		int c = arr[0].length;
		int i,j;
		for(i=0;i<r;++i) {
			for(j=0;j<c;++j)  System.err.print(arr[i][j]+" ");
			System.err.println();
		}
	}
	public static void debug(long[][] arr) {
		int r = arr.length;
		int c = arr[0].length;
		int i,j;
		for(i=0;i<r;++i) {
			for(j=0;j<c;++j)  System.err.print(arr[i][j]+" ");
			System.err.println();
		}
	}
	public static void debug(int ...var) {
		for(int i:var)  System.err.print(i+" ");
		System.err.println();
	}
	public static void debug(String ...var) {
		for(String i:var)  System.err.print(i+" ");
		System.err.println();
	}
	public static void debug(double ...var) {
		for(double i:var)  System.err.print(i+" ");
		System.err.println();
	}

	public static void debug(long ...var) {
		for(long i:var)  System.err.print(i+" ");
		System.err.println();
	}

    public static void main(String args[]) throws Exception{
        Reader scan = new Reader();
        //be careful of readLine() length of string;
        //Scanner scan = new Scanner(System.in);
		//scan.useDelimiter("");  // for reading character by character

        int n =scan.nextInt();
        int[] skills = new int[n];
        for(int i=0;i<n;++i) {
            skills[i]=scan.nextInt();
        }
        Arrays.sort(skills);
        int ans=0;
        for(int i=0;i<n;i+=2) {
            ans+=skills[i+1]-skills[i];
        }
        System.out.println(ans);

        scan.close();

    }
}

import java.util.Arrays;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int i,t,n,k,r=0,d;

		t = sc.nextInt();
		int a[] = new int[t];

		for(i=0;i<t;i++)
			a[i] = sc.nextInt();

		Arrays.sort(a);

		for(k=1;k<t;k=k+2)
		{
			d = a[k]-a[k-1];
			r=r+d;
		}

		System.out.printf("%d\n",r);
	}
}

import java.io.*;
import java.util.*;

public class Main {
    static int inf = (int) 1e9 + 7;

    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0;i < n; i++){
        a[i] = nextInt();
        }
        Arrays.sort(a);
        int sum = 0;
        for (int i = 1;i < n; i+=2){
        sum += a[i] - a[i-1];
        }
        out.print(sum);
        out.close();
    }

    static BufferedReader br;
    static StringTokenizer st = new StringTokenizer("");
    static PrintWriter out;

    static String next() throws IOException {
        while (!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}

class pair implements Comparator<pair>{
    int p, id, a;
    pair(int x, int id, int velo) {
        this.p = x;
        this.id = id;
        this.a = velo;
    }

    pair() {}

    @Override
    public int compare(pair pair, pair t1) {
        return Integer.compare(pair.p, t1.p);
    }
}

class dsu {
    int p[];

    dsu (int n) {
        p = new int [n];
        for(int i = 0;i < n;i++)
       	 p[i] = i;
    }

    int get(int v) {
        int x = v;
        while(v != p[v])
        	v = p[v];
         while(x != v) {
            int t = p[x];
            p[x] = v;
            x = t;
        }

        return v;
    }

    void union(int a, int b) {
        p[get(a)] = get(b);
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class Teams {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), res = 0;
		int[] a = new int[n];
		for(int i = 0; i < n; i++) a[i] = scan.nextInt();
		Arrays.sort(a);
		for(int i = 0; i < n; i += 2) res += a[i+1] - a[i];
		System.out.println(res);
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class ProblemB {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();
		Arrays.sort(a);
		int sum = 0;
		for(int i = 0; i < n / 2; i++) {
			sum += (a[2 * i + 1] - a[2 * i]);
		}
		System.out.println(sum);
	}
}

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = s.nextInt();
        }
        Arrays.sort(nums);
        ArrayList<Integer> differences = new ArrayList<>();
        for (int i = 0; i < n; i+=2) {
            int difference = nums[i + 1] - nums[i];
            differences.add(difference);
        }
        Collections.sort(differences);
        int sum = 0;
        for (int i = 0; i < differences.size(); i++) {
            sum += differences.get(i);
        }
        System.out.print(sum);
    }
}

	import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Scanner {
		BufferedReader br;
		StringTokenizer st;
		Scanner()
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() throws IOException
		{
			while(st == null ||  !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		int nextInt() throws IOException
		{
			return Integer.parseInt(next());
		}

	public static void main(String[] args) throws IOException {

			Scanner sc = new Scanner();
			int n = sc.nextInt();
			int a[] = new int[n];
			for(int i=0;i<a.length;i++)
				a[i] = sc.nextInt();
			Arrays.sort(a);
			int result = 0;
			for(int i=1;i<a.length;i=i+2)
			{
				result += a[i] - a[i-1];
			}
			System.out.println(result);

		}

	}

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
int y;
        int x =scan.nextInt();
        int []arr = new int[x];
        y=x/2;
for(int i=0;i<x;i++)
        {
             y=scan.nextInt();
            arr[i]=y;
        }
Arrays.sort(arr);
for(int i=0;i<x/2;i++)
{

int temp = arr[i];
arr[i]=arr[x-1-i];
arr[x-1-i]=temp;

}

        int sum=0;
        for (int i=0;i<x;i++)

        {
            if(i>=x)
                break;
            sum+=arr[i]-arr[i+1];
            i++;

        }
        System.out.println(sum);

}}

import java.util.*;

public class A{

    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
           a[i]=s.nextInt();
        int sm=0;
        Arrays.sort(a);
        for(int i=0;i<n-1;i+=2)
           sm+=a[i+1]-a[i];
        System.out.println(sm);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FstScn sc = new FstScn();
        int t = sc.nextInt();
        int[] arr = new int[t];
        for (int i = 0; i < t; i++)
            arr[i] = sc.nextInt();
        int diff = 0;
        Arrays.sort(arr);
        for (int i = 0; i < t - 1; i += 2) {
            diff += arr[i + 1] - arr[i];
        }
        System.out.println(diff);
    }

    static class FstScn {
        BufferedReader br;
        StringTokenizer st;

        public FstScn() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        float nextFloat() {
            return Float.parseFloat(next());
        }
    }
}

import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class CodeChef
{

	public static void main(String[] args) throws IOException
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int arr[] = new int[n];
		for(int i=0; i<n; i++) arr[i]=scan.nextInt();
		Arrays.sort(arr);
		int sum=0;
		for(int i=1; i<n; i+=2)
			sum += arr[i]-arr[i-1];
		System.out.println(sum);
   	}
}

import java.util.*;
public class team{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		ArrayList<Integer> miArray = new ArrayList<Integer>();

		int temp = 0;
		for(int i=0; i<n; i++){
			temp = sc.nextInt();
			miArray.add(temp);
		}

		Collections.sort(miArray);

		int suma = 0;

		for(int z=0; z<(n-1); z+=2){
			suma+= miArray.get(z+1)-miArray.get(z);
		}

		System.out.println(suma);

	}
}

import java.util.Scanner;

public class Ejercicio_4 {

	public static void main(String[] args) {
		int[] arr;
		int numero, acumulador=0;
		Scanner scanner = new Scanner(System.in);
		numero = scanner.nextInt();
		arr = new int[numero];

		if(2<=arr.length&&arr.length<=100) {
			for(int i=0;i<arr.length;i++)
				arr[i]= scanner.nextInt();

			for(int i = 0;i<arr.length;i++) {
				for(int j = 0; j<arr.length-i-1;j++) {
					if(arr[j]>arr[j+1]) {
						int tmp = arr[j+1];
						arr[j+1] = arr[j];
						arr[j] =tmp;
					}
				}
			}

			for(int i=0;i<arr.length;i+=2) {
				if(arr[i+1]!=arr[i])
					acumulador+= arr[i+1]-arr[i];
			}
		}System.out.println(acumulador);
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class TeamsForming {

    public static void main(String[] args) {
      Scanner input=new Scanner(System.in);
      int n,sum=0;
      n=input.nextInt();
      int[]a=new int[n];
        for (int i = 0; i < n; i++) {
            a[i]=input.nextInt();
        }
        Arrays.sort(a);
        for (int i = 0; i < n-1; i=i+2) {
            sum=sum+(a[i+1]-a[i]);
        }
        System.out.println(sum);
    }

}

import java.util.Scanner;

public class HackerEarth {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		HackerEarth he = new HackerEarth();

       Scanner sc = new Scanner (System.in);

       int n = sc.nextInt();
       int A[] = new int [n];
       for (int i = 0 ; i < n ; i++) {

    	   A[i] = sc.nextInt();

       }
       he.sort(A,0,A.length - 1);

      // for (int i =0 ; i< n ;i++) {
    	//   System.out.println(A[i]);
     //  }
       int t = n / 2;
       int sum = 0 ;
       for (int i= 0 ; i < n ;i++) {
    	   if (A[i] < A[i+1]) {
    		  sum+= A[i+1] - A[i];
    	   i++;
    	   }
    	   else {
    		   sum+= A[i] - A[i+1];
    		   i++;
    	   }
       }
    	   System.out.println(sum);
	}
	void sort (int A[] , int l , int r) {
		if (l < r) {

			int m =  (l + r)/2;
			sort (A,l,m);
            sort(A,m+1,r);
            merge(A,l,m,r);

		}
	}
	void merge (int A[], int l , int m , int r) {
		int n1 = m - l + 1;
		int n2 = r - m;

		int L[] = new int [n1];
		int R[] = new int [n2];

		for (int i = 0 ; i < n1 ; i++)
			L[i] = A[l + i];
		for (int j = 0 ; j < n2 ;j++)
			R[j] = A[m + j + 1 ];

		int i = 0 , j = 0 , k = l;

		while (i < n1 && j < n2) {
			if (L[i]< R[j]) {
				A[k] = L[i];
				i++;
			}else {
				A[k] = R[j];
				j++;
			}
			k++;
		}
		while (i < n1) {
			 A[k] = L[i] ;
			i++;
			k++;
		}
		while (j < n2) {
			R[j] = A[k];
			j++;
			k++;
		}
	}

}

import java.util.*;
public class div573{
	public static void main(String sp[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> al = new ArrayList<>();
		for(int i=0;i<n;i++)
			al.add(sc.nextInt());
		Collections.sort(al);
		long ans=0;

		for(int i=1;i<n;i+=2){
			ans+=(al.get(i)-al.get(i-1));
		}
		System.out.println(ans);

	}
}

import java.util.*;
public class JavaApplication7 {
    public static void main(String[] args) {
       Scanner obj =new Scanner(System.in);
       int size = obj.nextInt();
       int [] arr= new int [size];
       for(int i=0; i<size;i++)
       arr[i]=obj.nextInt();
       int c=0;
       Arrays.sort(arr);
       for(int i=0 ; i<size;i+=2){
           if(arr[i]!=arr[i+1])
           c+=(arr[i+1]-arr[i]); }
       System.out.println(c);
    }}

import java.util.*;
public class Main
{public static void main(String[] args)
{
Scanner S=new Scanner(System.in);
int n=S.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
 a[i]=S.nextInt();
Arrays.sort(a);
int sum=0;
for(int i=0;i<n;i=i+2)
 sum=sum+(a[i+1]-a[i]);
System.out.println(sum);
}}

import java.util.Scanner;

public class coin {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       byte n = sc.nextByte();
       byte [] a = new byte[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextByte();
        }
        sort(a);
        int count = 0;
        for (int i = 0; i < a.length-1; i+=2) {
            count+=a[i]-a[i+1];
        }
        System.out.println(count);

    }

    public static void sort(byte[] a){
        for (int i = 0; i < a.length-1; i++) {
            for (int j = i+1; j < a.length; j++) {
                if(a[i]<a[j]){
                    byte temp = a[i];
                    a[i]=a[j];
                    a[j] = temp;
                }
            }
        }
    }
}

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;

public class B {
    InputStream is;
    PrintWriter out;
    String INPUT = "";

    void solve() {
        Scanner sc = new Scanner(System.in);
            int n =sc.nextInt();
            ArrayList<Integer>list = new ArrayList<>();
        int xx [] = new int [101];
            while (n-->0){
                int o =sc.nextInt();
                list.add(o);
                    xx[o]++;
            }
            for(int i =0;i<list.size();++i){
                    xx[list.get(i)] =   xx[list.get(i)]%2;

                    }
            long sum = 0,min=0,max=0;
            boolean test1= true,test2=true;
            for(int i =0;i<=100;++i){

                if(xx[i]!=0&&test1){
                    min = i;
                    test1 = false;
                    xx[i]=0;
                }
                if(xx[i]!=0&&test2){
                    max = i;
                    test2 = false;
                }
                if(!test1&&!test2){
                    sum+= (max-min);
                    test1 = true;
                    test2 = true;
                }

            }
        System.out.println(sum);
    }

    void run() throws Exception
    {
        is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        solve();
        out.flush();
        //tr(System.currentTimeMillis()-s+"ms");
    }

    public static void main(String[] args) throws Exception { new B().run(); }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
//    private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

//package learning;
import java.util.*;
public class Answer {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n;
		n=sc.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=sc.nextInt();
		Arrays.sort(arr);
		int ans=0;
		for(int i=1;i<n;i+=2) {
			ans+=Math.abs(arr[i]-arr[i-1]);
		}
		System.out.println(ans);
		sc.close();
	}
}

import java.util.*;
import java.io.*;

public class OptimalTeam{

	static class FastReader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long readLong(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int readInt(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double readDouble() throws IOException {return Double.parseDouble(next()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
        public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=readInt();}}
        public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=readLong();}}
        public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }
    }

	public static void main(String args[]){

		FastReader r = new FastReader();

		int i = r.readInt();
		int s = 0;
		int a[] =  new int[i];

		r.scanIntArr(a);
		Arrays.sort(a);
		for(int j=0;j<a.length;j+=2){
			s = s + (a[j+1]-a[j]);
		}
		System.out.println(s);
	}

}

import java.util.*;
import java.util.Scanner;

public class Hola {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in)  ;

        int x = in.nextInt();

        int arr[]=new int[x];
        for (int i = 0; i < x; i++) {
            arr[i]=in.nextInt();
        }
        Arrays.sort(arr);
       int sol=0;
        for (int i = 0; i <x; i+=2) {
            sol+=arr[i+1]-arr[i];
        }

        System.out.println(sol);

            }
        }

import java.util.Scanner;
import java.util.Stack;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] Arr = new int[n + 5];
        for(int i = 0 ; i < n ; i++){
            Arr[i] = input.nextInt();
        }
        Stack < Integer > s = new Stack < Integer >();
        s.push(0);
        s.push(n - 1);
        int temp;
        while(!s.empty()){
            int en = s.pop();
            int st = s.pop();
            int i = st, j = en - 1;
            while(i < j){
                if(Arr[i] >= Arr[en]) i++;
                else if(Arr[j] < Arr[en]) j--;
                else {
                    temp = Arr[i];
                    Arr[i] = Arr[j];
                    Arr[j] = temp;
                }
            }
            if(Arr[i] > Arr[en]){
                i++;
            }
            temp = Arr[en];
            Arr[en] = Arr[i];
            Arr[i] = temp;
            if(en - i > 1) {
                s.push(i + 1);
                s.push(en);
            }
            if(i - st >= 1) {
                s.push(st);
                s.push(i - 1);
            }
        }
        int ans = 0;
        for(int i = 0 ; i < n ; i += 2){
            ans += Arr[i] - Arr[i + 1];
        }
        System.out.println(ans);
    }
}

import java.io.*;
import java.util.*;

public class C {

    //static FastInput k = new FastInput("/home/rajkin/Desktop/input.txt");
    FastInput k = new FastInput(System.in);
    FastOutput z = new FastOutput();

    long [] L = new long[110];
    long [] R = new long[110];

    void merge(long [] y, int l, int m, int r){
    	int n1 = m-l+1;
    	int n2 = r-m;

    	for(int i = 0; i<n1; i++){
    		L[i] = y[l + i];
    	}

    	for(int j = 0; j<n2; j++){
    		R[j] = y[m + 1 + j];
    	}

    	int i = 0, j = 0, k = l;

    	while(i < n1 && j < n2){
    		if(L[i] <= R[j]){
    			y[k++] = L[i++];
    		}
    		else{
    			y[k++] = R[j++];
    		}
    	}

    	while(i < n1){
    		y[k++] = L[i++];
    	}

    	while(j < n2){
    		y[k++] = R[j++];
    	}
    }

    void mergeSort(long [] y, int l, int r){
    	if(l < r){
    		int m = (l + r) / 2;

    		mergeSort(y, l, m);
    		mergeSort(y, m+1, r);

    		merge(y, l, m, r);
    	}
    }

    void startAlgorithm(){
    	while(k.hasNext()){
    		int n = k.nextInt();
    		long [] y = new long[n];
    		for(int i = 0; i<n; i++){
    			y[i] = k.nextInt();
    		}

    		//Arrays.sort(y);
    		mergeSort(y, 0, y.length-1);

    		long summ = 0;
    		for(int i = 0; i<y.length - 1; i+=2){
    			summ += (y[i+1] - y[i]);
    		}

    		z.println(summ);
    	}

    	z.flush();
    	System.exit(0);
    }

    public static void main(String[] args) throws Exception {
    	new C().startAlgorithm();
    }

    class FastInput {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public FastInput(InputStream stream){
        	reader = new BufferedReader(new InputStreamReader(stream));
        }

	    public FastInput(String path){
	        try {
	        	reader = new BufferedReader(new FileReader(path));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	        tokenizer = null;
	    }

        public String next() {
            return nextToken();
        }

        public String nextLine() {
            try {
				return reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

            return null;
        }

        public boolean hasNext(){
            try {
                return reader.ready();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return false;
        }

        public String nextToken() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                String line = null;
                try {
                    line = reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (line == null) {
                    return null;
                }
                tokenizer = new StringTokenizer(line);
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.parseInt(nextToken());
        }

        public Long nextLong() {
            return Long.valueOf(nextToken());
        }
    }

    class FastOutput extends PrintWriter {
    	public FastOutput() {
            super(new BufferedOutputStream(System.out));
    	}
    }
}

//package com.baba;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
        int ans = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        Arrays.sort(arr);
        for (int i = 0; i < n; i += 2) {
            if (arr[i] != arr[i + 1]) {
                ans += arr[i + 1] - arr[i];
            }
        }
        System.out.println(ans);
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class CF2
{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int[]arr = new int[num];
        for (int i = 0; i < num; i++)
        {
            arr[i] = scanner.nextInt();
        }
        Arrays.sort(arr);
        int count = 0;
        for (int i = 0; i < num; i += 2)
        {
            count += arr[i + 1] - arr[i];
        }
        System.out.println(count);
    }
}

import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A1092 {

    public static void main(String[] args) throws IOException {

//        OutputStream outputStreamt = new FileOutputStream("output.txt");
//        InputStream inputStreamt = new FileInputStream("input.txt");
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
//        outputStreamt.close();
//        inputStreamt.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt();
            int arr[] = new int[k];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = in.nextInt();
            }

            for (int o = arr.length - 1; o >= 0; o--) {
                for (int i = 0; i < o; i++) {
                    if (arr[i] > arr[i + 1]) {
                        int t = arr[i];
                        arr[i] = arr[i + 1];
                        arr[i + 1] = t;
                    }
                }
            }
            int c = 0;
            for (int i = 0; i < arr.length - 1; i+=2) {
                c += arr[i + 1] - arr[i];
            }
            out.println(c);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public Long nextLong() {
            return Long.parseLong(next());
        }

    }
}

// 作者：杨成瑞先生
import java.io.*;
import java.util.*;

public class team {
	public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] teams = new int[n];

        StringTokenizer st = new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++) {
            teams[i] = Integer.parseInt(st.nextToken());
        }

        Arrays.sort(teams);

        //System.out.println(Arrays.toString(teams));

        int problems = 0;

        for(int i=1;i<n;i+=2) {
            problems += teams[i] - teams[i - 1];
        }

        System.out.println(problems);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

public class Cf1092B {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        List<Integer> list = new ArrayList<>(n);
        StringTokenizer stk = new StringTokenizer(br.readLine());
        for (int i = 0; i < n; i++) {
            list.add(Integer.parseInt(stk.nextToken()));
        }
        int counter = 0;
        Integer firstMax;
        Integer secondMax;
        while (!list.isEmpty()){
            firstMax = Collections.max(list);
            list.remove(firstMax);
            secondMax = Collections.max(list);
            list.remove(secondMax);
            counter += firstMax - secondMax;
        }
        System.out.println(counter);
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class TeamsForming {
    public static void main(String[]args) {
        Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n=s.nextInt();
        int[]array=new int[n];
        for(int i=0;i<n;i++)
            array[i]=s.nextInt();
        array=sort(array);
        int cnt=0;
        for(int i=0;i<array.length-1;i+=2){
            cnt+=array[i+1]-array[i];
        }
        System.out.print(cnt);

    }
    static int[]sort(int []array){
        for(int i=0;i<array.length-1;i++){
            for(int j=i+1;j<array.length;j++){
                if(array[j]<array[i])
                    array=swap(array,i,j);
            }
        }
        return array;
    }
    static int[]swap(int[]array,int i,int j){
        int temp=array[i];
        array[i]=array[j];
        array[j]=temp;
        return array;
    }
    }

import java.io.*;
import java.util.*;

public class B {

	public static void main(String[] args) throws IOException {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		Integer a[] = new Integer[n];
		for (int i = 0; i < n; i++)
			a[i] = scn.nextInt();
		Arrays.sort(a);
		int ans = 0;
		for (int i = 0; i + 1 < n; i++) {
			ans += a[i + 1] - a[i];
			i++;
		}
		System.out.println(ans);
	}

	static class Scanner {

		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}

import java.security.SecureRandom;
import java.sql.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int sum = 0;
        Arrays.sort(a);
        for (int i = 0; i < n - 1; i+=2) {
            sum += Math.abs(a[i] - a[i + 1]);

        }
        System.out.println(sum);

    }
}

import java.util.Scanner;

public class MyMain {

	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int arr[] = new int[n];

		int sum = 0;

		for(int i=0; i<n; i++)
		{
		    arr[i] = in.nextInt();
		}

		QuickSort(arr, 0, n-1);

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

		System.out.println(sum);

	}

	public static int partition(int arr[], int start, int end)
    {
        int pivot = arr[end];
        int j = (start-1);

        for (int i=start; i<end; i++)
        {
            if (arr[i] <= pivot)
            {
                j++;
                int temp = arr[j];
                arr[j] = arr[i];
                arr[i] = temp;
            }
        }

        int temp = arr[j+1];
        arr[j+1] = arr[end];
        arr[end] = temp;

        return j+1;
    }

    public static void QuickSort(int arr[], int start, int end)
    {
        if (start < end)
        {
            int j = partition(arr, start, end);

            QuickSort(arr, start, j-1);
            QuickSort(arr, j+1, end);
        }
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class Cards {

	public static void main(String args[]) {
		Scanner scn = new Scanner(System.in);
//		int t = scn.nextInt();
//		while (t-- > 0) {
//			int n = scn.nextInt();
//			String s = scn.next();
////		char[] c = s.toCharArray();
//
//			String out = "";
//			for (int i = 0; i < s.length(); i++) {
//				if (s.charAt(i) == 'z') {
//					out = out + "0 ";
//				} else if (s.charAt(i) == 'n') {
//					out = "1 " + out;
//				}
//			}
//			System.out.println(out);

//		System.out.println(freq.toString());
		int n = scn.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = scn.nextInt();
		}
		System.out.println(teamForming(arr));
		// }
	}

	public static int teamForming(int[] arr) {
		int team = arr.length / 2;
		/*
		 * if (team % 2 != 0) { return 0; }
		 */
		Arrays.sort(arr);
		int ans = 0;
		for (int i = 0; i < arr.length; i += 2) {
			ans += Math.abs(arr[i] - arr[i + 1]);
		}
		return ans;
	}

}

import java.util.Arrays;
import java.util.Scanner;

public class TeamsForming {

	public static void main(String [] args)
	{
		Scanner reader = new Scanner(System.in);
		int n = reader.nextInt();

		int [] a = new int[n];
		for(int i = 0; i < n; i++)
			a[i] = reader.nextInt();

		int sum = 0;
		Arrays.sort(a);
		for(int i = 0; i < n-1; i += 2)
			if(a[i] != a[i+1])
				sum += a[i+1] - a[i];
		System.out.println(sum);
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class TeamsForming {

    public static void main(String[] args) throws IOException {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        if(n % 2 == 0)
        {
            int[] studentSkills = new int[n];

            for (int i = 0; i < n; i++) {
                studentSkills[i] = input.nextInt();
            }

            Arrays.sort(studentSkills);
            int sum = 0;
            for (int i = 1; i <= studentSkills.length/2; i++) {
                sum += studentSkills[2*i-1] - studentSkills[2*i - 2];
            }
            System.out.println(sum);
        }
    }
}

import java.util.*;
import java.io.*;
import java.io.File;
import java.util.AbstractSet;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.math.*;
public class Hello {

  //static FastReader in = new FastReader(System.in);
  public static void main(String[] args) {
    //try {
    //  FileInputStream fis = new FileInputStream("data.txt");
    //  System.setIn(fis);
      Scanner in = new Scanner(System.in);
      // Scanner in = new Scanner(new File("input.txt"));
      // PrintWriter out = new PrintWriter("output.txt");

      int n = in.nextInt();

      int []a = new int[n];
      for (int i = 0;i < n;++i) {
	a[i] = in.nextInt();
      }
      Arrays.sort(a);
      int ans = 0;

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

      System.out.println(ans);
    //} catch (FileNotFoundException e){
    //  System.out.println("error");
    //}
  }
///////////////////////
}
class Graph {
  public static final int REMOVED_BIT = 0;

  protected int vertexCount;
  protected int edgeCount;

  private int[] firstOutbound;
  private int[] firstInbound;

  private Edge[] edges;
  private int[] nextInbound;
  private int[] nextOutbound;
  private int[] from;
  private int[] to;
  private long[] weight;
  private long[] capacity;
  private int[] reverseEdge;
  private int[] flags;

  public Graph(int vertexCount) {
    this(vertexCount, vertexCount);
  }

  public Graph(int vertexCount, int edgeCapacity) {
    this.vertexCount = vertexCount;
    firstOutbound = new int[vertexCount];
    Arrays.fill(firstOutbound, -1);

    from = new int[edgeCapacity];
    to = new int[edgeCapacity];
    nextOutbound = new int[edgeCapacity];
    flags = new int[edgeCapacity];
  }

  public int addEdge(int fromID, int toID, long weight, long capacity, int reverseEdge) {
    ensureEdgeCapacity(edgeCount + 1);
    if (firstOutbound[fromID] != -1)
      nextOutbound[edgeCount] = firstOutbound[fromID];
    else
      nextOutbound[edgeCount] = -1;
    firstOutbound[fromID] = edgeCount;
    if (firstInbound != null) {
      if (firstInbound[toID] != -1)
	nextInbound[edgeCount] = firstInbound[toID];
      else
	nextInbound[edgeCount] = -1;
      firstInbound[toID] = edgeCount;
    }
    this.from[edgeCount] = fromID;
    this.to[edgeCount] = toID;
    if (capacity != 0) {
      if (this.capacity == null)
	this.capacity = new long[from.length];
      this.capacity[edgeCount] = capacity;
    }
    if (weight != 0) {
      if (this.weight == null)
	this.weight = new long[from.length];
      this.weight[edgeCount] = weight;
    }
    if (reverseEdge != -1) {
      if (this.reverseEdge == null) {
	this.reverseEdge = new int[from.length];
	Arrays.fill(this.reverseEdge, 0, edgeCount, -1);
      }
      this.reverseEdge[edgeCount] = reverseEdge;
    }
    if (edges != null)
      edges[edgeCount] = createEdge(edgeCount);
    return edgeCount++;
  }

  protected final GraphEdge createEdge(int id) {
    return new GraphEdge(id);
  }

  public final int addFlowWeightedEdge(int from, int to, long weight, long capacity) {
    if (capacity == 0) {
      return addEdge(from, to, weight, 0, -1);
    } else {
      int lastEdgeCount = edgeCount;
      addEdge(to, from, -weight, 0, lastEdgeCount + entriesPerEdge());
      return addEdge(from, to, weight, capacity, lastEdgeCount);
    }
  }

  protected int entriesPerEdge() {
    return 1;
  }

  public final int addFlowEdge(int from, int to, long capacity) {
    return addFlowWeightedEdge(from, to, 0, capacity);
  }

  public final int vertexCount() {
    return vertexCount;
  }

  public final int firstOutbound(int vertex) {
    int id = firstOutbound[vertex];
    while (id != -1 && isRemoved(id))
      id = nextOutbound[id];
    return id;
  }

  public final int nextOutbound(int id) {
    id = nextOutbound[id];
    while (id != -1 && isRemoved(id))
      id = nextOutbound[id];
    return id;
  }

  public final int source(int id) {
    return from[id];
  }

  public final int destination(int id) {
    return to[id];
  }

  public final long weight(int id) {
    if (weight == null)
      return 0;
    return weight[id];
  }

  public final long capacity(int id) {
    if (capacity == null)
      return 0;
    return capacity[id];
  }

  public final long flow(int id) {
    if (reverseEdge == null)
      return 0;
    return capacity[reverseEdge[id]];
  }

  public final void pushFlow(int id, long flow) {
    if (flow == 0)
      return;
    if (flow > 0) {
      if (capacity(id) < flow)
	throw new IllegalArgumentException("Not enough capacity");
    } else {
      if (flow(id) < -flow)
	throw new IllegalArgumentException("Not enough capacity");
    }
    capacity[id] -= flow;
    capacity[reverseEdge[id]] += flow;
  }

  public final boolean flag(int id, int bit) {
    return (flags[id] >> bit & 1) != 0;
  }

  public final boolean isRemoved(int id) {
    return flag(id, REMOVED_BIT);
  }

  protected void ensureEdgeCapacity(int size) {
    if (from.length < size) {
      int newSize = Math.max(size, 2 * from.length);
      if (edges != null)
	edges = resize(edges, newSize);
      from = resize(from, newSize);
      to = resize(to, newSize);
      nextOutbound = resize(nextOutbound, newSize);
      if (nextInbound != null)
	nextInbound = resize(nextInbound, newSize);
      if (weight != null)
	weight = resize(weight, newSize);
      if (capacity != null)
	capacity = resize(capacity, newSize);
      if (reverseEdge != null)
	reverseEdge = resize(reverseEdge, newSize);
      flags = resize(flags, newSize);
    }
  }

  protected final int[] resize(int[] array, int size) {
    int[] newArray = new int[size];
    System.arraycopy(array, 0, newArray, 0, array.length);
    return newArray;
  }

  private long[] resize(long[] array, int size) {
    long[] newArray = new long[size];
    System.arraycopy(array, 0, newArray, 0, array.length);
    return newArray;
  }

  private Edge[] resize(Edge[] array, int size) {
    Edge[] newArray = new Edge[size];
    System.arraycopy(array, 0, newArray, 0, array.length);
    return newArray;
  }

  public final boolean isSparse() {
    return vertexCount == 0 || edgeCount * 20 / vertexCount <= vertexCount;
  }

  protected class GraphEdge implements Edge {
    protected int id;

    protected GraphEdge(int id) {
      this.id = id;
    }

  }

}

class MinCostFlow {
  private final Graph graph;
  private final int source;
  private final int destination;
  private final long[] phi;
  private final long[] dijkstraResult;
  private final int[] lastEdge;
  private final Heap heap;
  private final int vertexCount;
  private final int[] visited;
  private int visitIndex;

  public MinCostFlow(Graph graph, int source, int destination, boolean hasNegativeEdges) {
    this.graph = graph;
    this.source = source;
    this.destination = destination;
    vertexCount = graph.vertexCount();
    phi = new long[vertexCount];
    if (hasNegativeEdges)
      fordBellman();
    dijkstraResult = new long[vertexCount];
    lastEdge = new int[vertexCount];
    if (graph.isSparse()) {
      heap = new Heap(vertexCount, new IntComparator() {
	  public int compare(int first, int second) {
	  return IntegerUtils.longCompare(dijkstraResult[first], dijkstraResult[second]);
	  }
	  }, vertexCount);
      visited = null;
    } else {
      heap = null;
      visited = new int[vertexCount];
    }
  }

  private void fordBellman() {
    Arrays.fill(phi, Long.MAX_VALUE);
    phi[source] = 0;
    boolean[] inQueue = new boolean[vertexCount];
    int[] queue = new int[vertexCount + 1];
    queue[0] = source;
    inQueue[source] = true;
    int stepCount = 0;
    int head = 0;
    int end = 1;
    int maxSteps = 2 * vertexCount * vertexCount;
    while (head != end) {
      int vertex = queue[head++];
      if (head == queue.length)
	head = 0;
      inQueue[vertex] = false;
      int edgeID = graph.firstOutbound(vertex);
      while (edgeID != -1) {
	long total = phi[vertex] + graph.weight(edgeID);
	int destination = graph.destination(edgeID);
	if (graph.capacity(edgeID) != 0 && phi[destination] > total) {
	  phi[destination] = total;
	  if (!inQueue[destination]) {
	    queue[end++] = destination;
	    inQueue[destination] = true;
	    if (end == queue.length)
	      end = 0;
	  }
	}
	edgeID = graph.nextOutbound(edgeID);
      }
      if (++stepCount > maxSteps)
	throw new IllegalArgumentException("Graph contains negative cycle");
    }
  }

  class Heap {
    IntList list;
    int shift;
    int[] index;

    public Heap(int vertexCount, IntComparator intComparator, int vertexCount1) {
      list = new IntArrayList(vertexCount);
      index = new int[vertexCount1];
      Arrays.fill(index, -1);
    }

    public void add(int source) {
      index[source] = 0;
      list.add(source);
    }

    public boolean isEmpty() {
      return shift == list.size();
    }

    public int poll() {
      int result = list.get(shift++);
      index[result] = -1;
      return result;
    }

    public int getIndex(int next) {
      return index[next];
    }

    public void shiftUp(int index) {
    }

    public void clear() {
      list = new IntArrayList();
      shift = 0;
      Arrays.fill(index, -1);
    }
  }

  public Pair<Long, Long> minCostMaxFlow() {
    return minCostMaxFlow(Long.MAX_VALUE);
  }

  public Pair<Long, Long> minCostMaxFlow(long maxFlow) {
    long cost = 0;
    long flow = 0;
    while (maxFlow != 0) {
      if (graph.isSparse())
	dijkstraAlgorithm();
      else
	dijkstraAlgorithmFull();
      if (lastEdge[destination] == -1)
	return Pair.makePair(cost, flow);
      for (int i = 0; i < dijkstraResult.length; i++) {
	if (dijkstraResult[i] != Long.MAX_VALUE)
	  phi[i] += dijkstraResult[i];
      }
      int vertex = destination;
      long currentFlow = maxFlow;
      long currentCost = 0;
      while (vertex != source) {
	int edgeID = lastEdge[vertex];
	currentFlow = Math.min(currentFlow, graph.capacity(edgeID));
	currentCost += graph.weight(edgeID);
	vertex = graph.source(edgeID);
      }
      maxFlow -= currentFlow;
      cost += currentCost * currentFlow;
      flow += currentFlow;
      vertex = destination;
      while (vertex != source) {
	int edgeID = lastEdge[vertex];
	graph.pushFlow(edgeID, currentFlow);
	vertex = graph.source(edgeID);
      }
    }
    return Pair.makePair(cost, flow);
  }

  private void dijkstraAlgorithm() {
    Arrays.fill(dijkstraResult, Long.MAX_VALUE);
    Arrays.fill(lastEdge, -1);
    dijkstraResult[source] = 0;
    heap.clear();
    heap.add(source);
    while (!heap.isEmpty()) {
      int current = heap.poll();
      int edgeID = graph.firstOutbound(current);
      while (edgeID != -1) {
	if (graph.capacity(edgeID) != 0) {
	  int next = graph.destination(edgeID);
	  long total = graph.weight(edgeID) - phi[next] + phi[current] + dijkstraResult[current];
	  if (dijkstraResult[next] > total) {
	    dijkstraResult[next] = total;
	    if (heap.getIndex(next) == -1)
	      heap.add(next);
	    else
	      heap.shiftUp(heap.getIndex(next));
	    lastEdge[next] = edgeID;
	  }
	}
	edgeID = graph.nextOutbound(edgeID);
      }
    }
  }

  private void dijkstraAlgorithmFull() {
    visitIndex++;
    Arrays.fill(dijkstraResult, Long.MAX_VALUE);
    lastEdge[destination] = -1;
    dijkstraResult[source] = 0;
    for (int i = 0; i < vertexCount; i++) {
      int index = -1;
      long length = Long.MAX_VALUE;
      for (int j = 0; j < vertexCount; j++) {
	if (visited[j] != visitIndex && dijkstraResult[j] < length) {
	  length = dijkstraResult[j];
	  index = j;
	}
      }
      if (index == -1) {
	return;
      }
      visited[index] = visitIndex;
      int edgeID = graph.firstOutbound(index);
      while (edgeID != -1) {
	if (graph.capacity(edgeID) != 0) {
	  int next = graph.destination(edgeID);
	  if (visited[next] != visitIndex) {
	    long total = graph.weight(edgeID) - phi[next] + phi[index] + length;
	    if (dijkstraResult[next] > total) {
	      dijkstraResult[next] = total;
	      lastEdge[next] = edgeID;
	    }
	  }
	}
	edgeID = graph.nextOutbound(edgeID);
      }
    }
  }
}

class Pair<U, V> implements Comparable<Pair<U, V>> {
  public final U first;
  public final V second;

  public static<U, V> Pair<U, V> makePair(U first, V second) {
    return new Pair<U, V>(first, second);
  }

  private Pair(U first, V second) {
    this.first = first;
    this.second = second;
  }

  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Pair pair = (Pair) o;

    return !(first != null ? !first.equals(pair.first) : pair.first != null) && !(second != null ? !second.equals(pair.second) : pair.second != null);

  }

  public int hashCode() {
    int result = first != null ? first.hashCode() : 0;
    result = 31 * result + (second != null ? second.hashCode() : 0);
    return result;
  }

  public String toString() {
    return "(" + first + "," + second + ")";
  }

  public int compareTo(Pair<U, V> o) {
    int value = ((Comparable<U>)first).compareTo(o.first);
    if (value != 0)
      return value;
    return ((Comparable<V>)second).compareTo(o.second);
  }
}

abstract class IntCollection {
  public abstract IntIterator iterator();
  public abstract int size();
  public abstract void add(int value);

  public void addAll(IntCollection values) {
    for (IntIterator it = values.iterator(); it.isValid(); it.advance()) {
      add(it.value());
    }
  }

}

interface IntIterator {
  public int value() throws NoSuchElementException;
  /*
   * @throws NoSuchElementException only if iterator already invalid
   */
  public void advance() throws NoSuchElementException;
  public boolean isValid();
}

interface Edge {
}

abstract class IntList extends IntCollection implements Comparable<IntList> {

  public abstract int get(int index);

  public IntIterator iterator() {
    return new IntIterator() {
      private int size = size();
      private int index = 0;

      public int value() throws NoSuchElementException {
	if (!isValid())
	  throw new NoSuchElementException();
	return get(index);
      }

      public void advance() throws NoSuchElementException {
	if (!isValid())
	  throw new NoSuchElementException();
	index++;
      }

      public boolean isValid() {
	return index < size;
      }
    };
  }

  public int hashCode() {
    int hashCode = 1;
    for (IntIterator i = iterator(); i.isValid(); i.advance())
      hashCode = 31 * hashCode + i.value();
    return hashCode;
  }

  public boolean equals(Object obj) {
    if (!(obj instanceof IntList))
      return false;
    IntList list = (IntList)obj;
    if (list.size() != size())
      return false;
    IntIterator i = iterator();
    IntIterator j = list.iterator();
    while (i.isValid()) {
      if (i.value() != j.value())
	return false;
      i.advance();
      j.advance();
    }
    return true;
  }

  public int compareTo(IntList o) {
    IntIterator i = iterator();
    IntIterator j = o.iterator();
    while (true) {
      if (i.isValid()) {
	if (j.isValid()) {
	  if (i.value() != j.value()) {
	    if (i.value() < j.value())
	      return -1;
	    else
	      return 1;
	  }
	} else
	  return 1;
      } else {
	if (j.isValid())
	  return -1;
	else
	  return 0;
      }
      i.advance();
      j.advance();
    }
  }

}

class IntArrayList extends IntList {
  private int[] array;
  private int size;

  public IntArrayList() {
    this(10);
  }

  public IntArrayList(int capacity) {
    array = new int[capacity];
  }

  public IntArrayList(IntList list) {
    this(list.size());
    addAll(list);
  }

  public int get(int index) {
    if (index >= size)
      throw new IndexOutOfBoundsException();
    return array[index];
  }

  public int size() {
    return size;
  }

  public void add(int value) {
    ensureCapacity(size + 1);
    array[size++] = value;
  }

  public void ensureCapacity(int newCapacity) {
    if (newCapacity > array.length) {
      int[] newArray = new int[Math.max(newCapacity, array.length << 1)];
      System.arraycopy(array, 0, newArray, 0, size);
      array = newArray;
    }
  }

}

interface IntComparator {

}

class IntegerUtils {

  public static int longCompare(long a, long b) {
    if (a < b)
      return -1;
    if (a > b)
      return 1;
    return 0;
  }

}

import java.util.Scanner;

public class Teams_Forming {
    public static void main(String args[]) {
        Scanner reader = new Scanner(System.in);

        short n = reader.nextShort();
        short[] a = new short[n];
        for (int i = 0; i < n; i++)
            a[i] = reader.nextShort();

        reader.close();

        for (int i = 0; i < n; i++)
            for (int j = 0; j < n - i - 1; j++) {
                if (a[j] > a[j + 1]) {
                    short temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }

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

        System.out.print(counter);
    }
}

// 作者：杨成瑞先生
import java.io.*;
import java.util.*;

public class cf527b {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();

        int[] students = new int[n];
        for(int i=0;i<n;i++) {
            students[i] = sc.nextInt();
        }

        Arrays.sort(students);

        //System.out.println(Arrays.toString(students));

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

        System.out.println(ans);
	}

}

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Created by sbhowmik on 18/12/18
 */
public class TeamsForming {

    public static void main(String []args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int arr[] = new int[n];
        int i = 0;
        while ( i < n) {
            arr[i++] = scanner.nextInt();
        }
        Arrays.sort(arr);
        int sum = 0;
        for (i = 0; i < n-1; i++) {
            sum = sum + (arr[i+1] - arr[i]);
            i++;
        }
        System.out.println(sum);
    }
}

import java.util.*;
public class Main
{public static void main(String[] args)
{
Scanner S=new Scanner(System.in);
int n=S.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
 a[i]=S.nextInt();
Arrays.sort(a);
int sum=0;
for(int i=0;i<n;i=i+2)
 sum=sum+(a[i+1]-a[i]);
System.out.println(sum);
}}

import java.util.*;
import java.io.*;

public class Solution {

	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
        int n = scan.nextInt(),a[] = new int[n],minque = 0;

		for(int i=0;i<n;i++){
		    a[i] = scan.nextInt();
		}

		Arrays.sort(a);

		for(int i = 1;i < n;i += 2){
		    minque += (a[i]-a[i-1]);
		}
		System.out.println(minque);
		scan.close();
	}
}

import java.util.*;

public class A1{
  public static void main(String[] args){
    Scanner in=new Scanner(System.in);
    int N;
    N=in.nextInt();
    int[] a=new int[N];
    for(int i=0;i<N;i++){
      a[i]=in.nextInt();
    }
    Arrays.sort(a);
    int res=0;
    for(int i=0;i<N;i+=2){
      res+=a[i+1]-a[i];
    }
    System.out.println(res);
  }
}

import java.util.*;
import java.lang.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i=0;i<n;i++){
		    a[i]=sc.nextInt();
		}
		Arrays.sort(a);
		int ans=0;
		for(int i=1;i<n;i+=2){
		    ans = ans + a[i]-a[i-1];
		}
		System.out.println(ans);
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class B1092_TeamsForming {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] skills = new int[n];
        for (int i = 0; i < n; i++)
            skills[i] = scanner.nextInt();

        Arrays.sort(skills);
        int res = 0;
        for (int i = 0; i < n - 1; i += 2)
            res += skills[i + 1] - skills[i];
        System.out.println(res);
    }
}

import java.io.*;
import java.lang.*;
import java.util.*;

public class MyClass {
    public static void main(String args[]) throws IOException{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      int n = Integer.parseInt(br.readLine());

      String str[] = br.readLine().trim().split(" ");

      int arr[] = new int[n];
      for(int i=0; i<n; i++)
      {
          arr[i] = Integer.parseInt(str[i]);
      }
      Arrays.sort(arr);

      int total = 0;

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

      System.out.println(total);
    }
}

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = s.nextInt();
        }
        Arrays.sort(nums);
        ArrayList<Integer> differences = new ArrayList<>();
        for (int i = 0; i < n; i+=2) {
            int difference = nums[i + 1] - nums[i];
            differences.add(difference);
        }
        Collections.sort(differences);
        int sum = 0;
        for (int i = 0; i < differences.size(); i++) {
            sum += differences.get(i);
        }
        System.out.print(sum);
    }
}

import java.util.*;
public class C {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int all[] = new int[n];
		for(int i = 0 ; i<n; i++) {
			all[i] = sc.nextInt();
		}
		Arrays.sort(all);
		int res = 0;
	//	System.out.println(Arrays.toString(all));
		for(int i = 0 ; i<n; i++) {
			if(i%2==0)res+=all[i];
			else res-=all[i];
		//	System.out.println(res);
		}
		System.out.println(Math.abs(res));
	}
}

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in= new Scanner(System.in);
        int n= in.nextInt();
        int array[]= new int[n];
        for(int i=0;i<n;i++)
            array[i]=in.nextInt();
        Arrays.sort(array);
        int ans=0;
        for(int i=0;i<n-1;i+=2){

            ans+=(array[i+1]-array[i]);
        }
        System.out.println(ans);
    }
 }

import java.util.*;
public class teams
{
 public static void main(String args[])
 {
   Scanner sc=new Scanner(System.in);
   int n=sc.nextInt();int c=0;
   int a[]=new int[n];
   for(int i=0;i<n;i++)
     a[i]=sc.nextInt();
   Arrays.sort(a);
   for(int j=0;j<n-1;j=j+2)
   {
    c=c+(a[j+1]-a[j]);
   }
   System.out.println(c);
 }
}

import java.util.*;

public class Main {

	public static void main(String arg[]){

		int n;
		Scanner cin=new Scanner(System.in);
		n=cin.nextInt();

		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=cin.nextInt();
		}

		Arrays.sort(a);

		int sum=0;
		for(int i=0;i<n;i+=2){
			sum+=a[i+1]-a[i];
		}
		System.out.println(sum);
		//System.out.println("Hello wrld");
	}

}

// Coded by Vishal Mourya - The Legendary Coder
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.lang.*;

public class Main
{
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) throws java.lang.Exception {
		try {

		    FastReader sc = new FastReader();

		            long n = sc.nextLong();
		            ArrayList<Long> a = new ArrayList<>();

		            for( int i = 0 ; i < n ; i++ )
		                a.add( sc.nextLong() );

		           Collections.sort(a);
		           int sum = 0;
		           for( int i = 0 ; i < n ; i++ ) {
		               sum += Math.abs( a.get(i) - a.get(i+1) );
		               i++;
		           }

		           System.out.println(sum);

		   }  // End of try block

		catch( Exception e ) {
		    System.out.println( e.getMessage() );
		}

	} // End of main method
}

import java.util.Arrays;
import java.util.Scanner;

public class test {
      public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for(int i =0;i<n;i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int sum = 0;
        for(int i = 0;i<(a.length - 1);i = i+2){
            sum += Math.abs(a[i] - a[i+1]);

        }
          System.out.println(sum);

    }
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
import java.math.BigInteger;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     public static void main (String[] args) throws java.lang.Exception
     {
     	Scanner in =new Scanner(System.in);
		int t=1,i,j,l,n,m,k=0,p=0,h=0;
		String s="",st="";
		n=in.nextInt();
		int a[]=new int[n];
		for(j=0;j<n;j++)
		     a[j]=in.nextInt();
		Arrays.sort(a);
		for(j=0;j<n;j+=2)
		     p+=Math.abs(a[j+1]-a[j]);
		System.out.println(p);
	}
}

import java.util.*;
public class main
{
	public static void main(String[] args) {
		Scanner c = new Scanner(System.in);
		int n = c.nextInt();
		int[] arr = new int[n];
		int temp = 0;
		for(int i=0;i<n;i++)
		{
			arr[i] = c.nextInt();
		}
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(arr[i]>arr[j])
				{
					temp = arr[i];
					arr[i] = arr[j];
					arr[j] = temp;
				}
			}
		}
		int x=0;
		for(int i=0;i<n;i=i+2)
		{
				x = x + arr[i+1]-arr[i];
		}
		System.out.print(x);

	}
}

import java.util.*;
public class mohammad {
    public static void main(String[] args) {
        //HashMap<Integer, Integer>map = new HashMap<>();
        //ArrayList<Integer> list = new ArrayList<>();
        /* --------------->Mohammad Abohasan<--------------- */
        Scanner sc = new Scanner (System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int s = 0 ;
        for (int i = 0; i < n; i++)
            a[i] = sc.nextInt();
        Arrays.sort(a);
        for (int i = 0; i < n-1; i+=2)
            s += a[i+1] - a[i];
        System.out.println(s);
    }
}
/*
6
5 10 2 3 14 5
2
1 100
*/

import java.util.PriorityQueue;
import java.util.Scanner;

public final class TeamsForming {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());

        int[] a = new int[n];

        String[] aItems = scanner.nextLine().split(" ");
        scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

        for (int i = 0; i < n; i++) {
            int aItem = Integer.parseInt(aItems[i]);
            a[i] = aItem;
        }

        heapSort(n, a);

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

        System.out.println(count);

        scanner.close();
    }

    public static int[] heapSort(int size, int[] a) {
        PriorityQueue<Integer> heap = new PriorityQueue<>();
        for (int i = 0; i < size; i++) {
            heap.add(a[i]);
        }

        int index = 0;
        while (!heap.isEmpty()) {
            a[index++] = heap.poll();
        }
        return a;
    }
}

import java.util.*;

public class A{

    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
           a[i]=s.nextInt();
        int sm=0;
        Arrays.sort(a);
        for(int i=0;i<n-1;i+=2)
           sm+=a[i+1]-a[i];
        System.out.println(sm);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	static class FastReader
	{
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }
	}

	public static void main(String[] args) {

		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++)
			a[i] = sc.nextInt();

		Arrays.sort(a);
		int result =0;
		for(int i=1; i<n; i+=2) {
			result += a[i]-a[i-1];
		}
		System.out.println(result);

	}

}

import java.io.*;
import java.util.Arrays;

public class TeamsForming1092B {
    public static void main(String[] args) throws IOException {
        Reader reader = new Reader();
        int n = reader.nextInt();
        int[] skills = new int[n];
        for (int i = 0;i < n;i++)
            skills[i] = reader.nextInt();
        int tot = 0;

        Arrays.sort(skills);

        for (int i = 0; i < n; i+=2) {
            tot += skills[i+1]-skills[i];
        }
        System.out.println(tot);
    }
    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }
}

// https://codeforces.com/problemset/problem/1092/B

import java.util.Scanner;
import java.util.Arrays;

public class TeamsForming {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		scanner.nextLine();
		int students[] = new int[n];
		int ans = 0;

		for (int i = 0; i < n; i++) {
			students[i] = scanner.nextInt();
		}
		Arrays.sort(students);

		for (int i = 0; i < n; i += 2) {
			ans = ans + Math.abs(students[i] - students[i + 1]);

		}
		System.out.println(ans);

	}

}

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
int y;
        int x =scan.nextInt();
        int []arr = new int[x];
        y=x/2;
for(int i=0;i<x;i++)
        {
             y=scan.nextInt();
            arr[i]=y;
        }
Arrays.sort(arr);
for(int i=0;i<x/2;i++)
{

int temp = arr[i];
arr[i]=arr[x-1-i];
arr[x-1-i]=temp;

}

        int sum=0;
        for (int i=0;i<x;i++)

        {
            if(i>=x)
                break;
            sum+=arr[i]-arr[i+1];
            i++;

        }
        System.out.println(sum);

}}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class CF1092B {
    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int N = Integer.parseInt(in.readLine());
        int[] data = new int[N];
        StringTokenizer st = new StringTokenizer(in.readLine());
        for (int i = 0; i < N; ++i) {
            data[i] = Integer.parseInt(st.nextToken());
        }
        Arrays.sort(data);
        int ans = 0;
        for (int i = 1; i < N ; i+=2) {
            ans += data[i] - data[i-1];
        }
        sb.append(ans).append("\n");
        System.out.print(new String(sb));
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class CF1092B {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int[] students = new int[n];
        for (int i = 0; i < n; i++) {
            students[i] = in.nextInt();
        }
        System.out.println(solve(students));
    }

    public static int solve(int[] students) {
        Arrays.sort(students);
        int count = 0;
        for (int i = 0; i < students.length - 1; i += 2) {
            while (students[i] < students[i + 1]) {
                students[i]++;
                count++;
            }
        }
        return count;
    }
}

import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		int[] a = new int[t];
		for(int i=0; i<t; i++) a[i] = sc.nextInt();
		int ans = 0;
		Arrays.sort(a);
		for(int i=0; i<t-1; i+=2){
			ans += Math.abs(a[i]-a[i+1]);
		}
		System.out.println(ans);
	}
}

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();

        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }

        for(int i=1; i<n; i++) {
            int number = a[i];
            int j = -1;

            for(j=i-1; j>=0; j--) {
                if(a[j] > number) {
                    a[j+1] = a[j];
                }
                else {
                    a[j+1] = number;
                    break;
                }
            }

            if(j == -1) {
                a[0] = number;
            }
        }

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

        System.out.println(ans);
    }
}

//package com.baba;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
        int ans = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        Arrays.sort(arr);
        for (int i = 0; i < n; i += 2) {
            if (arr[i] != arr[i + 1]) {
                ans += arr[i + 1] - arr[i];
            }
        }
        System.out.println(ans);
    }
}

import java.util.*;

public class Miguel {
    static void process(Scanner ler) {
    }

    public static void main(String[] args) {
        Scanner ler = new Scanner(System.in);
	/*
	int t = ler.nextInt();
	ler.nextLine();
	while (t-- > 0) process(ler);
	*/
	int n = ler.nextInt(), ans = 0;
	int arr[] = new int[200];
	for (int i = 0; i < n; i++) arr[i] = ler.nextInt();
	Arrays.sort(arr, 0, n);

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

	System.out.println(ans);
    }
}

import java.util.*;
import java.io.*;

public class Main{
    static boolean[] vis;                       //line 74 and 91 hasElement ans pth_fnd
    static int MOD=1000000007;
    //
    static int[] ans;
    static int cnt;
    static long set1=0,set2=0;
    //
    public static void main(String[] args) throws IOException{
        // long sttm=System.currentTimeMillis();
        FastReader sc=new FastReader();
        OutputStream out=new BufferedOutputStream(System.out);
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        Arrays.sort(a);
        int sum=0;
        for(int i=0;i<n;i+=2){
            sum+=a[i+1]-a[i];
        }
        System.out.println(sum);
    }

    public static boolean dfsCycle(ArrayList<Integer>[] arrl,int[] vis,int st,int pr){
        vis[st]=1;
        int cupr=st;
        for(int elm:arrl[st]){
            if(vis[elm]==1 && elm!=pr){
                return true;
            }
            else if(vis[elm]==0 && dfsCycle(arrl, vis, elm, cupr)){
                return true;
            }
        }
        vis[st]=2;
        return false;
    }

    public static long pow(long n,long k){                 //n-pow(k)
        if(k==1){
            return n%MOD;
        }
        if(k==0){
            return 1;
        }
        long val=pow(n,k/2)%MOD;
        if(k%2==0)return ((val%MOD)*(val%MOD))%MOD;
        else return (((val*val)%MOD)*n)%MOD;
    }

    public static HashMap<Integer,Integer> lcm(int num){
        ArrayList<Integer> arrl=new ArrayList<Integer>();
        HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
        while(num%2==0){

            if(!map.containsKey(2)){
                arrl.add(2);
                map.put(2, 1);
            }
            else{
                map.put(2,map.get(2)+1);
            }
            num/=2;
        }
        for(int i=3;i*i<=num;i+=2){
            while(num%i==0){
                if(!map.containsKey(i)){
                    arrl.add(i);
                    map.put(i, 1);
                }
                else{
                    map.put(i,map.get(i)+1);
                }
                num/=i;
            }
        }
        if(num>2){
            if(!map.containsKey(num)){
                arrl.add(num);
                map.put(num, 1);
            }
            else{
                map.put(num,map.get(num)+1);
            }
        }
        return map;
    }

    static long m=998244353l;
    static long modInverse(long a,long m)
    {
        long m0 = m;
        long y = 0l, x = 1l;

        if (m == 1)
            return 0l;

        while (a > 1)
        {

            long q = a / m;

            long t = m;

            m = a % m;
            a = t;
            t = y;

            y = x - q * y;
            x = t;
        }
        if (x < 0)
            x += m0;

        return x;
    }

    public static int num_fact(int num){
        ArrayList<Integer> arr=new ArrayList<Integer>();
        int cnt=0;
        for(int i=1;i*i<=num;i++){
            if(num%i==0){
                if(i*i==num){
                    cnt+=1;
                }
                else{
                    cnt+=2;
                }
            }
        }
        return cnt;
    }

    public static void sort_inc(int[][] arr,int col){        //change dimention if req
        Arrays.sort(arr, new Comparator<int[]>() {
            public int compare(final int[] entry1,final int[] entry2) {
                if (entry1[col] > entry2[col])              //this is for inc
                    return 1;
                else if(entry1[col]==entry2[col])
                    return 0;
                else
                    return -1;
            }
        });
    }

    public static boolean prime(int n){
        for(int i=2;i*i<=n;i++){
            if(n%i==0){
                return false;
            }
        }
        return true;
    }

    static long gcd(long a, long b)
	{
	if (b == 0)
		return a;
	return gcd(b, a % b);
    }

    public static long lcmOfTwo(int a,int b){
        return a*b/gcd(a,b);
    }

}

class FastReader{
    BufferedReader br;
    StringTokenizer st;

    public FastReader(){
        br = new BufferedReader(new
                 InputStreamReader(System.in));
    }

    String next(){
        while (st == null || !st.hasMoreElements()){
            try{
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException  e){
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt(){
        return Integer.parseInt(next());
    }

    long nextLong(){
        return Long.parseLong(next());
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String nextLine(){
        String str = "";
        try{
            str = br.readLine();
        }
        catch (IOException e){
            e.printStackTrace();
        }
        return str;
    }
}

import java.lang.reflect.Array;
import java.util.*;
import java.lang.*;

public final class Solution {

    static Scanner in = new Scanner(System.in);

    static int min(int... a){
        int min = a[0];
        for (int x: a){
            if (x < min) min = x;
        }
        return min;
    }

    static int max(int... a){
        int max = a[0];
        for (int x: a){
            if (x > max) max = x;
        }
        return max;
    }

    static int gcd(int a, int b){
        int r;
        while (b != 0){
            r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

    static int[] calcZ(String s){
        int n = s.length();
        int[] z = new int[(int) n];
        int l = 0, r = 0;
        for (int i = 1; i < n; i++){
            if (r >= i) z[i] = min(z[i-l], r-i+1);
            while (z[i]+i < n && s.charAt(z[i]) == s.charAt(z[i]+i)) z[i]++;
            if (i + z[i] - 1 > r){
                l = i;
                r = i + z[i] - 1;
            }
        }
        return z;
    }

    static int in() { return in.nextInt(); }

    static void println(Object obj) { System.out.println(obj); }

    static void println() { System.out.println(); }

    static void print(String s) { System.out.print(s); }

    static String reverse(String s){
        StringBuilder r = new StringBuilder();
        int n = s.length();
        for (int i = 0; i < n; i++){
            r.append(s.charAt(n-i-1));
        }
        return r.toString();
    }

    static int abs(int a) { return Math.abs(a); }

    static void printf(String s, Object... args) { System.out.printf(s, args); }

    static void solve(){
        int n = in();
        int[] a = new int[n];
        for (int i = 0; i < n; i++){
            a[i] = in();
        }
        Arrays.sort(a);
        int ans = 0;
        for (int i = 1; i < n; i+=2){
            ans += abs(a[i]-a[i-1]);
        }
        println(ans);
    }

    public static void main(String[] args) {
        //int t = in.nextInt(); while (t-- > 0)
            solve();
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class TeamsForming {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        int min = 0;
        for (int i = 0; i < n/2; i++)
        {
            min += arr[i+1]-arr[i];
        }
        System.out.println(min);
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class TeamsForming {
// please be solved
	public static void main(String[] args) {
			Scanner in= new Scanner(System.in);
			int n=in.nextInt();
			int[] arr= new int[n];
			for(int i=0;i<arr.length;i++){
			arr[i]=in.nextInt();
			}
			Arrays.sort(arr);
			int max=0;
			for(int i=0;i<arr.length-1;i++){
				if((arr[i+1]-arr[i])>max){
					max=arr[i+1]-arr[i];
				}
			}
			System.out.println(max);

	}

}

import java.util.Scanner;

public class Abhi {

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int a[] = new int[n];

		int sum1 = 0;
		int sum2 = 0;

		for(int i = 0; i<n; i++) {
			a[i] = s.nextInt();

			if(i < n/2) {
				sum1 += a[i];
			}
			else {
				sum2 += a[i];
			}
		}

		System.out.println(Math.abs(sum2 - sum1));

	}
}

/*==============================================
Name        : Shadman Shariar                 ||
Email       : shadman.shariar@northsouth.edu  ||
University  : North South University (NSU)    ||
Facebook    : shadman.shahriar.007            ||
==============================================*/

import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner (System.in);

		int t = input.nextInt();

		int []  arr  = new int [t];

		for (int i = 0; i < t; i++) {

			arr[i] = input.nextInt();

		}

		int max =1 ;
		Arrays.sort(arr);
		for (int i = 1; i < arr.length; i++) {
			int sum = Math.abs(arr[i]-arr[i-1]);
			if (sum>max)max=sum;
		}

		System.out.println(max);
		input.close();

	}
}

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int n = console.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
          array[i] = console.nextInt();
        }
        Arrays.sort(array);
        int total = 0;
        for (int i = 0; i < n-1; i++) {
          total += array[i+1] - array[i];
        }
        System.out.println(total);
    }
}

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int n = console.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
          array[i] = console.nextInt();
        }
        Arrays.sort(array);
        int repeats = 0;
        for (int i = n/2; i < n - 1; i++) {
          if (array[i] == array[i+1]) {
            repeats++;
          }
        }
        int total = 0;
        for (int i = 0; i < n/2; i++) {
          total += array[n/2 - repeats] - array[i];
        }
        System.out.println(total);
    }
}

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int n = console.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
          array[i] = console.nextInt();
        }
        Arrays.sort(array);
        int total = 0;
        for (int i = 0; i < n/2; i++) {
          total += array[n/2] - array[i];
        }
        System.out.println(total);
    }
}

import java.io.*;
import java.util.*;

/*
Good, better, best. Never let it rest. 'Til your good is better and your better is best.
 */

public class Main {

    // SOLVER
    static void solve() {
        // INPUT OUTPUT
        InputReader in = new InputReader(System.in);
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        int testCase = 1;
        StringBuilder result = new StringBuilder();
        while (--testCase >= 0)
        /**************************************************************************/ {
            // SOLVE
            final int noOfStudents = in.nextInt();
            HashMap<Integer, Integer> skillCount = new HashMap<>();
            for (int i = 0; i < noOfStudents; i++) {
                int temp = in.nextInt();
                if (skillCount.containsKey(temp)){
                    skillCount.put(temp, skillCount.get(temp) + 1);
                }else {
                    skillCount.put(temp, 1);
                }
            }
            ArrayList<Integer> uniqueSkill = new ArrayList<>();
            for (Map.Entry<Integer, Integer> map :
                    skillCount.entrySet()) {
                if (map.getValue() % 2 == 1){
                    uniqueSkill.add(map.getKey());
                }
            }
            long minProblemToSolve = 0L;
            for (int i = 1; i < uniqueSkill.size(); i += 2) {
                minProblemToSolve += Math.abs(uniqueSkill.get(i) - uniqueSkill.get(i - 1));
            }
            result.append(minProblemToSolve);
            /*****************************************/
        }
        pw.println(result.toString().trim());
        // *************************************
        {
            pw.close();
        }
    }

    /**************************************************************************
     *************************************************************************/
    // DRIVER CODE
    public static void main(String[] args) {
        solve();
    }

    // FAST INPUT
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();

        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }

        for(int i=1; i<n; i++) {
            int number = a[i];
            int j = -1;

            for(j=i-1; j>=0; j--) {
                if(a[j] > number) {
                    a[j+1] = a[j];
                }
                else {
                    a[j+1] = number;
                    break;
                }
            }

            if(j == -1) {
                a[0] = number;
            }
        }

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

        System.out.println(ans);
    }
}

import java.util.*;
import java.lang.Math;
public class B1092 {

	public static void main(String[] args) {
		Scanner sh = new Scanner(System.in);
		int n=sh.nextInt();
		int[] freq= new int[101];
		int[] mainarr= new int[n];
		int[] newarr= new int[n];
		int sum=0, c=0;
		for(int i=0;i<n;i++) {
			 mainarr[i]=sh.nextInt();
			++freq[mainarr[i]];
		}
		for(int i=1;i<=100;i++) {
			if(freq[i]==1) {
				newarr[c]=i;
				c++;
			}
			if(freq[i]>2) {
				newarr[c]=i;
				c++;
			}
		}
		for(int i=0;i<newarr.length-1;i=i+2) {
			if(newarr[i]!=0)
				sum=sum+newarr[i+1]-newarr[i];
		}
		System.out.println(sum);

	}

}

import java.util.*;
import java.lang.Math;
public class B1092 {

	public static void main(String[] args) {
		Scanner sh = new Scanner(System.in);
		int n=sh.nextInt();
		int[] freq= new int[101];
		int[] mainarr= new int[n];
		int[] newarr= new int[n];
		int sum=0, c=0;
		for(int i=0;i<n;i++) {
			 mainarr[i]=sh.nextInt();
			++freq[mainarr[i]];
		}
		for(int i=1;i<=100;i++) {
			if(freq[i]==1) {
				newarr[c]=i;
				c++;
			}
			if(freq[i]>2) {
				newarr[c]=i;
				c++;
			}
		}
		for(int i=0;i<newarr.length-1;i=i+2) {
			if(newarr[i]!=0)
				sum=sum+newarr[i+1]-newarr[i];
		}
		System.out.println(Math.abs(sum));

	}

}

import java.io.*;
import java.util.*;

/*
Good, better, best. Never let it rest. 'Til your good is better and your better is best.
 */

public class Main {

    // SOLVER
    static void solve() {
        // INPUT OUTPUT
        InputReader in = new InputReader(System.in);
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        int testCase = 1;
        StringBuilder result = new StringBuilder();
        while (--testCase >= 0)
        /**************************************************************************/ {
            // SOLVE
            final int noOfStudents = in.nextInt();
            HashMap<Integer, Integer> skillCount = new HashMap<>();
            for (int i = 0; i < noOfStudents; i++) {
                int temp = in.nextInt();
                if (skillCount.containsKey(temp)){
                    skillCount.put(temp, skillCount.get(temp) + 1);
                }else {
                    skillCount.put(temp, 1);
                }
            }
            ArrayList<Integer> uniqueSkill = new ArrayList<>();
            for (Map.Entry<Integer, Integer> map :
                    skillCount.entrySet()) {
                if (map.getValue() % 2 == 1){
                    uniqueSkill.add(map.getKey());
                }
            }
            long minProblemToSolve = 0L;
            for (int i = 1; i < uniqueSkill.size(); i += 2) {
                minProblemToSolve += uniqueSkill.get(i) - uniqueSkill.get(i - 1);
            }
            result.append(minProblemToSolve);
            /*****************************************/
        }
        pw.println(result.toString().trim());
        // *************************************
        {
            pw.close();
        }
    }

    /**************************************************************************
     *************************************************************************/
    // DRIVER CODE
    public static void main(String[] args) {
        solve();
    }

    // FAST INPUT
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class B1092{
	   public static void main(String[] args) throws FileNotFoundException{

	    Scanner scan = new Scanner(System.in);
		int[] arr = new int[scan.nextInt()];
	    for(int i =0 ; i < arr.length; i ++) {
	    	arr[i] = scan.nextInt();
	    }
	    Arrays.sort(arr);
	    //System.out.println(Arrays.toString(arr));
	    ArrayList<Integer> ooga = new ArrayList<Integer>();
	    for(int i =0 ; i < arr.length-1; i ++) {
	    	ooga.add(Math.abs(arr[i] - arr[i + 1]));
	    }
	   // System.out.println(ooga);

	    Collections.sort(ooga);
	    System.out.println(ooga.get(ooga.size() -1));
    }

}

/*

There are 𝑛 students in a university. The number of students is even. The 𝑖-th student has programming skill equal to 𝑎𝑖.

The coach wants to form 𝑛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 𝑛2 teams (i.e. each pair of students should form a team). Your task is to find this number.

*/

import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class teamforming{

    public static class FastReader{

        BufferedReader br;
        StringTokenizer st;

        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next(){
            while(st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }
                catch(IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt(){
            return Integer.parseInt(next());
        }

    }

    /*

        Take each number and find the closest number to it.
        Maintain 2 variables - index (of closest element), diff.
        Output result += diff

    */

    public static void main(String[] args){
        int result = 0;
        FastReader fr = new FastReader();
        int n = fr.nextInt();
        int[] arr = new int[n];
        for(int a=0; a<n; a++){
            arr[a] = fr.nextInt();
        }
        for(int i=0; i<n-1; i++){
            if(arr[i] == Integer.MAX_VALUE){
                continue;
            }
            int index = i, diff = Integer.MAX_VALUE;
            for(int j=i+1; j<n; j++){
                int current_diff = arr[i] - arr[j];
                if(current_diff < 0){
                    current_diff = current_diff * -1;
                }
                if(current_diff < diff){
                    diff = current_diff;
                    index = j;
                }
            }
            result += diff;
            arr[index] = Integer.MAX_VALUE;
        }
        System.out.print(result);
    }
}

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;

public class B {
    InputStream is;
    PrintWriter out;
    String INPUT = "";

    void solve() {
        Scanner sc = new Scanner(System.in);
            int n =sc.nextInt();
            ArrayList<Integer>list = new ArrayList<>();
            while (n-->0){
                list.add(sc.nextInt());
            }
            long sum = 0;
            while (list.size()>0){
                int min =0,min1=0,l=0;
                for(int i =1;i<list.size();++i){
                    if(list.get(i)<list.get(l)){
                        l = i;
                    }
                }
                min = list.get(l);
                list.remove(l);
                for(int i =1;i<list.size();++i){
                    if(list.get(i)<list.get(l)){
                        l = i;
                    }
                }
                min1 = list.get(l);
                list.remove(l);
                sum+=(min1-min);
            }
        System.out.println(sum);
    }

    void run() throws Exception
    {
        is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        solve();
        out.flush();
        //tr(System.currentTimeMillis()-s+"ms");
    }

    public static void main(String[] args) throws Exception { new B().run(); }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
//    private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;

public class B {
    InputStream is;
    PrintWriter out;
    String INPUT = "";

    void solve() {
        Scanner sc = new Scanner(System.in);
            int n =sc.nextInt();
            ArrayList<Integer>list = new ArrayList<>();
            while (n-->0){
                list.add(sc.nextInt());
            }
            int sum = 0;
            while (list.size()>0){
                int min =0,min1=0,l=0;
                for(int i =1;i<list.size();++i){
                    if(list.get(i)<list.get(l)){
                        l = i;
                    }
                }
                min = list.get(l);
                list.remove(l);
                for(int i =1;i<list.size();++i){
                    if(list.get(i)<list.get(l)){
                        l = i;
                    }
                }
                min1 = list.get(l);
                list.remove(l);
                sum+=(min1-min);
            }
        System.out.println(sum);
    }

    void run() throws Exception
    {
        is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        solve();
        out.flush();
        //tr(System.currentTimeMillis()-s+"ms");
    }

    public static void main(String[] args) throws Exception { new B().run(); }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
//    private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

import java.util.*;
public class sol{
    public static void main(String args[]){
        int n;
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        int ar[]=new int[n];
        for(int i=0;i<n;i++){
            ar[i]=sc.nextInt();
        }
        Arrays.sort(ar);
        int cnt=0;
        for(int i=0;i<n-1;i=i+2){
            cnt=ar[i+1]-ar[i];
        }
        System.out.println(cnt);
    }
}

import java.util.*;
public class HelloWorld{

     public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i != j && a[i] == a[j]){
                    a[i] = 0;
                    a[j] = 0;
                }
            }
        }
        int min;
        int c = 0;
        for(int i = 0; i < n; i++){
            if(a[i] != 0){
                min = Integer.MAX_VALUE;
                int k = 0;
                for(int j = i+1; j < n; j++){
                    if(a[j] != 0 && min >= Math.abs(a[i]-a[j])){
                        min = Math.abs(a[i]-a[j]);
                        k = j;
                    }
                }
                c = c + min;
                a[i] = 0;
                a[k] = 0;
            }
        }
        System.out.println(c);
     }
}

import java.util.*;
public class HelloWorld{

     public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i != j && a[i] == a[j]){
                    a[i] = 0;
                    a[j] = 0;
                }
            }
        }
        int min;
        int c = 0;
        for(int i = 0; i < n; i++){
            if(a[i] != 0){
                min = Integer.MAX_VALUE;
                int k = 0;
                for(int j = i+1; j < n; j++){
                    if(a[j] != 0 && min > Math.abs(a[i]-a[j])){
                        min = Math.abs(a[i]-a[j]);
                        k = j;
                    }
                }
                c = c + min;
                a[i] = 0;
                a[k] = 0;
            }
        }
        System.out.println(c);
     }
}

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
int y;
        int x =scan.nextInt();
        int []arr = new int[x];
        y=x/2;
for(int i=0;i<x;i++)
        {
             y=scan.nextInt();
            arr[i]=y;
        }
Arrays.sort(arr);
int sum=0;
for (int i=0;i<x;i+=2)
{
    if (i>=x)
        break;
    sum+=(arr[i]*-1)+arr[i+1];
    i=i+2;

}
        System.out.println(sum);

}}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class B527 {
	public static void main(String [] args) {
		FastReader sc = new FastReader();

		int n=sc.nextInt();
		Map<Integer,Integer> map=new HashMap<>();
		for(int i=0;i<n;i++)
		{
			int num=sc.nextInt();
			if(map.containsKey(num))
			{
				int val=map.get(num);
				if(val%2==1)
					map.put(num,1);
				else
					map.put(num,0);
			}
			else
			{
				map.put(num,1);
			}
		}
		int res=0;
		int last=-1;
		//System.out.println(map);
		for(Map.Entry<Integer,Integer>e:map.entrySet())
		{
			int key=e.getKey();
			int val=e.getValue();
			if(last==-1){
				if(val==1) {
					last = key;
				}
			}
			else{
				if(val==1) {

					res += Math.abs(key - last);
					last = -1;
				}
			}

		}

			System.out.println(res);

	}
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

	}
}

import java.util.*;
public class Main{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int size=sc.nextInt();
		int arr[]=new int[size];
		for(int i=0;i<size;i++)
		{
			arr[i]=sc.nextInt();
		}

		int j=0;
		int sec=0,sum=0,index=-1;
		boolean check=false;
		for(int i=0;i<size-1;i++)
		{
			check=false;
			int min=999999;
			for(j=i+1;j<size;j++)
			{
				if(arr[i]!=-1 && arr[j]!=-1){
					if(Math.abs(arr[i]-arr[j]) < min)
						{min=Math.abs(arr[i]-arr[j]);
						sec=arr[j];index=j;}
					check=true;
				}
				//sum+=Math.abs(sec-arr[i]);

			}
			if(check)
				{sum+=Math.abs(sec-arr[i]);
				arr[index]=-1;}

		}
		System.out.println(sum);

	}
}

import java.util.*;
public class Main{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int size=sc.nextInt();
		int arr[]=new int[size];
		for(int i=0;i<size;i++)
		{
			arr[i]=sc.nextInt();
		}
		int j=0;
		int sec=0,sum=0;
		for(int i=0;i<size/2;i++)
		{
			int min=999999;
			for(j=i+1;j<size;j++)
			{
					if(Math.abs(arr[i]-arr[j]) < min)
						{min=Math.abs(arr[i]-arr[j]);
						sec=arr[j];}

			}
			sum+=Math.abs(sec-arr[i]);
		}
		System.out.println(sum);
	}
}

/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;

public class GFG {

   	public static void main (String[] args) throws Exception{
	   BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
	   int n=Integer.parseInt(bf.readLine());
	   String s[]=bf.readLine().trim().split("\\s+");
	   Integer a[]=new Integer[n];
	   for(int i=0;i<n;i++)
	     a[i]=Integer.parseInt(s[i]);

	   Arrays.sort(a,Collections.reverseOrder());
	   HashSet<Integer> set=new HashSet<>();
	   for(int i=0;i<n;i+=2){
	      set.add(a[i]);
	   }

	   int res=0;
	   for(int i=1;i<n;i+=2)
	   {
	       while(!set.contains(a[i]))
	       {
	           a[i]+=1;
	           res++;
	           //System.out.println(res);
	       }

	   }
	   System.out.println(res);
	}
}

import java.util.*;
public class CF {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in= new Scanner(System.in);
		int t=in.nextInt();
		in.nextLine();
		int[] arr=new int[t];
		for(int i=0;i<t;i++) {
			arr[i]=in.nextInt();
		}
		Arrays.sort(arr);
		int max=arr[t/2];
		int count=0;
		for(int j=0;j<t/2;j++) {
			count+=max-arr[j];
		}
		System.out.println(count);
	}
}

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.TreeSet;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Admin
 */

public class bars {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner s=new Scanner(System.in);

            int n=Integer.parseInt(s.nextLine());

            String []a=s.nextLine().split(" ");

            Arrays.sort(a);

        int diff=0;
            for(int i=0;i<n-1;i++)
            {
            diff+=Integer.parseInt(a[i+1])-Integer.parseInt(a[i]);
            i++;
            }
            System.out.println(diff);

       }

 static boolean aa(int a,int b,int c)
    {
        if((a+b)>c )
        {
        return true;
        }
        else
            return false;

    }

          }

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.TreeSet;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Admin
 */

public class bars {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner s=new Scanner(System.in);

            int n=Integer.parseInt(s.nextLine());

            String []a=s.nextLine().split(" ");

            Arrays.sort(a);

        int diff=0;
            for(int i=0;i<a.length;i+=2)
            {
            diff+=Integer.parseInt(a[i+1])-Integer.parseInt(a[i]);

            }
            System.out.println(diff);

       }

 static boolean aa(int a,int b,int c)
    {
        if((a+b)>c )
        {
        return true;
        }
        else
            return false;

    }

          }

import java.util.Scanner;

public class Main {

	 public static void main(String[] args) {
         Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int [] arr = new int[n];
		int i,j,temp=0;
		for(i=0;i<n;i++) {
			arr[i] = input.nextInt();
		}
		for(i=0;i<n;i++) {
			for(j=1;j<n;j++) {
				if(arr[j-1]>arr[j]) {
					temp = arr[j];
					arr[j] = arr[j-1];
					arr[j-1] = temp;
				}
			}
		}
		int counter=0;
		for(i=0;i<n-1;i=i+2) {
			counter+=Math.abs(arr[i] - arr[i+1]);
		}

     }
  }

import java.util.Scanner;
import java.util.Stack;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] Arr = new int[n + 5];
        for(int i = 0 ; i < n ; i++){
            Arr[i] = input.nextInt();
        }
        Stack < Integer > s = new Stack < Integer >();
        s.push(0);
        s.push(n - 1);
        int temp;
        while(!s.empty()){
            int en = s.pop();
            int st = s.pop();
            int i = st, j = en - 1;
            while(i < j){
                if(Arr[i] >= Arr[en]) i++;
                else if(Arr[j] < Arr[en]) j--;
                else {
                    temp = Arr[i];
                    Arr[i] = Arr[j];
                    Arr[j] = temp;
                }
            }
            if(Arr[i] > Arr[en]){
                i++;
            }
            temp = Arr[en];
            Arr[en] = Arr[i];
            Arr[i] = temp;
            if(en - i > 1) {
                s.push(i + 1);
                s.push(en);
            }
            if(i - st >= 1) {
                s.push(st);
                s.push(i - 1);
            }
        }
        int ans = 0;
        for(int i = 0 ; i < n ; i += 2){
            ans += Arr[i + 1] - Arr[i];
        }
        System.out.println(ans);
    }
}

import java.util.Arrays;

public class TeamBuildingExample {

    public static void main(String[] args) {
        // This is unsorted array
        Integer[] array = new Integer[]{5, 10, 2, 3, 14, 5};
        int min = 0;
        quickSort(array, 0, array.length - 1);
        for (int i = 0; i < array.length - 1; i += 2) {
            int j = i + 1;
            int val = array[j] - array[i];
            min += val;
        }
        System.out.println(min);
    }

    public static void quickSort(Integer[] arr, int low, int high) {
        //check for empty or null array
        if (arr == null || arr.length == 0) {
            return;
        }

        if (low >= high) {
            return;
        }

        //Get the pivot element from the middle of the list
        int middle = low + (high - low) / 2;
        int pivot = arr[middle];

        // make left < pivot and right > pivot
        int i = low, j = high;
        while (i <= j) {
            //Check until all values on left side array are lower than pivot
            while (arr[i] < pivot) {
                i++;
            }
            //Check until all values on left side array are greater than pivot
            while (arr[j] > pivot) {
                j--;
            }
            //Now compare values from both side of lists to see if they need swapping
            //After swapping move the iterator on both lists
            if (i <= j) {
                swap(arr, i, j);
                i++;
                j--;
            }
        }
        //Do same operation as above recursively to sort two sub arrays
        if (low < j) {
            quickSort(arr, low, j);
        }
        if (high > i) {
            quickSort(arr, i, high);
        }
    }

    public static void swap(Integer array[], int x, int y) {
        int temp = array[x];
        array[x] = array[y];
        array[y] = temp;
    }
}

import java.util.Arrays;

public class TeamBuildingExample {

    public static void main(String[] args) {
        // This is unsorted array
        Integer[] array = new Integer[]{5, 10, 2, 3, 14, 5};
        int min = 0;
        quickSort(array, 0, array.length - 1);
        for (int i = 0; i < array.length - 1; i += 2) {
            int j = i + 1;
            int val = array[j] - array[i];
            min += val;
        }
        System.out.println(Arrays.toString(array));
        System.out.println(min);
    }

    public static void quickSort(Integer[] arr, int low, int high) {
        //check for empty or null array
        if (arr == null || arr.length == 0) {
            return;
        }

        if (low >= high) {
            return;
        }

        //Get the pivot element from the middle of the list
        int middle = low + (high - low) / 2;
        int pivot = arr[middle];

        // make left < pivot and right > pivot
        int i = low, j = high;
        while (i <= j) {
            //Check until all values on left side array are lower than pivot
            while (arr[i] < pivot) {
                i++;
            }
            //Check until all values on left side array are greater than pivot
            while (arr[j] > pivot) {
                j--;
            }
            //Now compare values from both side of lists to see if they need swapping
            //After swapping move the iterator on both lists
            if (i <= j) {
                swap(arr, i, j);
                i++;
                j--;
            }
        }
        //Do same operation as above recursively to sort two sub arrays
        if (low < j) {
            quickSort(arr, low, j);
        }
        if (high > i) {
            quickSort(arr, i, high);
        }
    }

    public static void swap(Integer array[], int x, int y) {
        int temp = array[x];
        array[x] = array[y];
        array[y] = temp;
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner jin = new Scanner(System.in);

		int n = jin.nextInt();
		int arr[] = new int[n];

		for (int i = 0; i < n; ++i) {
			arr[i] = jin.nextInt();
		}

		boolean taken[] = new boolean[n];
		int total = 0;
		for (int i = 0; i < n; ++i) {
			if (taken[i])
				continue;
			int minAbs = Integer.MAX_VALUE;
			int min = -1;
			for (int j = 0; j < n; ++j) {
				if (i == j || taken[j])
					continue;
				else {
					if (Math.abs(arr[i] - arr[j]) < minAbs) {
						minAbs = Math.abs(arr[i] - arr[j]);
						min = j;
					}
				}
			}
			taken[min] = true;
			taken[i] = true;
			total += Math.abs(arr[i] - arr[min]);
		}

		System.out.println(total);
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int i,t,n,k,r=0,d;

		t = sc.nextInt();
		int a[] = new int[t];

		for(i=0;i<t;i++)
		{
			a[i] = sc.nextInt();

			Arrays.sort(a);

			for(k=1;k<t;k++)
			{
				d = a[k]-a[k-1];
				r=r+d;
			}

			System.out.printf("%d\n",r);
		}
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int i,t,n,k,r=0,d;

		t = sc.nextInt();
		int a[] = new int[t];

		for(i=0;i<t;i++)
			a[i] = sc.nextInt();

		Arrays.sort(a);

		for(k=1;k<t;k++)
		{
			d = a[k]-a[k-1];
			r=r+d;
		}

		System.out.printf("%d\n",r);
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int i,t,n,k,r=0,d;

		System.out.printf("\n");
		t = sc.nextInt();
		int a[] = new int[t];

		for(i=0;i<t;i++)
		{
			a[i] = sc.nextInt();

			Arrays.sort(a);

			for(k=1;k<t;k++)
			{
				d = a[k]-a[k-1];
				r=r+d;
			}

			System.out.printf("%d\n",r);
		}
	}
}

import java.util.*;
public class HelloWorld{

     public static void main(String []args){

     Scanner s=new Scanner(System.in);
     int n=s.nextInt();
      int arr[]=new int[n];
     for(int i=0;i<n;i++)
    arr[i]=s.nextInt();
    Arrays.sort(arr);
    for(int z=0;z<n;z++)
    System.out.println(arr[z]);
    int diff=0;
      for(int j=1;j<=n-1;j+=2)
      diff+=Math.abs(arr[j]-arr[j-1]);

    System.out.println(diff);
}
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner cv=new Scanner(System.in);
        int n=cv.nextInt();
        int arr[]=new int[n];
        int sum1=0,sum2=0;
        for (int i = 0; i < n ; i++) {
            arr[i]=cv.nextInt();
            if(i<n/2){
                sum1+=arr[i];
            }
            else
            {
                sum2+=arr[i];
            }
        }
        if(sum1>sum2){
            System.out.println(sum1-sum2);
        }else {
            System.out.println(sum2-sum1);
        }
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class aseel {
public static void main (String args []) {
	Scanner in = new Scanner(System.in);
	int [] arr =new int [in.nextInt()];
	for (int i=0; i<arr.length ;i ++) {
		arr[i]=in.nextInt();
	}
Arrays.sort(arr);
int c=0;
for (int i=0 ; i< arr.length-1 ; i++) {
	c+=(arr[i+1]-arr[i]);
}
System.out.println(c);
}
}

import java.util.Arrays;
import java.util.Scanner;

public class TeamsForming
{
    public static void main( String args [] )
    {
        Scanner input = new Scanner( System.in );

        int numberOfStudents = input.nextInt();

        int skills [] = new int [ numberOfStudents ];

        int teamCounter = 0;

        for( int i = 0; i < numberOfStudents; i++ )
            skills [ i ] = input.nextInt();

        Arrays.sort( skills );

        for( int i = 0; i < numberOfStudents - 1; i++ )
        {
            if ( skills [ i ] == skills [ i + 1 ] )
            {
                teamCounter ++;
            }
            else
            {
                teamCounter = skills [ i + 1 ] - skills [ i ];

                skills [ i ] = 0;

                skills [ i + 1 ] = 0;

                i++;
            }
        }

        System.out.println( teamCounter );
    }
}

import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		LinkedList<Integer> ll = new LinkedList<>();
		int n = in.nextInt();
		int ans = 0;
		for(int i=0 ; i<n ; i++) {
			ll.add(in.nextInt());
		}
		Collections.sort(ll);

		while(!ll.isEmpty()) {
			int x = ll.removeFirst();
			int y = ll.removeFirst();
			int z = y-x;
			if(z!=0) {
				ans += z;
			}else {
				ans++;
			}

		}

		System.out.println(ans);

	}

}

import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		LinkedList<Integer> ll = new LinkedList<>();
		int n = in.nextInt();
		int ans = 0;
		for(int i=0 ; i<n ; i++) {
			ll.add(in.nextInt());
		}
		Collections.sort(ll);
		System.out.println(ll);
		while(!ll.isEmpty()) {
			int x = ll.removeFirst();
			int y = ll.removeFirst();
			int z = y-x;
			if(z!=0) {
				ans += z;
			}else {
				ans++;
			}

		}

		System.out.println(ans);

	}

}

import java.util.*;
public class A{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int sum = 0;
        int[] ara = new int[n];

        for(int i = 0; i < n; i++){
            ara[i] = s.nextInt();

        }

        for(int j = 0, k = n-1; j<n/2; j++){
            sum+=Math.abs(ara[j]-ara[k--]);
        }

        System.out.println(sum);
    }
}

import java.util.*;
public class Solution{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int arr[]=new int[n];
        for(int i=0;i<n;i++)
        arr[i]=sc.nextInt();
        Arrays.sort(arr);
        int sum=0;
        for(int i=0;i<n;i=i+2){
            sum=sum+(arr[i+1]=arr[i]);
        }
        System.out.println(sum);
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class TeamForming {

	public static void main(String[] args) {
		Scanner scan= new Scanner(System.in);
		int n =scan.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++)
		{
			a[i]=scan.nextInt();
		}
		Arrays.sort(a);
		int max =a[0],min = 0;
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				min=Math.abs(a[i]-a[j]);
				if(min>max)
				{
					max=min;
					i++;
					break;
				}
			}
		}
		System.out.println(max);
	}

}

import sun.applet.Main;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * Created by jai on 18/12/18.
 */
public class p1092b {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> ar= new ArrayList<>();
        for (int i = 0; i < n; i++) {
            ar.add(sc.nextInt());
        }
        int ans = 0;
        for (int i = 0; i < n/2; i++) {
            Iterator<Integer> itr = ar.iterator();
            int min =  Integer.MAX_VALUE;
            int i1 = 0,i2 = 0;
            int e1 = 0, e2 = 0;
            while (itr.hasNext())
            {
                int t1 = itr.next();
                Iterator<Integer> itr2 = ar.iterator();
                i2 = 0;
                while (itr2.hasNext())
                {
                    int t2 = itr2.next();
                    if(i1 != i2)
                    {
                        if (Math.abs(t2 - t1) < min)
                        {
                            min = Math.abs(t2 - t1);
                            e1 = i1;
                            e2 = i2;

                        }
                    }
                    i2++;
                }
                i1++;
            }
            ans = ans + min;
            if(e1 > e2) {
                ar.remove(e1);
                ar.remove(e2);
            }
            else
            {
                ar.remove(e2);
                ar.remove(e1);
            }
        }
        System.out.println(ans);
    }
}

import java.util.Scanner;

/**
 * Created by jai on 15/12/18.
 */
public class p1093b {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int i = 0; i <t; i++) {
            String s = sc.next();
            StringBuffer sb = new StringBuffer(s);
            if(sb.reverse().toString().equals(s))
            {
                boolean poss = false;
                char ch = s.charAt(0);
                for (int j = 0; j < s.length(); j++) {
                    if(s.charAt(j) != ch)
                    {
                        poss = true;
                        break;
                    }
                }
                if(poss)
                    System.out.println(s.substring(1 , s.length()) + s.charAt(0));
                else
                    System.out.println(-1);
            }
            else
                System.out.println(s);
        }
    }
}

import java.util.*;
public class A
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=sc.nextInt();
        }
        int count=0;
        Arrays.sort(a);
        for(int i=0;i<n-1;i++)
        {
            count+=(a[i+1]-a[i]);
        }
        System.out.println(count);
    }
}

import java.util.Scanner;
import java.util.Arrays;
public class Sol
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
            int n=s.nextInt();
            int a[]=new int[101];
            int count=0;
            int sum=0;
            for(int j=1;j<=n;j++)
            a[j]=s.nextInt();
            Arrays.sort(a);
            for(int k=1;k<=n;k=k+2)
            {
                sum=a[k+1]-a[k];
                count=count+sum;
            }
            System.out.println(count);
    }
}

import java.util.Scanner;
import java.util.Arrays;
public class Sol
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
            int n=s.nextInt();
            int a[]=new int[101];
            int count=0;
            int sum=0;
			int temp=0;
            for(int j=1;j<=n;j++)
            a[j]=s.nextInt();
            for(int t=1;t<=n;t++){
				for(int q=t+1;q<=n;q++)
				{
					if(a[q]<a[t])
					{
						temp=a[t];
						a[t]=a[q];
						a[q]=temp;
					}
				}
			}
            for(int k=1;k<=n;k=k+2)
            {
                sum=a[k+1]-a[k];
                System.out.println(sum);
            }

    }
}

import java.util.Scanner;

public class TeamsForming {

	void merge(int a[],int l,int mid,int u) {
		int n1 = mid-l+1;
		int n2 = u-mid;

		int[] le = new int[n1];
		int[] ri = new int[n2];

		int i,j;
		i=0;
		j=0;

		for(i=0;i<n1;i++) {
			le[i]=a[l+i];
		}
		i=0;
		for(i=0;i<n2;i++) {
			ri[i]=a[mid+1+i];
		}
		i=0;
		j=0;
		int k=l;
		while(i<n1&&j<n2) {
			if(le[i]<ri[j]) {
				a[k]=le[i];
				i++;
			}else {
				a[k]=ri[j];
				j++;
			}
			k++;
		}

		while(i<n1) {
			a[k]=le[i];
			i++;
			k++;
		}

		while(j<n2) {
			a[k]=ri[j];
			j++;
			k++;
		}

	}

	void sort(int a[],int l,int u) {

		if(l<u) {
			int mid = l+u;
			mid=mid/2;

			sort(a,l,mid);
			sort(a,mid+1,u);

			merge(a,l,mid,u);

		}

	}

	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int i;
		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a[i]=in.nextInt();
		}

		TeamsForming ob = new TeamsForming();
		ob.sort(a, 0, a.length-1);
		int s=0;
		for(i=0;i<n-1;i=i+2) {
			int x= a[i];
			int y = a[i+1];
			System.out.println(x+" "+y);
			int d=y-x;
			s=s+d;
		}

		System.out.println(s);

	}

}

import java.util.Scanner;

public class coin {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       byte n = sc.nextByte();
       byte [] a = new byte[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextByte();
        }
        sort(a);
        int count = 0;
        for (int i = 0; i < a.length; i+=2) {
            count+=a[i]-a[i+1];
        }
        System.out.println(count);
    }

    public static void sort(byte[] a){
        for (int i = 0; i < a.length-1; i++) {
            for (int j = 0; j < a.length; j++) {
                if(a[i]>a[j]){
                    byte temp = a[i];
                    a[i]=a[j];
                    a[j] = temp;
                }
            }
        }
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class Problemset1092B {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        int count = 0;
        for(int i=0; i < n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        for(int i = 0; i<n-1; i++){
            count += a[i+1]-a[i];
        }
        System.out.println(count);
    }
}

import java.util.*;
public class team{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		ArrayList<Integer> miArray = new ArrayList<Integer>();

		int temp = 0;
		for(int i=0; i<n; i++){
			temp = sc.nextInt();
			miArray.add(temp);
		}

		Collections.sort(miArray);

		int suma = 0;

		for(int k=0; k<miArray.size(); k++){
			System.out.println(miArray.get(k));
		}

		for(int z=0; z<(n-1); z+=2){
			suma+= miArray.get(z+1)-miArray.get(z);
			System.out.println("Suma: " + suma);
		}

		System.out.println(suma);

	}
}

/**
 * @author okasha
 */
import java.util.*;

public class B1092 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), i, sum = 0;
        int[] arr = new int[109];
        for (i = 0; i < n; ++i) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        for (i = 1; i < n; ++i) {
            sum += (arr[i] - arr[i - 1]);
        }
        System.out.println(sum);
    }
}

import java.util.*;
import java.io.IOException;

public class Begin {
   static int[] Sort(int[] srt){
       int rem = 0;
      for (int j = 0; j<srt.length;j++) {
          for (int i = 0; i < srt.length - 1; i++) {
              if (srt[i] > srt[i + 1]) {
                  rem = srt[i];
                  srt[i] = srt[i + 1];
                  srt[i + 1] = rem;
              }

          }

      }
      return srt;
   }
    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] skills = new int[N];
        int sum = 0;
        for(int i = 0; i< N;i++){
            skills[i] = scan.nextInt();
        }
        skills = Sort(skills);
        for(int i =0; i<skills.length-1; i++){
            sum+= skills[i+1] - skills[i];
        }
        System.out.print(sum);

    }

}

import java.util.*;
import java.io.*;

public class OptimalTeam{

	public static void main(String args[]){

	}

}

import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int[] arr=new int[n];
        int sum1=0;
        int sum2=0;
        for (int i = 1; i <=n ; i++) {
            arr[i-1]=scan.nextInt();
            if (i<=(n/2)){
                sum1+=arr[i-1];
            }else {
                sum2+=arr[i-1];
            }
        }
        System.out.println(Math.abs(sum1-sum2));

    }
}

import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int[] arr=new int[n];
        int sum1=0;
        int sum2=0;
        for (int i = 0; i <n ; i++) {
            arr[i]=scan.nextInt();
            if (i<(n/2)){
                sum1+=arr[i];
            }else {
                sum2+=arr[i];
            }
        }
        System.out.println(Math.abs(sum1-sum2));

    }
}

 import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b[] = new int[a];
		for (int i = 0; i < a; i++) {
			b[i] = scan.nextInt();

		}

		Arrays.sort(b);
		int x=0;
		for (int i = 0; i < a-1 ; i++) {
			x=b[i+1]-b[i];
			i=i+2;
		}

		System.out.println(x);
	}

}

import java.util.*;

public class A{

    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
           a[i]=s.nextInt();
        int sm=0;
        Arrays.sort(a);
        for(int i=0;i<n-1;i++)
           sm+=a[i+1]-a[i];
        System.out.println(sm);
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class ProblemB {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();
		Arrays.sort(a);
		System.out.println(a[n / 2]);
	}
}

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int []a = new int[101];
		for(int i = 0; i < n; i++) {
			a[sc.nextInt()]++;
		}
		int cnt = 0;
		for(int i = 0; i < 101; i++) {
			if(a[i] > 1) {
				System.out.println(i);
				System.exit(0);
			}else if(a[i] == 0) {
				cnt++;
			}
		}
		System.out.println(101 - cnt);
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class ProblemB {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();
		Arrays.sort(a);
		System.out.println(a[n / 2 - 1]);
	}
}

import java.io.*;
import java.util.*;

public class CFB {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    private static final long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};
    private static final String yes = "Yes";
    private static final String no = "No";

    void solve() throws IOException {

    }
    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    long gcd(long a, long b) {
        while(a != 0 && b != 0) {
            long c = b;
            b = a % b;
            a = c;
        }
        return a + b;
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    private void formatPrint(double val) {
        outln(String.format("%.9f%n", val));
    }
    public CFB() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFB();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

import java.util.Scanner;
import java.util.Arrays;

public class Main {
    static void Do(){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i = 0 ; i<n ; i++){
            a[i] = in.nextInt();
        }
        Arrays.sort(a,0,n-1);
        int sum = 0 ;
        for(int i = 0 ; i< n -2; i=i+2 )

            if(a[i] < a[i+1]){
                sum = sum + a[i+1]- a[i];

            }
        System.out.println(sum);

    }

    public static void main(String[] args) {
        Do();

    }
}

import java.util.Scanner;
import java.util.Arrays;

public class Main {
    static void Do(){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i = 0 ; i<n ; i++){
            a[i] = in.nextInt();
        }
        Arrays.sort(a,0,n-1);
        int sum = 0 ;
        for(int i = 0 ; i< n -1 ; i++ )
            if(a[i] < a[i+1]){
                sum += a[i+1]- a[i];

            }
        System.out.println(sum);

    }

    public static void main(String[] args) {
        Do();

    }
}

import java.util.Scanner;
import java.util.Arrays;

public class Main {
    static void Do(){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i = 0 ; i<n ; i++){
            a[i] = in.nextInt();
        }
        Arrays.sort(a,0,n-1);
        int sum = 0 ;
        for(int i = 0 ; i< n-1 ; i+=2 )

            if(a[i] < a[i+1]){
                sum += a[i+1]- a[i];

            }
        System.out.println(sum);

    }

    public static void main(String[] args) {
        Do();

    }
}

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = s.nextInt();
        }
        Arrays.sort(nums);
        int problems = 0;
        ArrayList<Integer> differences = new ArrayList<>();
        for (int i = 0; i < n - 1; i++) {
            int difference = nums[i + 1] - nums[i];
            differences.add(difference);
        }
        Collections.sort(differences);
        System.out.print(differences.get(-1 + differences.size()));
    }
}

import java.util.*;
public final class Main
{
	private static int ARRAY_SIZE, count = 0;

	public static void main (String[] args)  {
	Scanner scanner = new Scanner(System.in);
	ARRAY_SIZE = scanner.nextInt();
	int[] array = new int[ARRAY_SIZE];
	for(int i = 0; i < ARRAY_SIZE; i++) {
		array[i] = scanner.nextInt();
	}
	Arrays.sort(array);

	for(int i = 0; i < ARRAY_SIZE -2; i+=2) {
		count += array[i+1] - array[i];
	}

	System.out.println(count);
	scanner.close();
	}

}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.*;
/**
 *
 * @author MANAV PATEL
 */
public class NewClass7
{
    public static void main(String[] args)
    {
        int n;
        Scanner sc = new Scanner(System.in);
        n= sc.nextInt();
        int arr[] = new int[n];
        for(int i=0; i<n; i++)
        {
            arr[i]=sc.nextInt();
        }
        Arrays.sort(arr);
        int k=0;
        //System.out.println(Arrays.toString(arr));
        for(int i=0; i<=n/2; i=i+2)
        {
            k=k+Math.abs(arr[i]-arr[i+1]);

        }
        System.out.println(k+arr[n-1]-arr[n-2]);
    }

}

import java.util.Arrays;
import java.util.Scanner;

public class Polycarp_Pocket {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        int[] value = new int[number];
        int[] max = new int[number];
        int pocket = 1;
        for (int i = 0; i < number; i++) {
            value[i]=sc.nextInt();
        }
        Arrays.sort(value);
        int j=0,maxc=0;
        for(int i=0;i<number-1;i++){
            if(value[i]==value[i+1]){
                pocket++;
                max[j]=pocket;
                j++;
            }
            else{
                pocket=1;
            }
        }
        for(int i=0;i<max.length;i++){
            if(max[i]>maxc){
                maxc=max[i];
            }
        }
        System.out.println(maxc);
    }
}