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 hack{

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

        String [] nextArray(){
            StringTokenizer tokens = new StringTokenizer(nextLine(), " ");
            String[] splited = new String[tokens.countTokens()];
            int index = 0;
            while(tokens.hasMoreTokens()){
              splited[index] = tokens.nextToken();
              if(splited[index]!="")
                ++index;
            }
            return splited;
        }

        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 BigInteger factorial(int num){
    if (num<=1)
        return BigInteger.ONE;
    else
        return factorial(num-1).multiply(BigInteger.valueOf(num));
    }*/
    /*static class Graph {
    // A user define class to represent a graph.
    // A graph is an array of adjacency lists.
    // Size of array will be V (number of vertices
    // in graph)
    int V;
    LinkedList<Integer>[] adjListArray;

    // constructor
    Graph(int V) {
        this.V = V+1;
        // define the size of array as
        // number of vertices
        adjListArray = new LinkedList[this.V];

        // Create a new list for each vertex
        // such that adjacent nodes can be stored

        for(int i = 1; i <= V ; i++){
            adjListArray[i] = new LinkedList<Integer>();
        }
    }

    // Adds an edge to an undirected graph
    void addEdge( int src, int dest) {
        // Add an edge from src to dest.
        adjListArray[src].add(dest);

        // Since graph is undirected, add an edge from dest
        // to src also
        adjListArray[dest].add(src);
    }

    int DFSUtil(int v,boolean visited[])
    {
        // Mark the current node as visited and print it
        int c=0;
        visited[v] = true;
        c=1;
        //System.out.print(v+" ");

        // Recur for all the vertices adjacent to this vertex
        Iterator<Integer> i = adjListArray[v].listIterator();
        while (i.hasNext())
        {
            int n = i.next();
            if (!visited[n])
                c=c+DFSUtil(n, visited);
        }
        return c;
    }

    // The function to do DFS traversal. It uses recursive DFSUtil()
    int DFS(int v)
    {
        int c=0;
        // Mark all the vertices as not visited(set as
        // false by default in java)
        boolean visited[] = new boolean[V];

        // Call the recursive helper function to print DFS traversal
        c=DFSUtil(v, visited);
        return c;
    }
  }*/
    public static void main (String args[]) throws IOException{
       //Reader in = new Reader();
       FastReader in=new FastReader();
       BufferedOutputStream out=new BufferedOutputStream(System.out);
       StringBuilder sb = new StringBuilder();
       //Scanner in=new Scanner(System.in);

       int n=in.nextInt(),i,d=0,flag=1;
       int[]a=new int[n];
       a[0]=in.nextInt();
       a[1]=in.nextInt();
       d=a[1]-a[0];
       for(i=2;i<n;i++){
         a[i]=in.nextInt();
         if(a[i]-a[i-1]!=d)
            flag=0;
       }
       if(flag==0)
        sb.append(a[n-1]+"\n");
       else
        sb.append((a[n-1]+d)+"\n");

       out.write(sb.toString().getBytes());
       out.flush();
    }

    public static int solve(int n){
      int t=n/2,p=n-t;
      return (t*(t+1))-p*p;
    }

    public static long isPrime(long a){
      long i;
      for(i=2;i<=(long)Math.sqrt(a);i++){
        if(a%i==0)
          return i;
      }
      return -1l;
    }


  public static int binarySearch(int []a,int s, int e,int k){
     int mid=s+(e-s)/2;
     if(s<=e){
       if(k<=a[mid]&&k>a[mid-1])
        return mid;
       if(a[mid]<k)
        return binarySearch(a,mid+1,e,k);
       if(a[mid]>k)
        return binarySearch(a,s,mid-1,k);
     }
     return -1;
   }
/*
public static int binarySearch(int arr[], int first, int last, int key){
      if (last>=first){
          int mid = first + (last - first)/2;
          if (arr[mid] == key){
          return mid;
          }
          if (arr[mid] > key){
          return binarySearch(arr, first, mid-1, key);//search in left subarray
          }else{
          return binarySearch(arr, mid+1, last, key);//search in right subarray
          }
      }
      else{
        if(first>=arr.length)
          first=arr.length-1;
        if(key<arr[first])
          return first-1;
        else
          return first;
      }
  }
*/   public static void insertionSort(String []a){
     int i,n=a.length;
     for(i=1;i<n;i++){
       for(int j=i;j>0;j--){
         if(a[j].length()>a[i].length()){
           String k=a[j];
           a[j]=a[j-1];
           a[j-1]=k;
         }
         else
          break;
       }
     }
     for(int j=0;j<a.length;j++)
      System.out.print(a[j]+" ");
   }


   public static void mergeSort(int []a,int s,int e ){

     if(s>=e||e-s==1)
      return;
     {
       int m=(s+e)/2;

       mergeSort(a,s,m);
       mergeSort(a,m,e);

       merge(a,s,m,e);
     }
   }

   public static void merge(int []a,int s, int m,int e){
     int []z=new int[e-s];
     int k1=s,k2=m,i=0;

     while(k1!=m && k2!=e){
       z[i++]=a[k1]<=a[k2]?a[k1++]:a[k2++];
     }
     while(k1!=m)
      z[i++]=a[k1++];
     while(k2!=e)
      z[i++]=a[k2++];
     for(i=s;i<e;i++){
       a[i]=z[i-s];
     }
   }
   static class Helper{
     int u,v,w;
     Helper(int u,int v,int w){
       this.u=u;
       this.v=v;
       this.w=w;
     }
   }
   public static void countsort(long arr[],int n,long place)
  {
          int i,range=100000;
          int freq[]=new int[range];         //range for integers is 10 as digits range from 0-9
          long output[]=new long[n];
          for(i=0;i<n;i++)
                  freq[(int)((arr[i]/place)%range)]++;
          for(i=1;i<range;i++)
                  freq[i]+=freq[i-1];
          for(i=n-1;i>=0;i--)
          {
                  output[freq[(int)((arr[i]/place)%range)]-1]=arr[i];
                  freq[(int)((arr[i]/place)%range)]--;
          }
          for(i=0;i<n;i++){
                  arr[i]=output[i];
                  //sb.append(arr[i]+" ");
          }
          //sb.append("\n");
  }
/*  public static void radixsort(int arr[],int n,int maxx,StringBuilder sb)
  {
          int mul=1;
          while(maxx>0)
          {
                  countsort(arr,n,mul,sb);
                  mul*=10;
                  maxx/=10;
          }
  }
*/

}
