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

public class Mr_Mehaya_never_ends {
	public static void main(String[] args) throws Exception {
		BufferedReader Pr = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int count = 0, x, y = -1, egaba = 0;
		boolean t = false;

		int Addad = Integer.parseInt(Pr.readLine());
		int[] arr = new int[Addad];
		st = new StringTokenizer(Pr.readLine());
		for (int i = 0; i < Addad; i++) {
			arr[i] = Integer.parseInt(st.nextToken());
		}
		Arrays.sort(arr);
		for (int i = 0; i < arr.length - 1; i++) {
			if (arr[i] != arr[i + 1]) {
				x = arr[i + 1] - arr[i];
				// System.out.println(x);
				count++;
				if (y != -1 && x != y) {
					// System.out.println("d5l hna");
					egaba = -1;
					t = true;
					break;
				} else {
					y = x;
				}
			}
		}
		if (t)
			;
		else {
			if (y == -1)
				egaba = 0;
			else if (count == 0)
				egaba = 0;
			else if (count == 1)
				egaba = (y) % 2 != 0 ? y : (y) / 2;
			else if (count == 2)
				egaba = y;
			else
				egaba=-1;
		}
		System.out.println(egaba);
	}
}

import java.util.*;
import java.util.stream.IntStream;

import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode;

import java.io.*;

public class ProbA {

  private static StringTokenizer st;

    public static void nextLine(BufferedReader br) throws IOException
    {
        st = new StringTokenizer(br.readLine());
    }

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

    public static String next()
    {
        return st.nextToken();
    }

    public static long nextLong()
    {
        return Long.parseLong(st.nextToken());
    }

    public static double nextDouble()
    {
        return Double.parseDouble(st.nextToken());
    }

    void solve() throws IOException{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

         int t=1;
         // t=nextInt();
         PrintWriter out = new PrintWriter(System.out);
         while(t!=0){
             nextLine(br);
            int n=nextInt();
            // if(n==1){
            //     nextLine(br);
            //     int a=nextInt();
            //     a=-1;
            //     out.print(a);
            //     t--;
            //     break;
            // }
           HashSet<Integer> set=new HashSet<>();
           nextLine(br);
           for(int i=0;i<n;i++){
            set.add(nextInt());
           }
           int[] arr=new int[set.size()];
           Iterator it=set.iterator();
           int j=0;
           while(it.hasNext()){
            arr[j]=(int)it.next();
           // out.println(arr[j]);
            j++;
           }
           int sum=IntStream.of(arr).sum();
          // out.println(sum);
           double avg=(double)sum/arr.length;
         // out.println(avg);
           int avgc=sum/arr.length;
          // out.println(avgc);
           if(avg-avgc==0.0000000000000){
               HashSet<Integer> s=new HashSet<>();
               int c=0;
               for(int i=0;i<arr.length;i++){
                   if(avgc-arr[i]!=0){
                       s.add((int)Math.abs(avgc-arr[i]));
                   }
                   else{
                       c++;
                   }
               }
               if(s.size()==1||c==arr.length)
               {
                   if(s.size()==1){
                    Iterator it1=s.iterator();
                   out.println((int)it1.next());
                   }
                   else
                   out.println("0");

               }
               else{
                   out.print((checkdiff(arr)==0)? -1:checkdiff(arr));

               }
           }
           else{
             //  out.println("jii");
            out.print((checkdiff(arr)==0)? -1:checkdiff(arr));

           }

            t--;
         }

        out.close();
    }
    public int checkdiff(int[] arr){
        // Arrays.sort(arr);
        // HashSet<Integer> sd=new HashSet<>();
        // for(int i=arr.length-1;i>0;i--){
        //     sd.add(arr[i]-arr[i-1]);
        // }
        if(arr.length==2)
        return ((int)Math.abs(arr[0]-arr[1]));
        else
        return -1;
    }

    public static void main(String[] args) throws IOException {
        new Thread(null, new Runnable() {
            public void run() {
                try {
                    new ProbA().solve();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (StackOverflowError e) {
                    System.out.println("RTE");
                }
            }
        }, "1", 1 << 26).start();
    }

    }

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();
		List<Integer> l = new ArrayList<>();
		for(int i=0;i<n;i++){
		    int a = sc.nextInt();
		    if(!l.contains(a)){
		        l.add(a);
		    }
		}
		if(l.size()>3) System.out.println(-1);
		else if(l.size()==3){
		    Collections.sort(l);
		    if(l.get(2)-l.get(1)==l.get(1)-l.get(0)) System.out.println(l.get(1)-l.get(0));
		    else System.out.println(-1);
		}
		else if(l.size()==2){
		    Collections.sort(l);
		   int x = l.get(0);
		   int y = l.get(1);
		   if((x%2==0&&y%2==0)||(x%2==1&&y%2==1)) System.out.println(y - (x+y)/2);
		   else System.out.println(l.get(1)-l.get(0));
		}
		else{
		    System.out.println(0);
		}
	}
}

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

public class Makethemequal {
    static int removeDuplicates(int arr[], int n) {
        if (n == 0 || n == 1)
            return n;
        int[] temp = new int[n];

        int j = 0;
        for (int i = 0; i < n - 1; i++)
            if (arr[i] != arr[i + 1])
                temp[j++] = arr[i];

        temp[j++] = arr[n - 1];

        for (int i = 0; i < j; i++)
            arr[i] = temp[i];
        return j;
    }

    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();
        }
        if (n > 1) {
            Arrays.sort(arr);
            int res = -1;
            int len = removeDuplicates(arr, n);
            int diff = arr[1] - arr[0];
            if(len==1){
                res = 0;
            }
            else if (len == 3) {
                for (int i = 0; i < len - 1; i++) {
                    if (arr[i + 1] - arr[i] == diff) {
                        res = diff;
                    } else {
                        res = -1;
                        break;
                    }
                }
            } else if (len == 2) {
                if(diff % 2 == 0) {
                    res = diff / 2;
                }
                else
                    res = diff;
            } else
                res = -1;
            System.out.println(res);

        } else {
            System.out.println(0);
        }
    }
}

	/*package whatever //do not write package name here */
import java.io.*;
import java.util.*;
public final class Contest
{
	 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 IOException
    {
    	FastReader sc=new FastReader();
    	int n=sc.nextInt();
    	ArrayList<Integer> list=new ArrayList<Integer>();
    	for(int i=0;i<n;i++)
    	{
    		int input=sc.nextInt();
    		list.add(input);
    	}
    	ArrayList<Integer> nl=removeDuplicates(list);
    	Collections.sort(nl);
    	if(nl.size()>3)
    		System.out.println(-1);
    	else if(nl.size()==3)
    	{
    		int a=nl.get(1)-nl.get(0);int b=nl.get(2)-nl.get(1);
    		if(a==b)
    			System.out.println(a);
    		else
    			System.out.println(-1);
    	}
    	else if(nl.size()==2)
    	{
    		int a=nl.get(0);int b=nl.get(1);
    		if((b-a)%2!=0)
    			System.out.println(b-a);
    		else
    			System.out.println((b-a)/2);

    	}
    	else if(nl.size()==1)
    		System.out.print(0);
    }
    public static <T> ArrayList<T> removeDuplicates(ArrayList<T> list)
    {

        // Create a new ArrayList
        ArrayList<T> newList = new ArrayList<T>();

        // Traverse through the first list
        for (T element : list) {

            // If this element is not present in newList
            // then add it
            if (!newList.contains(element)) {

                newList.add(element);
            }
        }

        // return the new list
        return newList;
    }

}

import java.util.*;
public class make_them_equal
{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		Integer arr[]=new Integer[n];
		Set<Integer> set = new HashSet<>();
		for(int i=0;i<n;i++)
		{
			arr[i]=in.nextInt();
			set.add(arr[i]);
		}
		if(set.size()==1)
			System.out.println("0");
		else if(set.size()==2)
		{
			int diff[]=new int[2];
			int c=0;
			for(int i:set)
			{
				diff[c]=i;
				c++;
			}

			if((diff[1]-diff[0])%2==0)
				System.out.println(Math.abs(diff[1]-diff[0])/2);
			else
				System.out.println(Math.abs(diff[1]-diff[0]));
		}
		else
		{
			Arrays.sort(arr);
			boolean  bool=false;
			int diff=(arr[n-1]-arr[0])%2==0 ? (arr[n-1]-arr[0])/2:arr[n-1]-arr[0];
			for(int i=1;i<=arr.length-2;i++)
			{
				if(arr[i]!=arr[0])
				{
					if(arr[i]+diff!=arr[n-1] && arr[i]!=arr[n-1])
					{
						System.out.println("-1");
						bool=true;break;
					}
				}
			}
			if(bool==false)
				System.out.println(diff);
		}
	}
}

//Created by Aminul on 4/16/2019.

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

import static java.lang.Math.abs;

public class B {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        int ans = -1;
        for (int i = -1000; i <= 1000; i++) {
            int d = check(i, a);
            if (d != -1) {
                if (ans == -1) ans = d;
                else ans = Math.min(ans, d);
            }
        }
        pw.println(ans);
        pw.close();
    }

    static int check(int x, int a[]) {
        HashSet<Integer> set = new HashSet<>();
        for (int i : a) {
            if (i == x) continue;
            set.add(abs(x - i));
        }
        if (set.size() > 1) return -1;
        for (int i : set) return i;
        return 0;
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}

import java.util.*;
public class make_them_equal
{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		Integer arr[]=new Integer[n];
		Set<Integer> set = new HashSet<>();
		for(int i=0;i<n;i++)
		{
			arr[i]=in.nextInt();
			set.add(arr[i]);
		}
		if(set.size()==1)
			System.out.println("0");
		else if(set.size()==2)
		{
			int diff[]=new int[2];
			int c=0;
			for(int i:set)
			{
				diff[c]=i;
				c++;
			}

			if((diff[1]-diff[0])%2==0)
				System.out.println(Math.abs(diff[1]-diff[0])/2);
			else
				System.out.println(Math.abs(diff[1]-diff[0]));
		}
		else
		{
			Arrays.sort(arr);
			boolean  b=false;
			int diff=(arr[n-1]-arr[0])%2==0 ? (arr[n-1]-arr[0])/2:arr[n-1]-arr[0];
			for(int i=1;i<=arr.length-2;i++)
			{
				if(arr[i]!=arr[0])
				{
					if(arr[i]+diff!=arr[n-1] && arr[i]!=arr[n-1])
					{
						System.out.println("-1");
						b=true;break;
					}
				}
			}
			if(b==false)
				System.out.println(diff);
		}
	}
}

import java.util.*;
import java.io.*;
public class codeforce{
    public static void main(String args[])throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        String str[]=br.readLine().split(" ");
        int arr[]=new int[n];
        for(int i=0;i<n;i++)
        arr[i]=Integer.parseInt(str[i]);
        boolean same=true;
        for(int i=1;i<n;i++)
        {
            if(arr[i]!=arr[0])
            {
                same=false;
                break;
            }
        }
        if(same)
        pw.println(0);
        else
        {
            int ans=-1;
            outer:for(int j=1;j<=200;j++)
            {
                TreeMap<Integer,Integer> tmap=new TreeMap<>();
                for(int i=0;i<n;i++)
                {
                    tmap.put(arr[i],tmap.getOrDefault(arr[i],0)+1);
                    tmap.put(arr[i]-j,tmap.getOrDefault(arr[i]-j,0)+1);
                    tmap.put(arr[i]+j,tmap.getOrDefault(arr[i]+j,0)+1);
                }

                for(Map.Entry<Integer,Integer> me:tmap.entrySet())
                {
                   if(me.getValue()>=n)
                   {
                       ans=j;
                       break outer;
                   }
                }
            }
            pw.println(ans);
        }
        pw.flush();
        pw.close();
    }
}

import java.util.*;

public class lottery {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int len = scan.nextInt();
        TreeSet<Integer> set = new TreeSet<>();
        for(int i = 0; i<len; i++){
            set.add(scan.nextInt());
        }
        if(set.size() == 1) System.out.println(0);
        else if(set.size() == 2) {
            float avg = (float)(set.last()-set.first())/2;
            if( avg%1 == 0) System.out.println((int)avg);
            else System.out.println(set.last()-set.first());
        }
        else if(set.size() == 3){
            int first = set.pollFirst();
            int last = set.last();
            float avg = (float)(first+last)/2;
            //System.out.println(set.first());
            if(set.first() == avg) System.out.println(set.first()-first);
            else System.out.println(-1);
        }
        else System.out.println(-1);

    }
}

import java.util.*;
import java.io.*;
public class house
{
	public static void main(String args[]) throws IOException
	{
		try{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=0;
		n=Integer.parseInt(br.readLine());
		String arr[]=br.readLine().split(" ");
		int brr[]=new int[n];
		int sum=0;
		HashSet<Integer> map=new HashSet<Integer>();
		for(int i=0;i<n;i++)
		{
		brr[i]=Integer.parseInt(arr[i]);
		map.add(brr[i]);
		}
		ArrayList<Integer> v=new ArrayList<Integer>(map);
		Collections.sort(v);
		if(v.size()<=3)
		{
			if(v.size()==3)
			{
				if(Math.abs(v.get(1)-v.get(0))==Math.abs(v.get(1)-v.get(2)))
				{
					System.out.println(Math.abs(v.get(1)-v.get(0)));
				}
				else
				{
					System.out.println("-1");
				}
			}
			else if(v.size()==2)
			{
				int sum2=0;
				sum2=Math.abs(v.get(0)-v.get(1));
				if(sum2%2!=0)
				{
					System.out.println(sum2);
				}
				else
				{
					System.out.println(sum2/2);
				}
			}
			else if(v.size()==1)
			{
				System.out.println("0");
			}
		}
		else
		{
			System.out.println("-1");
		}
		}
	catch(Exception e){}
}}

import java.util.*;

/**
 * taskB
 */

public class taskB {

    public static int abstwo(ArrayList array , int i , int j) {
        return Math.abs((int)array.get(i) - (int)array.get(j));
    }

    public static boolean contains( ArrayList array,  int key) {
        for ( int i = 0 ; i < array.size() ; i++) {
            if ((int)array.get(i) == key) {
                return true;
            }
        }
        return false;
    }

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

        ArrayList<Integer> val = new ArrayList<Integer>();
        val.add(sr.nextInt());
        int test = 0;
        int count = 1;
        for (int i = 1; i < n; i++) {
            test = sr.nextInt();
            if (!contains(val , test)) {
                val.add(test);
                count++;
            }
        }
        Collections.sort(val);;
        if(n==1) System.out.print(0);
        else if(n==2) {
            if(val.size()==2 && ((int)val.get(0) != (int)val.get(1)) && ((int)val.get(0) + (int)val.get(1))%2!=1) System.out.print(abstwo(val, 0, 1)/2);
            else if(val.size()==2 && ((int)val.get(0) != (int)val.get(1)) && ((int)val.get(0) + (int)val.get(1))%2==1) System.out.print(abstwo(val, 0, 1));
            else System.out.print(0);
        }
        else{
            if(val.size() == 1)System.out.print(0);
            else if(val.size()==2 && ((int)val.get(0) != (int)val.get(1)) && ((int)val.get(0) + (int)val.get(1))%2!=1) System.out.print(abstwo(val, 0, 1)/2);
            else {

            int pace = abstwo(val, 0, 1);
            int min = (int)val.get(0);
            int max = (int)val.get(0);
            for (int i = 1; i < count; i++) {
                if((int)val.get(i) >= max) max = (int)val.get(i);
                if((int)val.get(i) <= min) min = (int)val.get(i);
            }
            boolean cond = (max - min)==(2*pace);

            boolean flag = true;
            for (int i = 1; i < count-1; i++) {
                if(!(cond && (abstwo(val, i, i+1) == pace))){
                    flag = false;
                    break;
                }
            }
            if(flag) {
                boolean condition = val.size()==2 && (Math.max((int)val.get(0),(int)val.get(1)) % Math.min((int)val.get(0),(int)val.get(1))==0) && Math.max((int)val.get(0),(int)val.get(1))!=1 && Math.min((int)val.get(0),(int)val.get(1))!= 1;
                if(condition) System.out.print(pace/2);
                else System.out.print(pace);
            }
            else System.out.print(-1);
            }
        }
        sr.close();
    }
}

import java.util.*;

/**
 * taskB
 * Make them equal
 */

public class Problem1154B {

    public static int substwo(int[] array , int i , int j) {
        return array[i] - array[j];
    }

    public static boolean contains( int [] array,  int key) {
        for ( int i = 0 ; i < array.length ; i++) {
            if (array[i] == key) {
                return true;
            }
        }
        return false;
    }

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

        int [] val = new int [n];
        val[0] = sr.nextInt();
        int test;
        int count = 1;
        for (int i = 1; i < n; i++) {
            test = sr.nextInt();
            if (!contains(val , test)) {
                val[count] = test;
                count++;
            }
        }

        int [] resize = new int [count];
        for (int i = 0; i <count; i++) {
            resize[i] = val[i];
        }

        Arrays.sort(resize);

        if(resize.length > 3) System.out.print(-1);
        else if (resize.length == 3){
            if(substwo(resize, 1, 0) == substwo(resize, 2, 1)) System.out.print(substwo(resize, 1, 0));
            else System.out.print(-1);
        }
        else if (resize.length == 2){
            if(substwo(resize, 1, 0) % 2 == 0) System.out.print(substwo(resize, 1, 0)/2);
            else System.out.print(substwo(resize, 1, 0));
        }
        else System.out.print(0);

        sr.close();
    }
}

import java.util.*;
import java.lang.*;
public class Equal_2{
	public static void main(String args[])
	{
		int n,i,d,flag=0,k=0,is=0,m=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int arr[]=new int[n];
		int arr2[]=new int[n];
		for(i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
		}

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

            int j;
            for (j = 0; j < i; j++)
            if (arr[i] == arr[j])
                break;
            if (i == j)
			{
               arr2[m]=arr[i];
		       m++;
			}
		}
		int temp,j;
   for ( i = 0; i < m; i++) {
    for ( j = i; j >0; j--) {
     if (arr2[j] < arr2 [j - 1]) {
      temp = arr2[j];
      arr2[j] = arr2[j - 1];
      arr2[j - 1] = temp;
     }
    }
   }

       if(m>3)
           System.out.println(-1);
	   else
	   {
		   if(m==1)
			   System.out.println(0);
		   else if(m==3)
		   {
		     if (arr2[1] - arr2[0] != arr2[2] - arr2[1]) {
				System.out.println(-1);
			} else {
				System.out.println(arr2[1]-arr2[0]);
			}
		   }
		   else
	   {
		   if((arr2[1]-arr2[0])%2==0)
			   System.out.println((arr2[1]-arr2[0])/2);
		   else
			   System.out.println(arr2[1]-arr2[0]);
	   }

	   }

	}
}

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

public class Main
{

    public static void process()throws IOException
    {
        int n=ni();
        TreeSet<Integer> set = new TreeSet<Integer>();
        for(int i=1;i<=n;i++) set.add(ni());

        if(set.size()>3){
            pn(-1);
            return;
        }

        if(set.size()==1){
            pn(0);
            return;
        }

        int a=set.pollFirst(),b=set.pollFirst();
        if(set.size()==0){
            if((b*1l+a*1l)%2l==0)
                pn(b-(b*1l+a*1l)/2l);
            else
                pn(b-a);
            return;
        }

        //Integer a=null,b=null;;

        int res=0;
        Integer c=set.pollFirst();
        if(b-a==c-b){
            pn(b-a);
            return;
        }
        pn(-1);
    }

       static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new AnotherReader();
        boolean oj = true;

        oj = System.getProperty("ONLINE_JUDGE") != null;
        if(!oj) sc=new AnotherReader(100);

        long s = System.currentTimeMillis();
        int t=1;
        while(t-->0)
            process();
        out.flush();
        if(!oj)
            System.out.println(System.currentTimeMillis()-s+"ms");
        System.out.close();
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;

/////////////////////////////////////////////////////////////////////////////////////////////////////////

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

import java.util.*;
public class cf1154b {
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 diff[]=new int[4];
diff[0]=arr[0];
int c=1;
for(int i=1;i<n;i++)
{if(arr[i]!=arr[i-1])
{c++;
diff[c-1]=arr[i];}
if(c>3)
break;}
if(c>3)
System.out.println(-1);
else if(c==1)
System.out.println(0);
else if(c==2)
{if((diff[1]-diff[0])%2==0)
System.out.println((diff[1]-diff[0])/2);
else
System.out.println(diff[1]-diff[0]);}
else if(c==3 && diff[2]-diff[1]==diff[1]-diff[0])
System.out.println(diff[2]-diff[1]);
else
System.out.println(-1);
sc.close();
}}

import java.util.Scanner;

/**
 * Created by suren on 4/16/19.
 */
public class TestB {
    public static void main(String[] args) {

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

        for (int i = 0 ; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        D:
        for(int d = 0; d <= 100; d++) {

            int max = a[0] + d;
            int min = a[0] - d;
            int mid = a[0];
            boolean canBeMax = true;
            boolean canBeMin = true;
            boolean canBeMid = true;

            for (int i = 1 ; i < n; i++) {
                if(canBeMax) {
                    if (a[i] + d != max && a[i] - d != max && a[i] != max) {
                        canBeMax = false;
                    }
                }
                if(canBeMin) {
                    if (a[i] + d != min && a[i] - d != min && a[i] != min) {
                        canBeMin = false;
                    }
                }
                if(canBeMid) {
                    if (a[i] + d != mid && a[i] - d != mid && a[i] != mid) {
                        canBeMid = false;
                    }
                }
                if ((canBeMax || canBeMid || canBeMin) == false) {
                    continue D;
                }

            }
            if (canBeMax || canBeMid || canBeMin) {
                System.out.println(d);
                scanner.close();
                return;
            }
        }
        System.out.println(-1);
        scanner.close();
    }
}

import java.util.*;
public class Cf1154B {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n,i,j,s=0,temp,p;
		n=sc.nextInt();
		int []arr=new int[3];
		for(i=0;i<n;i++) {
			p=sc.nextInt();
			if(s==4)
				continue;
			else if(s==0) {
				arr[0]=p;
				s++;
			}
			else if(s==1) {
				if(p!=arr[0]) {
					arr[1]=p;
					s++;
				}
			}
			else if(s==2) {
				if(p!=arr[0] && p!=arr[1]) {
					arr[2]=p;
					s++;
				}
			}
			else {
				if(p!=arr[0] && p!=arr[1] && p!=arr[2])
					s=4;
			}

		}
		if(s==4)
			System.out.println("-1");
		else if(s==1)
			System.out.println("0");
		else if(s==2) {
			if((arr[1]-arr[0])%2!=0)
				System.out.println(Math.max(arr[0],arr[1])-Math.min(arr[0],arr[1]));
			else
				System.out.println((Math.max(arr[0],arr[1])-Math.min(arr[0],arr[1]))/2);
		}
		else {
			Arrays.sort(arr);
			if(arr[2]-arr[1]==arr[1]-arr[0])
				System.out.println(arr[2]-arr[1]);
			else
				System.out.println("-1");
		}
		sc.close();
	}

}

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

public class Make_Them_Equal {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		int[] abc = new int[3];
		boolean flagA = false;
		boolean flagB = false;
		boolean flagC = false;
		for (int i = 0; i < n; i++) {
			arr[i] = scan.nextInt();
			if (arr[i] != abc[0] && !flagA) {
				abc[0] = arr[i];
				flagA = true;
			} else if (arr[i] != abc[1] && arr[i] != abc[0] && !flagB) {
				abc[1] = arr[i];
				flagB = true;
			} else if (arr[i] != abc[2] && arr[i] != abc[1] && arr[i] != abc[0] && !flagC) {
				abc[2] = arr[i];
				flagC = true;
			} else if(arr[i] != abc[0] && arr[i] != abc[1] && abc[2] != arr[i]) {
				System.out.print(-1);
				System.exit(0);
			}
		}
		Arrays.sort(abc);
		if (abc[0] != 0 && abc[1] != 0 && abc[2] != 0) {
			if (abc[2] - abc[1] != abc[1] - abc[0]) {
				System.out.println(-1);
			} else {
				if (abc[0] == 0 && abc[1] == 0) {
					System.out.print(0);
				} else if (abc[0] == 0) {
					if ((abc[2] - abc[1]) % 2 == 0) {
						System.out.print((abc[2] - abc[1]) / 2);
					} else {
						System.out.print((abc[2] - abc[1]));
					}

				} else {
					System.out.print((abc[2] - abc[0]) / 2);

				}
			}
		} else {
			if (abc[0] == 0 && abc[1] == 0) {
				System.out.print(0);
			} else if (abc[0] == 0) {
				if ((abc[2] - abc[1]) % 2 == 0) {
					System.out.print((abc[2] - abc[1]) / 2);
				} else {
					System.out.print((abc[2] - abc[1]));
				}
			} else {
				System.out.print((abc[2] - abc[0]) / 2);
			}
		}

		scan.close();
	}

}

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

public class Make_Them_Equal_552_B {

    public static void main(String[] args) {

        HashSet<String> uniqueNumber = new HashSet<>();
        Scanner scanner = new Scanner(System.in);
        int totalNumber = scanner.nextInt();
        for (int i = 0; i < totalNumber; i++) {
            uniqueNumber.add(String.valueOf(scanner.nextInt()));
        }

        if (uniqueNumber.size() > 3)
            System.out.println(-1);
        else {
            int[] numbers = new int[uniqueNumber.size()];
            int j = 0;
            for (String i : uniqueNumber) {
                numbers[j++] = Integer.valueOf(i);
            }
            Arrays.sort(numbers);
            if (numbers.length == 1)
                System.out.println(0);
            else if (numbers.length == 2) {
                if ((numbers[1] - numbers[0]) % 2 == 0)
                    System.out.println((numbers[1] - numbers[0]) / 2);
                else
                    System.out.println(numbers[1] - numbers[0]);
            } else {
                if (numbers[2] - numbers[1] == numbers[1] - numbers[0])
                    System.out.println(numbers[2] - numbers[1]);
                else
                    System.out.println(-1);
            }
        }
    }
}

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

public class Make_Them_Equal {

	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) {
		// TODO Auto-generated method stub
		FastReader t = new FastReader();
		PrintWriter o = new PrintWriter(System.out);
		int n = t.nextInt();
		HashSet<Integer> a = new HashSet<>();

		for (int i = 0; i < n; i++) {
			int el = t.nextInt();

			a.add(el);
		}

		if (a.size() == 1) {
			o.println(0);
		} else if (a.size() == 2) {
			int p = 0, q = 0;

			for (int alpha : a) {
				if (p == 0)
					p = alpha;
				else
					q = alpha;
			}

			int diff = Math.abs(p - q);

			if (diff % 2 == 0)
				o.println(diff / 2);
			else
				o.println(diff);
		} else if (a.size() == 3) {
			int p = 0, q = 0, r = 0;
			int[] ok = new int[3];

			for (int alpha : a) {
				if (ok[0] == 0)
					ok[0] = alpha;
				else if (ok[1] == 0)
					ok[1] = alpha;
				else
					ok[2] = alpha;

			}

			Arrays.sort(ok);

			int d1 = ok[1] - ok[0], d2 = ok[2] - ok[1];

			if (d1 == d2)
				o.println(d1);
			else
				o.println(-1);
		} else {
			o.println(-1);
		}

		o.flush();
		o.close();
	}

}

import java.util.*;
import java.io.*;
public class Codeforces {
	static int MAX = (int)1e5+1;
	static boolean leaf[];
	//static int count[],n,m;
	//static int n,m,arr[],size;
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		 int n = input.nextInt();
		 int arr[] = new int[n];
		 int ans = 99999;
		 for(int i =0;i<n;i++)arr[i] = input.nextInt();
		 boolean ok = false;
		 for(int i =1;i<=100;i++) {
			 HashSet<Integer>set = new HashSet<>();
			 int target = i;
			 for(int j =0;j<n;j++) {
				 if(target - arr[j]== 0)continue;
				//if(target == 5) System.out.println(target-arr[j]);
				 set.add(Math.abs(target-arr[j]));
			 }
			 if(set.size() == 0)ans = 0;
			 if(set.size() ==1) {
				 int val = set.iterator().next();
				ans = Math.min(val,ans);
				ok = true;
			 }
		 }
		 if(!ok)System.out.println(-1);
		 else System.out.println(ans);
	}
}

/*****************************************Notes**********************************************

1.Never use String.charAt for integers=> only works till 9 if integer val is 28,39,555
charAt would pick only the first digit. Better use Integer.parseInt() to convert string to Integer

2. even empty for loop can be used in certain cases.eg 'C - Pinkie Pie Eats Patty-cakes'.
the check function of binary search. extra code but learnt some approach = SecondThreads implementation

3. The two list subsequence method eg:D. Binary String To Subsequences (works only in the case of two characters)

4. when there is a range that is computed there are case where index out of bounds might occur to keep
the ranges proper use min max trick=> leftfarthest = max(0,computed) && rightFarthest = min(n-1,computed)

*/

import java.util.Scanner;

public class B552 {

	public static void main(String[] args) {
		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();
		}
		for(int i = 0;i<=200;i++){
			for(int j = 0;j<n;j++){
				int val = arr[j]+i;
				int val1 = arr[j]-i;
				int val2 = arr[j];
				boolean good = true;
				for(int k = 0;k<n;k++){
					if(k==j)continue;
					if(arr[k]>val){
						int now = arr[k]-i;
						if(now!=val){
							good = false;
							break;
						}
					}
					if(arr[k]<val){
						int now = arr[k]+i;
						if(now!=val){
							good = false;
							break;
						}
					}
				}
				if(good){
					System.out.println(i);
					return;
				}
				good = true;
				for(int k = 0;k<n;k++){
					if(k==j)continue;
					if(arr[k]>val1){
						int now = arr[k]-i;
						if(now!=val1){
							good = false;
							break;
						}
					}
					if(arr[k]<val1){
						int now = arr[k]+i;
						if(now!=val1){
							good = false;
							break;
						}
					}
				}
				if(good){
					System.out.println(i);
					return;
				}
				good = true;
				for(int k = 0;k<n;k++){
					if(k==j)continue;
					if(arr[k]>val2){
						int now = arr[k]-i;
						if(now!=val2){
							good = false;
							break;
						}
					}
					if(arr[k]<val2){
						int now = arr[k]+i;
						if(now!=val2){
							good = false;
							break;
						}
					}
				}
				if(good){
					System.out.println(i);
					return;
				}
			}

		}
		System.out.println(-1);
	}

}

import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.BitSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.math.BigInteger;

public class codeforces{

 public static void main(String[] args) throws NumberFormatException, IOException {
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
String[] str=br.readLine().split(" ");
TreeSet<Integer> set=new TreeSet<Integer>();
for(int i=0;i<t;i++){
int k=Integer.parseInt(str[i]);
set.add(k);
}
if(set.size()==1){
  System.out.println(0);
  return;
}

if(set.size()>3){
  System.out.println(-1);
}
else{
  if(set.size()==2){
    int diff=set.last()-set.first();
 if(diff%2==0){
   System.out.println(diff/2);
 }
 else{
  System.out.println(diff);

 }
  }
  else{
    int first=set.first();
    set.remove(first);
    int second=set.first();
    int last=set.last();
    if(second-first==last-second){
      System.out.println(second-first);
    }
    else{
      System.out.println(-1);

    }

  }

}
}

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

}

}

import java.util.*;
public class make_them_equal
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		HashSet<Integer> h=new 	HashSet<Integer>();
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
		}
		int flag=0;
		Arrays.sort(a);
		for(int i=0;i<n;i++)
		{
			h.add(a[i]);
		}
		int min=a[0];
		int max=a[n-1];
		int req=(max-min)/2;
		if(h.size()>2)
		{
			for(int i=0;i<n;i++)
			{
				if(a[i]==min)
				{
					a[i]+=req;
				}
				else if(a[i]==max)
				{
					a[i]-=req;
				}
			}
			for(int i=0;i<n-1;i++)
			{
				if(a[i]!=a[i+1])
				{
					flag=1;
					break;
				}
			}
			if(flag==1)
			{
				System.out.println("-1");
			}
			else
			{
				System.out.println(req);
			}
		}

		if(h.size()==2)
		{
			if(max%2!=min%2)
			{
				req=max-min;
			}
			System.out.println(req);
		}

		if(h.size()==1)
		{
			System.out.println("0");
		}

	}
}

import javax.print.DocFlavor;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.nio.Buffer;
import java.sql.BatchUpdateException;
import java.util.*;
import java.util.stream.Stream;
import java.util.Vector;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import static java.lang.Math.*;
import java.util.*;
import java.nio.file.StandardOpenOption;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Iterator;
import java.util.PriorityQueue;

public class icpc
{
    public static void main(String[] args)throws IOException
    {
        Reader in = new Reader();

        int n = in.nextInt();
        int[] A = new int[n];
        HashSet<Integer> h = new HashSet<>();
        for(int i=0;i<n;i++)
        {
            A[i] = in.nextInt();
            h.add(A[i]);
        }
        if(h.size() > 3)
            System.out.println(-1);
        else if(h.size() == 1)
            System.out.println(0);
        else if(h.size() == 2)
        {
            Iterator iter = h.iterator();
            int a = (int)iter.next();
            int b = (int)iter.next();
            if((int)Math.abs(a-b) % 2 == 0)
                System.out.println((int)Math.abs(a-b)/2);
            else
                System.out.println((int)Math.abs(a-b));
        }
        else
        {
            Iterator iter = h.iterator();
            int a = (int)iter.next();
            int b = (int)iter.next();
            int c = (int)iter.next();
            ArrayList<Integer> B = new ArrayList<>();
            B.add(a);
            B.add(b);
            B.add(c);
            Collections.sort(B);
            if((B.get(1) - B.get(0)) == (B.get(2) - B.get(1)))
            {
                System.out.println(B.get(1)- B.get(0));
            }

            else
                System.out.println(-1);
        }

    }
}
class Game
{
    int x;
    int y;
    Game(int a,int b)
    {
        this.x = a;
        this.y = b;
    }
}
class MergeSort
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(long arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        long L[] = new long [n1];
        long R[] = new long [n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(long arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }
}
class Node
{
    String a;
    String b;
    Node(String s1,String s2)
    {
        this.a = s1;
        this.b = s2;
    }
    @Override
    public boolean equals(Object ob)
    {
        if(ob == null)
            return false;
        if(!(ob instanceof Node))
            return false;
        if(ob == this)
            return true;
        Node obj = (Node)ob;
        if(this.a.equals(obj.a) && this.b.equals(obj.b))
            return true;
        return false;
    }

    @Override
    public int hashCode()
    {
        return (int)this.a.length();
    }
}
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();
    }
}
class SegmentTree
{
    public int nextPowerOfTwo(int num)
    {
        if(num == 0)
            return 1;
        if(num > 0 && (num & (num - 1)) == 0)
            return num;
        while((num &(num - 1)) > 0)
        {
            num = num & (num - 1);
        }
        return num << 1;
    }

}
class FenwickTree
{
    public void update(long[] fenwickTree,long delta,int index)
    {
        index += 1;
        while(index < fenwickTree.length)
        {
            fenwickTree[index] += delta;
            index = index + (index & (-index));
        }
    }
    public long prefixSum(long[] fenwickTree,int index)
    {
        long sum = 0L;
        index += 1;
        while(index > 0)
        {
            sum += fenwickTree[index];
            index -= (index & (-index));
        }
        return sum;
    }
}
class SegmentTree1
{
    public int nextPowerOfTwo(int num)
    {
        if(num == 0)
            return 1;
        if(num > 0 && (num & (num - 1)) == 0)
            return num;
        while((num &(num - 1)) > 0)
        {
            num = num & (num - 1);
        }
        return num << 1;
    }
    public int[] createSegmentTree(int[] input)
    {
        int np2 = nextPowerOfTwo(input.length);
        int[] segmentTree = new int[np2 * 2 - 1];

        for(int i=0;i<segmentTree.length;i++)
            segmentTree[i] = Integer.MAX_VALUE;

        constructSegmentTree(segmentTree,input,0,input.length-1,0);
        return segmentTree;

    }
    private void constructSegmentTree(int[] segmentTree,int[] input,int low,int high,int pos)
    {
        if(low == high)
        {
            segmentTree[pos] = input[low];
            return;
        }
        int mid = (low + high)/ 2;
        constructSegmentTree(segmentTree,input,low,mid,2*pos + 1);
        constructSegmentTree(segmentTree,input,mid+1,high,2*pos + 2);
        segmentTree[pos] = Math.min(segmentTree[2*pos + 1],segmentTree[2*pos + 2]);
    }
    public int rangeMinimumQuery(int[] segmentTree,int qlow,int qhigh,int len)
    {
        return rangeMinimumQuery(segmentTree,0,len - 1,qlow,qhigh,0);
    }
    private int rangeMinimumQuery(int[] segmentTree,int low,int high,int qlow,int qhigh,int pos)
    {
        if(qlow <= low && qhigh >= high)
        {
            return segmentTree[pos];
        }
        else if(qlow > high || qhigh < low)
        {
            return Integer.MAX_VALUE;
        }
        int mid = (low + high)/2;
        return Math.min(rangeMinimumQuery(segmentTree,low,mid,qlow,qhigh,2*pos+1),rangeMinimumQuery(segmentTree,mid+1,high,qlow,qhigh,2*pos+2));
    }
    public void updateSegmentTreeRangeLazy(int[] input,int[] segmentTree,int[] lazy,int startRange,int endRange,int delta)
    {
        updateSegmentTreeRangeLazy(input,segmentTree,lazy,startRange,endRange,delta,0,input.length-1,0);
    }
    private void updateSegmentTreeRangeLazy(int[] input,int[] segmentTree,int[] lazy,int startRange,int endRange,int delta,int low,int high,int pos)
    {
        if(low > high)
        {
            return;
        }
        if(lazy[pos] != 0)
        {
            segmentTree[pos] += lazy[pos];
            if(low != high)
            {
                lazy[2*pos+1] += lazy[pos];
                lazy[2*pos + 2] += lazy[pos];
            }
            lazy[pos] = 0;
        }
        if(startRange > high || endRange < low)
            return;
        if(startRange <= low && endRange >= high)
        {
            segmentTree[pos] += delta;
            if(low != high)
            {
                lazy[2*pos + 1] += delta;
                lazy[2*pos + 2] += delta;
            }
            return;
        }
        int mid = (low + high)/2;
        updateSegmentTreeRangeLazy(input,segmentTree,lazy,startRange,endRange,delta,low,mid,2*pos + 1);
        updateSegmentTreeRangeLazy(input,segmentTree,lazy,startRange,endRange,delta,mid + 1,high,2 * pos + 2);
        segmentTree[pos] += Math.min(segmentTree[2*pos + 1],segmentTree[2*pos + 2]);
    }
    public int rangeMinimumQueryLazy(int[] segmentTree,int[] lazy,int qlow,int qhigh,int len)
    {
        return rangeMinimumQueryLazy(segmentTree,lazy,qlow,qhigh,0,len - 1,0);
    }
    private int rangeMinimumQueryLazy(int[] segmentTree,int[] lazy,int qlow,int qhigh,int low,int high,int pos)
    {
        if(low > high)
            return Integer.MAX_VALUE;
        if(lazy[pos] != 0)
        {
            segmentTree[pos] += lazy[pos];
            if(low != high)
            {
                lazy[2*pos + 1] += lazy[pos];
                lazy[2*pos + 2] += lazy[pos];
            }
            lazy[pos] = 0;
        }
        if(qlow > high || qhigh < low)
            return Integer.MAX_VALUE;
        if(qlow <= low && qhigh >= low)
            return segmentTree[pos];
        int mid = (low + high)/2;
        return Math.min(rangeMinimumQueryLazy(segmentTree,lazy,qlow,qhigh,low,mid,2*pos + 1),rangeMinimumQueryLazy(segmentTree,lazy,qlow,qhigh,mid + 1,high,2*pos + 2));
    }
}

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];

        ArrayList<Integer> al=new ArrayList<>();
        for(int i=0;i<n;i++) {
        a[i]=sc.nextInt();
        if(!al.contains(a[i]))
        al.add(a[i]);
        }
        Collections.sort(al);
        if(al.size()>3)
        System.out.println(-1);
        else {
            if(al.size()==3) {
                if(al.get(2)-al.get(1)==al.get(1)-al.get(0))
                System.out.println(al.get(1)-al.get(0));
                else
                System.out.println(-1);
            }
            else if(al.size()==2) {
                if((al.get(1)-al.get(0))%2==0)
                System.out.println((al.get(1)-al.get(0))/2);
                else
                 System.out.println((al.get(1)-al.get(0)));
            }
            else
            System.out.println(0);
        }

    }
}

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

public class MyClass {
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(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;
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String s = sc.nextLine();
        int n = Integer.parseInt(s);
        int[] a = new int[n];
        String ss = sc.nextLine();
        String[] c = ss.split(" ");
        for(int i=0;i<n;i++)
        {
            a[i] = Integer.parseInt(c[i]);
        }
        Arrays.sort(a);
        int num = 0;
        int first =0;
        if(n==1)
        {
            System.out.println(0);
            return;
        }else if(n==2)
        {
            if((a[1]-a[0])%2==0)
            {
                System.out.println(((a[1]-a[0])/2));
                return;
            }else
            {
                System.out.println(a[1]-a[0]);
                return;
            }
        }else
        {

            for(int i=1;i<n;i++)
            {
                if(a[i]-a[i-1]!=0)
                {
                    if(num==0||num==a[i]-a[i-1]){
                        if(first==2)
                        {
                            System.out.println(-1);
                            return;
                        }
                        num = a[i]-a[i-1];
                        first++;
                    }else
                    {
                        System.out.println(-1);
                        return;
                    }
                }
            }
        }
        //
        if(first==1)
        {
            if(num%2==0)
            {
                System.out.println(num/2);
                return;
            }else
            {
                System.out.println(num);
                return;
            }
        }
        System.out.println(num);
    }
}

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class MakeThemEqual implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    int n = in.ni();
    int[] x = new int[n];
    for (int i = 0; i < n; i++) {
      x[i] = in.ni();
    }
    Arrays.sort(x);
    int d = (x[n - 1] - x[0]) % 2 == 0 ? (x[n - 1] - x[0]) / 2 : (x[n - 1] - x[0]);
    for (int i = 1; i < n - 1; i++) {
      if (!(x[i] == x[0] || x[i] == x[n - 1] || x[i] == x[0] + d || x[i] == x[n - 1] - d)) {
        out.println(-1);
        return;
      }
    }
    out.println(d);
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  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 ni() {
      return Integer.parseInt(next());
    }

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

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (MakeThemEqual instance = new MakeThemEqual()) {
      instance.solve();
    }
  }
}

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

public class Backtracking {

    static char[] chars;
    public static void main(String[] args) {
        Scanner io = new Scanner(System.in);
        int N = io.nextInt();
        Set<Integer> tmp = new HashSet<>();
        for(int i = 0; i < N; i++) tmp.add(io.nextInt());
        Integer arr[] = new Integer[tmp.size()];
        tmp.toArray(arr);
        Arrays.sort(arr);
        if(arr.length > 3) { System.out.println(-1); return; }
        if(arr.length == 1) { System.out.println(0); return; }
        if(arr.length == 2) {
            if((arr[0] + arr[1]) % 2 == 0)
                System.out.println(arr[1] - (arr[0] + arr[1]) / 2);
            else
                System.out.println(arr[1] - arr[0]);
            return;
        }
        if(((arr[2] + arr[0]) / 2.0) % 1 != 0 || Arrays.binarySearch(arr, (arr[2] + arr[0]) / 2) < 0) System.out.println(-1);
        else System.out.println(arr[2] - arr[1]);
    }
}

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

public class MyClass {
    public static void main(String args[]) {
        ABCDEFGHIJKLMNOPQRSTUVWXYZScanner scan = new ABCDEFGHIJKLMNOPQRSTUVWXYZScanner();
        int n = scan.nextInt();
        int[] a = scan.nia(n);
        Arrays.sort(a);
        int d = a[n-1]-a[0];
        if(d == 0) {
            System.out.println(0);
        }
        else {
            boolean check = false;
            for(int i = 1; i < n-1; i++) {
                if(a[i] != a[0]) {
                    if(a[0] + d != a[i]) {
                        if(d % 2 == 1 || a[0] + d/2 != a[i]) {
                            System.out.println(-1);
                            return;
                        }
                        check = true;
                    }
                }
            }
            if(check) System.out.println(d/2);
            else {
                if(d % 2 == 0) System.out.println(d/2);
                else System.out.println(d);
            }
        }

    }

    static class ABCDEFGHIJKLMNOPQRSTUVWXYZScanner
    {
        BufferedReader br;
        StringTokenizer st;

        public ABCDEFGHIJKLMNOPQRSTUVWXYZScanner()
        {
            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());
        }

        int[] nia(int n) {
            int[] res =  new int[n];
            for(int i = 0; i < n; i++) res[i] = nextInt();
            return res;
        }

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

        long[] nla(int n) {
            long[] res =  new long[n];
            for(int i = 0; i < n; i++) res[i] = nextLong();
            return res;
        }

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

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

//I AM THE CREED
/* //I AM THE CREED
/* package codechef; // don't place package name! */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;

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

        Scanner input = new Scanner(System.in);
        while(input.hasNext()){
            int n=input.nextInt();
            HashSet<Integer> s=new HashSet<>();
            int max=Integer.MIN_VALUE;
            int min=Integer.MAX_VALUE;
            for(int i=0;i<n;i++){
                int ele=input.nextInt();
                max=Math.max(max, ele);
                min=Math.min(min, ele);
                s.add(ele);
            }
            if(s.size()>3){
                System.out.println(-1);
                continue;
            }
            if(s.size()==1){
                System.out.println(0);
                continue;
            }
            if(s.size()==2){
                if((min-max)%2==0){
                    System.out.println((max-min)/2);
                    continue;
                }
                System.out.println(max-min);
                continue;
            }
            if(s.size()==3){
                int middle=-1;
                for(int ele:s){
                    if(ele!=min && ele!=max){
                        middle=ele;
                        break;
                    }
                }
                if((max-min)%2==0 && (max+min)/2==middle){
                    System.out.println((max-min)/2);
                    continue;
                }
                System.out.println(-1);
            }

        }
    }
}

import java.util.*;

public class Example {
	public static void main(String args[])
	{ Scanner sc = new Scanner(System.in);
	int n;
	n=sc.nextInt();
	TreeSet<Integer> ts = new TreeSet<Integer>();
	for(int i=0;i<n;i++)
	{
	    int a= sc.nextInt();
	    ts.add(a);
	}  int t=-1;
	if(ts.size()==3)
	{
	    Integer[] arr = ts.toArray( new Integer[ts.size()] );
	    int a= arr[1]-arr[0];
	    int b= arr[2]-arr[1];
	    if(a==b)
	    t=a;

	}
	if(ts.size()==2)
	{
	    int a= ts.first();
	    int b= ts.last();
	    int c= b-a;
	    if(c%2==0)
	    t= c/2;
	    else
	    t=c;
	}
	if(ts.size()==1)
	t=0;
	System.out.println(t);
	}
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;

public class Main
{
    public static void main(String[] args)
    {
        MainRun mainSolve = new MainRun();
        mainSolve.run(0, 0);
    }
}

class Task
{
    public void solve(InputReader in, PrintWriter out)
    {
        int n = in.nextInt();
        int a[] = new int[n];
        int mn = Integer.MAX_VALUE;
        int mx = Integer.MIN_VALUE;
        Set<Integer> set = new TreeSet<>();
        for (int i = 0; i < n; i++)
        {
            a[i] = in.nextInt();
            mn = Math.min(mn, a[i]);
            mx = Math.max(mx, a[i]);
            set.add(a[i]);
        }

        if (set.size() == 1 || set.size() > 3)
        {
            out.println(set.size() == 1 ? 0 : -1);
            return;
        }
        if (set.size() == 2)
        {
            out.println((mx - mn) % 2 == 0 ? (mx - mn) / 2 : mx - mn);
            return;
        }
        if ((mx + mn) % 2 == 0) {
            int x = (mx + mn) / 2;
            for (int i = 0; i < n; i++) {
                if (a[i] != mn && a[i] != mx && a[i] != x) {
                    out.println(-1);
                    return;
                }
            }
            out.println(mx - x);
        }
        else
        {
            Iterator<Integer> iterator = set.iterator();
            iterator.next();
            int middle = iterator.next();
            int r = mx - middle;
            if (mn + r == mx && mx - r == mn)
            {
                out.println(middle);
                return;
            }
            else {
                out.println(-1);
                return;
            }
        }
    }
}

class MainRun
{
    void run(int inF, int outF)
    {
        String input = "input.txt";
        String output = "output.txt";
        InputReader in = inF == 1 ? new InputReader(input) : new InputReader(System.in);
        PrintWriter out = outF == 1 ? getPrintWriter(output) : getPrintWriter(System.out);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    public static PrintWriter getPrintWriter(OutputStream stream)
    {
        return new PrintWriter(stream);
    }

    public static PrintWriter getPrintWriter(String f)
    {
        try
        {
            return new PrintWriter(new File(f));
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
        return null;
    }
}

class InputReader
{
    BufferedReader reader;
    StringTokenizer tokenizer;

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

    InputReader(String f)
    {
        try
        {
            reader = new BufferedReader(new FileReader(f));
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
        tokenizer = null;
    }

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

    public String getLine()
    {
        try
        {
            return (String) reader.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return "";
    }

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

    public char nextChar()
    {
        return next().charAt(0);
    }

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

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

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

public class MakeThemEqual {
    public static void main(String[] args) {
       int n;
       Scanner sc= new Scanner(System.in);
       n = sc.nextInt();
       Integer [] arr = new Integer[n];
       sc.nextLine();
       String [] s = sc.nextLine().split(" ");
       for(int i =0 ; i< n;i++) {
           arr[i] = Integer.parseInt(s[i]);
       }
       int max = Collections.max(Arrays.asList(arr));
       int min = Collections.min(Arrays.asList(arr));
       Map <Integer, Integer> mp = new HashMap();
       int coun = 0;
       for(int i =0 ; i< n;i++) {
           if(!mp.containsKey(arr[i])) {
               mp.put(arr[i], 1);
               coun++;
           }
       }
       double d = (max-min) / 2.0;
       if(coun==1) {
           System.out.println(0);
       }
       else if(coun==2) {
           if(!(d%1 == 0)) {
               System.out.println(max-min);
           }
           else {
               System.out.println((int) d);
           }
       }
       else if(coun == 3) {
           if(!(d%1 == 0)) {
               System.out.println(-1);
           }
           else if(mp.containsKey(min+(int)d)) {
               System.out.println((int)d);
           }
           else {
               System.out.println(-1);
           }
       }
       else {
          System.out.println(-1);
       }
    }
}

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

import static java.lang.Math.*;

public class input2 {
    //    public static void merge(int arr[], int l, int m, int r) {
    //        // Find sizes of two subarrays to be merged
    //        int n1 = m - l + 1;
    //        int n2 = r - m;
    //
    //        /* Create temp arrays */
    //        int L[] = new int[n1];
    //        int R[] = new int[n2];
    //
    //        /*Copy data to temp arrays*/
    //        for (int i = 0; i < n1; ++i)
    //            L[i] = arr[l + i];
    //        for (int j = 0; j < n2; ++j)
    //            R[j] = arr[m + 1 + j];
    //
    //
    //        /* Merge the temp arrays */
    //
    //        // Initial indexes of first and second subarrays
    //        int i = 0, j = 0;
    //
    //        // Initial index of merged subarry array
    //        int k = l;
    //        while (i < n1 && j < n2) {
    //            if (L[i] <= R[j]) {
    //                arr[k] = L[i];
    //                i++;
    //            } else {
    //                arr[k] = R[j];
    //                j++;
    //            }
    //            k++;
    //        }
    //
    //        /* Copy remaining elements of L[] if any */
    //        while (i < n1) {
    //            arr[k] = L[i];
    //            i++;
    //            k++;
    //        }
    //
    //        /* Copy remaining elements of R[] if any */
    //        while (j < n2) {
    //            arr[k] = R[j];
    //            j++;
    //            k++;
    //        }
    //    }
    //
    //    // Main function that sorts arr[l..r] using
    //    // merge()
    //    public static void sort(int arr[], int l, int r) {
    //        if (l < r) {
    //            // Find the middle point
    //            int m = (l + r) / 2;
    //
    //            // Sort first and second halves
    //            sort(arr, l, m);
    //            sort(arr, m + 1, r);
    //
    //            // Merge the sorted halves
    //            merge(arr, l, m, r);
    //        }
    //    }
    //
    //    public static long gcd(long n, long m) {
    //        if (n % m == 0) {
    //            return m;
    //        }
    //        return gcd(m, n % m);
    //    }
    //
    //    static class Pair {
    //        public char x1;
    //        public int x2;
    //
    //        Pair(char x, int y) {
    //            this.x1 = x;
    //            this.x2 = y;
    //        }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        TreeSet<Integer>T = new TreeSet<>();
        StringTokenizer st =  new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++){
            T.add(Integer.parseInt(st.nextToken()));
        }
        if(T.size()>3){
            System.out.println(-1);
        }
        else if(T.size() == 1){
            System.out.println(0);
        }
        else if(T.size() == 2){
            Object arr[] = T.toArray();
            int diff = ((int)arr[1]-(int)arr[0]);
            if(diff%2 == 0){
                System.out.println(diff/2);
            }
            else
                System.out.println(diff);
        }
        else if(T.size() == 3){
            Object a[] = T.toArray();
            int diff1 = (int)a[2]-(int)a[1];
            int diff2 = (int)a[1]-(int)a[0];
            if(diff1 == diff2) System.out.println(diff1);
            else System.out.println(-1);
        }
    }
}

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

public class B552 {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        int [] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = sc.nextInt();
        int cur = a[0]; int ans = Integer.MAX_VALUE;
        ArrayList<Integer> pos = new ArrayList<>();
        boolean allSame = true;
        for (int i = 0; i < n; i++) {
            if (a[i] != cur) {
                allSame = false;
                pos.add(a[i]);
                pos.add(cur);
                if ((a[i] + cur) % 2 == 0) pos.add((a[i] + cur) / 2);
                break;
            }
        }
        for (Integer same: pos) {
            boolean ok = true;
            int d = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] == same) continue;
                if (d == 0) {
                    d = same - a[i];
                    continue;
                } else if (a[i] + d == same || a[i] - d == same) continue;
                ok = false;
            }
            if (ok) ans = Math.min(ans, Math.abs(d));
        }
        if (allSame) ans = 0;
        out.println(ans == Integer.MAX_VALUE ? -1 : ans);
        out.close();
    }

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
          Scanner sc=new Scanner(System.in);
          int n=sc.nextInt();
          if(n==1) {
        	  System.out.println("0");
        	  return;
          }
          int arr[]=new int [n];
          for(int i=0;i<arr.length;i++) {
        	  arr[i]=sc.nextInt();
          }
          HashSet<Integer> s=new HashSet<>();
          for(int i=0;i<arr.length;i++) {
        	  s.add(arr[i]);
          }
          if(s.size()==1) {
        	  System.out.println("0");
        	  return ;
          }
          if(s.size()>3) {
        	  System.out.println("-1");
    		  return;
          }
          if(s.size()==2) {
        	  int[] ar=new int [s.size()];
	          int j=0;
	          for(Integer i:s) {
	        	  ar[j]=i;
	        	  j++;
	          }
	        	 if((ar[1]+ar[0])%2==0) {
	        		 int b=(ar[1]+ar[0])/2;
	        		 System.out.println(Math.abs(ar[1]-b));
	        	 }else {

	        		 System.out.println(Math.abs(ar[1]-ar[0]));
	        	 }

          }
          if(s.size()==3) {
	          int[] ar=new int [s.size()];
	          int j=0;
	          for(Integer i:s) {
	        	  ar[j]=i;
	        	  j++;
	          }
	          Arrays.sort(ar);
	          int cha=ar[1]-ar[0];
	          for(int i=0;i<ar.length-1;i++) {
	        	  if(ar[i+1]-ar[i]!=cha) {
	        		  System.out.println("-1");
	        		  return;
	        	  }
	          }
	         System.out.println(cha);
          }

         }

	}

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.*;
import java.io.*;
public class Tree
{
    public static void main (String args[]) throws Exception
    {
        Scanner in =new Scanner(System.in);
        int N=in.nextInt();
        int a[] = new int[N];
        int max=-1;int min=101;
        for (int x=0;x<N;x++)
        {
            a[x]=in.nextInt();
            min=Math.min(min,a[x]);
            max=Math.max(max,a[x]);
        }
        if (min==max)
          System.out.println ("0");
          else
          {
            int k=0;int p=0;int w=0;int m=0;
            int K=Integer.MAX_VALUE;
            //System.out.println (K);
            for (int x=min;x<=max;x++)
            {
                p=0;k=Math.abs(x-a[0]);
                m=0;
                while (k==0)
                {
                    m++;
                    k=Math.abs(x-a[m]);
                }
                for (int y=m+1;y<N;y++)
                {
                    if (Math.abs(a[y]-x)==k || Math.abs(a[y]-x)==0)
                    continue;
                    else
                    {p=1;break;}
                }
                if (p==0)
                {K=Math.min(K,k);w=1;}
            }
            if (w==0)
            System.out.println ("-1");
            else
            System.out.println (K);
          }
    }
}

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

public class B {
	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();
		}

		ArrayList<Integer> elements = new ArrayList<Integer>();
		for(int i = 0; i < n; i++) {
			if(!elements.contains(a[i])) {
				elements.add(a[i]);
			}
		}
		Collections.sort(elements);
		int ans = -1;
		if(elements.size() == 3) {
			if(elements.get(2) - elements.get(1) == elements.get(1) - elements.get(0)) {
				ans = elements.get(2) - elements.get(1);
			} else {
				ans = -1;
			}
		} else if(elements.size() == 2) {
			if((elements.get(1) - elements.get(0)) % 2 == 0) {
				ans = (elements.get(1) - elements.get(0)) / 2;
			} else {
				ans = (elements.get(1) - elements.get(0));
			}
		} else if(elements.size() == 1) {
			ans = 0;
		} else {
			ans = -1;
		}
		System.out.println(ans);
	}
}

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

public class ReturningArraywithoutDuplicates {

	public static int[] takeInput()
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=in.nextInt();
		}
		return arr;
	}
	public static int [] NonDuplicates(int arr[])
	{
		int t=0;
		for(int i=0;i<arr.length-1;i++)
		{
			if(arr[i]!=-1)
			{
				for(int j=i+1;j<arr.length;j++)
				{
					if(arr[i]==arr[j])
					{
						arr[j]=-1;
						t=t+1;
					}
				}

			}
		}
		int temp[]=new int[arr.length-t];
		int k=0;
		for(int i=0;i<arr.length;i++)
		{
			if(arr[i]!=-1)
			{
				temp[k]=arr[i];
				k++;
			}
		}
		return temp;
	}

	public static void main(String[] args) {
		int arr1[]=takeInput();
		int arr[]=NonDuplicates(arr1);
	    Arrays.sort(arr);
		if(arr.length>3)
		{
			System.out.println("-1");
		}
		else if(arr.length==2 ||arr.length==3)
		{
			if(arr.length==3)
			{
				if(arr[1]-arr[0]==arr[2]-arr[1])
				{
					System.out.println(arr[2]-arr[1]);
				}
				else
					System.out.println("-1");
			}
			else
			{
				if((arr[1]-arr[0])%2==0)
				{
					System.out.println((arr[1]-arr[0])/2);
				}
				else
					System.out.println((arr[1]-arr[0]));
			}

		}
		else
			System.out.println("0");

	}
}

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

public class p2{
    public static void main(String args[]) throws IOException{
       // Scanner sc = new Scanner(System.in);
	   Reader r = new Reader();
	   float n = r.nextInt();
	   HashSet<Float> hs = new HashSet<>();
	   ArrayList<Float> al = new ArrayList<>();

	   while(n-->0){
		   float a  = r.nextInt();
		   if(!hs.contains(a))
		   	al.add(a);
		   hs.add(a);
	   }
	   if(hs.size() > 3){
		   System.out.println("-1");
		   return;
	   }

	   if(al.size() == 1){
		   System.out.println(0);
		   return;
	   }

	   if(al.size() == 2){
		   float mid = Math.abs(al.get(0) - al.get(1));
		   if(mid % 2 != 0){
			System.out.println((int)mid);
			return;
		   }
		   else{
			System.out.println((int)(mid/2));
			return;
		   }
	   }else{
		   Collections.sort(al);
		   float mid = Math.abs(al.get(0) - al.get(2));
		   if(mid % 2 != 0 || mid/2 + al.get(0) != al.get(1)){
			System.out.println("-1");
			return;
		   }
		   else{
			System.out.println((int)(mid/2));
			return;
		   }
	   }

    }
}

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();
		}
	}

// Working program using Reader Class
import java.io.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main
{
	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();
		}
	}

	public static int gcd(int a, int b)
    {
        // Everything divides 0
        if (a == 0 || b == 0)
           return 0;

        // base case
        if (a == b)
            return a;

        // a is greater
        if (a > b)
            return gcd(a-b, b);
        return gcd(a, b-a);
    }

	public static long change(char c,char d,long A,long B,long C) {
		if(c==d) {
			return 0;
		}
		else if((c=='1' && d=='3') || (c=='3' && d=='1')) {
			return C;
		}
		else if((c=='1' && d=='2') || (c=='2' && d=='1')) {
			return A;
		}
		else {
			return B;
		}
	}

	public static void main(String[] args) throws IOException
	{
		//Reader scan=new Reader();
		Scanner scan=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=scan.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		Arrays.sort(a);
		int ans=Integer.MAX_VALUE;
		for(int i=a[0];i<=a[n-1];i++) {
			int d=0;
			int done=0;
			for(int j=0;j<n;j++) {
				if(a[j]!=i) {
					if(d==0) {
						d=Math.abs(a[j]-i);
					}
					else {
						if(a[j]+d!=i && a[j]-d!=i) {
							done=1;
							break;
						}
					}
				}
			}
			if(done==0) {
				ans=Math.min(ans, d);
			}
		}
		if(ans==Integer.MAX_VALUE) {
			out.print(-1);
		}
		else {
			out.print(ans);
		}
		out.close();
	}
}

import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class B {

    public static void main(String[] args) throws Exception {
        FastScanner scanner = new FastScanner();
        int n = scanner.nextInt();
        ArrayList<Integer> a = scanner.nextIntegerArrayList();
        Collections.sort(a);
        int step = 0;
        int target = 0;
        int i;

        for (i = 0; i < a.size() - 1; i++) {
            if (a.get(i) < a.get(i + 1)) {
                step = a.get(i + 1) - a.get(i);
                target = a.get(i + 1);
                break;
            }
        }
        if (step == 0) {
            System.out.println(step);
            System.exit(0);
        }

        boolean error1 = false;
        for (int j = i + 1; j < a.size(); j++) {
            if (a.get(j) != target && a.get(j) != target + step) {
                error1 = true;
                break;
            }
        }

        boolean error2 = false;
        if (error1 && step % 2 != 0)
            error2 = true;
        if (step % 2 == 0) {
            step /= 2;
            target -= step;
            for (int j = i + 1; j < a.size(); j++) {
                if (a.get(j) != target && a.get(j) != target + step) {
                    error2 = true;
                }
            }
        }
        if (error2)
            step *= 2;
        if (!(error1 && error2))
            System.out.println(step);
        else
            System.out.println(-1);

    }

    private static class FastScanner {
        private BufferedReader br;

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

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

        public ArrayList<Integer> nextIntegerArrayList() throws IOException {
            String line = br.readLine();
            String[] strings = line.trim().split("\\s+");
            ArrayList<Integer> array = new ArrayList<Integer>();
            for (int i = 0; i < strings.length; i++)
                array.add(Integer.parseInt(strings[i]));
            return array;
        }
    }
}

import java.util.*;
import java.util.stream.Collectors;

import static java.lang.Math.*;

public class Main {

    public static void main(String[] args) {
        new Solution().solve();
    }
}

class Solution {
    void solve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> temp = new ArrayList<>();
        for (int i = 0; i < n; i++)
            temp.add(sc.nextInt());
        List<Integer> list = temp.stream().distinct().collect(Collectors.toList());
        int D = -1;
        for (int i = 0; i <= 100; i++) {
            int d = -1;
            boolean fail = false;
            for (int e : list) {
                if (i == e) { if (d < 1) d = 0; }
                else if (d == -1 || d == 0) d = abs(i - e);
                else if (e + d != i && e - d != i) {
                    fail = true;
                    break;
                }
            }
            if (!fail) {
                assert d != -1;
                if (D == -1) D = d;
                else D = min(d, D);
            }
        }
        System.out.println(D);
    }
}

//package com.karancp;
import java.io.*;
import java.util.*;

public class Solution {
    public static void main(String args[])
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader z = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        task solver =new task();
        solver.solve(z,out);
        out.close();
    }
    static class task {

        public static void solve(InputReader z, PrintWriter out) {
            int n = z.nextInt();
            int ar[] = new int[n];
            int min=Integer.MAX_VALUE;
            int i;
            for(i=0;i<n;i++)ar[i]=z.nextInt();
            int d;
            HashSet<Integer> set=new HashSet<>();
            for(d=0;d<=10000;d++)
            {
                if(d%n==0) {
                    int a=d/n;
                    int di=0;
                    for (i = 0; i < n; i++) {
                        int p = Math.abs(ar[i]-a);
                        if(p!=0)
                        {
                            set.add(p);
                            di=p;
                        }
                    }
                    if(set.size()==1||set.size()==0)
                    {
                        if(min>di)min=di;
                    }

                    set.clear();
                }
            }
            if(min!=Integer.MAX_VALUE)out.println(min);
            else out.println("-1");
        }
    }

    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.util.ArrayList;
import java.util.Scanner;

public class JavaApplication66 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        int x;
        for (int i = 0; i < n; i++) {
            x = input.nextInt();
            if (!a.contains(x)) {
                a.add(x);
            }
            if (a.size() > 3) {
                System.out.println("-1");
                break;
            }
        }
        if (a.size() <= 3) {
            int max = max(a);
            int min = min(a);
            int r = (max - min) / 2;
            if (a.size() == 3) {
                if((max+min)%2==0){
                if (a.contains(max-r)) {
                    System.out.println(r);
                } else {
                    System.out.println("-1");
                }
                }else
                    System.out.println("-1");
            } else if(a.size()==2){
                if((max+min)%2==0)
                    System.out.println(r);
                else
                    System.out.println(max-min);
            }else
                System.out.println("0");
        }

    }

    public static int max(ArrayList<Integer> a) {
        int max = a.get(0);
        for (int i = 1; i < a.size(); i++) {
            if (a.get(i) > max) {
                max = a.get(i);
            }
        }
        return max;
    }

    public static int min(ArrayList<Integer> a) {
        int min = a.get(0);
        for (int i = 1; i < a.size(); i++) {
            if (a.get(i) < min) {
                min = a.get(i);
            }
        }
        return min;
    }

}

import java.util.*;

public class Main {

	static int Maxn=105;

	public static void main(String arg[]){

		Set<Integer>s=new TreeSet<>();
		Scanner cin=new Scanner(System.in);
		int n=cin.nextInt();
		int a[]=new int[n];

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

		if(s.size()==1){
			System.out.println(0);
		}else if(s.size()==2){

			Arrays.sort(a);

			int tt=a[n-1]-a[0];
			if(tt%2==0)System.out.println(tt/2);
			else System.out.println(tt);

		}else if(s.size()==3){
			int b[]=new int[Maxn];
			int cnt=0;
			for(Integer value:s){
				b[cnt++]=value;
			}

			int temp=b[1]-b[0];
			int flag=0;
			for(int i=1;i<cnt-1;i++){
				if(b[i+1]-b[i]!=temp){
					flag=1;
					break;
				}
			}
			if(flag==1){
				System.out.println(-1);
			}else{
				System.out.println(temp);

			}
		}else{
			System.out.println(-1);
		}
		cin.close();
	}

}

//comment the next imports before submitting
import java.io.File;
import java.io.PrintStream;
//imports to be deleted ends here

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

//Problem URL here

public class MakeThemEqual1154B {

    public static void solve(int[] arr, int n) {
        HashSet<Integer> set = new HashSet<>();
        for (int i : arr) {
            set.add(i);
        }
        if (set.size() > 3) {
            System.out.println(-1);
            return;
        }

        if (set.size() == 3) {
            PriorityQueue<Integer> heap = new PriorityQueue<>(set);
            int a = heap.remove();
            int b = heap.remove();
            int c = heap.remove();

            if ((b - a) == (c - b)) {
                System.out.println(b - a);
                return;
            } else {
                System.out.println(-1);
                return;
            }
        }

        if (set.size() == 2) {
            int d = 0;
            for (Integer integer : set) {
                d = integer - d;
            }

            d = Math.abs(d);

            System.out.println((d % 2 == 0) ? d / 2 : d);
            return;
        }

        if (set.size() == 1) {
            System.out.println(0);
            return;
        }
    }

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

        FastReader reader = new FastReader();

        // int t = reader.nextInt();
        // while (t-- > 0) {
        int n = reader.nextInt();

        int arr[] = new int[n];

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

        // Arrays.sort(arr, new Comparator<Integer>() {
        // public int compare(Integer i1, Integer i2) {
        // return i1.intValue() - i2.intValue();
        // }
        // });

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

        solve(arr, n);
        // }

    }

    private static void sieveOfEratosthenes(boolean[] arr, int len) {
        for (int j = 2; j * j <= len; j++) {
            if (arr[j]) {
                for (int k = 2; k * j < len; k++) {
                    arr[k * j] = false;
                }
            }
        }
    }

    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;
        }
    }

}

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

public class Main {

    public static void main(String[] args) throws IOException {
        // write your code here
        BufferedReader reader  = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        String[] inp = reader.readLine().split(" ");
        int a[] = new int[101];
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int c =0;
        for (String anInp : inp) {
            int num = Integer.parseInt(anInp);
            if (a[num] == 0) {
                a[num] = 1;
                c++;
            }
            if (num > max) {
                max = num;
            }
            if (num < min) {
                min = num;
            }
        }

        if(c==2){
            if(Math.ceil(((double) max - (double) min)/2)==(max - min)/2){
                System.out.println((max - min)/2);
            } else {
                System.out.println(max-min);
            }
        } else if(a[min + (max - min)/2] ==1 && Math.ceil(((double) max - (double) min)/2)==(max - min)/2 && c<=3){
            System.out.println((max - min)/2);
        } else {
            System.out.println(-1);
        }

    }
}

import java.util.*;
public class equal {
public static int[] turn(int x , int[]y) {
	for(int i=0;i<y.length;i++) {
		if(y[i]==x)
			y[i]=-1;
	}
return y;
}
public static int[] different (int []x) {
	int []y=new int[3];
	int []f= {-1,-1};
	int g=0;
	for(int i=0;i<x.length;i++) {
		for(int j=0;j<x.length;j++) {
			if(x[i]!=x[j]&x[i]!=-1) {
				if(g<3) {
				y[g]=x[i];
				turn(x[i],x);
				}
				g++;
			}
			if(g>3)
				return f;
		}
	}
Arrays.sort(y);
return y;
}
public static int[] onlytwo(int[]x) {
	int g[]=new int [2];
	Arrays.sort(x);
	if(x[0]==0) {
		g[0]=x[1];
		g[1]=x[2];
		return g;
	}
	else
		return x;

}
public static String ToString (int []x) {
	String s="";
	for(int i=0;i<x.length;i++) {
		s=s+x[i]+" ";
	}
return s;
}
public static void main (String []args) {
	Scanner a=new Scanner(System.in);
	Scanner b=new Scanner(System.in);
	int g=0;
	int[]f= {-1,-1};
	int[]y=new int [1];
	y[0]=a.nextInt();
	int []x=new int[y[0]];
	int r=0;
	for(int i=0;i<y[0];i++) {
		x[i]=a.nextInt();
	}
x=onlytwo(different(x));
//System.out.println(ToString(x));
if((x[0]==f[0]))
	System.out.println(-1);
else {
if(x.length==3) {
	r=(x[2]-x[0])/2;
	if(x[0]+r==x[1]&x[2]-r==x[1])
		System.out.println(r);
	else
		System.out.println(-1);
}
	else {
	g=(x[1]-x[0])/2;
	r=(x[1]-x[0]);
	if(x[0]+g==x[1]-g)
		System.out.println(g);
	else
		System.out.println(r);
	}
}
}
}

import java.io.*;

import java.util.*;

public class Main {
    static  OutputWriter out;
    public static void main(String[] args) throws Exception
    {
        Scanner in = new Scanner(System.in);
        out = new OutputWriter(System.out);
          int n =in.nextInt();
          int[]a = new int[n];
          for (int i =0;i<n;i++)
              a[i]=in.nextInt();
          int diff = 0;
          Arrays.sort(a);
          for (int i =1;i<n;i++)
          {
              if (Math.abs(a[i]-a[i-1])!=0)
              {
                  diff = Math.abs(a[i]-a[i-1]);
                  break;
              }
          }
          boolean check = true;
          for (int i =2;i<n;i++)
          {
              if (Math.abs(a[i]-a[i-1])!=diff&&Math.abs(a[i]-a[i-1])!=0)
              {
                  check=false;
                  break;
              }
          }
        Set<Integer> s = new HashSet<>();
        for (int i =0;i<n;i++)
            s.add(a[i]);
        if (s.size()>3)
            check=false;
          if (!check)
              out.printLine(-1);
          else
          {

              if (diff%2==0&&s.size()<3)
                  out.printLine(diff/2);
              else
                  out.printLine(diff);
          }
        out.flush();
    }

}

class Graph {

    int n;
    ArrayList<Integer>[] adjList;

    public Graph(int n) {
        this.n = n;
        adjList = new ArrayList[n];
        for (int i = 0; i < n; i++)
            adjList[i] = new ArrayList<>();
    }

}
class pair  implements Comparable
{

    int key;
    int value;

    public pair(Object key, Object value) {

        this.key = (int)key;
        this.value=(int)value;

    }

    @Override
    public int compareTo(Object o) {
        pair temp =(pair)o;
        return  key-temp.key;
    }
}
class Scanner {

    StringTokenizer st;
    BufferedReader br;

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

    public Scanner (FileReader f) {
        br = new BufferedReader(f);
    }

    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());
    }

    public String nextLine() throws IOException {
        return br.readLine();
    }

    public double nextDouble() throws IOException {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if (x.charAt(0) == '-') {
            neg = true;
            start++;
        }
        for (int i = start; i < x.length(); i++)
            if (x.charAt(i) == '.') {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            } else {
                sb.append(x.charAt(i));
                if (dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg ? -1 : 1);
    }

    public boolean ready() throws IOException {
        return br.ready();
    }

    public boolean nextEmpty() throws IOException {
        String s = nextLine();
        st = new StringTokenizer(s);
        return s.isEmpty();
    }
}
class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

    public void flush() {
        writer.flush();
    }

}

import java.util.*;
import java.io.*;
public class equal{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] s = br.readLine().trim().split(" ");
		int[] nums = new int[n];
		for(int i=0;i<n;i++) nums[i] = Integer.parseInt(s[i]);
		Set<Integer> set = new TreeSet<>();
		for(int i=0;i<n;i++){
			set.add(nums[i]);
		}
		//System.out.print(set.size());
		int d =0;
		if(set.size()==2){
			int a=0,b=0,i=0,ans= 101;
			for(int key : set) {
				if(i==0) a= key;
				else b =key;
				i++;
			}
			if((b-a) == 2 *((b-a)/2)) ans = (b-a)/2;

			d = Math.min(Math.abs(a-b),ans);
		}
		else if(set.size()>3) d = -1;
		else if(set.size()==3){
			int a = 0,b=0,c=0,i=0;
			for(int key:set){
				if(i==0) a= key;
				else if(i==1) b= key;
				else c = key;
				i++;
			}
			i =0;

			if((c+a) == 2 *((c+a)/2)) i =(c+a)/2;
			//System.out.println(i);
			if(i==b) d = (c-a)/2;
			else d = -1;

		}
		System.out.println(d);

	}
}

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

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

            int n = Integer.parseInt(st.nextToken());
            HashSet<Integer> set = new HashSet<>();

            int ans = -1;
            int max = 0, min = Integer.MAX_VALUE;
            st = new StringTokenizer(br.readLine());
            for(int i=0; i<n; i++)
            {
                int num = Integer.parseInt(st.nextToken());
                set.add(num);

                max = Math.max(num,max);
                min = Math.min(num,min);
            }

            if(set.size() == 3 && (min+max) %2 == 0 && set.contains((min+max)/2)) ans = (min+max)/2 - min;
            else if(set.size() == 2)
            {
                if(min %2 == max %2) ans = (min+max)/2 - min;
                else ans = max - min;
            }
            else if(set.size() == 1) ans = 0;

            System.out.println(ans);
      }
}

/*
    Author: Anthony Ngene
    Created: 26/09/2020 - 05:11
*/

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

public class B {
// checks: 1. edge cases   2. overflow   3. possible errors (e.g 1/0, arr[out])   4. time/space complexity
    void solver() throws IOException {
        int n = in.intNext();
        int[] arr = in.nextIntArray(n);
        u.sort(arr);
        int chosen = -1;
        int diff = arr[n - 1] - arr[0];
        if (diff % 2 == 0) chosen = choose(arr[0] + diff/2, diff/2, arr);
        else chosen = choose(arr[0] + diff, diff, arr);
        out.println(chosen);

    }

    int choose(int target, int diff, int[] arr) {
        for (int num : arr) {
            if ((num < target && num + diff != target) || (num > target && num - diff != target)) return -1;
        }
        return diff;
    }

// Generated Code Below:
private static final FastWriter out = new FastWriter();
private static FastScanner in;
static ArrayList<Integer>[] adj;
private static long e97 = (long)1e9 + 7;
public static void main(String[] args) throws IOException {
    in = new FastScanner();
    new B().solver();
    out.close();
}

static class FastWriter {
    private static final int IO_BUFFERS = 128 * 1024;
    private final StringBuilder out;
    public FastWriter() { out = new StringBuilder(IO_BUFFERS); }
    public FastWriter p(Object object) { out.append(object); return this; }
    public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }
    public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public FastWriter pp(int[] args) { for (int ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public FastWriter pp(long[] args) { for (long ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public FastWriter pp(char[] args) { for (char ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public void println(long[] arr) { for(long e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(int[] arr) { for(int e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(char[] arr) { for(char e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(double[] arr) { for(double e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(boolean[] arr) { for(boolean e: arr) out.append(e).append(" "); out.append("\n"); }
    public <T>void println(T[] arr) { for(T e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(long[][] arr) {  for (long[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public void println(int[][] arr) {  for (int[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public void println(char[][] arr) {  for (char[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public void println(double[][] arr) {  for (double[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public <T>void println(T[][] arr) {  for (T[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public FastWriter println(Object object) { out.append(object).append("\n"); return this; }
    public void toFile(String fileName) throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
        writer.write(out.toString());
        writer.close();
    }
    public void close() throws IOException { System.out.print(out); }
}
static class FastScanner {
    private InputStream sin = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(){}
    public FastScanner(String filename) throws FileNotFoundException {
        File file = new File(filename);
        sin = new FileInputStream(file);
    }
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = sin.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long longNext() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int intNext() {
        long nl = longNext();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double doubleNext() { return Double.parseDouble(next());}
    public long[] nextLongArray(final int n){
        final long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = longNext();
        return a;
    }
    public int[] nextIntArray(final int n){
        final int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = intNext();
        return a;
    }
    public double[] nextDoubleArray(final int n){
        final double[] a = new double[n];
        for (int i = 0; i < n; i++)
            a[i] = doubleNext();
        return a;
    }
    public ArrayList<Integer>[] getAdj(int n) {
        ArrayList<Integer>[] adj = new ArrayList[n + 1];
        for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
        return adj;
    }
    public ArrayList<Integer>[] adjacencyList(int nodes, int edges) throws IOException {
        return adjacencyList(nodes, edges, false);
    }
    public ArrayList<Integer>[] adjacencyList(int nodes, int edges, boolean isDirected) throws IOException {
        adj = getAdj(nodes);
        for (int i = 0; i < edges; i++) {
            int a = intNext(), b = intNext();
            adj[a].add(b);
            if (!isDirected) adj[b].add(a);
        }
        return adj;
    }
}
static class u {
    public static int upperBound(long[] array, long obj) {
        int l = 0, r = array.length - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj < array[c]) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }
    public static int upperBound(ArrayList<Long> array, long obj) {
        int l = 0, r = array.size() - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj < array.get(c)) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }
    public static int lowerBound(long[] array, long obj) {
        int l = 0, r = array.length - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj <= array[c]) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }
    public static int lowerBound(ArrayList<Long> array, long obj) {
        int l = 0, r = array.size() - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj <= array.get(c)) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }
    static <T> T[][] deepCopy(T[][] matrix) { return Arrays.stream(matrix).map(el -> el.clone()).toArray($ -> matrix.clone()); }
    static int[][] deepCopy(int[][] matrix) { return Arrays.stream(matrix).map(int[]::clone).toArray($ -> matrix.clone()); }
    static long[][] deepCopy(long[][] matrix) { return Arrays.stream(matrix).map(long[]::clone).toArray($ -> matrix.clone()); }
    private static void sort(int[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }
    private static void sort(long[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }
    private static <T>void rSort(T[] arr) { Arrays.sort(arr, Collections.reverseOrder()); }
    private static void customSort(int[][] arr) {
        Arrays.sort(arr, new Comparator<int[]>() {
            public int compare(int[] a, int[] b) {
                if (a[0] == b[0]) return Integer.compare(a[1], b[1]);
                return Integer.compare(a[0], b[0]);
            }
        });
    }
    public static int[] swap(int[] arr, int left, int right) {
        int temp = arr[left];
        arr[left] = arr[right];
        arr[right] = temp;
        return arr;
    }
    public static char[] swap(char[] arr, int left, int right) {
        char temp = arr[left];
        arr[left] = arr[right];
        arr[right] = temp;
        return arr;
    }
    public static int[] reverse(int[] arr, int left, int right) {
        while (left < right) {
            int temp = arr[left];
            arr[left++] = arr[right];
            arr[right--] = temp;
        }
        return arr;
    }
    public static boolean findNextPermutation(int[] data) {
        if (data.length <= 1) return false;
        int last = data.length - 2;
        while (last >= 0) {
            if (data[last] < data[last + 1]) break;
            last--;
        }
        if (last < 0) return false;
        int nextGreater = data.length - 1;
        for (int i = data.length - 1; i > last; i--) {
            if (data[i] > data[last]) {
                nextGreater = i;
                break;
            }
        }
        data = swap(data, nextGreater, last);
        data = reverse(data, last + 1, data.length - 1);
        return true;
    }
    public static int biSearch(int[] dt, int target){
        int left=0, right=dt.length-1;
        int mid=-1;
        while(left<=right){
            mid = (right+left)/2;
            if(dt[mid] == target) return mid;
            if(dt[mid] < target) left=mid+1;
            else right=mid-1;
        }
        return -1;
    }
    public static int biSearchMax(long[] dt, long target){
        int left=-1, right=dt.length;
        int mid=-1;

        while((right-left)>1){
            mid = left + (right-left)/2;
            if(dt[mid] <= target) left=mid;
            else right=mid;
        }
        return left;
    }
    public static int biSearchMaxAL(ArrayList<Integer> dt, long target){
        int left=-1, right=dt.size();
        int mid=-1;

        while((right-left)>1){
            mid = left + (right-left)/2;
            if(dt.get(mid) <= target) left=mid;
            else right=mid;
        }
        return left;
    }
    private static <T>void fill(T[][] ob, T res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(boolean[][] ob,boolean res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(int[][] ob, int res){      for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(long[][] ob, long res){    for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(char[][] ob, char res){    for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(double[][] ob, double res){for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(int[][][] ob,int res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
    private static void fill(long[][][] ob,long res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
    private static <T>void fill(T[][][] ob,T res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
    private static void fill_parent(int[] ob){ for(int i=0; i<ob.length; i++) ob[i]=i; }
    private static boolean same3(long a, long b, long c){
        if(a!=b) return false;
        if(b!=c) return false;
        if(c!=a) return false;
        return true;
    }
    private static boolean dif3(long a, long b, long c){
        if(a==b) return false;
        if(b==c) return false;
        if(c==a) return false;
        return true;
    }
    private static double hypotenuse(double a, double b){
        return Math.sqrt(a*a+b*b);
    }
    private static long factorial(int n) {
        long ans=1;
        for(long i=n; i>0; i--){ ans*=i; }
        return ans;
    }
    private static long facMod(int n, long mod) {
        long ans=1;
        for(long i=n; i>0; i--) ans = (ans * i) % mod;
        return ans;
    }
    private static long lcm(long m, long n){
        long ans = m/gcd(m,n);
        ans *= n;
        return ans;
    }
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    private static boolean isPrime(long a){
        if(a==1) return false;
        for(int i=2; i<=Math.sqrt(a); i++){  if(a%i == 0) return false;  }
        return true;
    }
    static long modInverse(long a, long mod) {
    /* Fermat's little theorem: a^(MOD-1) => 1
    Therefore (divide both sides by a): a^(MOD-2) => a^(-1) */
        return binpowMod(a, mod - 2, mod);
    }
    static long binpowMod(long a, long b, long mod) {
        long res = 1;
        while (b > 0) {
            if (b % 2 == 1) res = (res * a) % mod;
            a = (a * a) % mod;
            b /= 2;
        }
        return res;
    }
    private static int getDigit2(long num){
        long cf = 1;    int d=0;
        while(num >= cf){   d++;    cf = 1<<d;  }
        return d;
    }
    private static int getDigit10(long num){
        long cf = 1;    int d=0;
        while(num >= cf){   d++;    cf*=10;     }
        return d;
    }
    private static boolean isInArea(int y, int x, int h, int w){
        if(y<0) return false;
        if(x<0) return false;
        if(y>=h) return false;
        if(x>=w) return false;
        return true;
    }
    private static ArrayList<Integer> generatePrimes(int n) {
        int[] lp = new int[n + 1];
        ArrayList<Integer> pr = new ArrayList<>();
        for (int i = 2; i <= n; ++i) {
            if (lp[i] == 0) {
                lp[i] = i;
                pr.add(i);
            }
            for (int j = 0; j < pr.size() && pr.get(j) <= lp[i] && i * pr.get(j) <= n; ++j) {
                lp[i * pr.get(j)] = pr.get(j);
            }
        }
        return pr;
    }
    static long nPrMod(int n, int r, long MOD) {
        long res = 1;
        for (int i = (n - r + 1); i <= n; i++) {
            res = (res * i) % MOD;
        }
        return res;
    }
    static long nCr(int n, int r) {
        if (r > (n - r))
            r = n - r;
        long ans = 1;
        for (int i = 1; i <= r; i++) {
            ans *= n;
            ans /= i;
            n--;
        }
        return ans;
    }
    static long nCrMod(int n, int r, long MOD) {
        long rFactorial = nPrMod(r, r, MOD);
        long first = nPrMod(n, r, MOD);
        long second = binpowMod(rFactorial, MOD-2, MOD);
        return  (first * second) % MOD;
    }
    static void printBitRepr(int n) {
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < 32; i++) {
            int mask = (1 << i);
            res.append((mask & n) == 0 ? "0" : "1");
        }
        out.println(res);
    }
    static String bitString(int n) {return Integer.toBinaryString(n);}
    static int setKthBitToOne(int n, int k) { return (n | (1 << k)); } // zero indexed
    static int setKthBitToZero(int n, int k) { return (n & ~(1 << k)); }
    static int invertKthBit(int n, int k) { return (n ^ (1 << k)); }
    static boolean isPowerOfTwo(int n) { return (n & (n - 1)) == 0; }
    static HashMap<Character, Integer> counts(String word) {
        HashMap<Character, Integer> counts = new HashMap<>();
        for (int i = 0; i < word.length(); i++) counts.merge(word.charAt(i), 1, Integer::sum);
        return counts;
    }
    static HashMap<Integer, Integer> counts(int[] arr) {
        HashMap<Integer, Integer> counts = new HashMap<>();
        for (int value : arr) counts.merge(value, 1, Integer::sum);
        return counts;
    }
    static HashMap<Long, Integer> counts(long[] arr) {
        HashMap<Long, Integer> counts = new HashMap<>();
        for (long l : arr) counts.merge(l, 1, Integer::sum);
        return counts;
    }
    static HashMap<Character, Integer> counts(char[] arr) {
        HashMap<Character, Integer> counts = new HashMap<>();
        for (char c : arr) counts.merge(c, 1, Integer::sum);
        return counts;
    }
    static long hash(int x, int y) {
        return x* 1_000_000_000L +y;
    }
    static final Random random = new Random();
    static void sort(int[] a) {
        int n = a.length;// shuffle, then sort
        for (int i = 0; i < n; i++) {
            int oi = random.nextInt(n), temp = a[oi];
            a[oi] = a[i];
            a[i] = temp;
        }
        Arrays.sort(a);
    }
    static void sort(long[] arr) {
        shuffleArray(arr);
        Arrays.sort(arr);
    }
    static void shuffleArray(long[] arr) {
        int n = arr.length;
        for(int i=0; i<n; ++i){
            long tmp = arr[i];
            int randomPos = i + random.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }
    }
}
static class Tuple implements Comparable<Tuple> {
    int a;
    int b;
    int c;
    public Tuple(int a, int b) {
        this.a = a;
        this.b = b;
        this.c = 0;
    }
    public Tuple(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }
    public int getA() { return a; }
    public int getB() { return b; }
    public int getC() { return c; }
    public int compareTo(Tuple other) {
        if (this.a == other.a) {
            if (this.b == other.b) return Long.compare(this.c, other.c);
            return Long.compare(this.b, other.b);
        }
        return Long.compare(this.a, other.a);
    }
    @Override
    public int hashCode() { return Arrays.deepHashCode(new Integer[]{a, b, c}); }
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Tuple)) return false;
        Tuple pairo = (Tuple) o;
        return (this.a == pairo.a && this.b == pairo.b && this.c == pairo.c);
    }
    @Override
    public String toString() { return String.format("(%d %d %d)  ", this.a, this.b, this.c); }
}
private static int abs(int a){  return (a>=0) ? a: -a;  }
private static int min(int... ins){ int min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static int max(int... ins){ int max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static int sum(int... ins){ int total = 0; for (int v : ins) { total += v; } return total; }
private static long abs(long a){    return (a>=0) ? a: -a;  }
private static long min(long... ins){ long min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static long max(long... ins){ long max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static long sum(long... ins){ long total = 0; for (long v : ins) { total += v; } return total; }
private static double abs(double a){    return (a>=0) ? a: -a;  }
private static double min(double... ins){ double min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static double max(double... ins){ double max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static double sum(double... ins){ double total = 0; for (double v : ins) { total += v; } return total; }

}

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

public class Main {

    public static void main(String[] args) {
        FastReader f = new FastReader();

        int n = f.nextInt();

        int[] arr = new int[3];

        while (n-- > 0) {
            int loc = f.nextInt();

            if(arr[0] == 0 || arr[0] == loc) {
                arr[0] = loc;
            } else if(arr[1] == 0 || arr[1] == loc) {
                arr[1] = loc;
            } else if(arr[2] == 0 || arr[2] == loc) {
                arr[2] = loc;
            } else {
                System.out.println(-1);
                return;
            }
        }

        int cnt = 0;
        for(int i : arr) {
            if(i != 0) {
                cnt++;
            }
        }

        //System.out.println(cnt);
        if(cnt == 1) {
            System.out.println(0);
            return;
        }

        if(cnt == 2) {
            if(arr[0] % 2 == arr[1] % 2) {
                System.out.println(Math.abs(arr[0]-arr[1])/2);
            } else {
                System.out.println(Math.abs(arr[0]-arr[1]));
            }
            return;
        }

        Arrays.sort(arr);

        if(arr[1] - arr[0] != arr[2] - arr[1]) {
            System.out.println(-1);
            return;
        }

        System.out.println(arr[1] - arr[0]);

    }

    //fast input reader
    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;
        }
    }
}

import java.util.*;
import java.io.*;
public class Main
{
    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();
        }
    }
    public static long gcd(long a,long b)
    {
        if(b%a==0)
        return a;
        return gcd(b%a,a);
    }
    public static void main(String args[])throws Exception
    {
        //Reader sc=new Reader();
        Scanner sc=new Scanner(System.in);
        PrintWriter pw=new PrintWriter(System.out);
        int t=1;//sc.nextInt();
        while(t-->0)
        {
            int n=sc.nextInt();
            TreeSet<Integer> ts=new TreeSet<>();
            for(int i=0;i<n;i++)
            ts.add(sc.nextInt());
            if(ts.size()==1)
            pw.println(0);
            else if(ts.size()==2)
            {
                int a=ts.pollFirst();
                int b=ts.pollFirst();
                if((b-a)%2!=0)
                pw.println(b-a);
                else
                pw.println((b-a)/2);
            }
            else if(ts.size()==3)
            {
                int arr[]=new int[ts.size()];
                int in=-1;
                while(ts.size()>0)
                arr[++in]=ts.pollFirst();
                for(int i=1;i<=in;i++)
                ts.add(arr[i]-arr[i-1]);
                if(ts.size()==1)
                pw.println(ts.pollFirst());
                else
                pw.println(-1);
            }
            else
            pw.println(-1);
        }
        pw.flush();
        pw.close();
    }
}

import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		    int n = sc.nextInt();
		    long a[] = new long[n];
		    long b[] = new long[3];
		    b[0] = -1;
		    b[1] = -1;
		    b[2] = -1;
		    int cnt = 0;
		    for(int i=0;i<n;i++){
		        a[i] = sc.nextLong();
		        if(cnt==0){
		            b[cnt] = a[i];
    		        cnt++;
		        }
		        if(b[0]!=a[i] && cnt==1){
		            b[cnt] = a[i];
		            cnt++;
		        }
		        if(b[0]!=a[i] && b[1]!=a[i] && cnt==2){
		            b[cnt] = a[i];
		            cnt++;
		        }
                if(cnt==3 && a[i]!=b[0] && a[i]!=b[1] && a[i]!=b[2]){
		            cnt++;
		        }
		    }
		    if(cnt>3){
		        System.out.println(-1);
            }
		    else{
		        Arrays.sort(b);
		        if(cnt==1){
		            System.out.println(0);
		        }
		        else if(cnt==2){
		            if((b[2]-b[1])%2==0){
		                System.out.println((b[2]-b[1])/2);
		            }
		            else{
		                System.out.println(b[2]-b[1]);
		            }

		        }
		        else if(cnt==3 && ((b[1]-b[0])==(b[2]-b[1]))){
		            System.out.println(b[2]-b[1]);
		        }
		        else{
		            System.out.println(-1);
		        }
		    }

	}
}

//package equal;
import java.util.*;
public class Main {

    public static void main(String[] args)
    {
        Scanner ab=new Scanner(System.in);
        int x=ab.nextInt();
        int k[]=new int [x];
        int i[]=new int[x];
      int max=0;
        for(int y=0;y<x;y++)
        {
            k[y]=ab.nextInt();
            i[y]=k[y];
            if(k[y]>max)
            max=k[y];

        }
        if(x==1)
{
    System.out.println("0");

}
else
{

        int min=k[0];
        for(int q=0;q<x;q++)
        {
            if(k[q]<min)
            {
                min=k[q];
            }
        }
        int mid=0;
        int p=0;
        for(int b=0;b<x;b++)
        {
            if(k[b]>min&&k[b]<max)
            {
                mid=k[b];
                p++;
                break;

            }
        }

        int sum=0,sum2=0;
        if(p>0)
        {
        for(int g=0;g<x;g++)
        {
            if(k[g]==mid)
                continue;
            else if(k[g]>mid&&k[g]==max)
            {
                for(int h=1;;h++)
                {
                    if(k[g]==mid)
                    {
                        break;
                    }
                        else
                        {
                        k[g]--;
                        sum=h;

                         }

                }
            }
            else if(k[g]<mid&&k[g]==min)
            {
                for(int n=1;;n++)
                {
                    if(k[g]==mid)
                    {
                        break;
                    }
                    else
                    {
                    k[g]++;
                    sum2=n;
                    }
                }
            }

        }

if(sum==sum2)
{int sum3=0;
    for(int t=0;t<x-1;t++)
    {
        if(k[t]==k[t+1])
        {
            sum3++;
        }
    }
    if(sum3==x-1)
   System.out.println(sum);
    else
        System.out.println("-1");
}
else
   System.out.println("-1");
        }
     else
        {
            int l=0;
            int a=0;
            int u=0;
            for(int v=0;v<1;v++)
            {
                 for(u=0;;u++)

                {
                    if(u>max)
                    {
                        if(min==max)
                        {
                            System.out.println("0");
                        }
                        else
                        {
                        int f=max-min;
                       System.out.println(f);
                        }
                        break;
                    }
                    else
                    {

                    for(int c=0;c<x;c++)
                    {
                    if(k[c]==min)
                    {
                        k[c]+=u;
                    }
                    else
                        if(k[c]==max)
                        {
                            k[c]-=u;
                        }
                    }
           for(int e=0;e<x-1;e++)
           {
               if(k[e]==k[e+1])
                       {
                        l++;
                       }
           }
           if(l==x-1)
           {
               a=u;
               System.out.println(a);
               break;
           }
           else
           {
               l=0;
               for(int j=0;j<x;j++)
               {
                   k[j]=i[j];
               }

           }
                }
                }

            }
        }
    }
    }
}

import java.awt.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;

public class MakeThemEqual {

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

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashSet<Integer> set = new HashSet<>();
		for(int i=0;i<n;i++){
			int num = sc.nextInt();
			set.add(num);
		}
		if(set.size()>3)
			System.out.println(-1);
		else if(set.size() == 1)
			System.out.println(0);
		else{
			ArrayList<Integer> list = new ArrayList<>(set);
			Collections.sort(list);
			if(set.size()==2){
				if((list.get(0)+list.get(1))%2!=0){
					System.out.println(list.get(1)-list.get(0));
				}
				else{
					int num = list.get(0)+list.get(1);
					num = num/2;
					if((list.get(1)-num)>(list.get(1)-list.get(0)))
						System.out.println((list.get(1)-list.get(0)));
					else
						System.out.println((list.get(1)-num));
				}
			}
			else{
				int num = list.get(0)+list.get(1)+list.get(2);
				if(num%3 !=0){
					System.out.println("-1");
				}
				else if(list.contains(num/3)){
					int ans = list.get(2)-num/3;
					System.out.println(ans);
				}
				else
					System.out.println("-1");
			}
		}

	}

}

import java.util.Scanner;
import java.util.TreeSet;

public class Equal{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeSet<Integer> set = new TreeSet<>();
        for (int i = 1; i <= n; i++){
            int val = sc.nextInt();
            set.add(val);
        }
        if(set.size() > 3){
            System.out.println(-1); return;
        }
        if(set.size() == 1){
            System.out.println(0); return;
        }
        if(set.size() == 2){
            int a = set.pollFirst();
            int b = set.pollFirst();
            if((b-a)%2 == 0){
                System.out.println((b-a)/2);
            }else{
                System.out.println(b-a);
            }
            return;
        }
        if(set.size() == 3){
            int a = set.pollFirst();
            int b = set.pollFirst();
            int c = set.pollFirst();
            if(b-a == c-b){
                System.out.println(b-a);
            }
            else
                System.out.println(-1);
        }
    }
}

import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n,i,j,s=0,temp,p;
		n=sc.nextInt();
		int []arr=new int[3];
		for(i=0;i<n;i++) {
			p=sc.nextInt();
			if(s==4)
				continue;
			else if(s==0) {
				arr[0]=p;
				s++;
			}
			else if(s==1) {
				if(p!=arr[0]) {
					arr[1]=p;
					s++;
				}
			}
			else if(s==2) {
				if(p!=arr[0] && p!=arr[1]) {
					arr[2]=p;
					s++;
				}
			}
			else {
				if(p!=arr[0] && p!=arr[1] && p!=arr[2])
					s=4;
			}

		}
		if(s==4)
			System.out.println("-1");
		else if(s==1)
			System.out.println("0");
		else if(s==2) {
			if((arr[1]-arr[0])%2!=0)
				System.out.println(Math.max(arr[0],arr[1])-Math.min(arr[0],arr[1]));
			else
				System.out.println((Math.max(arr[0],arr[1])-Math.min(arr[0],arr[1]))/2);
		}
		else {
			Arrays.sort(arr);
			if(arr[2]-arr[1]==arr[1]-arr[0])
				System.out.println(arr[2]-arr[1]);
			else
				System.out.println("-1");
		}
		sc.close();
	}

}

// package cp;
import java.io.*;
import java.util.*;
public class Cf_three {
	public static void main(String[] args) throws IOException {
		PrintWriter out = new PrintWriter(System.out);
		Readers.init(System.in);
		int n=Readers.nextInt();
		int[] a=new int[n];
		HashSet<Integer> set=new HashSet<>();
		for (int i = 0; i < a.length; i++) {
			a[i]=Readers.nextInt();
			set.add(a[i]);
		}
		ArrayList<Integer> ans=new ArrayList<>();
		if(set.size()>3)System.out.println(-1);
		else {
			for(Integer j:set) {
				ans.add(j);
			}
			Collections.sort(ans);
			if(set.size()==3) {
				if(ans.get(2)-ans.get(1)==ans.get(1)-ans.get(0)) {
					System.out.println(ans.get(2)-ans.get(1));
				}
				else System.out.println(-1);
			}
			else if(set.size()==2) {
				if((ans.get(0)+ans.get(1))%2==0) {
					System.out.println((ans.get(1)-ans.get(0))/2);
				}
				else System.out.println(ans.get(1)-ans.get(0));
			}
			else {
				System.out.println(0);
			}
		}
		out.flush();
	}

}
class Readers {

    static BufferedReader reader;

    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */

    static void init(InputStream input) {

        reader = new BufferedReader(

                     new InputStreamReader(input) );

        tokenizer = new StringTokenizer("");

    }

    /** get next word */

    static String next() throws IOException {

        while ( ! tokenizer.hasMoreTokens() ) {

            //TODO add check for eof if necessary

            tokenizer = new StringTokenizer(

                   reader.readLine() );

        }

        return tokenizer.nextToken();

    }

    static int nextInt() throws IOException {

        return Integer.parseInt( next() );

    }

    static double nextDouble() throws IOException {

        return Double.parseDouble( next() );

    }

    static long nextLong() throws IOException{

		return Long.parseLong(next());
	}

}

import java.io.*;
import java.math.BigInteger;
import java.security.KeyPair;
import java.util.*;

public class hellowordl {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        HashMap<Integer,Integer>m=new HashMap<Integer, Integer>();
        int n=sc.nextInt();
        ArrayList <Integer>li=new ArrayList<Integer>();
        for(int i=0;i<n;i++)
        {
            int a=sc.nextInt();
            Integer c=m.get(a);
            if(c==null)
            {
                li.add(a);
                m.put(a,1);
            }

        }
        Collections.sort(li);
        int size=li.size();
        //System.out.println(size);
        if(size<=3)
        {
           if(size==1)
               System.out.println(0);
           else if(size==2)
           {
               int d=li.get(1)-li.get(0);
               if(d%2==0)
                   System.out.println(d/2);
               else
                   System.out.println(d);
           }
           else
           {
               int mid=li.get(1);
               int d1=mid-li.get(0);
               int d2=li.get(2)-mid;
               if(d1==d2)
                   System.out.println(d1);
               else
                   System.out.println(-1);
           }
        }
        else
        System.out.println(-1);

    }
}

import java.util.*;

/**
 * @Author: Harry
 * @Date: 2019-04-19 21:37
 * @Version 1.0
 */
public class Main {

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

        while (input.hasNext()){
            int n = input.nextInt();

            int arr[] = new int[n];

            Set<Integer> s = new HashSet<Integer>();

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

            if(n == 1 || s.size() == 1){
                System.out.println(0);
                continue;
            }

            int tp[] = new int[s.size()];
            Set<Integer> check = new HashSet<Integer>();

            int counter = 0;
            for(int x:s){
                tp[counter++] = x;
            }

            Arrays.sort(tp);

            for(int i = 1;i < tp.length;i++){
                check.add(tp[i] - tp[i - 1]);
                if(((tp[i] - tp[i - 1]) & 1) != 1)
                    check.add((tp[i] - tp[i - 1]) / 2);
                //System.out.println(tp[i] - tp[i - 1]);
            }

            int d = 999999999;

            for(int dd:check){
                Map<Integer,Integer> map = new HashMap<Integer,Integer>();
                //System.out.println("dd:" + dd);
                for(int x:arr){
                    int a = x + dd;
                    int b = x - dd;
                    int c = x;

                    //System.out.println(a + " " + b + " " + c);

                    cal(a,map);
                    cal(b,map);
                    cal(c,map);
                }

                for(Map.Entry<Integer,Integer> entry:map.entrySet()){
                    if(entry.getValue() == n){
                        d = Math.min(d,dd);
                    }
                }
            }

            if(d == 999999999){
                System.out.println(-1);
            }
            else{
                System.out.println(d);
            }
        }

    }

    public static void cal(int a,Map<Integer,Integer> map){
        if(map.containsKey(a)){
            map.put(a,map.get(a) + 1);
        }
        else{
            map.put(a,1);
        }
    }

}

import java.util.*;
import java.lang.*;
import java.lang.reflect.Array;
import java.io.*;
import java.math.*;
import java.text.DecimalFormat;

public class Prac{

    static class InputReader {

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

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

		public int read() {
			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 ni() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

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

		public String rs() {
			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 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 boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

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

	}
    static PrintWriter w = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        InputReader sc=new InputReader(System.in);
      int n=sc.ni();
      int arr[]=new int[n];
      for(int i=0;i<n;i++){
          arr[i]=sc.ni();
      }

      int ans=-1;
       boolean found=false;
       if(n==1)
           w.println(0);
       else{
            for(int i=0;i<=500;i++){
                found=false;
                 int a=arr[0]-i;
                int b=arr[0]+i;
                 int c=arr[0];
                 for(int j=1;j<n;j++){
                     if(arr[j]-i!=a&&arr[j]+i!=a&&arr[j]!=a){
                         found=true;
                         break;
                     }
                 }
                 if(!found){
                     w.println(i);
                     break;
                 }
                 found=false;
                 for(int j=1;j<n;j++){
                     if(arr[j]-i!=b&&arr[j]+i!=b&&arr[j]!=b){
                         found=true;
                         break;
                     }
                 }
                 if(!found){
                     w.println(i);
                     break;
                 }
                 found=false;
                 for(int j=1;j<n;j++){
                     if(arr[j]-i!=c&&arr[j]+i!=c&&arr[j]!=c){
                         found=true;
                         break;
                     }
                 }
                 if(!found){
                     w.println(i);
                     break;
                 }
             }
          if(found)
              w.println(-1);
       }
        w.close();
    }
}

//package R552Div3;

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

public class MakeThemEqual {

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

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

        Arrays.sort(array);

        int diff = 0;

        for (int i = 0; i < n - 1; i++) {
            if (array[i] < array[i + 1]) {
                diff = array[i+1] - array[i];
                break;
            }
        }

        if (diff == 0) {
            System.out.println(0);
            return;
        }

        boolean found = false;

        for (int minDiff = 1; minDiff <= diff ; minDiff++) {
            int equal = array[0] + minDiff;
            int j = 0;
            for (; j < n; j++) {

                if (array[j] + minDiff == equal || array[j] - minDiff == equal || array[j] == equal) {
                    continue;
                }
                break;
            }
            found = j == n;
            if(found) {
                System.out.println(minDiff);
                return;
            }
        }

        System.out.println(-1);
    }
}

//package codeforces.Round552Div3;

//import Algorithm.OutputVerifier;

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

public class MakeThemEqual {

    private void solve(int[] array) {

        Arrays.sort(array);

        int n = array.length;
        int diff = 0;

        for (int i = 0; i < n - 1; i++) {
            if (array[i] < array[i + 1]) {
                diff = array[i+1] - array[i];
                break;
            }
        }

        if (diff == 0) {
            out.println(0);
            return;
        }

        boolean found = false;

        for (int minDiff = 1; minDiff <= diff ; minDiff++) {
            int equal = array[0] + minDiff;
            int j = 0;
            for (; j < n; j++) {

                if (array[j] + minDiff == equal || array[j] - minDiff == equal || array[j] == equal) {
                    continue;
                }
                break;
            }
            found = j == n;
            if(found) {
                out.println(minDiff);
                return;
            }
        }

        out.println(-1);
    }

    public static Scanner sc;
    public static PrintWriter out;

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

        boolean fileInOut = false;

        //sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        //out = new PrintWriter(new BufferedOutputStream(System.out), true);

        sc = new Scanner(new BufferedReader(new InputStreamReader(fileInOut ? MakeThemEqual.class.getResourceAsStream("in.txt") : System.in)));
        out = new PrintWriter(new BufferedOutputStream(fileInOut ? new FileOutputStream("out.txt") : System.out), true);

        MakeThemEqual makeThemEqual = new MakeThemEqual();

        //int testCase = sc.nextInt();

        //for (int i = 0; i < testCase; i++) {

            int n = sc.nextInt();

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

            makeThemEqual.solve(array);
        //}

        //OutputVerifier.verify(MakeThemEqual.class.getResource("ans.txt").getFile());
    }
}

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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new PrintStream(System.out));
        int n=Integer.parseInt(f.readLine());
        StringTokenizer st=new StringTokenizer(f.readLine());
        int[]arr=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=Integer.parseInt(st.nextToken());
        }
        boolean printed=true;
        for(int i=0;i<n;i++){
            if(arr[i]!=arr[0]){
                printed=false;
            }
        }
        if(printed){
            System.out.println(0);
        }
        a:
        for(int i=1;i<=100;i++){
            if(printed)break;
            HashMap<Integer,Integer>hm=new HashMap<>();

            for(int j=0;j<n;j++){
                if(hm.containsKey(arr[j]+i)){
                   hm.put(arr[j]+i,hm.get(arr[j]+i)+1);
                }
                else{
                    hm.put(arr[j]+i,1);
                }
                if(hm.containsKey(arr[j]-i)){
                    hm.put(arr[j]-i,hm.get(arr[j]-i)+1);
                }
                else{
                    hm.put(arr[j]-i,1);
                }
                if(hm.containsKey(arr[j])){
                    hm.put(arr[j],hm.get(arr[j])+1);
                }
                else{
                    hm.put(arr[j],1);
                }
            }

            for (Integer key : hm.keySet()) {
                if(hm.get(key)==n){
                    printed=true;
                    System.out.println(i);
                    break a;
                }
            }
        }
        if(!printed){
            System.out.println(-1);
        }
        f.close();
        out.close();
    }
}
//import java.util.*;
//import java.io.*;
//
//public class Main {
//    public static void main(String[] args) throws IOException{
//        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
//        PrintWriter out = new PrintWriter(new PrintStream(System.out));
//        int n=Integer.parseInt(f.readLine());
//        StringTokenizer st=new StringTokenizer(f.readLine());
//        int []arr=new int[n];
//        for(int i=0;i<n;i++){
//            arr[i]=Integer.parseInt(st.nextToken());
//        }
//        HashSet<Integer>has=new HashSet<>();
//        has.add(1);
//        boolean a=has.contains(1);
//        boolean bool=true;
//        po:
//        for(int i=0;i<=100;i++){
//            HashMap<Integer>hs=new HashSet<>();
//            p:
//            for(int j=0;j<n;j++){
//                if(hs.contains(arr[j]+i)|| hs.contains(arr[j]-i) || hs.contains(arr[j])){
//                    hs.add(arr[j]+i);
//                    hs.add(arr[j]-i);
//                    hs.add(arr[j]);
//                }
//                else{
//                   if(j==0){
//                       hs.add(arr[j]+i);
//                       hs.add(arr[j]-i);hs.add(arr[j]);
//
//                       continue p;
//                   }
//                   else{
//                       continue po;
//                   }
//
//                }
//            }
//            Iterator<Integer> it = hs.iterator();
//            int dif=0;
//            op:
//            while(it.hasNext()){
//                int o=it.next();
//                for(int j=0;j<n;j++){
//                    if((Math.abs(arr[j]-o)!=dif && o-arr[j]!=0) && j!=0){
//                        continue op;
//                    }
//                    if(o-arr[j]!=0){
//                        dif=arr[j]-o;
//                        dif= Math.abs(dif);
//                    }
//                }
//                bool=false;
//                System.out.println(dif);
//                break po;
//            }
//
//        }
//        if(bool){
//            out.println(-1);
//        }
//        f.close();
//        out.close();
//    }
//}

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

public class pa {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException {
        int n = readInt();
        int[] a = readArrayInt();

        for (int d = 0; d <= 100; d++) {
            for (int t = 0; t <= 100; t++) {
                boolean ch = false;
                for (int i = 0; i < n; i++)
                    if (!(a[i] == t || a[i] + d == t || a[i] - d == t)) {
                        ch = true;
                        break;
                    }
                if (!ch) {
                    System.out.println(d);
                    return;
                }
            }
        }
        System.out.println(-1);
    }

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

    static char[] readString() throws IOException {
        return br.readLine().toCharArray();
    }

    static int[] readArrayInt() throws IOException {
        String s[] = br.readLine().split(" ");
        int a[] = new int[s.length];
        for (int i = 0; i < s.length; i++)
            a[i] = Integer.parseInt(s[i]);
        return a;
    }

    static char[][] readArrayString() throws IOException {
        String s[] = br.readLine().split(" ");
        char a[][] = new char[s.length][];
        for (int i = 0; i < s.length; i++)
            a[i] = s[i].toCharArray();
        return a;
    }

/*
    Arrays.sort(a, (char[] p1, char[] p2) -> {
                if (p1.length != p2.length)
                    return Integer.compare(p1.length, p2.length);
                return p1.toString().compareTo(p2.toString());
        });

    //Collections.sort(odd);

 for (Map.Entry<Integer, Integer> e: b.entrySet()) {
            int k = e.getKey();
            int v = e.getValue();

        }*/

}

//package codeforces552;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class B {
  InputStream is;
  PrintWriter out;
  String INPUTA = "6\n" +
      "1 4 4 7 4 1";
  String INPUT = "3\n" +
      "1 2 4";

  void solve() {
    int n = ni();
    int[] a = na(n);
    TreeSet<Integer> treeSet = new TreeSet<>();
    for (int i = 0; i < n; i++) {
      treeSet.add(a[i]);
    }
    if (treeSet.size() == 1)  {
      out.println(0);
    } else if (treeSet.size() == 2) {
      int d = treeSet.last() - treeSet.first();
      if (treeSet.first() + d / 2 == treeSet.last() - d / 2) {
        out.println(d / 2);
      } else {
        out.println(d);
      }
    } else if (treeSet.size() == 3) {
      int d = (treeSet.last() - treeSet.first()) / 2;
      if ((treeSet.last() - treeSet.first()) % 2 == 0 && treeSet.contains(treeSet.first() + d)) {
        out.println(d);
      } else {
        out.println(-1);
      }
    } else {
      out.println(-1);
    }
  }

  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 = true;

  private void tr(Object... o) {
    if (!oj) System.out.println(Arrays.deepToString(o));
  }
}

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

public class B {

	private static int MIN_MID = Integer.MAX_VALUE;

	public static void dfs(int i, int [] arr, int mid) {
		if (i == arr.length) {
			boolean ok = true;
			for (int j = 0; j < arr.length - 1; ++ j) {
				if (arr[j] != arr[j + 1]) {
					ok = false;
					break;
				}
			}
			if (ok) {
				MIN_MID = Math.min(MIN_MID, mid);
			}
			return;
		}
		// Decrease mid to i
		arr[i] -= mid;
		dfs(i + 1, arr, mid);
		arr[i] += mid + mid;
		dfs(i + 1, arr, mid);
		arr[i] -= mid;
		dfs(i + 1, arr, mid);
	}

	public static void main(final String [] args) throws Exception {
		final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

		int n = Integer.parseInt(reader.readLine());
		ArrayList<Integer> list = new ArrayList<>();

		String [] parts = reader.readLine().split(" ");
		HashSet<Integer> set = new HashSet<Integer>();

		for (int i = 0; i < n; ++ i) {
			int val = Integer.parseInt(parts[i]);
			if (!set.contains(val)) {
				list.add(val);
				set.add(val);
			}
		}

		int [] arr = new int[list.size()];
		for (int i = 0; i < arr.length; ++ i) {
			arr[i] = list.get(i);
		}

		Arrays.sort(arr);

		n = arr.length;
		if (n > 3) {
			writer.write("-1\n");
		} else {
			for (int i = 0; i < arr[n - 1]; ++ i) {
				dfs(0, arr, i);
			}
			if (MIN_MID == Integer.MAX_VALUE) {
				writer.write("-1\n");
			} else {
				writer.write(MIN_MID + "\n");
			}
		}

		reader.close();
		writer.close();
	}
}

//package codeforces552;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Set;

public class B {
  InputStream is;
  PrintWriter out;
  String INPUT = "2\n" +
      "1 1";
  String INPUTB = "6\n" +
      "1 4 4 7 4 1";

  void solve() {
    int n = ni();
    int[] a = na(n);
    int ans = 10000;
    if (n == 1) {
      out.println(0);
      return;
    }
    for (int x = -100; x <= 100; x++) {
      int d = -1000;
      boolean ok = true;
      for (int j = 0; j < n; j++) {
        if (a[j] == x) {
        } else {
          if (d == -1000) {
            d = Math.abs(a[j] - x);
          } else if (Math.abs(a[j] - x) == d) {
          } else {
            ok = false;
            break;
          }
        }
      }
      if (d == -1000) {
        d = 0;
      }
      if (ok) {
        ans = Math.min(ans, d);
      }
    }
    if (ans == 10000) {
      out.println(-1);
    } else {
      out.println(ans);
    }
  }

  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 = true;

  private void tr(Object... o) {
    if (!oj) System.out.println(Arrays.deepToString(o));
  }
}

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

import static java.util.Arrays.stream;

public class M {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        int[] m = stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        Set<Integer> set = new TreeSet<>(Comparator.comparingInt(o1 -> o1));
        for (int x : m) set.add(x);
        List<Integer> list = new ArrayList<>(set);
        if (list.size() > 3) {
            System.out.println(-1);
            System.exit(0);
        }
        if (list.size() == 3) {
            int diff = list.get(1) - list.get(0);
            if (list.get(2) - list.get(1) != diff) System.out.println(-1);
            else System.out.println(diff);
        } else if (list.size() == 1) System.out.println(0);
        else {
            if (list.get(0) % 2 == 1 && list.get(1) % 2 == 1) System.out.println((list.get(1) - list.get(0)) / 2);
            else if (!(list.get(0) % 2 == 0) || !(list.get(1) % 2 == 0))
                System.out.println((list.get(1) - list.get(0)));
            else System.out.println((list.get(1) - list.get(0)) / 2);
        }

    }
}

import java.util.*;

public class GFG {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int d = -1;

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

		boolean cont = true;

		Arrays.sort(a);

		if ((a[n-1] - a[0]) % 2 == 0)
		{
		    d = (a[n-1] - a[0])/2;

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

		        if (((a[n-1] - d) == a[i]) && ((a[0] + d) == a[i]))
		        {

		        }
		        else if (a[n-1] == a[i])
		        {

		        }
		        else if (a[0] == a[i])
		        {

		        }
		        else
		        {
		            d = -1;
		            cont = false;
		        }

		    }
		}
		else if ((a[n-1] - a[0]) % 2 == 1)
		{

		    d = (a[n-1] - a[0]);

		    for (int i = 1; (i < n-1) && cont; i++)
		    {
	            if (a[n-1] == a[i])
	            {

	            }
	            else if (a[0] == a[i])
	            {

    	        }
    	        else
    	        {
    	            d = -1;
    	            cont = false;
    	        }
		    }
		}
		System.out.println(d);
	}
}

import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        String str[]=br.readLine().split(" ");
        int arr[]=new int[n];
        //long arr2[]=new long[4];
        for(int i=0;i<n;i++)
        arr[i]=Integer.parseInt(str[i]);
        boolean same=true;
        for(int i=1;i<n;i++)
        {
            if(arr[i]!=arr[0])
            {
                same=false;
                break;
            }
        }
        if(same)
        pw.println(0);
        else
        {
            int ans=-1;
            outer:for(int j=1;j<=200;j++)
            {
                TreeMap<Integer,Integer> tmap=new TreeMap<>();
                for(int i=0;i<n;i++)
                {
                    tmap.put(arr[i],tmap.getOrDefault(arr[i],0)+1);
                    tmap.put(arr[i]-j,tmap.getOrDefault(arr[i]-j,0)+1);
                    tmap.put(arr[i]+j,tmap.getOrDefault(arr[i]+j,0)+1);
                }

                for(Map.Entry<Integer,Integer> me:tmap.entrySet())
                {
                   if(me.getValue()>=n)
                   {
                       ans=j;
                       break outer;
                   }
                }
            }
            pw.println(ans);
        }
        pw.flush();
        pw.close();
    }
}

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;

public class AA {
	static HashSet<String> set = new HashSet<>();
	public static void main(String[] args) throws Exception {
		InputReader scan = new InputReader(new BufferedInputStream(System.in));
		int n = scan.nextInt();
		int[] arr = scan.nextIntArray(n);
		HashSet<Integer> set = new HashSet<>();
		for(int i:arr)set.add(i);
		Integer D = null;
		if (set.size()==1) {
			D = 0;
			//for (int i:arr)System.out.print(i+" ");
			System.out.println(0);
		} else if (set.size() == 2) {
			int[] arr1 = new int[2];
			int i=0;
			for (int i1:set)arr1[i++]=i1;
			int mid = (arr1[1]-arr1[0])/2;
			int d = Math.min(mid, arr1[1]-mid);
			System.out.println(d);

		} else if (set.size() == 3) {
			int[] arr1 = new int[3];
			int i=0;
			for (int i1:set)arr1[i++]=i1;
			Arrays.sort(arr1);
			if (arr1[1]-arr1[0] == arr1[2]-arr1[1]) {
				int d = arr1[1]-arr1[0];
				System.out.println(d);
			} else
				System.out.println(-1);

		}else
			System.out.println(-1);
		scan.close();
	}

	static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

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

		public void close() throws IOException {
			this.stream.close();
		}

		public static boolean isWhitespace(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		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 boolean isSpaceChar(int c) {
			if (filter != null) {
				return filter.isSpaceChar(c);
			}
			return isWhitespace(c);
		}

		public interface SpaceCharFilter {

			public boolean isSpaceChar(int ch);
		}

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

		public String nextString() {
			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 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() {
			return Long.parseLong(nextString());
		}

		public Double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public char nextCharacter() {
			return nextString().charAt(0);
		}

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

		public long[] nextLongArray(int N) {
			long A[] = new long[N];
			for (int i = 0; i < N; i++) {
				A[i] = nextLong();
			}
			return A;
		}

		public double[] nextDoubleArray(int N) {
			double A[] = new double[N];
			for (int i = 0; i < N; i++) {
				A[i] = nextDouble();
			}
			return A;
		}
	}

	int min(int... a) {
		int min = Integer.MAX_VALUE;
		for (int v : a) {
			min = Math.min(min, v);
		}
		return min;
	}

	long min(long... a) {
		long min = Long.MAX_VALUE;
		for (long v : a) {
			min = Math.min(min, v);
		}
		return min;
	}

	double min(double... a) {
		double min = Double.MAX_VALUE;
		for (double v : a) {
			min = Math.min(min, v);
		}
		return min;
	}

	int max(int... a) {
		int max = Integer.MIN_VALUE;
		for (int v : a) {
			max = Math.max(max, v);
		}
		return max;
	}

	long max(long... a) {
		long max = Long.MIN_VALUE;
		for (long v : a) {
			max = Math.max(max, v);
		}
		return max;
	}

	double max(double... a) {
		double max = Double.MIN_VALUE;
		for (double v : a) {
			max = Math.max(max, v);
		}
		return max;
	}
}

// Working program using Reader Class
import java.io.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main
{
	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();
		}
	}

	public static int gcd(int a, int b)
    {
        // Everything divides 0
        if (a == 0 || b == 0)
           return 0;

        // base case
        if (a == b)
            return a;

        // a is greater
        if (a > b)
            return gcd(a-b, b);
        return gcd(a, b-a);
    }

	public static long change(char c,char d,long A,long B,long C) {
		if(c==d) {
			return 0;
		}
		else if((c=='1' && d=='3') || (c=='3' && d=='1')) {
			return C;
		}
		else if((c=='1' && d=='2') || (c=='2' && d=='1')) {
			return A;
		}
		else {
			return B;
		}
	}

	public static void main(String[] args) throws IOException
	{
		//Reader scan=new Reader();
		Scanner scan=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=scan.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		int ans=Integer.MAX_VALUE;
		for(int i=1;i<=n;i++) {
			int d=-1;
			int done=0;
			for(int j=0;j<n;j++) {
				if(a[j]!=i) {
					if(d==-1) {
						d=Math.abs(a[j]-i);
					}
					else {
						if(a[j]+d!=i && a[j]-d!=i) {
							done=1;
							break;
						}
					}
				}
			}
			if(done==0) {
				ans=Math.min(ans, d);
			}
		}
		if(ans==Integer.MAX_VALUE) {
			out.print(-1);
		}
		else {
			out.print(ans);
		}
		out.close();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
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)
    {
        FastReader sc=new FastReader();
        int n=sc.nextInt();
        int a[]=new int[n];
        TreeSet<Integer> set=new TreeSet<>();
        int ans=0;
       for(int i=0;i<n;i++){
        a[i]=sc.nextInt();
        set.add(a[i]);
       }
       if(set.size()==1)
         System.out.println(0);
     else if(set.size()==2){
        Integer a1=(Integer)set.pollFirst();
        Integer a2=(Integer)set.pollFirst();
        System.out.println(Math.abs(a2-a1));
     }
     else if(set.size()==3){
          Integer a1=(Integer)set.pollFirst();
        Integer a2=(Integer)set.pollFirst();
         Integer a3=(Integer)set.pollFirst();
        if((a2-a1)==(a3-a1-a2)){
            System.out.println(a2-a1);
        }else
         System.out.println(-1);

     }else

System.out.println(-1);

   }
}

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

public class Make_Them_Equal {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		int[] abc = new int[3];
		boolean flagA = false;
		boolean flagB = false;
		boolean flagC = false;
		for (int i = 0; i < n; i++) {
			arr[i] = scan.nextInt();
			if (arr[i] != abc[0] && !flagA) {
				abc[0] = arr[i];
				flagA = true;
			} else if (arr[i] != abc[1] && arr[i] != abc[0] && !flagB) {
				abc[1] = arr[i];
				flagB = true;
			} else if (arr[i] != abc[2] && arr[i] != abc[1] && arr[i] != abc[0] && !flagC) {
				abc[2] = arr[i];
				flagC = true;
			} else {
				System.out.print(-1);
				System.exit(0);
			}
		}
		Arrays.sort(abc);
		if (abc[0] != 0 && abc[1] != 0 && abc[2] != 0) {
			if (abc[2] - abc[1] != abc[1] - abc[0]) {
				System.out.println(-1);
			} else {
				if (abc[0] == 0 && abc[1] == 0) {
					System.out.print(0);
				} else if (abc[0] == 0) {
					if ((abc[2] - abc[1]) % 2 == 0) {
						System.out.print((abc[2] - abc[1]) / 2);
					} else {
						System.out.print((abc[2] - abc[1]));
					}

				} else {
					System.out.print((abc[2] - abc[0]) / 2);

				}
			}
		} else {
			if (abc[0] == 0 && abc[1] == 0) {
				System.out.print(0);
			} else if (abc[0] == 0) {
				if ((abc[2] - abc[1]) % 2 == 0) {
					System.out.print((abc[2] - abc[1]) / 2);
				} else {
					System.out.print((abc[2] - abc[1]));
				}
			} else {
				System.out.print((abc[2] - abc[0]) / 2);
			}
		}

		scan.close();
	}

}

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

public class B {
	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();
		}

		ArrayList<Integer> elements = new ArrayList<Integer>();
		for(int i = 0; i < n; i++) {
			if(!elements.contains(a[i])) {
				elements.add(a[i]);
			}
		}
		Collections.sort(elements);
		int ans = -1;
		if(elements.size() == 3) {
			if(elements.get(2) - elements.get(1) == elements.get(1) - elements.get(0)) {
				ans = elements.get(2) - elements.get(1);
			} else {
				ans = -1;
			}
		} else if(elements.size() == 2) {
			ans = elements.get(1) - elements.get(0);
		} else if(elements.size() == 1) {
			ans = 0;
		} else {
			ans = -1;
		}
		System.out.println(ans);
	}
}

import java.util.*;

public class ProblemB552 {
	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.parallelSort(a);
		if (n == 1)
			System.out.println(0);
		else {
			int nums = 1;
			int index = 0;
			int[] numbers = new int[100000 + 5];
			for (int i = 1; i < n; i++) {
				if (a[i] != a[i - 1]) {
					nums++;
				}
			}
			numbers[0] = a[0];
			for (int i = 1; i < n; i++) {
				if (a[i] != numbers[index]) {
					index++;
					numbers[index] = a[i];
				}
			}
			if (nums > 3)
				System.out.println(-1);
			else {
				if (nums == 3) {
					if (numbers[1] - numbers[0] != numbers[2] - numbers[1])
						System.out.println(-1);
					else
						System.out.println(numbers[1] - numbers[0]);
				}
				if (nums == 2) {
					if (n == 2) {
						System.out.println((numbers[1] - numbers[0])/2);
					} else
						System.out.println((numbers[1] - numbers[0]));
				}
				if (nums == 1)
					System.out.println(0);
			}
		}
	}
}

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

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

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

		List<Integer> differences = new ArrayList<Integer>();

		for (int i = 0; i < n - 1; i ++)
		{
			int difference = sequence[i + 1] - sequence[i];
			if (difference != 0 && !differences.contains(difference))
			{
				differences.add(difference);
			}

			if (differences.size() == 0)
			{
				continue;
			}
			else if (differences.size() > 2)
			{
				System.out.println(-1);
				return;
			}
			else if (differences.size() == 2 && Math.abs(differences.get(0)) != Math.abs(differences.get(1)))
			{
				System.out.println(-1);
				return;
			}
		}

		if (differences.size() == 0)
		{
			System.out.println(0);
		}
		else if (differences.size() == 1)
		{
			if (differences.get(0) % 2 == 0)
			{
				System.out.println(differences.get(0) / 2);
			}
			else
			{
				System.out.println(Math.abs(differences.get(0)));
			}
		}
		else if (differences.size() == 2)
		{
			System.out.println(Math.abs(differences.get(0)));
		}
	}
}

import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class B {

    public static void main(String[] args) throws Exception {
        FastScanner scanner = new FastScanner();
        int n = scanner.nextInt();
        ArrayList<Integer> a = scanner.nextIntegerArrayList();
        Collections.sort(a);
        int step = 0;
        int target = 0;
        int i;

        for (i = 0; i < a.size() - 1; i++) {
            if (a.get(i) < a.get(i + 1)) {
                step = a.get(i + 1) - a.get(i);
                target = a.get(i + 1);
                break;
            }
        }
        if (step == 0) {
            System.out.println(step);
            System.exit(0);
        }

        boolean error1 = false;
        for (int j = i + 1; j < a.size(); j++) {
            if (a.get(j) != target && a.get(j) != target + step) {
                error1 = true;
                break;
            }
        }

        boolean error2 = false;
        if (error1 && step % 2 != 0)
            error2 = true;
        if (step % 2 == 0) {
            step /= 2;
            for (int j = i + 1; j < a.size(); j++) {
                if (a.get(j) != target && a.get(j) != target + step) {
                    error2 = true;
                }
            }
        }
        if (error2)
            step *= 2;
        if (!(error1 && error2))
            System.out.println(step);
        else
            System.out.println(-1);

    }

    private static class FastScanner {
        private BufferedReader br;

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

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

        public ArrayList<Integer> nextIntegerArrayList() throws IOException {
            String line = br.readLine();
            String[] strings = line.trim().split("\\s+");
            ArrayList<Integer> array = new ArrayList<Integer>();
            for (int i = 0; i < strings.length; i++)
                array.add(Integer.parseInt(strings[i]));
            return array;
        }
    }
}

import java.util.*;
public class Equal_2{
	public static void main(String args[])
	{
		int n,i,j,max=0,min=9999999,d,flag=0,k=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int arr[]=new int[n];
		for(i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
			if(arr[i]>max)
				max=arr[i];
			if(arr[i]<min)
				min=arr[i];

		}
		d=(max+min)/2;

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

			if(arr[i]<d)
			{
				arr[i]=(d-arr[i]);
				k=d-arr[i];
			}
			if(arr[i]==d)
				arr[i]=k;
			if(arr[i]>d)
			{
				arr[i]=arr[i]-d;
				k=arr[i]-d;
			}
		}

		for(i=0;i<n-1;i++)
		{
			if(arr[i]!=arr[i+1])

				{
					flag=1;
					break;
				}
		}
		if(flag==1)
			System.out.println(-1);
		else
			System.out.println(arr[1]);

	}
}

import java.util.*;

public class lottery {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int len = scan.nextInt();
        TreeSet<Integer> set = new TreeSet<>();
        for(int i = 0; i<len; i++){
            set.add(scan.nextInt());
        }
        if(set.size() == 1) System.out.println(set.first());
        else if(set.size() == 2) System.out.println((set.last()-set.first())/2);
        else if(set.size() == 3){
            int first = set.pollFirst();
            int last = set.last();
            int avg = (first+last)/2;
            //System.out.println(set.first());
            if(set.first() == avg) System.out.println(set.first()-first);
            else System.out.println(-1);
        }
        else System.out.println(-1);

    }
}

import java.util.*;
public class Equal
{
    public static void main(String[]args)
    {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        boolean flag=true;
        int[] arr=new int[n];
        ArrayList<Integer> subtract=new ArrayList<>();
        int num;
        for(int i=0;i<n;i++)
        {
            arr[i]=scan.nextInt();
            if(!subtract.contains(arr[i]))
                subtract.add(arr[i]);
        }
        Collections.sort(subtract);
        if(n==1)
            System.out.println(0);
        else
        {
            if(subtract.size()==1)
                System.out.println(0);
            else
            {
            int sub=0;
            sub=subtract.get(1)-subtract.get(0);
            num=sub;
            if(subtract.size()==2&&sub%2==0)
                sub/=2;

            for(int i=2;i<subtract.size();i++)
            {
                sub=subtract.get(i)-subtract.get(i-1);
                if(sub!=num)
                {
                    flag=false;
                    break;
                }

            }
            if(flag)
                System.out.println(sub);
            else
                System.out.println(-1);
            }
        }
    }
}

import java.util.Scanner;
import java.util.TreeSet;

public class Equal{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeSet<Integer> set = new TreeSet<>();
        for (int i = 1; i <= n; i++){
            int val = sc.nextInt();
            set.add(val);
        }
        if(set.size() > 3){
            System.out.println(-1); return;
        }
        if(set.size() == 1){
            System.out.println(0); return;
        }
        if(set.size() == 2){
            System.out.println(Math.abs(set.pollFirst()-set.pollFirst()));
            return;
        }
        if(set.size() == 3){
            int a = set.pollFirst();
            int b = set.pollFirst();
            int c = set.pollFirst();
            if(b-a == c-b){
                System.out.println(b-a);
            }
            else
                System.out.println(-1);
        }
    }
}

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

public class Make_Them_Equal_552_B {

    public static void main(String[] args) {
        int n, D, dif, negative = 0;

        HashSet<String> hashSet = new HashSet<>();
        HashSet<String> numberSet = new HashSet<>();
        hashSet.add("0");
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        int[] diff = new int[n - 1];
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            numberSet.add(String.valueOf(a[i]));
        }

        for (int i = 0; i < n - 1; i++) {
            diff[i] = a[i + 1] - a[i];
            dif = a[i + 1] - a[i];
            hashSet.add(String.valueOf(Math.abs(dif)));
        }
        Arrays.sort(diff);

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

        int hasSize = hashSet.size();

        if (hasSize == 2 && numberSet.size() <= 3) {
            if (diff[0] < 0) {
                diff[0] = Math.abs(diff[0]);
                negative = 1;
            }

            if (diff[0] == diff[diff.length - 1] && diff[diff.length - 1] % 2 == 1) {
                System.out.println(diff[0]);
            } else if (negative == 1 && diff[diff.length - 1] % 2 == 0) {
                System.out.println(diff[diff.length - 1]);
            } else if (negative == 0 && diff[diff.length - 1] % 2 == 0) {
                System.out.println(diff[diff.length - 1] / 2);
            } else {
                System.out.println(diff[0]);
            }
        } else if (hasSize == 1) {
            System.out.println("0");
        } else {
            System.out.println("-1");
        }

    }
}

import java.util.*;
public class Cf1154B {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n,i,j,s=0,temp,p;
		n=sc.nextInt();
		int []arr=new int[3];
		for(i=0;i<n;i++) {
			p=sc.nextInt();
			if(s==4)
				continue;
			else if(s==0) {
				arr[0]=p;
				s++;
			}
			else if(s==1) {
				if(p!=arr[0]) {
					arr[1]=p;
					s++;
				}
			}
			else if(s==2) {
				if(p!=arr[0] && p!=arr[1]) {
					arr[2]=p;
					s++;
				}
			}
			else {
				if(p!=arr[0] && p!=arr[1] && p!=arr[2])
					s=4;
			}

		}
		if(s==4)
			System.out.println("-1");
		else if(s==1)
			System.out.println("0");
		else if(s==2)
			System.out.println(Math.max(arr[0],arr[1])-Math.min(arr[0],arr[1]));
		else {
			Arrays.sort(arr);
			if(arr[2]-arr[1]==arr[1]-arr[0])
				System.out.println(arr[2]-arr[1]);
			else
				System.out.println("-1");
		}
		sc.close();
	}

}

import java.io.BufferedReader;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

			public class MMAIN {

					static final int MAX = (int)1e5;
					public static void main(String[] args) throws FileNotFoundException {

							MyScanner scanner = new MyScanner();
							PrintWriter out = new PrintWriter(System.out);

							int n = scanner.nextInt();
							int[] a = new int[n];

							if(n == 0) {
								System.out.println(0);
								return;
							}

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

							int min = Integer.MAX_VALUE;
							loop:
							for(int i = 0; i <= 100; ++i) {
								int mm = Integer.MAX_VALUE;
								for(int j = 0; j < n ; ++j) {
									if(a[j] == i) continue;
									if(mm == Integer.MAX_VALUE) {
										mm = Math.abs(a[j] - i);
									}else {
										int dd = Math.abs(a[j] - i);
										if(dd != mm) continue loop;
									}
								}
								min = Math.min(min, mm);
							}

							if(min == Integer.MAX_VALUE) System.out.println(-1);
							else System.out.println(min);

							out.close();
					}

					static class MyScanner {
								BufferedReader br;
								StringTokenizer st;

								public MyScanner() throws FileNotFoundException {
								  // br = new BufferedReader	(new InputStreamReader(new FileInputStream("input.txt")));
									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.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(new InputStreamReader(System.in));
        int size = scanner.nextInt();
        ArrayList<Integer> nums = new ArrayList<>(size);

        for (int i = 0; i < size; i++) {
            nums.add(scanner.nextInt());
        }

        nums.sort(Integer::compareTo);

        Set<Integer> numSet = new HashSet<>(nums);
        ArrayList<Integer> numArray = new ArrayList<>(numSet);

        if (numArray.size() > 3){
            System.out.println(-1);
        }else if(numArray.size() == 3){
            int x1 = numArray.get(0);
            int x2 = numArray.get(1);
            int x3 = numArray.get(2);
            if (x2 - x1 == x3 - x2){
                System.out.println(x3 - x2);
            }else{
                System.out.println(-1);
            }
        }else if(numArray.size() == 2){
            System.out.println(numArray.get(1) - numArray.get(0));
        }else if(numArray.size() == 1){
            System.out.println(0);
        }
    }
}

import java.util.*;
import java.lang.*;
public class Equal_2{
	public static void main(String args[])
	{
		int n,i,d,flag=0,k=0,is=0,m=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int arr[]=new int[n];
		int arr2[]=new int[n];
		for(i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
		}

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

            int j;
            for (j = 0; j < i; j++)
            if (arr[i] == arr[j])
                break;
            if (i == j)
			{
               arr2[m]=arr[i];
		       m++;
			}
		}

       if(m>3)
           System.out.println(-1);
	   else
	   {
		   if(m==1)
			   System.out.println(0);
		   else if(m==3)
		   {
		     if (arr2[1] - arr2[0] != arr2[2] - arr2[1]) {
				System.out.println(-1);
			} else {
				System.out.println(arr2[1]-arr2[0]);
			}
		   }
		   else
	   {
		   if((arr2[1]-arr2[0])%2==0)
			   System.out.println((arr2[1]-arr2[0])/2);
		   else
			   System.out.println(arr2[1]-arr2[0]);
	   }

	   }

	}
}

/* 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 Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int arr[] = new int[n];
		int mx =-1;
		int min = 9999;
		for(int i =0;i<n;i++){
		    arr[i] = input.nextInt();
		    mx = Math.max(arr[i],mx);
		    min = Math.min(min,arr[i]);
		}int diff = 0;
		for(int i =min;i<=mx;i++){
		    HashSet<Integer>set = new HashSet<>();
		    for(int j =0;j<n;j++){
		         diff = Math.abs(arr[j]-i);
		        set.add(diff);
		    }
		    if(set.size() == 1){
		        System.out.println(diff);
		        return;
		    }
		}
		System.out.println("-1");

	}
	public static boolean check(int arr[]){
	    HashSet<Integer>set = new HashSet<>();
	    for(int it:arr)set.add(it);
	    return set.size() == 1?true:false;
	}
}

import java.util.*;
import java.lang.*;
import java.lang.reflect.Array;
import java.io.*;
import java.math.*;
import java.text.DecimalFormat;

public class Prac{

    static class InputReader {

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

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

		public int read() {
			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 ni() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

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

		public String rs() {
			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 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 boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

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

	}
    static PrintWriter w = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        InputReader sc=new InputReader(System.in);
      int n=sc.ni();
      int arr[]=new int[n];
      for(int i=0;i<n;i++){
          arr[i]=sc.ni();
      }

      int ans=-1;
       boolean found=false;
       if(n==1)
           w.println(0);
       else{
      for(int i=0;i<=500;i++){
          found=false;
          int a=arr[0]-i;
          int b=arr[0]+i;
          int c=arr[0];
          for(int j=1;j<n;j++){
              if(arr[j]-i==a||arr[j]+i==a||arr[j]-i==b||arr[j]+i==b||arr[j]-i==c||arr[j]+i==c||arr[j]==a||arr[j]==b||arr[j]==c){
                  found=true;
                  ans=i;

              }
              else{
                  found=false;
                  break;

              }
          }
          if(found){
              w.println(i);
              break;
          }
      }
     if(!found)
         w.println(-1);
       }
        w.close();
    }
}

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

public class Solution{

    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().split(" ");

    TreeSet<Integer> ts=new TreeSet<>();
    for(int i=0;i<n;i++)
        ts.add(Integer.parseInt(str[i]));
    int ans=0;
    ArrayList<Integer> arr=new ArrayList<>();
    arr.addAll(ts);

    if(ts.size()==1)
        ans=0;
    else if(ts.size()==2){
        if((arr.get(0)+arr.get(1))%2==0)
            ans=(arr.get(0)+arr.get(1))/2;
        else
            ans=arr.get(1)-arr.get(0);
    }
    else if(ts.size()==3){
        if(arr.get(1)-arr.get(0)==arr.get(2)-arr.get(1))
            ans=arr.get(1)-arr.get(0);
        else
            ans=-1;
    }
    else
        ans=-1;

    System.out.println(ans);
    }
}

	/*package whatever //do not write package name here */
import java.io.*;
import java.util.*;
public final class Contest
{
	 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 IOException
    {
    	FastReader sc=new FastReader();
    	int n=sc.nextInt();
    	int a[]=new int[n];
    	HashSet<Integer> hs=new HashSet<Integer>();
    	for(int i=0;i<n;i++)
    	{
    		a[i]=sc.nextInt();
    		hs.add(a[i]);
    	}
    	if(hs.size()>3)
    	{
    		System.out.println(-1);System.exit(0);
    	}
    	int k[]=new int[3];
    	int ctr=0;
    	for(Integer i:hs)
    	{
    		k[ctr++]=i;
    	}
    	Arrays.sort(k);

    	if((k[1]-k[0]==k[2]-k[1]) && (k[0]!=0))
    		System.out.println(k[1]-k[0]);
    	else if(k[0]==0)
    	{
    		if((k[2]-k[1])%2!=0)
    			System.out.println(k[2]-k[1]);
    		else
    			System.out.println((k[2]-k[1])/2);
    	}
    	else
    		System.out.println(-1);

    }

}

/*Author: Satyajeet Singh, Delhi Technological University*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.*;
public class Main1{
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static ArrayList<Long> factorial;
    static HashSet<Integer> graph[];
/****************************************Solutions Begins*****************************************/
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        int input[]=new int[n];
        st=br.readLine().split(" ");
        TreeSet<Integer> set=new TreeSet<>();
        for(int i=0;i<n;i++){
            input[i]=Integer.parseInt(st[i]);
            set.add(input[i]);
        }
        if(set.size()<=3){
            if(set.size()==1){
                out.println(0);
            }
            else if(set.size()==2){
                out.println(set.last()-set.first());
            }
            else{
                ArrayList<Integer> list=new ArrayList<>();
                for(int u:set){
                    list.add(u);
                }
                Collections.sort(list);
                int diff=list.get(1)-list.get(0);
                boolean flag=true;
                for(int i=0;i<2;i++){
                    if(diff!=list.get(i+1)-list.get(i)){
                        flag=false;
                        break;
                    }
                }
                if(flag){
                    out.println(diff);
                }
                else{
                    out.println(-1);
                }
            }
        }
        else{
            out.println(-1);
        }
/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }

/****************************************Template Begins************************************************/
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000000000");
        out.println(ft.format(d));
    }
/******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    }
    static void addEdge(int a,int b){
        graph[a].add(b);
    }
/*********************************************PAIR********************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return p1.v-p2.v;
            }
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }

        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }

        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }

        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }

        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }
/*************************************************Long Pair*************************************************/
    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return (int)(p1.v-p2.v);
            }
        }
    }
    static class Pairl implements Comparable<Pair> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }

            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }

            public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            }

            public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }

            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
/************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }
    }
/********************************************End***********************************************************/
}

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

public class cur {
    static int p=1000000007;
    public static void main(String[] args) throws Exception{
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc=new FastReader();
        StringBuilder sb=new StringBuilder();
        int n=sc.nextInt();
        int ar[]=new int[n];
       /// Set<Integer> s=new HashSet<>();
        int hs[]=new int[101];
        int s=0;
        for(int i=0;i<n;i++)
        {
            ar[i]=sc.nextInt();
            s+=ar[i];
            hs[ar[i]]++;
        }
        int ret=Integer.MAX_VALUE;
        if(s%n==0)
        {
            int lsdif=0;
            int c=0;
            for(int j=0;j<n;j++)
            {
                if(ar[j]!=s/n)
                {
                    int dif=Math.abs(ar[j]-s/n);
                    if(lsdif==0)
                        lsdif=dif;
                    if(lsdif!=dif)
                        break;
                    c++;
                }
            }
            if(n-hs[s/n]==c)
            {
                ret=Math.min(lsdif,ret);
            }

        }
        for(int i=0;i<=100;i++)
        {
            if(hs[i]>0)
            {
                int lsdif=0;
                int c=0;
                for(int j=0;j<n;j++)
                {
                    if(ar[j]!=i)
                    {
                        int dif=Math.abs(ar[j]-i);
                        if(lsdif==0)
                            lsdif=dif;
                        if(lsdif!=dif)
                            break;
                       c++;
                    }
                }
                if(n-hs[i]==c)
                {
                    ret=Math.min(lsdif,ret);
                }
            }
        }
        sb.append(ret==Integer.MAX_VALUE?-1:ret);
        out.write(sb.toString());
        out.flush();
    }

    ///////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////
    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;
        }
    }

}

import java.util.Scanner;

/**
 * Created by suren on 4/16/19.
 */
public class TestB {
    public static void main(String[] args) {

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

        for (int i = 0 ; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        D:
        for(int d = 0; d <= 100; d++) {

            int max = a[0] + d;
            int min = a[0] - d;
            int mid = a[0];
            boolean canBeMax = true;
            boolean canBeMin = true;
            boolean canBeMid = true;

            for (int i = 1 ; i < n; i++) {
                if(canBeMax) {
                    if (a[i] + d != max && a[i] - d != max && a[i] != max) {
                        canBeMax = false;
                    }
                }
                if(canBeMin) {
                    if (a[i] + d != min && a[i] - d != min && a[i] != min) {
                        canBeMax = false;
                    }
                }
                if(canBeMid) {
                    if (a[i] + d != mid && a[i] - d != mid && a[i] != mid) {
                        canBeMax = false;
                    }
                }
                if (canBeMax || canBeMid || canBeMin == false) {
                    continue D;
                }

            }
            if (canBeMax || canBeMid || canBeMin) {
                System.out.println(d);
                scanner.close();
                return;
            }
        }
        System.out.println(-1);
        scanner.close();
    }
}

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 Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	 Scanner sc=new Scanner(System.in);
	 int n=sc.nextInt();
	 ArrayList<Integer> al=new ArrayList<>();
	 Set<Integer> st=new HashSet<>();

	 for(int i=0;i<n;i++)
	 {
	     int a=sc.nextInt();
	     al.add(a);
	     st.add(a);
	 }
	 Collections.sort(al);
	 int max=al.get(n-1);
	 int min=al.get(0);
	 int c=0;
	 if(st.size()>1)
	 {
	 al.remove(al.get(n-1));
	 al.remove(al.get(0));
	 }
//	 System.out.println(al);
	 if((max-min)%2==0)
	 {
	      c=(max-min)/2;
	 }
	 else
	   c=max-min;
	 if(al.contains(max-c) || al.contains(min+c) || (st.size()==2 && max-c==min+c))
	  System.out.println(c);
	 else
	  System.out.println(-1);
	}
}

import java.util.Scanner;

public class problem1154B {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = 0, cnt = 0, sum = 0, small = 100, large = 0, x = 0;
        int ar[] = new int[101], arr[] = new int[100];

        for(int i = 0; i < n; i++) {
            k = sc.nextInt();
            if (k < small)
                small = k;
            if (k > large)
                large = k;
            ar[k] += 1;
            if(ar[k] == 1) {
                sum += k;
                cnt++;
                arr[x] = k;
                x++;
            }
        }
        sc.close();

        if (large == small) {
            System.out.println(0);
            return;
        }

        int avg = sum / cnt;
        int arrr[] = new int[arr.length],d = 0;
        for(int i = 0; i < x; i++) {
            arrr[i] = Math.abs(arr[i] - avg);
            if (arrr[i] != 0)
                d = arrr[i];
        }
        for(int i = 0; i <= x; i++) {
            if (arrr[i] != 0 && d != arrr[i]) {
                d = -1;
                break;
            }
        }

        System.out.println(d);
    }
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Main {
	static ArrayList<Integer> adj[];
	static ArrayList<Edge> adjlist[];

	static int n;

	public static void main(String args[]) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n=sc.nextInt();
		int a[]=new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}
		for (int i = 1; i <=200; i++) {
			int start=a[0]-i;
			boolean f=true;
			if(start<0)
				f=false;
			for (int j = 1; j <a.length; j++) {
				if(a[j]-i!=start&&a[j]+i!=start&&a[j]!=start) {
					f=false;
					break;
				}
			}

			if(f) {
				System.out.println(i);
				return;
			}
			 start=a[0]+i;
			 if(start<0)
					f=false;
			 f=true;
            for (int j = 1; j <a.length; j++) {
            	if(a[j]-i!=start&&a[j]+i!=start&&a[j]!=start) {
					f=false;
					break;
				}
			}

            if(f) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}
	static int up[][];
	static int tin[];
	static int tout[];
	static int timer=0;
	static int[] height,first;
	static int l=0;
	static int parent[];
	static void binarylifting(int v,int p) {
		tin[v] = ++timer;
		up[v][0] = p;

		    for (int i = 1; i <=l; ++i) {
		        up[v][i] = up[up[v][i-1]][i-1];

		    }
		        for (int i = 0; i < adj[v].size(); i++) {
		    		int u=adj[v].get(i);
		        	if (u != p)
			    	{
			    		binarylifting(u, v);
			    	}
				}

		        tout[v] = ++timer;
	}
	static boolean is_ancestor(int u, int v)
	{
	    return tin[u] <= tin[v] && tout[u] >= tout[v];
	}
	static int lca(int u, int v)
	{
	    if (is_ancestor(u, v))
	        return u;
	    if (is_ancestor(v, u))
	        return v;
	    for (int i = l; i >= 0; --i) {
	        if (!is_ancestor(up[u][i], v))
	            u = up[u][i];
	    }
	    return up[u][0];
	}
	static boolean vis[];
	static void dfs(int u,int h) {
		vis[u]=true;
		height[u]=h;
		for(int v:adj[u]) {
			if(!vis[v]) {
				parent[v]=u;
				dfs(v,h+1);
			}
		}
	}
	static class Edge implements Comparable<Edge>
	{
		int node;int cost;

		Edge(int a, int b) { node = a;	cost = b; }

		public int compareTo(Edge e){ return cost-e.cost;	}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

//  30/07/20  3:36 PM  Jul  2020

import java.io.*;
import java.sql.SQLIntegrityConstraintViolationException;
import java.util.*;

public class _1154B {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        HashSet<Integer> hset = new HashSet<>();
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            hset.add(arr[i]);
        }
        ArrayList<Integer> l = new ArrayList<>(hset);
        boolean check = true;
        if(l.size()==1)
            System.out.println("0");
        else if (l.size() == 2)
            System.out.println(Math.abs(l.get(1) - l.get(0)));
        else {
            if (Math.abs(l.get(0) - l.get(1)) != Math.abs(l.get(2) - l.get(1)))
                check = false;

            if (hset.size() > 3 || !check)
                System.out.println("-1");
            else {
                System.out.println(Math.abs(l.get(0) - l.get(1)));
            }
        }
    }
}

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

public class MakeThemEqual {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = scanner.nextInt();
        }
        Arrays.sort(arr);
        int first = arr[0];
        for(int i = 0; i < 50; i++){
            int j = 0;
            while (j < n){
                if (first + i == arr[j] || first + 2*i == arr[j] || first == arr[j]){
                    j++;
                    if(j == n){
                        System.out.println(i);
                        return;
                    }
                }else break;
            }
        }
        System.out.println(-1);
    }
}

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

public class ques2  {
    public static void main(String[] args) {
      Scanner scan=new Scanner(System.in);
      int n=0,p,q;
      if (scan.hasNext())
          n=scan.nextInt();
      HashSet<Integer> set=new HashSet<>();

      int[] arr=new int[n];
      for (int i=0;i<n;i++){
          if (scan.hasNext())
              arr[i] = scan.nextInt();
      }
      Arrays.sort(arr);

          for (int i=0;i<n-1;i++){
              set.add(arr[i+1]-arr[i]);
          }

        Iterator<Integer> it=set.iterator();
      if (set.size()==1){
          p=it.next();
          if (p%2==0)
          System.out.println(p/2);
          else
              System.out.println(p);
      }else if (set.size()==2){
          p=it.next();
          q=it.next();
          if (p==0){
              if (q%2==0)
              System.out.println(q/2);
              else
                  System.out.println(q);
          }else if(q==0){
              if (p%2==0)
              System.out.println(p/2);
              else
                  System.out.println(p);
          }else {
              System.out.println(-1);
          }

      }else{
          System.out.println(-1);
      }

    }
}

import java.io.*;

import java.util.*;

public class Main {
    static  OutputWriter out;
    public static void main(String[] args) throws Exception
    {
        Scanner in = new Scanner(System.in);
        out = new OutputWriter(System.out);
          int n =in.nextInt();
          int[]a = new int[n];
          for (int i =0;i<n;i++)
              a[i]=in.nextInt();
          int diff = 0;
          for (int i =1;i<n;i++)
          {
              if (Math.abs(a[i]-a[i-1])!=0)
              {
                  diff = Math.abs(a[i]-a[i-1]);
                  break;
              }
          }
          boolean check = true;
          for (int i =2;i<n;i++)
          {
              if (Math.abs(a[i]-a[i-1])!=diff&&Math.abs(a[i]-a[i-1])!=0)
              {
                  check=false;
                  break;
              }
          }
          if (!check)
              out.printLine(-1);
          else
          {
              if (diff%2==0)
                  out.printLine(diff/2);
              else
                  out.printLine(diff);
          }
        out.flush();
    }

}

class Graph {

    int n;
    ArrayList<Integer>[] adjList;

    public Graph(int n) {
        this.n = n;
        adjList = new ArrayList[n];
        for (int i = 0; i < n; i++)
            adjList[i] = new ArrayList<>();
    }

}
class pair  implements Comparable
{

    int key;
    int value;

    public pair(Object key, Object value) {

        this.key = (int)key;
        this.value=(int)value;

    }

    @Override
    public int compareTo(Object o) {
        pair temp =(pair)o;
        return  key-temp.key;
    }
}
class Scanner {

    StringTokenizer st;
    BufferedReader br;

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

    public Scanner (FileReader f) {
        br = new BufferedReader(f);
    }

    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());
    }

    public String nextLine() throws IOException {
        return br.readLine();
    }

    public double nextDouble() throws IOException {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if (x.charAt(0) == '-') {
            neg = true;
            start++;
        }
        for (int i = start; i < x.length(); i++)
            if (x.charAt(i) == '.') {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            } else {
                sb.append(x.charAt(i));
                if (dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg ? -1 : 1);
    }

    public boolean ready() throws IOException {
        return br.ready();
    }

    public boolean nextEmpty() throws IOException {
        String s = nextLine();
        st = new StringTokenizer(s);
        return s.isEmpty();
    }
}
class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

    public void flush() {
        writer.flush();
    }

}

// Working program using Reader Class
import java.io.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main
{
	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();
		}
	}

	public static int gcd(int a, int b)
    {
        // Everything divides 0
        if (a == 0 || b == 0)
           return 0;

        // base case
        if (a == b)
            return a;

        // a is greater
        if (a > b)
            return gcd(a-b, b);
        return gcd(a, b-a);
    }

	public static long change(char c,char d,long A,long B,long C) {
		if(c==d) {
			return 0;
		}
		else if((c=='1' && d=='3') || (c=='3' && d=='1')) {
			return C;
		}
		else if((c=='1' && d=='2') || (c=='2' && d=='1')) {
			return A;
		}
		else {
			return B;
		}
	}

	public static void main(String[] args) throws IOException
	{
		//Reader scan=new Reader();
		Scanner scan=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=scan.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		Arrays.sort(a);
		int ans=Integer.MAX_VALUE;
		for(int i=a[0];i<=a[n-1];i++) {
			int d=-1;
			int done=0;
			for(int j=0;j<n;j++) {
				if(a[j]!=i) {
					if(d==-1) {
						d=Math.abs(a[j]-i);
					}
					else {
						if(a[j]+d!=i && a[j]-d!=i) {
							done=1;
							break;
						}
					}
				}
			}
			if(done==0) {
				ans=Math.min(ans, d);
			}
		}
		if(ans==Integer.MAX_VALUE) {
			out.print(-1);
		}
		else {
			out.print(ans);
		}
		out.close();
	}
}

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.*;
import java.io.*;
public class Tree
{
    public static void main (String args[]) throws Exception
    {
        Scanner in =new Scanner(System.in);
        int N=in.nextInt();
        int a[] = new int[N];
        int max=-1;int min=101;
        for (int x=0;x<N;x++)
        {
            a[x]=in.nextInt();
            min=Math.min(min,a[x]);
            max=Math.max(max,a[x]);
        }
        int k=0;int p=0;int w=0;
        for (int x=min;x<=max;x++)
        {
            p=0;k=Math.abs(x-a[0]);
            for (int y=1;y<N;y++)
            {
                if (Math.abs(a[y]-x)==k || Math.abs(a[y]-x)==0)
                continue;
                else
                {p=1;break;}
            }
            if (p==0)
            {System.out.println (k);w=1;break;}
        }
        if (w==0)
        System.out.println ("-1");
    }
}

import java.util.*;
public class make_them_equal
{
	public static int gcd(int a,int b)
	{
		if(b==0)
		{
			return a;
		}
		else
			return gcd(b,a%b);
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		Integer arr[]=new Integer[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=in.nextInt();
		}
		if(n==2)
		{
			if((arr[1]-arr[0])%2==0)
				System.out.println((arr[1]-arr[0])/2);
			else
				System.out.println("-1");
			return;
		}
		Arrays.sort(arr);
		HashSet<Integer> set=new HashSet<Integer>();
		for(int i=0;i<n-1;i++)
		{
			if(Math.abs(arr[i+1]-arr[i])!=0)
			{
				set.add(Math.abs(arr[i+1]-arr[i]));
			}
		}
		if(set.size()==1)
		{
			for(int i:set)
			System.out.println(i);
		}
		else if(set.isEmpty())
		System.out.println("0");
		else
			System.out.println("-1");
	}
}

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

public class Backtracking {

    static char[] chars;
    public static void main(String[] args) {
        Scanner io = new Scanner(System.in);
        int N = io.nextInt();
        Set<Integer> tmp = new HashSet<>();
        for(int i = 0; i < N; i++) tmp.add(io.nextInt());
        Integer arr[] = new Integer[tmp.size()];
        tmp.toArray(arr);
        Arrays.sort(arr);
        if(arr.length > 3) { System.out.println(-1); return; }
        if(arr.length == 1) { System.out.println(0); return; }
        if(arr.length == 2) {
            if((arr[0] + arr[1]) % 2 == 0)
                System.out.println((arr[0] + arr[1]) / 2);
            else
                System.out.println(arr[1] - arr[0]);
            return;
        }
        if(Arrays.binarySearch(arr, (arr[2] + arr[0]) / 2) >= 0) System.out.println(arr[2] - arr[1]);
        else System.out.println(-1);
    }
    public static int summ(Integer[] arr) {
        int sum = 0;
        for(int a: arr) sum += a;
        return sum;
    }
}

/* 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 Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int arr[] = new int[n];
		int mx =-1;
		int min = 9999;
		for(int i =0;i<n;i++){
		    arr[i] = input.nextInt();
		    mx = Math.max(arr[i],mx);
		    min = Math.min(min,arr[i]);
		}int diff = 0;
		int res = 99999;
		boolean ok = false;
		for(int i =min;i<=mx;i++){
		    HashSet<Integer>set = new HashSet<>();
		    for(int j =0;j<n;j++){
		        if(arr[j] == i)continue;
		         diff = Math.abs(arr[j]-i);
		         set.add(diff);
		    }
		    if(set.size() == 1){
		       res = Math.min(res,diff);
		       ok = true;
		    }
		}
		if(ok)System.out.println(res);
		else System.out.println(-1);

	}
	public static boolean check(int arr[]){
	    HashSet<Integer>set = new HashSet<>();
	    for(int it:arr)set.add(it);
	    return set.size() == 1?true:false;
	}
}

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

public class Backtracking {

    static char[] chars;
    public static void main(String[] args) {
        Scanner io = new Scanner(System.in);
        int N = io.nextInt();
        Set<Integer> tmp = new HashSet<>();
        for(int i = 0; i < N; i++) tmp.add(io.nextInt());
        Integer arr[] = new Integer[tmp.size()];
        tmp.toArray(arr);
        Arrays.sort(arr);
        if(arr.length > 3) { System.out.println(-1); return; }
        if(arr.length == 1) { System.out.println(0); return; }
        if(arr.length == 2) {
            if((arr[0] + arr[1]) % 2 == 0)
                System.out.println(arr[0] - (arr[0] + arr[1]) / 2);
            else
                System.out.println(arr[1] - arr[0]);
            return;
        }
        if(Arrays.binarySearch(arr, (arr[2] + arr[0]) / 2) >= 0) System.out.println(arr[2] - arr[1]);
        else System.out.println(-1);
    }
    public static int summ(Integer[] arr) {
        int sum = 0;
        for(int a: arr) sum += a;
        return sum;
    }
}

import java.util.*;
public class B1
{
    public static void main(String ar[])
    {
        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);
        if(n==1)
        {
            System.out.println(0);
            return;
        }
        if(n==2)
        {
            System.out.println((a[1]-a[0])/2);
            return;
        }

        int t=0;
        for(int i=1;i<n-1;i++)
        {
            if(a[i]!=a[0] && a[i]!=a[n-1])
                t=1;
        }
        if(t==0)
        {
            if(a[0]==a[n-1])
            {
                System.out.println(0);return;
            }
            else
            {
                System.out.println((a[n-1]+a[0])/2);return;
            }
        }

        for(int i=1;i<n-1;i++)
        {
            int d=Math.abs(a[i]-a[0]);
            int j=0;
            for(j=0;j<n;j++)
            {
                if(a[j]!=a[i] && Math.abs(a[j]-a[i])!=d)
                    break;
            }
            if(j==n)
            {
                System.out.println(Math.abs(a[i]-a[0]));
                return;
            }
        }
        System.out.println(-1);
    }
}

import java.util.*;
import java.io.*;
public class aprail152
{
    static class InputReader {
        private InputStream stream;
        private byte[] inbuf = new byte[1024];
        private int start= 0;
        private int end = 0;
        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int readByte() {
            if (start == -1) throw new UnknownError();
            if (end >= start) {
                end= 0;
                try {
                    start= stream.read(inbuf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (start<= 0) return -1;
            }
            return inbuf[end++];
        }

        private boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        private int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

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

        public int nextInt() {
            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();
            }
        }

        public long nextLong() {
            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();
            }
        }
    }
    public static void main(String args[])
    {
        InputReader sc=new InputReader(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
            a[i]=sc.nextInt();
        TreeSet<Integer> t=new TreeSet<>();
        for(int i=0;i<n;i++)
            t.add(a[i]);
        int ar[]=new int[t.size()];
        int p=0,sum=0;
        for(Integer h:t)
        {
            ar[p]=h;
            p++;
        }
        int len=t.size();
        if(len==1)
        System.out.println(ar[0]);
        else if(len==2)
        {
           if(Math.abs(ar[0]-ar[1]+1)%2==0)
           System.out.println(Math.abs(ar[0]-ar[1]));
           else
           {
               int mean=(ar[0]-ar[1])/2;
               System.out.println(mean-ar[0]);
           }
        }
        else if(len==3)
        {
            if((ar[1]-ar[0])==(ar[2]-ar[1]))
            System.out.println(ar[1]-ar[0]);
            else
            System.out.println(-1);
        }
        else
        System.out.println(-1);
    }
}

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

public class Make_Them_Equal_552_B {

    public static void main(String[] args) {
        int n, D, dif, negative = 0;

        HashSet<String> hashSet = new HashSet<>();
        hashSet.add("0");
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        int[] diff = new int[n - 1];
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }

        for (int i = 0; i < n - 1; i++) {
            diff[i] = a[i + 1] - a[i];
            dif = a[i + 1] - a[i];
            hashSet.add(String.valueOf(Math.abs(dif)));
        }
        Arrays.sort(diff);

        int hasSize = hashSet.size();

        if (hasSize == 2) {
            if (diff[0] < 0) {
                diff[0] = Math.abs(diff[0]);
                negative = 1;
            }

            if (diff[0] == diff[diff.length - 1] && diff[diff.length - 1] % 2 == 1) {
                System.out.println(diff[0]);
            } else if (negative == 1 && diff[diff.length - 1] % 2 == 0) {
                System.out.println(diff[diff.length - 1]);
            } else if (negative == 0 && diff[diff.length - 1] % 2 == 0) {
                System.out.println(diff[diff.length - 1] / 2);
            }
        } else if (hasSize == 1) {
            System.out.println("0");
        } else {
            System.out.println("-1");
        }

    }
}

import java.util.*;
public class Cf1154B {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n,i,j,s=0,temp,p;
		n=sc.nextInt();
		int []arr=new int[3];
		for(i=0;i<n;i++) {
			p=sc.nextInt();
			if(s==4)
				continue;
			else if(s==0) {
				arr[0]=p;
				s++;
			}
			else if(s==1) {
				if(p!=arr[0]) {
					arr[1]=p;
					s++;
				}
			}
			else if(s==2) {
				if(p!=arr[0] && p!=arr[1]) {
					arr[2]=p;
					s++;
				}
			}
			else {
				if(p!=arr[0] && p!=arr[1] && p!=arr[2])
					s=4;
			}

		}
		if(s==4)
			System.out.println("-1");
		else if(s==1)
			System.out.println("0");
		else if(s==2)
			System.out.println(Math.max(arr[0],arr[1])-Math.min(arr[0],arr[1]));
		else {
			Arrays.sort(arr);
			if(arr[2]-arr[1]==arr[1]-arr[0])
				System.out.println(arr[2]-arr[1]);
			else
				System.out.println("-1");
		}
		sc.close();
	}

}

import java.util.*;

public class MyClass {
    static Scanner scan = new Scanner(System.in);

    static long[] arr = new long[2000005];
    static ArrayList<Long> numList = new ArrayList<Long>();
    public static void main(String args[]) {
        int n;
        n = scan.nextInt();
        for(int i=0;i<n;i++){
            long x=scan.nextLong();
            if(numList.size()==0){
                numList.add(x);
            }

            else{
                if(numList.contains(x)==false) numList.add(x);
                if(numList.size()>3) break;
            }
        }
        Collections.sort(numList);

        if(numList.size()==1) System.out.println("0");
        else if(numList.size()==2){
            long temp=numList.get(1)-numList.get(0);
            if(temp%2==0) temp/=2;
            System.out.println(temp);
        }

        else if(numList.size()==3){
            if(numList.get(1)-numList.get(0) == numList.get(2)-numList.get(1)){
                long temp=numList.get(1)-numList.get(0);
                System.out.println(temp);
            }
            else{
                System.out.println("-1");
            }
        }

    }
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class codeForces {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> l = new ArrayList<Integer>();
		int j = 0;

		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			if (!l.contains(x)) {
				l.add(x);
			}
		}

		if (l.size() > 3) {
			System.out.println(-1);
		} else if (l.size() == 1 && l.size() == 0) {
			System.out.println(0);
		} else if (l.size() == 2) {
			Collections.sort(l);
			int y = l.remove(0);
			int x = l.remove(0);

			if ((x-y) % 2 == 0) {
				System.out.println((x-y)/2);
			} else {
				System.out.println(x-y);
			}
		} else if (l.size() == 3) {
			Collections.sort(l);
			int x = l.remove(0);
			int y = l.remove(0);
			int z = l.remove(0);

			if (x-y == y -z) {
				System.out.println(y-x);
			} else {
				System.out.println(-1);
			}
		}

	}

}

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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new PrintStream(System.out));
        int n=Integer.parseInt(f.readLine());
        StringTokenizer st=new StringTokenizer(f.readLine());
        int []arr=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=Integer.parseInt(st.nextToken());
        }
        HashSet<Integer>has=new HashSet<>();
        has.add(1);
        boolean a=has.contains(1);
        boolean bool=true;
        po:
        for(int i=0;i<=100;i++){
            HashSet<Integer>hs=new HashSet<>();
            p:
            for(int j=0;j<n;j++){
                if(hs.contains(arr[j]+i)|| hs.contains(arr[j]-i) || hs.contains(arr[j])){
                    hs.add(arr[j]+i);
                    hs.add(arr[j]-i);
                    hs.add(arr[j]);
                }
                else{
                   if(j==0){
                       hs.add(arr[j]+i);
                       hs.add(arr[j]-i);hs.add(arr[j]);

                       continue p;
                   }
                   else{
                       continue po;
                   }

                }
            }
            Iterator<Integer> it = hs.iterator();
            int dif=-1;
            op:
            while(it.hasNext()){
                int o=it.next();
                for(int j=0;j<n;j++){
                    if((Math.abs(arr[j]-o)!=dif && o-arr[j]!=0) && j!=0){
                        continue op;
                    }
                    if(o-arr[j]!=0){
                        dif=arr[j]-o;
                        dif= Math.abs(dif);
                    }
                }
                bool=false;
                System.out.println(dif);
                break po;
            }

        }
        if(bool){
            out.println(-1);
        }
        f.close();
        out.close();
    }
}

	/*package whatever //do not write package name here */
import java.io.*;
import java.util.*;
public final class Contest
{
	 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 IOException
    {
    	FastReader sc=new FastReader();
    	int n=sc.nextInt();
    	int a[]=new int[n];
    	HashSet<Integer> hs=new HashSet<Integer>();
    	for(int i=0;i<n;i++)
    	{
    		a[i]=sc.nextInt();
    		hs.add(a[i]);
    	}
    	if(hs.size()>3)
    	{
    		System.out.println(-1);System.exit(0);
    	}
    	int k[]=new int[3];
    	int ctr=0;
    	for(Integer i:hs)
    	{
    		k[ctr++]=i;
    	}
    	Arrays.sort(k);

    	if((k[1]-k[0]==k[2]-k[1]) && (k[0]!=0))
    		System.out.println(k[1]-k[0]);
    	else if(k[0]==0)
    	{
    		if((k[2]-k[1])%2!=0)
    			System.out.println(k[2]-k[1]);
    		else
    			System.out.println((k[2]-k[1])/2);
    	}
    	else if(k[0]==0 && k[1]==0)
    		System.out.println(0);
    	else
    		System.out.println(-1);

    }

}

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
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 sum=0;

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

		int count=0;

		Map<Integer,Integer> map=new HashMap<>();

		ArrayList<Integer> list=new ArrayList<>();

		for(int i=0;i<n;i++)
		{
			if(!map.containsKey(arr[i]))
			{
				map.put(arr[i],1);
				list.add(arr[i]);
				count++;
			}
		}

		if(count>3)
		{
			System.out.println(-1);
		}
		else
		{
			if(count==1)
			{
				System.out.println(0);
			}
			else if(count==2)
			{
				int diff=Math.abs(list.get(0)-list.get(1));
				int exp=Integer.MAX_VALUE;

				if((list.get(0)+list.get(1))%2==0)
				{
					exp=list.get(1)-(list.get(0)+list.get(1))/2;
				}

				System.out.println(Math.min(diff,exp));
			}
			else
			{
				Collections.sort(list);

				if((list.get(0)+list.get(2))/2==list.get(1))
				{
					System.out.println(list.get(1)-list.get(0));
				}
				else
				{
					System.out.println(-1);
				}
			}
		}

	}

}

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();
		List<Integer> l = new ArrayList<>();
		for(int i=0;i<n;i++){
		    int a = sc.nextInt();
		    if(!l.contains(a)){
		        l.add(a);
		    }
		}
		if(l.size()>3) System.out.println(-1);
		else if(l.size()==3){
		    Collections.sort(l);
		    if(l.get(2)-l.get(1)==l.get(1)-l.get(0)) System.out.println(l.get(1)-l.get(0));
		    else System.out.println(-1);
		}
		else if(l.size()==2){
		   int x = l.get(0);
		   int y = l.get(1);
		   if((x%2==0&&y%2==0)||(x%2==1&&y%2==1)) System.out.println(y - (x+y)/2);
		   else System.out.println(l.get(1)-l.get(0));
		}
		else{
		    System.out.println(0);
		}
	}
}

import java.util.Scanner;

public class problem1154B {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = 0, cnt = 0, sum = 0, small = 100, large = 0;
        int ar[] = new int[101];

        for(int i = 0; i < n; i++) {
            k = sc.nextInt();
            if (k < small)
                small = k;
            if (k > large)
                large = k;
            ar[k] += 1;
            if(ar[k] == 1) {
                sum += k;
                cnt++;
            }
        }
        sc.close();

        if (large == small) {
            System.out.println(0);
            return;
        }

        int avg = sum / cnt;
        if (sum % cnt != 0) {
            if (cnt == 2)
                System.out.println(large - small);
            else
                System.out.println(-1);
        } else {
            if (avg == k)
                System.out.println(k);
            else
                System.out.println(Math.abs(k - avg));
        }

    }
}

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

public class B {

	public static int binSearchTwo(final int [] data) {
		int lo = 0;
		int hi = data[1] + 1;
		int minMid = Integer.MAX_VALUE;
		while (lo + 1 != hi) {
			int mid = (lo + hi) >> 1;
			if (data[0] + mid == data[1] - mid) {
				minMid = Math.min(minMid, mid);
				hi = mid;
			} else {
				// Si me paso del primero con mid entones debo bajarle a la cota superior
				if (data[0] + mid > data[1] - mid) {
					hi = mid;
				} else {
					lo = mid;
				}
			}
		}

		if (data[0] + lo == data[1] - lo) {
			minMid = Math.min(minMid, lo);
		}

		lo = 0;
		hi = data[1] + 1;
		while (lo + 1 != hi) {
			int mid = (lo + hi) >> 1;
			if (data[0] + mid == data[1]) {
				minMid = Math.min(minMid, mid);
				hi = mid;
			} else {
				// Si me paso del primero con mid entones debo bajarle a la cota superior
				if (data[0] + mid > data[1]) {
					hi = mid;
				} else {
					lo = mid;
				}
			}
		}

		if (data[0] + lo == data[1]) {
			minMid = Math.min(minMid, lo);
		}
		return minMid;
	}

	public static int findTheAnswerOther(final int [] data) {
		int n = data.length;
		outer : for (int mid = 1; mid < data[n - 1]; ++ mid) {
			int initialDiff = Math.abs(mid - data[0]);
			for (int i = 1; i < n; ++ i) {
				if (data[i] != mid) {
					int myDiff = Math.abs(mid - data[i]);

					// This mid cannot be assigned
					if (myDiff != initialDiff) {
						continue outer;
					}
				}
			}
			return initialDiff;
		}
		return -1;
	}

	public static void main(final String [] args) throws Exception {
		final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

		int n = Integer.parseInt(reader.readLine());
		ArrayList<Integer> list = new ArrayList<>();

		String [] parts = reader.readLine().split(" ");
		HashSet<Integer> set = new HashSet<Integer>();

		for (int i = 0; i < n; ++ i) {
			int val = Integer.parseInt(parts[i]);
			if (!set.contains(val)) {
				list.add(val);
				set.add(val);
			}
		}

		int [] arr = new int[list.size()];
		for (int i = 0; i < arr.length; ++ i) {
			arr[i] = list.get(i);
		}

		Arrays.sort(arr);

		n = arr.length;
		if (n == 2) {
			writer.write(binSearchTwo(arr) + "\n");
		} else {
			writer.write(findTheAnswerOther(arr) + "\n");
		}

		reader.close();
		writer.close();
	}
}

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

public class MyClass {
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(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;
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String s = sc.nextLine();
        int n = Integer.parseInt(s);
        int[] a = new int[n];
        String ss = sc.nextLine();
        String[] c = ss.split(" ");
        for(int i=0;i<n;i++)
        {
            a[i] = Integer.parseInt(c[i]);
        }
        Arrays.sort(a);
        int num = 0;
        if(n==1)
        {
            System.out.println(0);
            return;
        }else if(n==2)
        {
            if((a[1]-a[0])%2==0)
            {
                System.out.println(((a[1]-a[0])/2));
                return;
            }else
            {
                System.out.println(a[1]-a[0]);
                return;
            }
        }else
        {
            int first =0;
            for(int i=1;i<n;i++)
            {
                if(a[i]-a[i-1]!=0)
                {
                    if(num==0||num==a[i]-a[i-1]){
                        if(first==2)
                        {
                            System.out.println(-1);
                            return;
                        }
                        num = a[i]-a[i-1];
                        first++;
                    }else
                    {
                        System.out.println(-1);
                        return;
                    }
                }
            }
        }
        //
        if(num==0)
        {
            System.out.println(-1);
            return;
        }
        System.out.println(num);
    }
}

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

public class p2{
    public static void main(String args[]) throws IOException{
       // Scanner sc = new Scanner(System.in);
	   Reader r = new Reader();
	   float n = r.nextInt();
	   HashSet<Float> hs = new HashSet<>();
	   ArrayList<Float> al = new ArrayList<>();

	   while(n-->0){
		   float a  = r.nextInt();
		   if(!hs.contains(a))
		   	al.add(a);
		   hs.add(a);
	   }
	   if(hs.size() > 3){
		   System.out.println("-1");
		   return;
	   }
	   if(al.size() == 1){
		   System.out.println((int)al.get(0).floatValue());
		   return;
	   }
	   if(al.size() == 2){
		   float mid = Math.abs(al.get(0) - al.get(1));
		   if(mid % 2 != 0){
			System.out.println("-1");
			return;
		   }
		   else{
			System.out.println((int)mid/2);
			return;
		   }
	   }else{
		   Collections.sort(al);
		   float mid = Math.abs(al.get(0) - al.get(2));
		   if(mid % 2 != 0 || mid/2 + al.get(0) != al.get(1)){
			System.out.println("-1");
			return;
		   }
		   else{
			System.out.println((int)(mid/2));
			return;
		   }
	   }

    }
}

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();
		}
	}

import java.util.*;
import java.util.stream.IntStream;

import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode;

import java.io.*;

public class ProbA {

  private static StringTokenizer st;

    public static void nextLine(BufferedReader br) throws IOException
    {
        st = new StringTokenizer(br.readLine());
    }

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

    public static String next()
    {
        return st.nextToken();
    }

    public static long nextLong()
    {
        return Long.parseLong(st.nextToken());
    }

    public static double nextDouble()
    {
        return Double.parseDouble(st.nextToken());
    }

    void solve() throws IOException{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

         int t=1;
         // t=nextInt();
         PrintWriter out = new PrintWriter(System.out);
         while(t!=0){
             nextLine(br);
            int n=nextInt();
            // if(n==1){
            //     nextLine(br);
            //     int a=nextInt();
            //     a=-1;
            //     out.print(a);
            //     t--;
            //     break;
            // }
           HashSet<Integer> set=new HashSet<>();
           nextLine(br);
           for(int i=0;i<n;i++){
            set.add(nextInt());
           }
           int[] arr=new int[set.size()];
           Iterator it=set.iterator();
           int j=0;
           while(it.hasNext()){
            arr[j]=(int)it.next();
           // out.println(arr[j]);
            j++;
           }
           int sum=IntStream.of(arr).sum();
          // out.println(sum);
           double avg=(double)sum/arr.length;
         // out.println(avg);
           int avgc=sum/arr.length;
          // out.println(avgc);
           if(avg-avgc==0.0000000000000){
               HashSet<Integer> s=new HashSet<>();
               int c=0;
               for(int i=0;i<arr.length;i++){
                   if(avgc-arr[i]!=0){
                       s.add((int)Math.abs(avgc-arr[i]));
                   }
                   else{
                       c++;
                   }
               }
               if(s.size()==1||c==arr.length)
               {
                   out.println((int)Math.abs(avgc-arr[0]));

               }
               else{
                   out.print((checkdiff(arr)==0)? -1:checkdiff(arr));

               }
           }
           else{
             //  out.println("jii");
            out.print((checkdiff(arr)==0)? -1:checkdiff(arr));

           }

            t--;
         }

        out.close();
    }
    public int checkdiff(int[] arr){
        // Arrays.sort(arr);
        // HashSet<Integer> sd=new HashSet<>();
        // for(int i=arr.length-1;i>0;i--){
        //     sd.add(arr[i]-arr[i-1]);
        // }
        if(arr.length==2)
        return ((int)Math.abs(arr[0]-arr[1]));
        else
        return -1;
    }

    public static void main(String[] args) throws IOException {
        new Thread(null, new Runnable() {
            public void run() {
                try {
                    new ProbA().solve();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (StackOverflowError e) {
                    System.out.println("RTE");
                }
            }
        }, "1", 1 << 26).start();
    }

    }

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 Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	 Scanner sc=new Scanner(System.in);
	 int n=sc.nextInt();
	 ArrayList<Integer> al=new ArrayList<>();
	 Set<Integer> st=new HashSet<>();

	 for(int i=0;i<n;i++)
	 {
	     int a=sc.nextInt();
	     al.add(a);
	     st.add(a);
	 }
	 Collections.sort(al);
	 int max=al.get(n-1);
	 int min=al.get(0);
	 int c=0;
	 if(al.size()>1)
	 {
	 al.remove(al.get(n-1));
	 al.remove(al.get(0));
	 }
//	 System.out.println(al);
	 if((max-min)%2==0)
	 {
	      c=(max-min)/2;
	 }
	 else
	   c=max-min;
	 if(al.contains(max-c) || al.contains(min+c) || (st.size()==2 && max-c==min+c))
	  System.out.println(c);
	 else
	  System.out.println(-1);
	}
}

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 Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	 Scanner sc=new Scanner(System.in);
	 int n=sc.nextInt();
	 ArrayList<Integer> al=new ArrayList<>();
	 Set<Integer> st=new HashSet<>();

	 for(int i=0;i<n;i++)
	 {
	     int a=sc.nextInt();
	     al.add(a);
	     st.add(a);
	 }
	 Collections.sort(al);
	 int max=al.get(n-1);
	 int min=al.get(0);
	 int c=0;
	 if(st.size()>1)
	 {
	 al.remove(al.get(n-1));
	 al.remove(al.get(0));
	 }
//	 System.out.println(al);
	 if((max-min)%2==0)
	 {
	      c=(max-min)/2;
	 }
	 else
	   c=max-min;
	 if(st.size()>3)
	   c=-1;
	 if(al.contains(max-c) || al.contains(min+c) || (st.size()==2 && (max-c==min+c || max-c==min)))
	  System.out.println(c);
	 else
	  System.out.println(-1);
	}
}

/*
 * 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 Centrino
 */
public class NewClass2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      int [] a = new int [x];
        for (int i = 0; i < x; i++)
            a[i] = sc.nextInt();
        boolean t=false;

        int c []= new int [101];
        for (int i = 0; i < x; i++) {
            c[a[i]]++;
        }
        boolean v = false;
        for (int i = 0; i < x; i++) {
            if(a[0]!=a[i]){ v=true;}
        }
        int m1=0,m2=0,count=0,ch=0;
        for (int i = 99; i >= 0; i--) {
            if(m1!=0&&m2==0&&c[i]>0){m2=i;}
            if (m1==0&&c[i]>0){m1=i;}
        }
       // System.out.println(m1+" "+m2);

       ch = m1-m2;
        for (int i = 1; i < x; i++) {
            if(Math.abs(a[i]-a[i-1])!=ch&&Math.abs(a[i]-a[i-1])!=0) {t=true;}
        }
        if (!v)System.out.println(0);
        else{
        if(t)System.out.println(-1);
        else{
       boolean f =false;
        if((m1%2 == 0 && m2%2 == 0) ||(m1%2!=0 && m2%2!=0)){
            f=true;
        while(m1>0){
        m1--;
        m2++;
        count++;
        if(m1==m2)break;
        }
        }else System.out.println(ch);
        if(f){
            System.out.println(Math.min(ch, count));

        }
        }
    }
    }
    }

import java.util.*;
import java.io.*;
public class house
{
	public static void main(String args[]) throws IOException
	{
		try{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=0;
		n=Integer.parseInt(br.readLine());
		String arr[]=br.readLine().split(" ");
		int brr[]=new int[n];
		int sum=0;
		for(int i=0;i<n;i++)
		{
		brr[i]=Integer.parseInt(arr[i]);
		}
		Arrays.sort(brr);
		int median=0;
		if(brr.length%2!=0)
		{
			median=brr[((brr.length+1)/2)-1];
		}
		else
		{
			median=(brr[(brr.length/2)-1]+brr[(brr.length/2)])/2;
		}
		if(brr.length>1)
		{
		HashSet<Integer> map=new HashSet<Integer>();
		for(int i=0;i<brr.length;i++)
		{
			if(brr[i]!=median)
			{
				map.add(Math.abs(brr[i]-median));
			}
		}
		ArrayList<Integer> as=new ArrayList<Integer>(map);
		if(as.size()==1)
		{
			System.out.println(as.get(0));
		}
		else
		{
			if(as.size()==0)
			{
				System.out.println("0");
			}
			else
			{
			System.out.println("-1");}
		}}
		else
		{
			System.out.println("0");
		}
		}
	catch(Exception e){}
}}

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.*;
import java.io.*;
public class Tree
{
    public static void main (String args[]) throws Exception
    {
        Scanner in =new Scanner(System.in);
        int N=in.nextInt();
        int a[] = new int[N];
        int max=-1;int min=101;
        for (int x=0;x<N;x++)
        {
            a[x]=in.nextInt();
            min=Math.min(min,a[x]);
            max=Math.max(max,a[x]);
        }
        if (min==max)
          System.out.println ("0");
          else
          {
        int k=0;int p=0;int w=0;int m=0;
        for (int x=min;x<=max;x++)
        {
            p=0;k=Math.abs(x-a[0]);
m=0;
            while (k==0)
            {
                m++;
                k=Math.abs(x-a[m]);
            }
            for (int y=m+1;y<N;y++)
            {
                if (Math.abs(a[y]-x)==k || Math.abs(a[y]-x)==0)
                continue;
                else
                {p=1;break;}
            }
            if (p==0)
            {System.out.println (k);w=1;break;}
        }
        if (w==0)
        System.out.println ("-1");
          }
    }
}

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

public class Code {

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

    public static void main(String[] args) {
        int n = in.nextInt();
        int r = 0;
        int l = 0;
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        int i = 0;
        while (i < n - 1 && a[i] == a[i + 1] ) {
            i++;
        }
        if (i == n - 1) {
            System.out.println("0");
        } else {
            r = a[i + 1] - a[i];
            i++;
            l++;
            for (; i < n - 1; i++) {
                int b = a[i + 1] - a[i];
                if (b != r && b != 0) {
                    System.out.println("-1");
                    return;
                }
                if (b == r) {
                    l++;
                }
            }
            if(l==1 && r%2==0)System.out.println(r/2);
            if(l==1 && r%2!=0)System.out.println(r);
            if(l!=1)
            System.out.println(r);
        }
    }

}

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

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

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

		List<Integer> differences = new ArrayList<Integer>();

		for (int i = 0; i < n - 1; i ++)
		{
			int difference = sequence[i + 1] - sequence[i];
			if (difference != 0 && !differences.contains(difference))
			{
				differences.add(difference);
			}

			if (differences.size() == 0)
			{
				continue;
			}
			else if (differences.size() > 2)
			{
				System.out.println(-1);
				return;
			}
			else if (differences.size() == 2 && Math.abs(differences.get(0)) != Math.abs(differences.get(1)))
			{
				System.out.println(-1);
				return;
			}
		}

		if (differences.size() == 0)
		{
			System.out.println(0);
		}
		else if (differences.size() == 1)
		{
			if (differences.get(0) % 2 == 0)
			{
				System.out.println(differences.get(0) / 2);
			}
			else
			{
				System.out.println(Math.abs(differences.get(0)));
			}
		}
		else if (differences.size() == 2)
		{
			System.out.println(Math.abs(differences.get(0)));
		}
	}
}

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

public class Mehaya_ya3ood {
	public static void main(String[] args) throws Exception {
		boolean x1 = true;
		boolean x2 = false;
		int x = 0;

		BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
		int Addad = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());

		int arr[] = new int[Addad];

		for (int i = 0; i < Addad; i++) {
			arr[i] = Integer.parseInt(st.nextToken());
		}
		Arrays.sort(arr);
		// System.out.println(Arrays.toString(arr));

		for (int i = 0; i < arr.length - 1; i++) {
			if (arr[i] != arr[i + 1] && x1) {
				x = arr[i + 1] - arr[i];
				x1 = false;
				x2 = true;
			}
			if (arr[i] != arr[i + 1] && x2) {
				// System.out.println("2nd if");
				if (arr[i + 1] - arr[i] != x)
					x2 = false;
			}
		}
		if (Addad == 2)
			System.out.println((arr[0] + arr[1]) % 2 == 0 ? (arr[1] - arr[0]) / 2 : -1);
		else if (x2)
			System.out.println(x);
		else
			System.out.println(-1);
	}
}

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

public class Mehaya_ya3ood {
	public static void main(String[] args) throws Exception {
		boolean x1 = true;
		boolean x2 = false;
		int x = 0;
		BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
		int Addad = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());

		int arr[] = new int[Addad];
		ArrayList<Integer> list = new ArrayList<Integer>();

		for (int i = 0; i < Addad; i++) {
			arr[i] = Integer.parseInt(st.nextToken());
		}
		Arrays.sort(arr);
		System.out.println(Arrays.toString(arr));
		int y = arr[0];
		list.add(y);
		for (int i = 0; i < Addad; i++) {
			if (arr[i] != y) {
				list.add(arr[i]);
				y = arr[i];
			}
		}

		for (int i = 0; i < list.size() - 1; i++) {
			if (list.get(i) != list.get(i + 1) && x1) {
				x = list.get(i + 1) - list.get(i);
				x1 = false;
				x2 = true;
			}
			if (list.get(i) != list.get(i + 1) && x2) {
				if (list.get(i + 1) - list.get(i) != x)
					x2 = false;
			}
		}
		if (list.size() == 2)
			System.out.println((list.get(0) + list.get(1)) % 2 == 0 ? (list.get(1) - list.get(0)) / 2 : -1);
		else if (x2)
			System.out.println(x);
		else
			System.out.println(-1);
	}
}

import java.util.*;
import java.lang.*;
import java.lang.reflect.Array;
import java.io.*;
import java.math.*;
import java.text.DecimalFormat;

public class Prac{

    static class InputReader {

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

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

		public int read() {
			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 ni() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

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

		public String rs() {
			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 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 boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

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

	}
    static PrintWriter w = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        InputReader sc=new InputReader(System.in);
      int n=sc.ni();
      int arr[]=new int[n];
      for(int i=0;i<n;i++){
          arr[i]=sc.ni();
      }

      int ans=-1;
       boolean found=false;
       if(n==1)
           w.println(0);
       else{
      for(int i=0;i<=500;i++){
          found=false;
          int a=arr[0]-i;
          int b=arr[0]+i;
          int c=arr[0];
          for(int j=1;j<n;j++){
              if(arr[j]-i==a||arr[j]+i==a||arr[j]-i==b||arr[j]+i==b||arr[j]-i==c||arr[j]+i==c){
                  found=true;
                  ans=i;

              }
              else{
                  found=false;
                  break;

              }
          }
          if(found){
              w.println(i);
              break;
          }
      }
     if(!found)
         w.println(-1);
       }
        w.close();
    }
}

import java.util.Scanner;

public class a5 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		int num = input.nextInt();
		int[] arr = new int[num];
		for (int i = 0; i < num; i++) {
			arr[i] = input.nextInt();
		}
		int max = -10000000;
		int min = 10000000;
		int flag = 0;
		for (int i = 0; i < num; i++) {
			if (arr[i] > max) {
				max = arr[i];
			}
			if (arr[i] < min) {
				min = arr[i];
			}
		}

		int a = arr[0];
		for (int i = 0; i < num; i++) {
			if (arr[i] != a) {
				flag = 0;
				break;
			}
			if (arr[i] == a) {
				if (i == num - 1) {
					flag = 1;
					System.out.print(0);
				}
			}
		}
		if (flag == 0) {
			int b = max;
			for (int i = 0; i < num; i++) {
				if (arr[i] != a && arr[i] != b) {
					flag = 0;
					break;
				}
				if (i == num - 1) {
					flag = 1;
					if ((int) ((min + max) / 2) - (float) ((min + max) / 2) == 0.0) {

						System.out.print(max-(max - min)/2);
					}
					else {

						System.out.print(max - min);
				}
			}
		}
		if (flag == 0) {
			if ((int) ((min + max) / 2) - (float) ((min + max) / 2) != 0.0) {
				flag = 1;
			}
			if (flag == 0) {
				int c = (min + max) / 2;
				for (int i = 0; i < num; i++) {
					if (arr[i] != a && arr[i] != max && arr[i] != c) {
						flag = 0;
						System.out.print(-1);
						break;
					}
					if (i==num-1) {

						System.out.print(max-c);
					}
				}
			}
		}
	}
}
}

import java.util.*;

public class Main {

	static int Maxn=105;

	public static void main(String arg[]){

		Set<Integer>s=new TreeSet<>();
		Scanner cin=new Scanner(System.in);
		int n=cin.nextInt();
		int a[]=new int[n];

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

		if(s.size()==1){
			System.out.println(0);
		}else if(s.size()==2){

			Arrays.sort(a);

			int tt=a[n-1]-a[0];
			if(tt%2==0)System.out.println(tt/2);
			else System.out.println(tt);

		}else if(s.size()==3){
			int b[]=new int[Maxn];
			int cnt=0;
			for(Integer value:s){
				b[cnt++]=value;
			}

			int temp=b[1]-b[0];
			int flag=0;
			for(int i=1;i<cnt-1;i++){
				if(b[i+1]-b[i]!=temp){
					flag=1;
					break;
				}
			}
			if(flag==1){
				System.out.println(-1);
			}else{
				if(temp%2==0)System.out.println(temp/2);
				else System.out.println(temp);
			}
		}else{
			System.out.println(-1);
		}
		cin.close();

	}

}

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

public class Test {

    public static void main(String[] args) throws IOException {
        // write your code here
        BufferedReader reader  = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        String[] inp = reader.readLine().split(" ");
        int a[] = new int[101];
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int c =0;
        for (String anInp : inp) {
            int num = Integer.parseInt(anInp);
            if (a[num] == 0) {
                a[num] = 1;
                c++;
            }
            if (num > max) {
                max = num;
            }
            if (num < min) {
                min = num;
            }
        }

        if(c==2){
            if(Math.ceil(((double) max - (double) min)/2)==(max - min)/2){
                System.out.println((max - min)/2);
            } else {
                System.out.println(max-min);
            }
        } else if(a[min + (max - min)/2] ==1 && Math.ceil(((double) max - (double) min)/2)==(max - min)/2 && c<=2){
            System.out.println((max - min)/2);
        } else {
            System.out.println(-1);
        }

    }
}

import java.util.*;

public class ACM {
    static Scanner in = new Scanner(System.in);

    static void mergeSort(long arr[], int left, int right) {
        if (left < right) {
            int mid = (left + right) / 2;
            mergeSort(arr, left, mid);
            mergeSort(arr, mid + 1, right);
            merge(arr, left, mid, right);
        }
    }

    static void merge(long[] arr, int left, int mid, int right) {

        int sizeOfArray1 = mid - left + 1, sizeOfArray2 = right - mid;
        long[] arr1 = new long[sizeOfArray1], arr2 = new long[sizeOfArray2];

        for (int i = 0; i < sizeOfArray1; i++)
            arr1[i] = arr[left + i];

        for (int i = 0; i < sizeOfArray2; i++)
            arr2[i] = arr[mid + 1 + i];

        int i = 0, j = 0, k = left;
        while (i < sizeOfArray1 && j < sizeOfArray2) {
            if (arr1[i] < arr2[j]) {
                arr[k] = arr1[i];
                i++;
            } else {
                arr[k] = arr2[j];
                j++;
            }
            k++;
        }

        while (i < sizeOfArray1) {
            arr[k] = arr1[i];
            i++;
            k++;
        }
        while (j < sizeOfArray2) {
            arr[k] = arr2[j];
            k++;
            j++;
        }

    }

    public static void main(String[] args) {
        long n = in.nextLong(), arr[] = new long[(int) n], arrt[] = new long[(int) n];
        for (int i = 0; i < n; i++) {
            arr[i] = arrt[i] = in.nextLong();
        }
        mergeSort(arr, 0, arr.length - 1);

        if(Arrays.equals(arr , arrt)){
            System.out.println(0);
            return;
        }
        long c = 0, num1 = 0, num2 = arr[arr.length - 1];
        for (int i = (int) n - 1; i > -1; i--) {
            if (arr[i] != num2) {
                num1 = arr[i];
                break;
            }

        }

        long x = num1, y = num2;
        while (num1 != num2) {
            num1++;
            num2--;
            c++;
            if (num1 > num2) {
                c = y - x;
                break;
            }
        }
        long check = y - c;
        boolean b = true;
        for (int i = 0; i < n; i++) {
            if (arr[i] < check) {
                if (arr[i] + c == check)
                    continue;
                else {
                    b = false;
                    break;
                }
            } else if (arr[i] > check) {
                if (arr[i] - c == check)
                    continue;
                else {
                    b = false;
                    break;
                }
            }
        }

        if (b)
            System.out.println(c);
        else
            System.out.println(-1);
    }
}

//package CodeForces;

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

public class MakeThemEqual {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		HashMap<Integer,Boolean> map=new HashMap<>();
		for(int i=0;i<n;i++)
		{
			int temp=s.nextInt();
			map.put(temp,true);
		}

		if(map.size()<3)
		{
			if(map.size()==1)
			{
				System.out.println(0);
			}
			else
			{
				int arr[]=new int[2];
				int k=0;
				for(int x:map.keySet())
				{
					arr[k++]=x;
				}

				if((arr[0]+arr[1])%2==0)
				{
					System.out.println(arr[1]-(arr[0]+arr[1])/2);
				}
				else
				{
					System.out.println(arr[1]-arr[0]);
				}
			}
		}
		else if(map.size()==3)
		{
			int arr[]=new int[3];
			int k=0;
			for(int x:map.keySet())
			{
				arr[k++]=x;
			}
			Arrays.sort(arr);
			if(arr[1]-arr[0]==arr[2]-arr[1])
			{
				System.out.println(arr[1]-arr[0]);
			}
			else
			{
				System.out.println(-1);
			}
		}
		else
		{
			System.out.println(-1);
		}

	}

}

import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner ip=new Scanner(System.in);
		int n=ip.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
		{
		    a[i]=ip.nextInt();
		}
		if(n==1)
		{
		    System.out.println(a[0]);
		    System.exit(0);
		}
		int c=0;
		Arrays.sort(a);
		LinkedHashSet<Integer>s=new LinkedHashSet<Integer>();
		for(int i=0;i<n;i++)
		{
		    if(!s.contains(a[i]))
		    {
		        s.add(a[i]);
		        c++;
		    }
		}
		int b[]=new int[c];
		int k=0;
		for(int i:s)
		{
		    b[k]=i;
		    k++;
		}
		k=0;
	    for(int i=1;i<c;i++)
	    {
	        a[k]=b[i]-b[i-1];
	        k++;

	    }
	    int f=0;
	    for(int i=1;i<k;i++)
	    {
	        if(a[i]!=a[i-1])
	        {   f=1;
	            System.out.println(-1);
	            break;
	        }
	    }
	    if(f==0)
	    {
	            if(a[0]%2==0)
	                System.out.println(a[0]/2);
	            else
	                System.out.println(a[0]);
	        }

	}
}

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

public class Make_Them_Equal_552_B {

    public static void main(String[] args) {
        int n, D, dif, negative = 0;

        HashSet<String> hashSet = new HashSet<>();
        hashSet.add("0");
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        int[] diff = new int[n - 1];
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }

        for (int i = 0; i < n - 1; i++) {
            diff[i] = a[i + 1] - a[i];
            dif = a[i + 1] - a[i];
            hashSet.add(String.valueOf(Math.abs(dif)));
        }
        Arrays.sort(diff);

        int hasSize = hashSet.size();

        if (hasSize == 2) {
            if (diff[0] < 0) {
                diff[0] = Math.abs(diff[0]);
                negative = 1;
            }

            if (diff[0] == diff[diff.length - 1] && diff[diff.length - 1] % 2 == 1) {
                System.out.println(diff[0]);
            } else if (negative == 1 && diff[diff.length - 1] % 2 == 0) {
                System.out.println(diff[diff.length - 1]);
            } else if (negative == 0 && diff[diff.length - 1] % 2 == 0) {
                System.out.println(diff[diff.length - 1] / 2);
            }
        } else if (hasSize == 1) {
            System.out.println("0");
        } else {
            System.out.println("-1");
        }

    }
}

import java.util.Scanner;
import java.util.TreeSet;

public class Equal{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeSet<Integer> set = new TreeSet<>();
        for (int i = 1; i <= n; i++){
            int val = sc.nextInt();
            set.add(val);
        }
        if(set.size() > 3){
            System.out.println(-1); return;
        }
        if(set.size() == 1){
            System.out.println(0); return;
        }
        if(set.size() == 2){
            System.out.println(Math.abs(set.pollFirst()-set.pollFirst()));
            return;
        }
        if(set.size() == 3){
            int a = set.pollFirst();
            int b = set.pollFirst();
            int c = set.pollFirst();
            if(b-a == c-b){
                System.out.println(b-a);
            }
            else
                System.out.println(-1);
        }
    }
}

import java.util.Scanner;

public class a5 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		int num = input.nextInt();
		int[] arr = new int[num];
		for (int i = 0; i < num; i++) {
			arr[i] = input.nextInt();
		}
		int max = -10000000;
		int min = 10000000;
		int flag = 0;
		for (int i = 0; i < num; i++) {
			if (arr[i] > max) {
				max = arr[i];
			}
			if (arr[i] < min) {
				min = arr[i];
			}
		}

		int a = arr[0];
		for (int i = 0; i < num; i++) {
			if (arr[i] != a) {
				flag = 0;

				break;
			}
			if (arr[i] == a) {
				if (i == num - 1) {
					flag = 1;

					System.out.print(0);
				}
			}
		}
		if (flag == 0) {
			int b = max;

			for (int i = 0; i < num; i++) {
				if (arr[i] != a && arr[i] != b) {
					flag = 0;
					break;
				}
				if (i == num - 1) {
					flag = 1;
					if (min + max  == ((min + max) / 2)*2) {

						System.out.print((max - min)/2);
					}
					else {

						System.out.print(max - min);
				}
			}
		}

		if (flag == 0) {
			if (min + max  != ((min + max) / 2)*2) {
				flag = 1;System.out.print(-1);
			}
			if (flag == 0) {
				int c = (min + max) / 2;
				for (int i = 0; i < num; i++) {
					if (arr[i] != a && arr[i] != max && arr[i] != c) {
						flag = 0;
						System.out.print(-1);

						break;
					}
					if (i==num-1) {
						System.out.print(max-c);
					}
				}
			}
		}
	}
}
}

import java.util.*;
import java.io.*;
public class aprail152
{
    static class InputReader {
        private InputStream stream;
        private byte[] inbuf = new byte[1024];
        private int start= 0;
        private int end = 0;
        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int readByte() {
            if (start == -1) throw new UnknownError();
            if (end >= start) {
                end= 0;
                try {
                    start= stream.read(inbuf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (start<= 0) return -1;
            }
            return inbuf[end++];
        }

        private boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        private int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

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

        public int nextInt() {
            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();
            }
        }

        public long nextLong() {
            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();
            }
        }
    }
    public static void main(String args[])
    {
        InputReader sc=new InputReader(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
            a[i]=sc.nextInt();
        TreeSet<Integer> t=new TreeSet<>();
        for(int i=0;i<n;i++)
            t.add(a[i]);
        int ar[]=new int[t.size()];
        int p=0,sum=0;
        for(Integer h:t)
        {
            ar[p]=h;
            sum+=h;
            p++;
        }
        int mid=0,len=ar.length;
        if(len%2==0)
            mid=(len/2)-1;
        else
            mid=((len+1)/2)-1;
        t=new TreeSet<>();
        Set<Integer> s=new HashSet<>();
        int k=ar[mid];
        int k1=sum/len,l1=1000,l2=10000;
        if(len==2)
        {
            for(int i=0;i<len;i++)
            {
                if(ar[i]!=k1)
                {
                    s.add(Math.abs(k1-ar[i]));
                }
            }
            if(s.size()==1)
            {
                for(Integer h:s)
                l2=h;
            }
            System.out.println(Math.min(l2,Math.abs(ar[0]-ar[1])));
        }
        else
        {
            for(int i=0;i<len;i++)
            {
                if(ar[i]!=k)
                {
                    s.add(Math.abs(ar[i]-k));
                }
            }
            if(s.size()==1)
            {
                for(Integer h:s)
                System.out.println(h);
            }
            else
            System.out.println(-1);
        }
    }
}

import java.util.*;

/**
 * taskB
 */

public class taskB {

    public static int abstwo(ArrayList array , int i , int j) {
        return Math.abs((int)array.get(i) - (int)array.get(j));
    }

    public static boolean contains( ArrayList array,  int key) {
        for ( int i = 0 ; i < array.size() ; i++) {
            if ((int)array.get(i) == key) {
                return true;
            }
        }
        return false;
    }

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

        ArrayList<Integer> val = new ArrayList<Integer>();
        val.add(sr.nextInt());
        int test = 0;
        int count = 1;
        for (int i = 1; i < n; i++) {
            test = sr.nextInt();
            if (!contains(val , test)) {
                val.add(test);
                count++;
            }
        }

        if(n==1) System.out.print(0);
        else if(n==2) {
            if(val.size()==2 && ((int)val.get(0) != (int)val.get(1))) System.out.print(abstwo(val, 0, 1)/2);
            else System.out.print(0);
        }
        else{
            int pace = abstwo(val, 0, 1);
            boolean flag = true;
            for (int i = 1; i < count-1; i++) {
                if(!(abstwo(val, i, i+1) == pace)){
                    flag = false;
                    break;
                }
            }
            if(flag) {
                boolean condition = val.size()==2 && (Math.max((int)val.get(0),(int)val.get(1)) % Math.min((int)val.get(0),(int)val.get(1))==0) && Math.max((int)val.get(0),(int)val.get(1))!=1 && Math.min((int)val.get(0),(int)val.get(1))!= 1;
                if(condition) System.out.print(pace/2);
                else System.out.print(pace);
            }
            else System.out.print(-1);
        }
        sr.close();
    }
}

import java.util.Scanner;

public class Code {

	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();
		}
		int max = arr[0];
		int min = arr[0];
		for(int i=0;i<n;i++) {
			if(arr[i]>max)
				max = arr[i];
			if(arr[i]<min)
				min = arr[i];
		}
	float mid = (float)(0.0+ max+min)/2;
	for(int i=0;i<arr.length;i++) {
		if(arr[i]==max || arr[i]==min)
			arr[i]=-1;
	}
	boolean t1 = true;
	for(int i=0;i<n;i++){
		if((float)arr[i]!=mid && arr[i]!=-1)
			t1 = false;
	}
	//System.out.println(mid);
	if(t1 && mid%1==0) {
		System.out.println(max-(int)mid);
	}else if(mid%1!=0){
		System.out.println(max-min);
	}else {
		System.out.println(-1);
	}
	}
}

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

public class MakeThemEqual {

    public static void main(String[] args) {
        Scanner scanner = new Scanner();

        int n = scanner.nextInt();
        Set<Integer> set = new HashSet<>();
        List<Integer> unique = new ArrayList<>();

        for(int i=0; i<n; i++) {
            int val = scanner.nextInt();
            if(!set.contains(val)) {
                unique.add(val);
                set.add(val);
            }
        }

        Collections.sort(unique);

        if(unique.size() > 3) {
            System.out.println("-1");

        } else if(unique.size() == 3) {
            int v1 = unique.get(0);
            int v2 = unique.get(1);
            int v3 = unique.get(2);

            if(v2 - v1 == v3 - v2)
                System.out.println(v2-v1);
            else
                System.out.println("-1");

        } else if(unique.size() == 2) {
            int v1 = unique.get(0);
            int v2 = unique.get(1);

            if((v1+v2) % 2 != 0)
                System.out.println(v2-v1);
            else
                System.out.println((v1+v2)/2);

        } else {
            System.out.println(0);
        }
    }

    private static class Scanner {
        private BufferedReader br;
        private StringTokenizer st;

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

        String next() {
            if(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.util.ArrayList;
import java.util.Scanner;

public class JavaApplication66 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        int x;
        for (int i = 0; i < n; i++) {
            x = input.nextInt();
            if (!a.contains(x)) {
                a.add(x);
            }
            if (a.size() > 3) {
                System.out.println("-1");
                break;
            }
        }
        if (a.size() <= 3) {
            int max = max(a);
            int min = min(a);
            int r = (max - min) / 2;
            if (a.size() == 3) {
                if (a.contains(max-r)) {
                    System.out.println(r);
                } else {
                    System.out.println("-1");
                }
            } else if(a.size()==2){
                if((max+min)%2==0)
                    System.out.println(r);
                else
                    System.out.println(max-min);
            }else
                System.out.println("0");
        }

    }

    public static int max(ArrayList<Integer> a) {
        int max = a.get(0);
        for (int i = 1; i < a.size(); i++) {
            if (a.get(i) > max) {
                max = a.get(i);
            }
        }
        return max;
    }

    public static int min(ArrayList<Integer> a) {
        int min = a.get(0);
        for (int i = 1; i < a.size(); i++) {
            if (a.get(i) < min) {
                min = a.get(i);
            }
        }
        return min;
    }

}

/*
roses are red
memes are neat
all my test cases time out
lmao yeet
*/
import java.util.*;
import java.io.*;

   public class B
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         HashSet<Integer> set = new HashSet<Integer>();
         for(int i=0; i < N; i++)
         {
            arr[i] = Integer.parseInt(st.nextToken());
            set.add(arr[i]);
         }
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: set)
            pq.add(a);
         if(pq.size() == 1)
         {
            System.out.println(0);
            System.exit(0);
         }
         int x = pq.poll();
         int y = pq.poll();
         if(pq.size() == 0)
         {
            int res = y-x;
            if(res%2 == 0)
               res /= 2;
            System.out.println(res);
            System.exit(0);
         }
         int z = pq.poll();
         if(z-y == y-x)
         {
            int res = y-x;
            if(res%2 == 0)
               res /= 2;
            System.out.println(res);
         }
         else
            System.out.println(-1);
      }
   }

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

public class Diaa {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int Addad = sc.nextInt();
		int x, y, yar = -1, prevyar = 0;
		boolean flag = true;
		int a[] = new int[Addad];
		int output = 0;
		if (Addad == 2) {
			x = sc.nextInt();
			y = sc.nextInt();
			if ((y - x) % 2 == 0)
				output = (y - x) / 2;
		} else if (Addad > 2) {
			for (int i = 0; i < Addad; i++) {
				a[i] = sc.nextInt();
			}
			Arrays.sort(a);
			for (int u = 0; u < a.length - 1; u++) {
				System.out.println("for went 1 time");
				if (a[u] != a[u + 1]) {
					System.out.println("first if 1 time");
					yar = a[u + 1] - a[u];
					if (yar != -1 && yar != prevyar) {
						System.out.println("second if 1 time");
						output = -1;
						break;
					}
				}
				prevyar = yar;
				output = yar;
			}

		}

		System.out.println(output);
		if (output < 0)
			System.out.println(-1);
		sc.close();
	}
}

//1154 B
import java.util.*;
public class make{
  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[] b = Arrays.stream(a).distinct().sorted().toArray();
		if (b.length == 1) {
			System.out.println(0);
		} else if (b.length == 2) {
			int diff = b[1] - b[0];

			System.out.println((diff % 2 == 0) ? (diff / 2) : diff);
		} else if (b.length == 3) {
			int diff0 = b[1] - b[0];
			int diff1 = b[2] - b[1];

			if (diff0 == diff1) {
				 System.out.println(diff0);
			}
		}
		else{System.out.println(-1);}

  }
}

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

public class Solution{

    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().split(" ");

    TreeSet<Integer> ts=new TreeSet<>();
    for(int i=0;i<n;i++)
        ts.add(Integer.parseInt(str[i]));
    int ans=0;
    ArrayList<Integer> arr=new ArrayList<>();
    arr.addAll(ts);

    if(ts.size()==1)
        ans=0;
    else if(ts.size()==2){
        if((arr.get(0)+arr.get(1))/2==0)
            ans=(arr.get(0)-arr.get(1))/2;
        else
            ans=arr.get(1)-arr.get(0);
    }
    else if(ts.size()==3){
        if(arr.get(1)-arr.get(0)==arr.get(2)-arr.get(1))
            ans=arr.get(1)-arr.get(0);
        else
            ans=-1;
    }
    else
        ans=-1;

    System.out.println(ans);
    }
}

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

public class Main {
    public static void main(String[] args) {
        new Solution().solve();
    }
}

class Solution {
    void solve() {
        Scanner sc = new Scanner(System.in);
        long[] a = new long[4];
        for (int i = 0; i < 4; i++)
            a[i] = sc.nextLong();
        Arrays.sort(a);
        for (int i = 0; i < 3; i++)
            System.out.print(a[3] - a[i] + " ");
    }
}

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

public class MyClass {
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(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;
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String s = sc.nextLine();
        int n = Integer.parseInt(s);
        int[] a = new int[n];
        String ss = sc.nextLine();
        String[] c = ss.split(" ");
        for(int i=0;i<n;i++)
        {
            a[i] = Integer.parseInt(c[i]);
        }
        Arrays.sort(a);
        int num = 0;
        int first =0;
        if(n==1)
        {
            System.out.println(0);
            return;
        }else if(n==2)
        {
            if((a[1]-a[0])%2==0)
            {
                System.out.println(((a[1]-a[0])/2));
                return;
            }else
            {
                System.out.println(a[1]-a[0]);
                return;
            }
        }else
        {

            for(int i=1;i<n;i++)
            {
                if(a[i]-a[i-1]!=0)
                {
                    if(num==0||num==a[i]-a[i-1]){
                        if(first==2)
                        {
                            System.out.println(-1);
                            return;
                        }
                        num = a[i]-a[i-1];
                        first++;
                    }else
                    {
                        System.out.println(-1);
                        return;
                    }
                }
            }
        }
        //
        if(num==0)
        {
            System.out.println(-1);
            return;
        }if(first==1)
        {
            if(num%2==0)
            {
                System.out.println(num/2);
                return;
            }else
            {
                System.out.println(num);
                return;
            }
        }
        System.out.println(num);
    }
}

//package com.karancp;
import java.io.*;
import java.util.*;

public class Solution {
    public static void main(String args[])
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader z = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        task solver =new task();
        solver.solve(z,out);
        out.close();
    }
    static class task {

        public static void solve(InputReader z, PrintWriter out)
        {
            int n=z.nextInt();
            int ar[]=new int[n];
            int i;
            int sum=0;
            for(i=0;i<n;i++)
            {
                ar[i]=z.nextInt();

            }
           // int fl=0;
            int min=Integer.MAX_VALUE;
            int j;
            if(n==1)out.println("1");

            else
            {
                int diff[]=new int[n-1];
                Arrays.sort(ar);
                int pp=0;
                for(i=0;i<n-1;i++)
                {
                    diff[i]=ar[i+1]-ar[i];
                    if(diff[i]!=0)pp=diff[i];
                }
                int fl=0;
                //int pp=diff[0];
                for(i=0;i<n-1;i++)
                {
                    if(diff[i]!=pp&&diff[i]!=-pp&&diff[i]!=0)
                    {
                        fl=1;
                        break;
                    }
                }
                if(fl==1)out.println("-1");
                else
                {
                    if(pp==0)out.println("1");
                    else out.println(Math.abs(pp));
                }

            }

        }
        }

    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.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Mehaya_ya3ood {
	public static void main(String[] args) throws Exception {
		boolean x1 = true;
		boolean x2 = false;
		int x = 0;
		BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
		int Addad = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());

		int arr[] = new int[Addad];
		ArrayList<Integer> list = new ArrayList<Integer>();

		for (int i = 0; i < Addad; i++) {
			arr[i] = Integer.parseInt(st.nextToken());
		}
		Arrays.sort(arr);
		// System.out.println(Arrays.toString(arr));
		int y = arr[0];
		list.add(y);
		for (int i = 0; i < Addad; i++) {
			if (arr[i] != y) {
				list.add(arr[i]);
				y = arr[i];
			}
		}

		for (int i = 0; i < list.size() - 1; i++) {
			if (list.get(i) != list.get(i + 1) && x1) {
				x = list.get(i + 1) - list.get(i);
				x1 = false;
				x2 = true;
			}
			if (list.get(i) != list.get(i + 1) && x2) {
				if (list.get(i + 1) - list.get(i) != x)
					x2 = false;
			}
		}
		if (list.size() == 2)
			System.out.println((list.get(0) + list.get(1)) % 2 == 0 ? (list.get(1) - list.get(0)) / 2 : -1);
		else if (x2)
			System.out.println(x);
		else
			System.out.println(-1);
	}
}

import java.util.*;
public class Test1{
	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();
		}
		if(n==2){
			System.out.println((a[0]+a[1])/2 - a[0]);
		}
		else{
			Arrays.sort(a);
			int c=a[0];
			for(int i=1;i<n;i++){
				if(a[i]!=c){
					if((a[n-1]-(a[i]-c)) != a[i]){
						System.out.println(-1);
					}
					else{
						System.out.println(a[i]-c);
					}
					break;
				}
			}
		}
	}
}

import java.io.*;
import java.util.*;
public class test2 {
    static int removeDuplicates(int arr[], int n)
    {
        if (n == 0 || n == 1)
            return n;

        // To store index of next unique element
        int j = 0;

        // Doing same as done in Method 1
        // Just maintaining another updated index i.e. j
        for (int i = 0; i < n-1; i++)
            if (arr[i] != arr[i+1])
                arr[j++] = arr[i];

        arr[j++] = arr[n-1];

        return j;
    }
    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().split(" ");
        int[] arr=new int[n];
        for(int i=0;i<n;i++) {
            arr[i]=Integer.parseInt(str[i]);
        }
        Arrays.sort(arr);
        n = removeDuplicates(arr, n);
        int ans=0;
        for(int i=1;i<n-1;i++) {
            if(arr[i]-arr[i-1]==arr[i+1]-arr[i]&&n==3) {
                ans=arr[i]-arr[i-1];
            }
            else {
                ans=-1;
            }
        }
        if(ans%2==0&&n==2) {
            ans=ans/2;
        }
        System.out.println(ans);
    }
}

import java.util.HashSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int sum = 0;
        int min = 99999;
        int max = -99999;
        ArrayList<Integer> arrayList = new ArrayList<>();
        HashSet<Integer>has = new HashSet<>();
        for (int i = 0; i < n; i++) {
            int x = scanner.nextInt();
            arrayList.add(x);
            has.add(x);
            if (min > x) {
                min = x;
            }
            if (max < x) {
                max = x;
            }
        }
        for(Integer i3 : has){
            sum += i3;
        }
            int i = 0;int ss = -1;
            for(;i<arrayList.size();i++){
                if(i == 0){
                    ss = Math.abs(arrayList.get(i) - Math.floorDiv(sum,n));
                }else{
                    if(ss != Math.abs(arrayList.get(i) - Math.floorDiv(sum,n))){
                        break;
                    }
                }

            }
            if(i == arrayList.size()){
                arrayList.add(Math.floorDiv(sum,n));
            }else{
                i = 0;ss = -1;
            for(;i<arrayList.size();i++){
                if(i == 0){
                    ss = Math.abs(arrayList.get(i) - Math.floorDiv(sum,n)-1);
                }else{
                    if(ss != Math.abs(arrayList.get(i) - Math.floorDiv(sum,n) -1)){
                        break;
                    }
                }

            }
            if(i == arrayList.size()){
                arrayList.add(Math.floorDiv(sum,n)+1);
            }
            }

        int equal;
        Collections.sort(arrayList);
        for (Integer i2 : arrayList) {
            equal = i2;
            int same = 0;
            int j = 0;
            for (; j < arrayList.size(); j++) {
                if (arrayList.get(j) > equal) {
                    if (same == 0) {
                        same = arrayList.get(j) - equal;
                    } else if (same != arrayList.get(j) - equal) {
                        break;
                    }
                } else if (arrayList.get(j) < equal) {
                    if (same == 0) {
                        same = equal - arrayList.get(j);
                    } else if (same != equal - arrayList.get(j)) {
                        break;
                    }
                }
            }
            if (j == arrayList.size()) {
                System.out.println(same);
                return;
            }
        }
        System.out.println(-1);
    }
}

// Working program using Reader Class
import java.io.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main
{
	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();
		}
	}

	public static int gcd(int a, int b)
    {
        // Everything divides 0
        if (a == 0 || b == 0)
           return 0;

        // base case
        if (a == b)
            return a;

        // a is greater
        if (a > b)
            return gcd(a-b, b);
        return gcd(a, b-a);
    }

	public static long change(char c,char d,long A,long B,long C) {
		if(c==d) {
			return 0;
		}
		else if((c=='1' && d=='3') || (c=='3' && d=='1')) {
			return C;
		}
		else if((c=='1' && d=='2') || (c=='2' && d=='1')) {
			return A;
		}
		else {
			return B;
		}
	}

	public static void main(String[] args) throws IOException
	{
		//Reader scan=new Reader();
		Scanner scan=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=scan.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		int ans=Integer.MAX_VALUE;
		for(int i=0;i<=100;i++) {
			int d=-1;
			int done=0;
			for(int j=0;j<n;j++) {
				if(a[j]!=i) {
					if(d==-1) {
						d=Math.abs(a[j]-i);
					}
					else {
						if(a[j]+d!=i && a[j]-d!=i) {
							done=1;
							break;
						}
					}
				}
			}
			if(done==0) {
				ans=Math.min(ans, d);
			}
		}
		if(ans==Integer.MAX_VALUE) {
			out.print(-1);
		}
		else {
			out.print(ans);
		}
		out.close();
	}
}

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

public class B {
	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();
		}

		ArrayList<Integer> elements = new ArrayList<Integer>();
		for(int i = 0; i < n; i++) {
			if(!elements.contains(a[i])) {
				elements.add(a[i]);
			}
		}
		Collections.sort(elements);
		int ans = -1;
		if(elements.size() == 3) {
			if(elements.get(2) - elements.get(1) == elements.get(1) - elements.get(0)) {
				ans = elements.get(2) - elements.get(1);
			} else {
				ans = -1;
			}
		} else if(elements.size() == 2) {
			ans = elements.get(1) - elements.get(0);
		} else if(elements.size() == 1) {
			ans = 0;
		} else {
			ans = -1;
		}
		System.out.println(ans);
	}
}

/*Alone against all
Ahlawy UA07
*/
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import javafx.util.Pair;

public class codeforces {
static BigInteger add(BigInteger A, BigInteger B){return A.add(B);}
static BigInteger multiply(BigInteger A, BigInteger B){return A.multiply(B);}
static BigInteger div(BigInteger A, BigInteger B){return A.divide(B);}
static BigInteger sub(BigInteger A, BigInteger B){return A.subtract(B);}
/* help func */
static boolean prime(long a)
    {
        for(int i=2;i*i<=a;i++)
        {
            if(a%i==0)
                return false;
        }
        return true;
    }
public static int fact(int a)
{
    if(a==0)
        return 1;
    return a*fact(a-1);
}
                  /*main*/
 public static void main(String[] args) {
  Scanner read = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
  PrintWriter out=new PrintWriter(System.out);
  ArrayList<Pair<Integer,String>> arrofPair=new ArrayList<>();
  Set<Integer> set=new TreeSet<>();

  Stack S=new Stack();
  Map<Character ,Integer>map=new HashMap<>();
  StringBuilder Str= new StringBuilder();
                 /*code*/

 int n=read.nextInt();
 for(int i=0;i<n;i++)
 set.add(read.nextInt());
int s=set.size();
int arr[]=new int[s];
int d=0;
for(int j:set)
    arr[d++]=j;
if(s==1)
{     System.out.println(0);return;}
int temp=arr[1]-arr[0];
for(int i=1;i<s;i++)
{
    if(arr[i]-arr[i-1]==temp)
        continue;
    else
    {
        System.out.println(-1);
        return;
    }

}
if(temp%2==0)
         System.out.println(temp/2);
else
         System.out.println(temp);
    }

}

import java.util.*;

public class lottery {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int len = scan.nextInt();
        TreeSet<Integer> set = new TreeSet<>();
        for(int i = 0; i<len; i++){
            set.add(scan.nextInt());
        }
        if(set.size() == 1) System.out.println(set.first());
        else if(set.size() == 2) System.out.println((set.last()-set.first())/2);
        else if(set.size() == 3){
            int first = set.pollFirst();
            int last = set.last();
            int avg = (first+last)/2;
            //System.out.println(set.first());
            if(set.first() == avg) System.out.println(set.first()-first);
            else System.out.println(-1);
        }
        else System.out.println(-1);

    }
}

/*
 * 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.Scanner;

/**
 *
 * @author Centrino
 */
public class NewMain {

    /**
     * @param args the command line arguments
     */
 static long gcd(long a, long b)
    {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }

    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();
        }

         for (int i = 1; i <=100; i++) {
             boolean f=true;
             for (int j = 0; j < n; j++) {

                 for (int k = j+1; k < n; k++) {
                    if((Math.abs(arr[k]-arr[j])!=i&&Math.abs(arr[k]-arr[j])!=2*i)&&arr[j]!=arr[k])
                    {
                    f=false;
                    break;
                    }
                 }
                 if(!f)
                 {break;}
             }
             if(f)
             {
                 System.out.println(i);
                 return ;

             }
        }
         System.out.println("-1");
    }

}

import java.util.*;
public class B1
{
    public static void main(String ar[])
    {
        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 t1=1;
        int value=a[0];
        for(int i=1;i<n;i++)
        {
            if(a[i]!=value)
            {
                t1++;
                value=a[i];
            }
        }
        if(t1==1)
        {
            System.out.println(0);
            return;
        }
        if(t1==2)
        {
            System.out.println(a[n-1]-a[0]);
            return;
        }

        for(int i=1;i<n-1;i++)
        {
            int d=Math.abs(a[i]-a[0]);
            int j=0;
            for(j=0;j<n;j++)
            {
                if(a[j]!=a[i] && Math.abs(a[j]-a[i])!=d)
                    break;
            }
            if(j==n)
            {
                System.out.println(Math.abs(a[i]-a[0]));
                return;
            }
        }
        System.out.println(-1);
    }
}

import java.util.*;
import java.math.*;
public class Animal {
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		HashSet<Integer>h=new HashSet<Integer>();

		int x[]=new int [101];
		int n=scanner.nextInt();
		for(int i=0;i<n;i++)
		{
			x[i]=scanner.nextInt();
			if(!h.contains(x[i]))h.add(x[i]);
		}
		if(h.size()==1){
			System.out.print("0");
		}else if(h.size()==2){

			Iterator<Integer> it = h.iterator();
			int r=it.next();it.hasNext();
			int r2=it.next();
			if((r2+r)%2==0)
				System.out.println(r2-(r2+r)/2);
			else
				System.out.println("-1");
		}else if(h.size()==3){
			Iterator<Integer> it = h.iterator();
			int r1=it.next();it.hasNext();
			int r2=it.next();it.hasNext();
			int r3=it.next();
			if(r3-r2==r2-r1)
				System.out.println(r3-r2);
			else
				System.out.println("-1");
		}
		else{
			System.out.println("-1");
		}

	}
	public static class Fun{
		public HashMap<Integer, Integer>h1=new HashMap<Integer, Integer>();

		public long sum(long a1,long k){
			return (a1+a1+k-1)*k/2;
		}
	}
}