Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is integral.

Vasya believes that if the average temperatures over the last n days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (n + 1)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (n + 1)-th day will be equal to the temperature of the n-th day.

Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (n + 1)-th day.

Input

The first line contains a single integer n (2 ≤ n ≤ 100) — the number of days for which the average air temperature is known.

The second line contains a sequence of integers t1, t2, ..., tn ( - 1000 ≤ ti ≤ 1000) — where ti is the average temperature in the i-th day.

Output

Print the average air temperature in the (n + 1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000.

Examples

Input

5
10 5 0 -5 -10


Output

-15


Input

4
1 1 1 1


Output

1


Input

3
5 1 -5


Output

-5


Input

2
900 1000


Output

1100

Note

In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is  - 10 - 5 = - 15.

In the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1.

In the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to  - 5.

In the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100. So predicted average temperature in the third day is 1000 + 100 = 1100.
///package CodeForce;

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class ACMICPCM {

static int[] A;
  static int[] S;
  static long[] sum;
 public static int mod=1000000007;
 static LinkedHashMap<Long,Long> memo;
public static void main(String[] args) throws Exception
 {
 	InputReader in = new InputReader(System.in);
 	PrintWriter out=new PrintWriter(System.out);
    int n=in.ii();
    int[] A=in.iia(n);
   
    if(n==2)
    {
    	int d=A[2]-A[1];
    	out.println(A[2]+d);
    }
    else 
    { 
    	boolean b=true;
    	int d=A[2]-A[1];
    	for(int i=1;i<n;i++)
    	{
    		if(A[i+1]-A[i]!=d)
    		{
    			b=false; break;
    		}
    	}
    	if(b)
    		out.println(A[n]+d);
    	else out.println(A[n]);
    }
    
    
 	
 	out.close();
 }

static void su(int[] A)
{
	  sum=new long[1000001];
	  for(int i=1;i<=A.length-1;i++)
	  {
		  sum[i]=sum[i-1]+A[i];
	  }
}
private  static long dist(int x1, int y1, int x2, int y2) {
    return (x2 - x1) * 1L * (x2 - x1) + (y2 - y1) * 1L * (y2 - y1);
}

private static boolean collinaer(int x1, int y1, int x2, int y2, int x3, int y3) {
    return (x1 * 1L * (y2 - y3) + x2 * 1L * (y3 - y1) + x3 * 1L * (y1 - y2)) == 0 ? true : false;
}
public static  long grundy(long a) {
    if (a <= 2) return a;
    boolean[] tmpArr = new boolean[35];
    Long tmp = memo.get(a);
    if (tmp != null) return tmp;
    for (int j = 0; j < 35; j++) {
        if (a < (1L << j)) break;
        long next = ((1L << j) - 1) & a;
        next |= a >>> (j + 1);
        tmpArr[(int) grundy(next)] = true;
    }
    for (int j = 0; j < 35; j++) {
        if (!tmpArr[j]) {
            memo.put(a, (long) j);
            return j;
        }
    }
    return 0;
}

public class PrimeRoutines {
		
		int[] lowDivIdx;
		int[] lowDiv;
		int[] p;
		int N;
		
		public PrimeRoutines(int N) {
			this.N = N;
			p = new int[(int)(N / Math.log(N))];
			lowDivIdx = new int[N + 1];
			lowDiv = new int[N + 1];
			Arrays.fill(lowDivIdx, -1);
			int pCnt = 0;
			for (int i = 2; i <= N; i++) {
				if (lowDivIdx[i] == -1) {
					if (p.length == pCnt) {
						p = Arrays.copyOf(p, 2 * p.length);
					}
					lowDivIdx[i] = pCnt;
					lowDiv[i] = i;
					p[pCnt++] = i;	
				}
				int toJ = Math.min(pCnt, lowDivIdx[i] + 1);
				for (int j = 0; j < toJ; j++) {
					int x = i * p[j];
					if (x > N) {
						break;
					}
					lowDivIdx[x] = j;
					lowDiv[x] = p[j];
				}
			}
			p = Arrays.copyOf(p, pCnt); 
		}
		
		int[] divCount() {
			int[] ret = new int[N + 1];
			int[] tmp = new int[N + 1];
			ret[1] = 1;
			for (int i = 2; i <= N; i++) {
				int p = lowDiv[i];
				int j = i / p;
				if (p == lowDiv[j]) {
					int k = tmp[j];
					ret[i] = ret[j] / k * (k + 1);
					tmp[i] = k + 1;
				} else {
					ret[i] = ret[j] * 2;
					tmp[i] = 2;
				}
			}
			return ret;
		}
		
		List<Integer> getDivsNotSorted(int x) {
			List<Integer> ret = new ArrayList<Integer>(0);
			ret.add(1);
			while (x > 1) {
				int sz = ret.size();
				int pr = lowDiv[x];
				while (lowDiv[x] == pr) {
					int to = ret.size();
					for (int i = ret.size() - sz; i < to; i++) {
						ret.add(ret.get(i) * pr);
					}
					x /= pr;
				}
			}
			return ret;
		}

		int[] moebiusFunction() {
			int[] mu = new int[N + 1];
			mu[1] = 1;
			for (int i = 2; i <= N; i++) {
				int p = lowDiv[i];
				int j = i / p;
				if (p != lowDiv[j]) {
					mu[i] = -mu[j];
				}
			}
			return mu;
		}

		int[] eulerFunction() {
			int[] phi = new int[N + 1];
			phi[1] = 1;
			for (int i = 2; i <= N; i++) {
				int p = lowDiv[i];
				int j = i / p;
				phi[i] = phi[j] * (p != lowDiv[j] ? p - 1 : p);
			}
			return phi;
		}
	}

static BigInteger power2(BigInteger x, BigInteger y, BigInteger m){
				BigInteger ans = new BigInteger("1");
				BigInteger one  = new BigInteger("1");
				BigInteger two  = new BigInteger("2");
				BigInteger zero  = new BigInteger("0");
				while(y.compareTo(zero)>0){
					//System.out.println(y);
					if(y.mod(two).equals(one)){
						ans = ans.multiply(x).mod(m);
						y = y.subtract(one);
					}
					else{
						x = x.multiply(x).mod(m);
						y = y.divide(two);
					}
				}
				return ans;
			}
			static BigInteger power(BigInteger x, BigInteger y, BigInteger m)
			{
			    if (y.equals(new BigInteger("0")))
			        return (new BigInteger("1"));
			    BigInteger p = power(x, y.divide(new BigInteger("2")), m).mod(m);
			    p = (p.multiply(p)).mod(m);

			    return (y.mod(new BigInteger("2")).equals(new BigInteger("0")))? p : (p.multiply(x)).mod(m);
		}


public static int gcd(int x,int y)
{
	if(x%y==0)
		return y;
	else
		return gcd(y,x%y);
}


public static long pow(long n,long p,long m)
{
	 long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    if(result>=m)
	    result%=m;
	    p >>=1;
	    n*=n;
	    if(n>=m)
	    n%=m;
	}
	return result;
}
public static long pow(long n,long p)
{
	long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    p >>=1;
	    n*=n;
	}
	return result;

}

public static int[][] packU(int n, int[] from, int[] to, int max) {
  
  int[][] g = new int[n][];
  int[] p = new int[n];
  for (int i = 0; i < max; i++) p[from[i]]++;
  for (int i = 0; i < max; i++) p[to[i]]++;
  for (int i = 0; i < n; i++) g[i] = new int[p[i]];
  for (int i = 0; i < max; i++) {
      g[from[i]][--p[from[i]]] = to[i];
      g[to[i]][--p[to[i]]] = from[i];
  }
  return g;
}


static class Edge implements Comparator<Edge> {
	private int u;
	private int v;
	private int w;
	public Edge() {
	}
	public Edge(int u, int v, int w) {
		this.u=u;
		this.v=v;
		this.w=w;
	}
	public int getU() {
		return u;
	}
	public void setU(int u) {
		this.u = u;
	}
	public int getV() {
		return v;
	}
	public void setV(int v) {
		this.v = v;
	}
	public int getW() {
		return w;
	}
	public void setW(int w) {
		this.w = w;
	      }
	public int compare(Edge o1, Edge o2)
	  {
		return o2.getW() - o1.getW();
	}
	@Override
	public String toString() {
		return "Edge [u=" + u + ", v=" + v + ", w=" + w + "]";
	}
}



static class Pair implements Comparable<Pair>
{
	int a,b;
	Pair (int a,int b)
	{
		this.a=a;
		this.b=b;
	}

	public int compareTo(Pair o) {
		// TODO Auto-generated method stub
		if(this.a!=o.a)
		return -Integer.compare(this.a,o.a);
		else
			return -Integer.compare(this.b, o.b);
		//return 0;
	}
	public boolean equals(Object o) {
     if (o instanceof Pair) {
         Pair p = (Pair)o;
         return p.a == a && p.b == b;
     }
     return false;
 }
 public int hashCode() {
     return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
 }
}

static  class InputReader
{
 private InputStream stream;
 private byte[] buf = new byte[1024];

 private SpaceCharFilter filter;
  byte inbuffer[] = new byte[1024];
 int lenbuffer = 0, ptrbuffer = 0;
  final int M = (int) 1e9 + 7;
 int md=(int)(1e7+1);
  int[] SMP=new int[md];
 final double eps = 1e-6;
 final double pi = Math.PI;

	PrintWriter out;
 String check = "";
InputStream   obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes());
 public InputReader(InputStream stream)
 {
     this.stream = stream;
 }

  int readByte() {
	        if (lenbuffer == -1) throw new InputMismatchException();
	        if (ptrbuffer >= lenbuffer) {
	            ptrbuffer = 0;
	            try {
	                lenbuffer = obj.read(inbuffer);
	            } catch (IOException e) {
	                throw new InputMismatchException();
	            }
	        }
	        if (lenbuffer <= 0) return -1;
	        return inbuffer[ptrbuffer++];
 }

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

 String is() {
	        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 ii() {
	        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 il() {
	        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 int root(int i)
		     {
				 while(A[i]!=i)
				 {
					A[i]=A[A[i]];
					i=A[i];
				 }


				 return i;
			 }

		   public void union(int a,int b )
		   {
			   int r1=root(a);
			   int r2=root(b);
			     if(S[r1]>S[r2])
			   		{
			   			A[r2]=r1;
			   			S[r1]+=S[r2];
			   			S[r2]=0;
			   		}
			   		else
			   		{
			   			A[r1]=r2;
			   			S[r2]+=S[r1];
			   			S[r1]=0;
			        }

	      }

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

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

	    float nf() {
	        return Float.parseFloat(is());
	    }

	    double id() {
	        return Double.parseDouble(is());
	    }

	    char ic() {
	        return (char) skip();
	    }

	    int[] iia(int n) {
	        int a[] = new int[n+1];
	        for (int i = 1; i<=n; i++) a[i] = ii();
	        return a;
	    }

	    long[] ila(int n) {
	        long a[] = new long[n+1];
	        for (int i = 1; i <=n; i++) a[i] = il();
	        return a;
	    }

	    String[] isa(int n) {
	        String a[] = new String[n];
	        for (int i = 0; i < n; i++) a[i] = is();
	        return a;
	    }


		 long mul(long a, long b) { return a * b % M; }

			long div(long a, long b)
				 {
					return mul(a, pow(b, M - 2));

		           }



	    double[][] idm(int n, int m) {
	        double a[][] = new double[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = id();
	        return a;
	        }

	    int[][] iim(int n, int m) {
	        int a[][] = new int[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j <m; j++) a[i][j] = ii();
	        return a;
        }


 public String readLine() {
     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 interface SpaceCharFilter
 {
     public boolean isSpaceChar(int ch);
 }
 public boolean isEndOfLine(int c) {
     return c == '\n' || c == '\r' || c == -1;
 }
}

}
