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.
import java.io.*;
import java.util.*;

public class main
{
	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;
	//private static long mod = 1000000000 + 7;
	private static long mod=100000000;
	private static long mod1 = 1000000000 + 9;
	private static void soln()
	{
		int n=nextInt();
		int[] arr=nextIntArray(n);
		int d=arr[1]-arr[0];
		boolean f=true;
		for(int i=2;i<n;i++) {
			int d1=arr[i]-arr[i-1];
			if(d1!=d) {
				f=false;
				break;
			}
		}
		if(!f)
			pw.println(arr[n-1]);
		else
			pw.println(arr[n-1]+d);
	}
	private static long ans(int l,int r,int[] arr) {
		if(l>=r)
			return 0;
		int mid=l+(r-l)/2;
		long ret=ans(l,mid,arr);
		long ret1=ans(mid+1,r,arr);
		ret=(ret+ret1)%mod;
		int cnt1=0;
		int cnt2=0;
		for(int i=l;i<=mid;i++)
			cnt1+=arr[i];
		for(int i=mid+1;i<=r;i++)
			cnt2+=arr[i];
		cnt1=Math.max(cnt1, cnt2);
		long[] dp=new long[cnt1+1];
		dp[0]=1;
		HashMap<Integer,Long> map=new HashMap<>();
		int sum=0;
		for(int i=mid+1;i<=r;i++) {
			long[] dp1=new long[cnt1+1];
			sum+=arr[i];
			for(int j=0;j<=cnt1;j++) {
				dp1[j]=dp[j];
				if(j-arr[i]>=0)
					dp1[j]=(dp1[j]+dp[j-arr[i]])%mod;
				int key=sum-2*j;
				if(!map.containsKey(key))
					map.put(key, 0L);
				map.put(key, (map.get(key)+dp1[j])%mod);
			}
			dp=dp1;
		}
		Arrays.fill(dp, 0);
		dp[0]=1;
		sum=0;
		for(int i=mid;i>=l;i--) {
			long[] dp1=new long[cnt1+1];
			sum+=arr[i];
			for(int j=0;j<=cnt1;j++) {
				dp1[j]=dp[j];
				if(j-arr[i]>=0)
					dp1[j]=(dp1[j]+dp[j-arr[i]])%mod;
				int key=2*j-sum;
				if(map.containsKey(key)) {
					ret=(ret+(map.get(key)*dp1[j])%mod)%mod;
				}
			}
			dp=dp1;
		}
		return ret;
	}
	private static int[] buildSuffix(String s,int n){
		Integer[] order=new Integer[n];
		for(int i=0;i<n;i++) order[i]=n-i-1;
		Arrays.sort(order,(a,b) -> Character.compare(s.charAt(a),s.charAt(b)));
		int[] sa=new int[n];
		int[] m_tmp=new int[n];
		for(int i=0;i<n;i++){
			sa[i]=order[i];
			m_tmp[i]=s.charAt(i);
		}
		for(int len=1;len<n;len<<=1){
			int[] tmp=m_tmp.clone();
			m_tmp[sa[0]]=0;
			for(int i=1;i<n;i++){
				m_tmp[sa[i]] = (tmp[sa[i-1]]==tmp[sa[i]] && sa[i-1] + len < n && 
								tmp[(sa[i-1]+(len>>1))]==tmp[(sa[i]+(len>>1))]) ? m_tmp[sa[i-1]]:i;
			}
			int[] cnt=new int[n];
			for(int i=0;i<n;i++) cnt[i]=i;
			int[] sa_tmp=sa.clone();
			for(int i=0;i<n;i++){
				int s1=sa_tmp[i]-len;
				if(s1>=0)
					sa[cnt[m_tmp[s1]]++]=s1;
			}
		}
		return sa;
	}
	private static int[] buildLCP(int[] sa,String s,int n){
		int[] ind=new int[n];
		for(int i=0;i<n;i++)
			ind[sa[i]]=i;
		int[] lcp=new int[n];
		for(int i=0, k=0; i<n; i++)
			if(ind[i] < n-1){
				for(int j=sa[ind[i]+1]; Math.max(i,j)+k < n && s.charAt(i+k)==s.charAt(j+k);) k++;
				lcp[ind[i]]=k;
				if(k>0) k--;
			}
		return lcp;
	}
	private static class Edge{
		int u,v;
		public Edge(int a,int b) {
			u=a;v=b;
		}
	}
	private static void shortestPath(LinkedList<Edge>[] l,int n,int k,int[] masks) {
		int tot=(int) Math.pow(2,k);
		int[][] dist=new int[n][tot];
		int[][] from=new int[n][tot];
		for(int i=0;i<n;i++)
			Arrays.fill(dist[i], Integer.MAX_VALUE);
		dist[0][masks[0]]=0;
		from[0][masks[0]]=-1;
		PriorityQueue<Long> q=new PriorityQueue<>();
		q.add((long) masks[0]);
		//System.out.println(0);
		while(!q.isEmpty()) {
			long cur=q.poll();
			//System.out.println(cur);
			int u = ((int) cur)>>>10;
			int mask=(int) (cur&(tot-1));
			//System.out.println((u+1)+" "+mask+" "+dist[u][mask]);
			if((cur>>>32) != dist[u][mask])
				continue;
			//System.out.println((u+1)+" "+Integer.toBinaryString(mask)+" "+dist[u][mask]);
			Iterator<Edge> it=l[u].listIterator();
			while(it.hasNext()) {
				Edge e=it.next();
				int len=dist[u][mask]+e.v;
				if(dist[e.u][mask|masks[e.u]]>len) {
					//System.out.println((e.u+1)+" "+(mask|masks[e.u])+" "+len+" "+Long.toBinaryString(((long)len << 32)+(e.u<<10)+mask));
					dist[e.u][mask|masks[e.u]]=len;
					from[e.u][mask|masks[e.u]]=u;
					q.add(((long)len << 32)+(e.u<<10)+(mask|masks[e.u]));
				}
			}
		}
		int ans=Integer.MAX_VALUE;
		//System.out.println(Integer.toBinaryString(tot-1));
		for(int i=0;i<tot;i++) {
			for(int j=0;j<tot;j++) {
				//System.out.println(Integer.toBinaryString(i)+" "+Integer.toBinaryString(j)+" "+dist[n-1][i]+" "+dist[n-1][j]);
				if((i|j) != (tot-1))
					continue;
				//System.out.println(i+" "+j);
				ans=Math.min(ans,Math.max(dist[n-1][i],dist[n-1][j]));
			}
		}
		pw.println(ans);
	}
	private static class Pair1 implements Comparable<Pair1>{
		int dist, affected, u;
		public Pair1(int a) {
			dist=Integer.MAX_VALUE;
			affected=Integer.MAX_VALUE;
			u=a;
		}
		public int compareTo(Pair1 another) {
			return this.dist!=another.dist?this.dist-another.dist:this.affected-another.affected;
		}
	}
	static void multiply(long[][] a, long[][] b, long m)
	{
		int n = a.length;
		long[][] mul = new long[n][n];
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				mul[i][j] = 0;
				for (int k = 0; k < n; k++)
					mul[i][j] = (mul[i][j] + (a[i][k] * b[k][j]) % m) % m;
			}
		}
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				a[i][j] = mul[i][j];
	}
	private static class DSU{
		int[] parent;
		int[] rank;
		int[] cnt;
		public DSU(int n){
			parent=new int[n];
			rank=new int[n];
			cnt=new int[n];
			for(int i=0;i<n;i++){
				parent[i]=i;
				rank[i]=1;
				cnt[i]=1;
			}
		}
		int find(int i){
	        while(parent[i] !=i){
	        	parent[i]=parent[parent[i]];
	        	i=parent[i];
	        }
	        return i;
	    }
		int Union(int x, int y){
	        int xset = find(x);
	        int yset = find(y);
	        if(xset==yset)
	        	return 0;
	        if(rank[xset]<rank[yset]){
	        	parent[xset] = yset;
		        rank[yset]+=rank[xset];
		        rank[xset]=0;
		        cnt[yset]+=cnt[xset];
		        cnt[xset]=0;
		        return yset;
	        }else{
	        	parent[yset]=xset;
	        	rank[xset]+=rank[yset];
	        	rank[yset]=0;
	        	cnt[xset]+=cnt[yset];
	        	cnt[yset]=0;
	        	return xset;
	        }
	    }
	}

	private static long pow(long a, long b, long c)
	{
		if (b == 0)
			return 1;
		long p = pow(a, b / 2, c);
		p = (p * p) % c;
		return (b % 2 == 0) ? p : (a * p) % c;
	}
	private static int block;
	private static class Mo implements Comparable<Mo>
	{
		int l;
		int r;
		int i;

		public Mo(int a, int b, int ind)
		{
			l = a;
			r = b;
			i = ind;
		}

		@Override
		public int compareTo(Mo arg0)
		{
			int b1 = this.l / block;
			int b2 = arg0.l / block;
			return (b1 != b2) ? (b1 - b2) : (this.r - arg0.r);
		}
	}

	private static long gcd(long n, long l)
	{
		if (l == 0)
			return n;
		return gcd(l, n % l);
	}
	public static void main(String[] args) throws Exception
	{
		new Thread(null, new Runnable()
		{
			@Override
			public void run()
			{
				/*
				 * try { InputReader(new FileInputStream(
				 * "C:\\Users\\hardik\\Desktop\\C-small-1-attempt1.in")); } catch
				 * (FileNotFoundException e) { // TODO Auto-generated catch block
				 * e.printStackTrace(); }
				 */
				InputReader(System.in);
				pw = new PrintWriter(System.out);
				/*
				 * try { pw=new PrintWriter(new
				 * FileOutputStream("C:\\Users\\hardik\\Desktop\\out.txt")); } catch
				 * (FileNotFoundException e) { // TODO Auto-generated catch block
				 * e.printStackTrace(); }
				 */
				soln();
				pw.close();
			}
		}, "1", 1 << 26).start();
	}

	public static void InputReader(InputStream stream1)
	{
		stream = stream1;
	}

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

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

	private static 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++];
	}

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

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

	private static String nextToken()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do
		{
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

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

	private static int[] nextIntArray(int n)
	{
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n)
	{
		long[] arr = new long[n];
		for (int i = 0; i < n; i++)
		{
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr)
	{
		for (int i = 0; i < arr.length; i++)
		{
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr)
	{
		for (int i = 0; i < arr.length; i++)
		{
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c)
	{
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private static char nextChar()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		char c1 = (char) c;
		while (!isSpaceChar(c))
			c = read();
		return c1;
	}

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