#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,ans=0,t=0;
int main(){
	cin>>a>>b>>c>>d;
	if( a-b==b-c && b-c==c-d ){
	    ans=2*d-c,t=1;}
	if( a*c==b*b && b*d==c*c ){
	    if( d*d%c!=0 ){
	    	cout<<42;
	    	return 0;
	    }
	    else ans=d*d/c,t=1;}
	if( t==0 )cout<<42;
	else cout<<ans;
	return 0;
}

/************** ITNOG **************/

#include <iostream>
#include <iomanip>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstdlib>
#include <utility>

#define size(x) ((int)(x).size())

using namespace std;

int main()
{
    double a, b, c, d;
    cin >> a >> b >> c >> d;

    if (b-a == c-b && c-b == d-c)
        cout << 2*d-c;
    else if (b/a == c/b && c/b == d/c && (d*d)/c == int((d*d)/c))
        cout << (d*d)/c;
    else
        cout << 42;

    return 0;
}

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    float arr[4] ,c,fraction;
    int eq;
    for(int i =0 ; i < 4 ; i++)
    {
        cin>>arr[i];
    }
    if ((arr[1]-arr[0]) == (arr[2]-arr[1]) && (arr[2]-arr[1]) == (arr[3]-arr[2]))
    {
        eq=arr[3]+(arr[3]-arr[2]);
        cout<<eq<<endl;
    }
    else if ((arr[1]/arr[0])==(arr[2]/arr[1]) && (arr[2]/arr[1])==(arr[3]/arr[2]))
    {   c=arr[3]/arr[2];
        eq=arr[3]*c;
        fraction=arr[3]*c;
        if(fraction>eq)
            cout<<"42"<<endl;
        else
        cout<<eq<<endl;
    }

    else
        cout<<"42"<<endl;

    return 0;
}

#include<iostream>
using namespace std;
int main(){
	double a,b,c,d,e;
	cin>>a>>b>>c>>d;
	if(a-b==b-c&&b-c==c-d||b-a==c-b&&c-b==d-c){
		e=d-c+d;
		if(e-int(e)==0){
			cout<<e;return 0;
		}
	}
	if(a/b==b/c&&b/c==c/d||b/a==c/b&&c/b==d/c){
		e=d/c*d;
		if(e-int(e)==0){
			cout<<e;return 0;
		}
	}
	cout<<"42";
	return 0;
}

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
     int n=4 ;
         float a[n];
         for ( int i=0 ; i< n ; i++ ){
             cin >> a[i];}

   int temp;
   if ( a[1] *a[1] == a[0]*a[2] && a[2]*a[2] == a[3]*a[1]) {

            float D=a[2]*a[2]/a[0];
        //    cout << D;
            if ( int(D) != D ) { cout << "42";}
            else cout << D;

   }
   else if ( 2*a[1]==a[0]+a[2]&&2*a[2]==a[1]+a[3] ) {
           cout << 2*a[2]-a[0];
        }
   else cout << "42";
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    double a,b,c,d,ans;

    cin>>a>>b>>c>>d;

    if(b-a==c-b && b-a==d-c)
    {
        cout<<d+(d-c)<<endl;

        return 0;
    }

    if(b/a==c/b && b/a==d/c)
    {
        ans=d*(c/b);

        if(ans!=(int)ans)
        {
            cout<<"42"<<endl;
        }

        else cout<<ans<<endl;

        return 0;
    }

    cout<<"42"<<endl;

    return 0;
}

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")

#define F first
#define S second
#define pb push_back
#define llong  long long
#define int llong
#define ld long double
#define endl '\n'

#ifdef BUCKY_IS_ALIVE
#else
#define cerr if(0) cerr
#endif // BUCKY_IS_ALIVE

using namespace std;

const int N = 1e5 + 2;
const int M = 3e5 + 5;
const int B = 2100;
const int sum = 2e9;
const int MOD = 1e9 + 7;
const int MOD1 = 1e9 + 7;
const int rx[4] = {0, 1, -1, 0};
const int ry[4] = {1, 0, 0, -1};
const char rr[5]= {'5', 'N', 'E', 'S', 'W'};

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef BUCKY_IS_ALIVE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif

    int n = 4;
    vector <int> a;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        a.pb(x);
    }

    int add = a[1] - a[0], ok = 1;
    for(int i = 1; i < n; i++){
        if (a[i] - add != a[i - 1]) ok = 0;
        cerr << a[i] - a[i - 1] << endl;
    }
    cerr << endl;

    if (ok){
        cout << a.back() + add << ' ';
        return 0;
    }
    cerr << add << endl;

    ld mem = a[1];
    ld lol = a[0];
    ld kek  = mem / lol;

    ok = 1;

    for(int i = 1; i < n; i++){
        if (a[i - 1] * kek != a[i]) ok = 0;
    }

    int b = a.back() * kek;
    if (b != a.back() * kek) ok = 0;

    if (ok){
        cout << a.back() * kek;
        return 0;
    }

    cout << 42;

    return 0;

}

#include <bits/stdc++.h>
using namespace std;
int main(){

    int input[4] = {0};
    for(int k = 0; k < 4; k++){
        cin>>input[k];
    }

    int diff = input[1] - input[0];
    double ratio = 1.0 * input[1] / input[0], intpart(0);

    if(input[2] - input[1] == diff && input[3] - input[2] == diff){
        cout<<input[3] + diff;
    }
    else if(1.0 * input[2] / input[1] == ratio && 1.0 * input[3] / input[2] == ratio && modf(ratio * input[3], &intpart) == 0.0){
            cout<< input[3] * ratio;
    }
    else{
        cout<<"42";
    }
    return 0;
}

#include <iostream>
#include <vector>
using namespace std;
int main(){
    vector <float> x;
    float y;
    double r;
    for (int i=0;i<4;i++){
        cin>>y;
        x.push_back(y);
    }
    y=x[1]-x[0];
    r=x[1]/x[0];
    /* arithmatic */ if(x[2]-x[1]==y&&x[3]-x[2]==y) {cout<<x[3]+y<<endl;}
    /*geometric */ else if(x[2]/x[1]==r&&x[3]/x[2]==r) {
        if((x[3]*r)-int(x[3]*r)==0){cout<<x[3]*r<<endl;}
        else {cout<<42<<endl;}
    }
    else cout<<42;
    return 0;
}

#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <cmath>
#include <sstream>
#include <utility>
#include <ctime>
#include <memory.h>
#include <cctype>
#include <cstdlib>
#include <limits>

using namespace std;

#pragma comment (linker, "/STACK:64000000")

#define y0 qwertyuiop
#define y1 asdfghjkl
#define forn(j, n) for(j=1; j<=n; j++)
#define sz size()
#define pb push_back
#define fors(w, s) for(map <ll, int> :: iterator w=s.begin(); w!=s.end(); w++)
#define pii pair<int, int>
#define uns unsigned
#define vi vector <int>
#define vvi vector <vi>
#define inf 2000000000
#define o 1000000007
#define ll long long
#define maxint 2147483648

int j, n, k, l, i, h, t, q[6], mx, sum, mex, p, q1[6], q2[6], a[1000500];

void tg ()
{
	freopen ("output.txt","r",stdin); freopen ("input.txt","w",stdout);

}

int gcd (int a, int b)
{
	while (b)
	{
		swap (a, b);
		b%=a;
	}
	return a;
}

int main()
{
	//tg (); return 0;
	//freopen ("input.txt","r",stdin); freopen ("output.txt","w",stdout);
    //freopen ("smith.in","r",stdin); freopen ("smith.out","w",stdout);
	scanf ("%d%d%d%d", &a[1], &a[2], &a[3], &a[4]);
	if (a[2]-a[1]==a[3]-a[2] && a[3]-a[2]==a[4]-a[3])
	{
		printf ("%d", 2*a[4]-a[3]);
		return 0;
	}
	if (!a[1] || !a[2] || !a[3] || !a[4])
	{
		printf ("42");
		return 0;
	}
	forn (j, 3)
	{
		q[j]=a[j+1]/a[j];
		q1[j]=a[j+1]%a[j];
		if (q1[j])
		{
			q2[j]=a[j];
			t=gcd(q1[j], q2[j]);
			q1[j]/=t;
			q2[j]/=t;
		}
	}
	if (q[1]!=q[2] || q[2]!=q[3] || q1[1]!=q1[2] || q1[2]!=q1[3] || q2[1]!=q2[2] || q2[2]!=q2[3])
	{
		printf ("42");
		return 0;
	}
	if (q2[1])
	{
		if (a[4]%q2[1])
		{
			printf ("42");
			return 0;
		}
	}
	if (q2[1])
	{
		t=a[4]/q2[1]*q1[1];
	}
	printf ("%d", q[1]*a[4]+t);
	return 0;
}

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int a,b,c,d;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(b-a==c-b&&c-b==d-c) printf("%d\n",d+b-a);
	 else if(a*c==b*b&&b*d==c*c){if(d*d%c==0) cout<<d*d/c<<"\n";else cout<<"42\n";}
	//else if(b*b==a*c&&c*c==b*d) printf("%d\n",d*c/b);
	else printf("42\n");
	return 0;
}

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int sz[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (b * b == a * c && c * c == b * d)
	{
		if (d * d % c) puts("42");
		else printf("%d\n", d * d / c);
		return 0;
	}
	if (2 * b == a + c && 2 * c == b + d)
	{
		printf("%d\n", 2 * d - c);
		return 0;
	}
	puts("42");
	return 0;
}

                                 //CREATED BY TARANG KAPOOR

#include <bits/stdc++.h>

using namespace std;

int main()
{
   float a,b,c,d;
   cin>>a>>b>>c>>d;
   if((b-a)==(c-b) && (c-b)==(d-c))
   {
       int ans=a+4*(b-a);
       cout<<ans<<endl;
   }
   else if((b/a)==(c/b) && (c/b)==(d/c) && a!=0 && b!=0 && c!=0 && d!=0){
        float ans2=d*(b/a);
        if((int)ans2==(float)ans2)
           {
               int x=ans2;
               cout<<x<<endl;
           }
           else
           cout<<"42"<<endl;
   }
   else
   cout<<"42"<<endl;

}

#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a-b==b-c&&b-c==c-d)
    cout<<d+b-a;
    else
    {
        float f=(float)b/a;
        if((float)c/b==f&&(float)d/c==f)
        if((d*f-(int)(d*f))==0)
        cout<<(int)(d*f);
        else
        cout<<"42";
        else
        cout<<"42";
    }
    return 0;
}

#include <iostream>
using namespace std;
int main()
{
double a,b,d,q,c,b1;
int i=2;
cin>>a;
cin>>b;
b1=b;
d=b-a;
q=b/a;
while(cin>>c)
{
i++;
if(d==NULL||a+(i-1)*d!=c)
d=NULL;
if(q==NULL||b*b1/a!=c)
q=NULL;
b=c;
}
if(d!=NULL&&int(a+(i)*d)==a+(i)*d)
cout<<a+(i)*d;
else if(q!=NULL&&int(b*b1/a)==b*b1/a)
cout<<b*b1/a;
else cout<<42;
}

#include<stdio.h>
#include<stdlib.h>
#include <time.h>
//#include<conio.h>

int main(){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(b-a==c-b && d-c==c-b) printf("%d\n",d+(d-c));
    else{
      double x,y,z;
      x = 1.0*b/a;
      y = 1.0*c/b;
      z = 1.0*d/c;
      if(x==y && y==z) {
        int temp = (int)z*c;
        if((d*d)%c==0) printf("%d\n",d*d/c);
        else {
          //printf("%.10lf\n",1.0*d*z);
          printf("42\n");
        }
      }
      else printf("42\n");
    }
    //getch();
    return 0;
}

#include<stdio.h>
#include<string.h>

int main()
{
    int x1, x2, x3, x4, x5, operation_code = 0, test_code = 0, t;
    int gap1, gap2, gap3;
    float dvd1, dvd2, dvd3;
    scanf("%d%d%d%d", &x1, &x2, &x3, &x4);
    gap1 = x2 - x1;
    gap2 = x3 - x2;
    gap3 = x4 - x3;
    if (gap1 == gap2 && gap2 == gap3) {
        operation_code = 1; goto te;
    }

    if (x1 >= x2)
    {
        dvd1 = (float) x1 / (float) x2;
        dvd2 = (float) x2 / (float) x3;
        dvd3 = (float) x3 / (float) x4;
        test_code = 1;
    }
    else if (x1 < x2)
    {
        dvd1 = (float) x2 / (float) x1;
        dvd2 = (float) x3 / (float) x2;
        dvd3 = (float) x4 / (float) x3;
        test_code = 2;
    }
    if (dvd1 != dvd2 || dvd2!=dvd3 || dvd1 != dvd3){ operation_code = 0; goto te;
}
    if (test_code == 1 && ((float)x4*dvd3 != (float)x3 || (float)x3*dvd2 != (float)x2 || (float)x2*dvd1 != (float)x1))
    {
        operation_code = 0;
        goto te;
    }
    else if (test_code == 1)
    {
        x5 = x4 / dvd1;
        t = dvd1 * x5;
        if (t != x4) operation_code = 0;
        else operation_code = 2;
        goto te;
    }

    if (test_code == 2 && ((float) x3*dvd3 != (float) x4 || (float) x2*dvd2 != (float) x3 || (float) x1*dvd1 != (float) x2))
    {
        operation_code = 0;
        goto te;
    }
    else if (test_code == 2)
    {
        x5 = x4 * dvd1;
        if (x5/dvd1 != x4) operation_code = 0;
        else operation_code = 2;
        goto te;
    }
te:

    if (operation_code == 0)
        printf("42\n");
    else if (operation_code == 1)
        printf("%d\n", x4 + gap1);
    else if (operation_code == 2)
        printf("%d\n", x5);
    return 0;
}

#include <cstdlib>
#include <iostream>
#include <Cmath>
using namespace std;

int main()
{
    double x,y,z;
    double a,b,c,d;
    cin>>a>>b>>c>>d;
    x=b/a;
    y=c/b;
    z=d/c;
    if(b-a==c-b  &&  d-c==c-b)
                 cout<<d+(b-a)<<endl;
    else if(x==y  &&  z==y){
         int r=floor(d);
         int s=floor(c);
         if((r*r)%s==0)
                       cout<<d*d/c<<endl;
         else
             cout<<"42"<<endl;
    }
    else
        cout<<"42"<<endl;
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
using namespace std;

int nod(int a, int b){
	while(a*b>0){
		if(b>a) {
			int k=b/a;
			b-=k*a;
		}
		else{
			int k=a/b;
			a-=k*b;
		}
	}
	return (a+b);
}

void main(){
	int a,b,c,d;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	if((d-c==c-b)&&(c-b==b-a)){
		printf("%d",d-c+d);
	}
	else{
		int n=nod(c,d);
		int k1=c/n,k2=d/n;
		if((k2*b==c*k1)&&(a*k2==b*k1)){
			if(d*k2%k1==0){
				printf("%d", d*k2/k1);
			}
			else
				printf("42");
		}
		else
			printf("42");
	}
}

#include<iostream>
#include<cstdio>
using namespace std;
int a,b,c,d;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a-b==b-c&&b-c==c-d)
	{
		printf("%d",d-(b-c));
		return 0;
	}
	if(b-a==c-b&&c-b==d-c)
	{
		printf("%d",d+(d-c));
		return 0;
	}
	else if(a*c==b*b && b*d==c*c) {
		if(!(d*d%c))printf("%d\n",d*d/c);
		else printf("%d\n",42);
	}
	else cout<<42;
	return 0;
}

// :)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {
	if (a < b)
		swap(a, b);
	if (a % b == 0)
		return b;
	return gcd(b, a % b);
}
int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n = 4;
	int a[n];
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	int d = a[1] - a[0];
	bool ok = true;
	for (int i = 1; i < n-1; i++)
		if (a[i+1] - a[i] != d)
			ok = false;
	if (ok) {
		cout << d + a[3] << "\n";
		return 0;
	}
	ok = true;
	pair<int,int> q = {a[0] / gcd(a[0], a[1]), a[1] / gcd(a[0], a[1])};
	for (int i = 1; i < n-1; i++) {
		pair<int,int> cur = {a[i] / gcd(a[i], a[i+1]), a[i+1] / gcd(a[i], a[i+1])};
		if (cur.first != q.first || cur.second != q.second)
			ok = false;
	}
	if (ok) {
		swap(q.first, q.second);
		if (a[3] * q.first % q.second == 0)
			cout << (double) a[3] * q.first / q.second << "\n";
		else
			cout << "42\n";
		return 0;
	}
	cout << "42\n";
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,c,d,w,q,k=0,l=0;
cin>>a>>b>>c>>d;
w=b-a;
if(c-b==w && d-c==w){
    w=w+d;
    cout<<w;
    return 0;}
else if((b*d==c*c) && (a*c==b*b))
{
    q=d*d/c;
    if((d*d)%c==0)
    cout<<q;
    else
        cout<<"42";
    return 0;
}
cout<<"42";
return 0;
}

#include <iostream>
using namespace std;
double a,b,c,d;
int main(){
	       cin>>a>>b>>c>>d;
	       if(b-a==c-b && c-b==d-c){cout<<d+(b-a); return 0;}
	       if(b/a==c/b && c/b==d/c){if(d*(d/c)==int(d*(d/c))/1){cout<<d*(d/c); return 0;}}
           cout<<"42";
}

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    int a,b,c,d,ag;
    double gp;
    while(cin>>a>>b>>c>>d){
        //arithmetic progression
        if(a>b) ag=-1*(a-b);
        else ag=b-a;
        //geometric progression
        gp=(double)b/(double)a;

        if(b==a+ag&&c==b+ag&&d==c+ag) cout<<d+ag<<endl;
        else if(b==gp*a&&c==gp*b&&d==gp*c){
            int k=gp*d;
            if(k==gp*d){
                cout<<d*gp<<endl;
            }
            else puts("42");
        }
        else puts("42");
    }
    return 0;
}

#include<iostream>
# include<cstdio>
# include<algorithm>
# include<cstring>
# include<vector>
# include<queue>
# include<cmath>
# include<bitset>
using namespace std;
typedef long long ll;
bool visited[100001];
vector< int > v;

int getchar_unlocked() { return getchar(); }
void r(int &x){
    register unsigned int c = getchar_unlocked();
    x = 0;int neg=0;
    for(;(c<48 || c>57) && c!='-';c = getchar_unlocked());
    if(c=='-'){neg=1; c=getchar_unlocked(); }
    for(;c>47 && c<58;c = getchar_unlocked() ) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg)x=-x;
}

bool eq(double a,double b){
	//cout<<a<<","<<b<<endl;
	return a-b<0.000001 and b-a<0.000001;
}

typedef double d;

int near(d a){
	int r=floor(a);
	if(a-r<0.5)return r;
}

int check(int i,int j,int k,int l){
	if(i!=j and j!=0 and k!=l and l!=0 and  eq(d(j)/d(i),d(k)/d(j)) and eq(d(l)/d(k),d(k)/d(j)))return eq(d(near(d(l*l)/d(k))),d(l*l)/d(k))?near(d(l*l)/d(k)):42;
	return 42;
}

int main(){
	int t,tt,i,j,k,l,beg,end,x,y;
	scanf("%d %d %d %d",&i,&j,&k,&l);
	if(i-j==j-k and j-k==k-l){cout<<2*l-k;}
	else cout<<check(i,j,k,l);
	return 0;
}

#include <iostream>
#include <set>
using namespace std;

inline int gcd(int a, int b) {
    if(!b)
        return a;
    return
        gcd(b, a % b);
}

int main() {

    int a, b, c, d; cin >> a >> b >> c >> d;

    int d1 =  b - a, d2 = c - b, d3 = d - c;

    pair<int, int> c1 = make_pair(a / gcd(a,b), b / gcd(a, b));
    pair<int, int> c2 = make_pair(b / gcd(b, c), c / gcd(c, b));
    pair<int, int> c3 = make_pair(c / gcd(c, d), d / gcd(c, d));

    if(d1 == d2 && d2 == d3) {
        cout << d + d1 << "\n";
        return 0;
    }

    set<pair<int, int>> S;
    S.insert(c1), S.insert(c2), S.insert(c3);

    if(S.size() == 1) {
        if(d % c1.first == 0) {
            cout << d / c1.first * c1.second << "\n";
            return 0;
        }
    }

    cout << 42 << "\n";

    return 0;
}

#include<iostream>

using namespace std;

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a-b==b-c&&b-c==c-d)
		cout<<d+b-a;
	else if(a*c==b*b&&b*d==c*c)
	{
		if(d*d%c==0)
			cout<<d*d/c;
		else
			puts("42");
	}
	else
		puts("42");
	return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn  = 10000+5;
double a[maxn];
int main()
{
    int n;
    while(scanf("%lf%lf%lf%lf",&a[1],&a[2],&a[3],&a[4])!=EOF)
    {
        if(a[2]-a[1]==a[3]-a[2]&&a[4]-a[3]==a[2]-a[1])
            printf("%.0f\n",a[4]+a[3]-a[2]);
        else if(a[3]*a[1]==a[2]*a[2]&&a[4]*a[2]==a[3]*a[3]&&a[2]!=a[3]&&a[1])
        {
            double p=a[4]*a[3]/a[2];
            if(p==(int)p)
                printf("%0.f\n",a[4]*a[3]/a[2]);
            else
                printf("42\n");
        }
       else
        printf("42\n");
    }
    return 0;
}

#include <cstdio>
#include <cmath>

using namespace std;

int main( void ){

    int a1, a2, a3, a4;

    scanf( "%d%d%d%d", &a1, &a2, &a3, &a4 );

    float d = (float)a2 - a1, q = (float)a2 / a1;

    float arit = ( (float)a1 + a3 ) / 2;
    float geom = a2 * q;
    float tmp = (int)( a1 * pow(q, 4) * 100 + 0.5 ) / 100;

    if ( arit == a2 && a3 == ((float)a4 + a2) / 2 ){
        printf( "%.0f\n", a1 + 4 * d );
    }
    else if ( geom == a3 && tmp == a4 * q ){
        printf( "%.0f\n", a4 * q );
    }
    else {
        printf( "42\n" );
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()

int a[4];

int main() {
	for (int i = 0; i < 4; i++) scanf("%d", &a[i]);
	if (a[0] + a[2] == a[1] * 2 && a[1] + a[3] == a[2] * 2)
		printf("%d\n", a[3] * 2 - a[2]);
	else if (a[0] * a[2] == a[1] * a[1] && a[1] * a[3] == a[2] * a[2] && a[3] * a[3] % a[2] == 0)
		printf("%d\n", a[3] * a[3] / a[2]);
	else printf("42\n");
	return 0;
}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int64, int64> pii;
typedef pair<double, double> pdd;
typedef vector<int64> vi;
typedef vector<pii> vpii;
typedef vector<double> vd;
typedef vector<vi>  vvi;

constexpr double eps = 1e-11;
constexpr double pi = acos(-1.0);
constexpr int64 p = 1000000007;
constexpr int64 countbit(int64 n) { return n == 0 ? 0: countbit(n / 2) + n % 2; }
constexpr int64 lowbit(int64 n) { return (n ^ (n-1) ) & n; }
constexpr int64 gcd(int64 a, int64 b) { return b == 0? a : gcd(b, a % b); }
constexpr int64 lcm(int64 a, int64 b) { return a * b / gcd(a, b); }
int64 toInt64(string s) { istringstream sin(s); int64 t; sin >> t; return t; }
string toStr(int64 t) { stringstream sin; sin << t; string s; sin >> s; return s; }
template<typename T> constexpr auto sqr(const T& n) -> decltype(n * n) { return n * n; }
template<typename T> void out(const T& array) {
   for(const T& value : array) cout << value << "\n";
   cout.flush();
}

struct Point {
    int64 x;
    int64 y;
    Point(){}
    Point(int x, int64 y): x(x), y(y){}
    bool operator<(const Point& that) const {
        return make_pair(x,y) < make_pair(that.x, that.y);
    }
};

#define all(a) (a).begin(), (a).end()
#define pb push_back

void solve() {
    int a ,b,c,d;
    cin >> a >> b >> c >> d;
    if (!a && !b && !c && !d) {
        cout << 0 << endl;
    } else if(a == b && b == c && c == d) {
        cout << d << endl;
    }
    else if (b-a == d-c && c-b == b-a) {
        cout << d + (d-c) << endl;
    } else if (c != 0) {
        if (d*a == b*c && b*b == c * a && b*d == c*c && d*d%c==0)
        cout << (d == 0?0:d * d/c) << endl;
        else cout <<42<<endl;
    } else {
        if (b == c&& c ==d)
        cout << 0;
        else cout <<42<<endl;
    }
}

int main() {
    cout.sync_with_stdio(false);
    cin.sync_with_stdio(false);
    solve();
    return EXIT_SUCCESS;
}

#include<bits/stdc++.h>
#include<algorithm>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
#define pf push_front
#define pb push_back
#define pob pop_back
#define pof pop_front
#define is insert
#define rep1(i,a,b) for(long long i=a;i<=b;i++)
#define mp make_pair
#define mh make_heap
#define F first
#define S second
//#define fin cin
//#define fout cout
#define file ifstream fin("input.txt");ofstream fout("output.txt");
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr(n) for(long long i=0;i<n;i++)
#define rep(i,a,b) for(long long i=a;i<b;i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long int ll;

typedef pair<ll,ll> pairs;
typedef vector<ll> vi;
typedef vector<pairs> vpair;

void solve()
{
    /*ll n,m;cin>>n>>m;
    vi v[n];
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>a;
            v[i].pb(a);
        }
    }*/
    long double a,b,c,d;
    cin>>a>>b>>c>>d;
    if((b-a)==(c-b) && (c-b)==(d-c))
    {
        //cout<<"here"<<endl;
        long double ans=2*d-c;
        if(ceil(ans)==ans)
        cout<<ans<<endl;
        else cout<<42;
        return ;
    }
    long double rat=((double)(b)/a);
    long double rat1=((double)(c)/b);
    long double rat2=((double)(d)/c);
    if(rat==rat1 && rat1==rat2)
    {
            long double ans=d*rat;
            if(ceil(ans)==ans)
            cout<<d*rat;
            else
                cout<<42;
            return ;

    }
    cout<<42;

}
int32_t main()
{
    int t=1;//cin>>t;
   fr(t)
    {
        solve();
    }

   return 0;
}

#include <iostream>
#include <algorithm>
#include <fstream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <iomanip>

using namespace std;

#define rep(i,o,n) for (int i=o;i<=n;i++)
#define rd cin >>
#define w cout <<
#define wl cout << endl
#define road pair<int,int>
//#define cin inf
//#define cout of
#define ll long long

int main()
{
	ifstream inf("input.txt");
	double x,y,x1,y1;
	rd x >> y >> x1 >> y1;
	if (y-x==x1-y && x1-y==y1-x1) { w y1+(y1-x1); return 0; }
	if (y/x==x1/y && x1/y==y1/x1 && y1*y1/x1==int(y1*(y1/x1))) { w y1*(y1/x1); return 0; }
	w 42;
}

#include <iostream>

using namespace std;

int main () {
	double a,b,c,d;
	cin >> a >> b >> c >> d;

	double r;
	double n;
	if(b/a == c/b && c/b == d/c){
		r = b/a;
		n = d * r;
		if(n == int(n)){
			cout << n << endl;
		}
		else{
			cout << 42 << endl;
		}
	}
	else if(b-a == c-b && c-b == d-c){
		r = b - a;
		n = r + d;
		cout << n << endl;
	}
	else{
		cout << 42 << endl;
	}
}

#include <bits/stdc++.h>

using namespace std;

int main(){
    vector<double> arr(4);
    double factor, diff, ans;
    for(int i=0; i<4; i++){
        cin>>arr[i];
    }
    diff = arr[1] - arr[0];
    factor = arr[1]/arr[0];
    if(arr[0]*factor == arr[1] && arr[1]*factor == arr[2] && arr[2]*factor == arr[3]){
        ans = arr[3]*factor;
        if(ans - int(ans) != 0) cout<<42<<"\n";
        else cout<<arr[3]*factor<<"\n";
    }
    else if(arr[1] - arr[0] == diff && arr[2] - arr[1] == diff && arr[3] - arr[2] == diff){
        ans = arr[3]+diff;
        if(ans - int(ans) != 0) cout<<42<<"\n";
        else cout<<ans<<"\n";
    }
    else cout<<42<<"\n";
    return 0;
}

/// In The Name Of ALLAH

/**

|       |    --------------     ---------    --------   -------   |\        |
|       |   |              |   |            |              |      | \       |
|       |   |              |   |            |              |      |  \      |
|       |   |              |   |            |              |      |   \     |
 -------    |              |    ---------    -------       |      |    \    |
|       |   |              |             |  |              |      |     \   |
|       |   |              |             |  |              |      |      \  |
|       |   |              |             |  |              |      |       \ |
|       |    --------------    ----------    --------   --------  |        \|

**/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < long long , long long > pll;

template < typename T > inline T maxer(T &a , T b){ a = max( a , b ); }
template < typename T > inline T miner(T &a , T b){ a = min( a , b ); }

void iOS() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }
void fin() { freopen( "in" , "r" , stdin); }
void fout() { freopen( "out" , "w" , stdout); }

#define endl '\n'
#define pb push_back
#define mp make_pair
#define F first
#define S second

const int inf = ~0u/10;
const long long linf = ~0ull/20;

const int maxn = 1e5+20;;

void print(long double x)
{
    if(x != (int) x)
        cout << 42;
    else
        cout << x;
    exit(0);
}

int main()
{
    iOS();
    long double a1 , a2 , a3 , a4;
    cin >> a1 >> a2 >> a3 >> a4;
    if(a1 != 0 && a2 != 0 && a3 != 0 && a4 != 0)
        if(a2/a1 == a3 / a2 && a4 / a3 == a3 /a2)
            print( a4 * (a4 / a3) );
    if(a2 - a1 == a3 - a2 && a4 - a3 == a3 - a2)
        print( a4 + a4 - a3 );
    cout << 42;
    return 0;
}

// In the Name Of God

#include <iostream>
#include <fstream>

#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cstring>
#include <istream>
#include <queue>

#define inf (int)(~0u/2)
#define ll_inf (int)1 << 62
#define int long long
#define float long double
#define eps (1e-8)
#define for2(i, a, b) for ( int (i) = (a); (i)<(b); (i)++ )
#define mp make_pair
#define pb push_back
#define sz(a) (int) a.size( )
#define fillArr(n, a) for2(i, 0, n) cin >> a[i];
#define print(a) cout << #a << endl;
#define umax(a,b) a = max ( a, b )
#define umin(a,b) a = min ( a, b )
using namespace std;

const int maxn = 1e6+10;
int a[maxn];
bool is[maxn];
int dp[maxn];
vector <int> ind;
int arr[maxn];
void main ( ){
	ios::sync_with_stdio ( 0 );
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ( b - a == c - b && c - b == d - c ){
		cout << d + d - c << endl;
	}
	else if ( b * b == a * c && c * c == b * d ){
		float g = ((float)d * d) / c;
		if ( g == (int) g )
			cout << g << endl;
		else
			cout << 42 << endl;
	}
	else
		cout << 42 << endl;
}

#include <iostream>
#include<vector>
#include<stdlib.h>
using namespace std;
int main()
{
    long double a,b,c,d,check1,l,ans,check2,check3;
    cin>>a>>b>>c>>d;
     int counter=0;
    check1 = a-b;
    check2=b-c;
    check3=c-d;
    if(check1==check2&&check1==check3&&check2==check3){
    l=check1+d;
    ans = a-4*check1;
    if((int)(ans)==ans)
        {
        counter++;
        cout<<ans<<endl;

        }
    else
        {
            counter++;
            cout<<"42"<<endl;

        }
    }
    long double a0,b0,c0,d0;
    a0=b/a;
    b0=c/b;
    c0=d/c;
    if(a0==b0&&a0==c0&&b0==c0&&c0!=1)
    {
        if((int)(c0*d)==c0*d)
            {
                counter++;
            cout<<c0*d<<endl;

            }
        else
            {
                  counter++;
                cout<<"42"<<endl;

            }
    }
   if(counter==0)
        cout<<"42"<<endl;

    return 0;
}

using namespace std;
#include<bits/stdc++.h>
typedef long long  ll;

///Input
#define pf printf
#define sf(n)       scanf("%lld", &n)
#define sff(a,b)    scanf("%lld %lld", &a, &b)
#define sfff(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define Case(no) printf("Case %d: ",++no)

///LOOP
#define rep(x,n) for(__typeof(n) x=0;x<(n);x++)
#define reps(i,x) for(int  i=0;i<(x.size());i++)
#define repp(x,n) for(__typeof(n) x=1;x<=(n);x++)
#define FOR(x,m,n) for(__typeof(n) x=(m);x<=(n);x++)
#define foreach(x,n) for(__typeof(n.begin()) x=n.begin();x!=n.end();x++)

///Shortcut
#define mem(ar,value) memset(ar,value,sizeof(ar))
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define len(s) s.size()
#define mp make_pair
#define pb push_back
#define xx first
#define yy second

///Min AND Max
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))

#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))

#define inf (1e15)
#define eps (1e-9)
#define PI acos(-1.0)
#define pi 3.14159265358979323846
#define isEq(a,b) (fabs((a)-(b))<eps)
#define Dist(x1,y1,x2,y2) (sqrt(sqr((x1)-(x2))+sqr((y1)-(y2))))
#define spDist(lat1,long1,lat2,long2,r) ((r)*acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos((long1)-(long2))))
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define dist4adj(x1,y1,x2,y2) ( abs(x1-x2) + abs(y1-y2) )
#define dist8adj(x1,y1,x2,y2) max( abs(x1-x2) , abs(y1-y2) )

///File
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)

/**Define Bitwise operation**/
template<class T> inline T lowbit(T n){return (n^(n-1))&n;}//NOTES:lowbit(
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}
#define check(n, pos) (n & (1<<(pos)))
#define biton(n, pos) (n | (1<<(pos)))
#define bitoff(n, pos) (n & ~(1<<(pos)))

#define ledzero(n) (__builtin_clz(n))
#define trailzero(n) (__builtin_ctz(n))
#define onbit(n) (__builtin_popcount(n))

///upper bound and lower bound
#define LB(a,value) (lower_bound(all(a),value)-a.begin())
#define UB(a,value) (upper_bound(all(a),value)-a.begin())

///DEBUG
#define dbg(x) cout<<#x<<": "<<x<<endl
#define dbgar(i,a) cout<<#a<<"["<<i<<"] = "<<a[i]<<" "<<endl

#define trace(x) cerr<<x<<endl;
#define d1(x) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<endl;
#define d2(x,y) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<endl;
#define d3(x,y,z) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<" | "#z" = "<<z<<endl;
#define d4(a,b,c,d) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#a" = "<<a<<" | "#b" = "<<b<<" | "#c" = "<<c<<" | "#d" = "<<d<<endl;
#define d5(a,b,c,d,e) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#a" = "<<a<<" | "#b" = "<<b<<" | "#c" = "<<c<<" | "#d" = "<<d<<" | "#e" = "<<e<<endl;
#define d6(a,b,c,d,e,f) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#a" = "<<a<<" | "#b" = "<<b<<" | "#c" = "<<c<<" | "#d" = "<<d<<" | "#e" = "<<e<<" | "#f" = "<<f<<endl;

///Gcd and Lcm
template<class T>T gcd(T a,T b){return b == 0 ? a : gcd(b, a % b);}
template<typename T>T lcm(T a, T b) {return a / gcd(a,b) * b;}

///Bigmod && Pow
template<class T>T my_pow(T n,T p){if(p==0)return 1;T x=my_pow(n,p/2);x=(x*x);if(p&1)x=(x*n);return x;} ///n to the power p
template<class T>T big_mod(T n,T p,T m){if(p==0)return (T)1;T x=big_mod(n,p/2,m);x=(x*x)%m;if(p&1)x=(x*n)%m;return x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} ///For Positive Negative No.

template<class T>T multiplication(T n,T p,T m){if(p==0)return (T)0;T x=multiplication(n,p/2,m);x=(x+x)%m;if(p&1)x=(x+n)%m;return x;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}

///string to int
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}/// extract words or numbers from a line

template<class T> string itos(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}///NOTES:toString(
ll stoi(string s){ll r=0;istringstream sin(s);sin>>r;return r;}///NOTES:toInt(
double toDouble(string s){double r=0;istringstream sin(s);sin>>r;return r;}

/**DIRECTION**/
///int month[]={31,28,31,30,31,30,31,31,30,31,30,31};                                   ///MONTH
///int col[8] = {0, 1, 1, 1, 0, -1, -1, -1};int row[8] = {1, 1, 0, -1, -1, -1, 0, 1};  ///8 DIRECTION
///int col[4] = {1, 0, -1, 0};int row[4] = {0, 1, 0, -1};                             ///4 DIRECTION
///int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};                    ///Knight Direction
///int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2};                       ///HEXAGONAL DIRECTION

const int mod= 1e9+7;
typedef   pair<ll,ll>  pii;
typedef   vector< pii > vpii;
typedef   vector<long long>   vi;
typedef   vector<string>   vs;
typedef   map<string,ll>  msi;
typedef   map<ll,ll>  mii;
typedef   map<char,ll>  mci;

struct node
{
    ll u,v,w;
    ll x,y,z;
}arr[100100];

bool com(node a,node b)
{
    return a.x<b.x;
}
ll a=0,b=0,c=0,d=0,cnt=0,f=0,ff=0,tot=0,sum=0,res=0,n,m;
ll mn=inf,mx=-inf;

string s,ss,ch[100100];
ll ar[654321],ar1[654321];

int main()
{
   ios_base::sync_with_stdio(false);
   rep(i,4)
   {
       cin>>ar[i];
   }
   ll diff=ar[0]-ar[1];
   rep(i,3)
   {

       if(diff==ar[i]-ar[i+1])
       {
           c++;
       }
   }
   if(c==3)
   {
       cout<<ar[3]-diff;
       return 0;
   }
   double ra=double(ar[1])/double(ar[0]);
   c=0;
   rep(i,3)
   {
       //d1(ar[i]/ar[])
       if(ra==double(ar[i+1])/double(ar[i]))
       {
           c++;
       }
   }
   if(c==3)
   {
       double aa=ra*ar[3];
      if(aa>=1 and aa==int(aa))
      {
          cout<<aa;
      }
      else cout<<42;
       return 0;
   }
   cout<<42;

    return 0;
}

// In the name of god
#include <bits/stdc++.h>
using namespace std;
double a,b,c,d;
int x;
int main(){
	cin>>a>>b>>c>>d;
	x=(d/c)*d;
	if(b/a==c/b&&c/b==d/c&&x>0&&x/d==d/c){
		cout<<x;
		return 0;
	}
	x=d+(d-c);
	if((b-a)==(c-b)&&(c-b)==(d-c)&&(x-d)==(d-c)){
		cout<<x;
	}
	else{
		cout<<42;
	}
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y,k,d;
	cin>>x>>y>>k>>d;
	if(x-y==y-k&&y-k==k-d){
		cout<<d+y-x;
	}
	else if(x*k==y*y&&y*d==k*k){
		if(d*d%k==0) cout<<d*d/k;
		else cout<<42;
	}
	else cout<<42;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a-b==b-c&&b-c==c-d)printf("%d",2*d-c);
    else if(b*b==a*c&&c*c==b*d){
        if((d*d)%c!=0)puts("42");
        else printf("%d",d*d/c);
    }
    else printf("42");
}

#include <bits/stdc++.h>
using namespace std;
int main (){
	long double a, b, c, d;
	cin >> a >> b >> c >> d;
	if(b - a == c - b && c - b == d - c){
		cout << d + (c - b);
		return 0;
	}
	if(b / a == c / b && c / b == d / c){
		if(int(d * (b / a)) != d * (b / a)){
			cout << 42;
			return 0;
		}
		cout << d * (b / a);
		return 0;
	}
	cout << 42;
	return 0;
}

// in the name of Alllah ;
#include<bits/stdc++.h>
using namespace std ;
long double t[5]  , q[5] , d[5] ;
int main ()
{
	for ( int i = 0 ; i < 4 ;i++ )
		cin >> t[i] ;
	for ( int i = 0 ; i < 3 ; i++ )
	{
		q[i] = t[i+1]/t[i] ;
		d[i] = t[i+1] - t[i] ;
	}
	bool qq = true , dd = true ;
	for ( int i = 0 ; i < 2 ; i++ )
	{
		if ( q[i] != q[i+1] )
			qq = false ;
		if ( d[i] != d[i+1] )
			dd = false ;
	}
	if ( !qq && !dd )
	{
		cout << 42 << endl;
		return 0;
	}
	if ( qq )
	{
		long double ans = t[3]*q[0] ;
		if ( (ans - (int)ans ) == 0  )
			cout << ans << endl;
		else
			cout << 42 << endl;
	}
	else if ( dd )
	{
		long double ans = t[3]+d[0] ;
		if (( ans - (int)ans)  == 0  )
			cout << ans << endl;
		else
			 cout << 42 << endl;
	}

}

    #include <iostream>

    using namespace std;

    int main()
    {
        double n1,n2,n3,n4;
        cin >> n1 >> n2 >> n3 >> n4;
        if(n2 - n1 == (n3 - n1)/2 && n2 - n1 == (n4 - n1)/3){
            double d = (n4 - n1)/3;
            if(d == (int)d)
                cout << (n1 + 4 * d);
            else
                cout << 42;
        }
        else if(n2 / n1 == n3 / n2 && n2 / n1 == n4 / n3){
            double q = n2 / n1;
            double n = n4 * q;
            if(n == (int)n)
                cout << n;
            else
                cout << 42;
        }
        else
            cout << 42;
        return 0;
    }

#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<vector>

using namespace std;

int n=1,m,k,l=0,x,y,z;
int a[4];

int main()
{
	//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	cin>>a[0]>>a[1]>>a[2]>>a[3];
	m = a[1]-a[0];
	double d = (a[0]==0?0:a[1]/(double)a[0]);
	for(int i = 2;i<4;++i)
	{
	if(a[i]-a[i-1]!=m)x=1;
	if(d==0 || a[i-1]==0 ||a[i]/(double)a[i-1]!=d)y = 1;
	}
	if(x==0)cout<<a[3]+m;
	else if(y==0 &&(double)(int)(a[3]*d)==a[3]*d)cout<<a[3]*d;
	else cout<<42;
	return 0;
}

#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>

using namespace std;

int f[5000];
int arr[10000];
char str[10000];

int main()
{
	int a[1000];
	for (int i = 0; i < 4; i++)
	{
		cin >> a[i];
	}

	int b = a[1] - a[0];
	double q = (double)a[1] / a[0];

	if (a[1] + b == a[2] && a[2] + b == a[3]) cout << a[3] + b << endl;
	else if (a[1] * q == a[2] && a[2] * q == a[3] && q != 1)
	{
		double d = a[3] * q;
		if (d - floor(d) != 0)  cout << 42 << endl;
		else cout << d << endl;

	}
	else cout << 42 << endl;

	return 0;
}

// http://codeforces.com/contest/328/problem/A

#include "iostream"
#include "vector"

#define LL long long
#define VT vector
#define FOR(x,a,b) for (x=a; x<=b; x++)

using namespace std;
LL kq;
VT <unsigned LL> a;

int main()
{
    a.resize(6);

    FOR (kq,1,4)
        cin>>a[kq];
    kq=42;
    if (a[2]-a[1]==a[3]-a[2] && a[4]-a[3]==a[3]-a[2])  kq=a[4]+(a[2]-a[1]);
    else if (a[2]*a[2]==a[3]*a[1] && a[3]*a[3]==a[4]*a[2])
    {
        if ((a[4]*a[2])%a[1]==0) kq=(a[4]*a[2])/a[1];
        else kq=42;
    }

    cout<<kq<<endl;
}

#include <bits/stdc++.h>
//arshak.khoshnevis

using namespace std;

const int inf = 1e9 + 7;
double a[4], ans[2] = {inf, inf};

bool isArithmetic() {
	for(int i = 1; i < 4; i++)
		if(a[i] - a[i - 1] != a[1] - a[0])
			return 0;
	return 1;
}

bool isGeometric() {
	for(int i = 1; i < 4; i++)
		if(a[i] / a[i - 1] != a[1] / a[0])
			return 0;
	return 1;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	if(!(isArithmetic()) && !(isGeometric()))
		return cout << 42 << endl, 0;
	if(isArithmetic())
		ans[0] = a[3] + (a[3] - a[2]);
	if(isGeometric())
		ans[1] = a[3] * (a[3] / a[2]);
	if(ceil(ans[0]) == ans[0] && ans[0] != inf)
		return cout << ans[0] << endl, 0;
	if(ceil(ans[1]) == ans[1] && ans[1] != inf)
		return cout << ans[1] << endl, 0;
	return cout << 42 << endl, 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int l=0;
    double m,n,p,ans;
    m=((double)b)/a;
    n=((double)c)/b;
    p=((double)d)/c;
    if((a-b)==(b-c)&&(b-c)==(c-d))
    {
        l=b-a+d;
        cout<<l;
    }
    else if((m==n)&&(n==p)&&(m!=1&&m!=0))
    {
        ans = m*d;
        if(((int)ans-ans)!=0)
            cout<<42;
        else
        {
            cout<<(int)ans;
        }
    }
    else
    {
        cout<<42;
    }

}

#include <iostream>

using namespace std;

int main()
{
    double a , b , c ,d;
    cin>>a>>b>>c>>d;
    if(b-a == c-b && c-b == d-c)
    {
        cout<<d+(d-c)<<endl;
    }
    else if(b/a == c/b && c/b == d/c)
    {
        if(d*(d/c) == int(d*(d/c)))
           cout<<d*(d/c)<<endl;
        else
           cout<<"42"<<endl;
    }
    else
        cout<<"42"<<endl;
    return 0;
}

#include<bits/stdc++.h>
#define F(i,a,b,c) for(register int i=(a);(b);i=(c))
#define Fu(i,a,b) F(i,(a),i<=(b),i+1)
#define Fd(i,a,b) F(i,(a),i>=(b),i-1)
#define inf 1073741823
#define LL long long
int Fl,ch;template<typename t>int in(t&a){a=0;ch=getchar();Fl=1;while(((ch<'0')||(ch>'9'))&&ch!=EOF)Fl=(ch=='-')?-Fl:Fl,ch=getchar();if(ch==EOF)return 0;while((ch>='0')&&(ch<='9'))a=a*10+ch-'0',ch=getchar();a*=Fl;return 1;}template<typename t,typename ...ARGS>int in(t&a,ARGS&...args){return in(a)+in(args...);}
using namespace std;
int a,b,c,d,e,f;
int main()
{
	cin>>a>>b>>c>>d;
	if(b-a==c-b&&c-b==d-c)cout<<d-a+b;
	else if(a*c==b*b&&b*d==c*c)printf("%d",(d*d%c)?42:d*d/c);
	else printf("42");
	return 0;
}
//BY 线段树蒟蒻

#include<cstdio>
#include<cmath>
bool A(int *a)
{
    int ind=a[1]-a[0];
    for(int i=2; i<4; i++)
    {
        if(a[i]-a[i-1]!=ind)
        {
            return 0;
        }
    }
    return 1;
}
bool G(int *a)
{
    int x=a[0],y=a[1];
    int z=x%y;
    while(z!=0)
    {
        x=y;
        y=z;
        z=x%y;
    }
    int Ag=a[0]/y,Bg=a[1]/y;
    for(int i=2; i<4; i++)
    {
        x=a[i-1],y=a[i];
        z=x%y;
        while(z!=0)
        {
            x=y;
            y=z;
            z=x%y;
        }
        int Ai=a[i-1]/y,Bi=a[i]/y;
        if(Ai!=Ag||Bi!=Bg)
            return 0;
    }
    return 1;
}
int main()
{
    int a[4];
    while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])==4)
    {
        int ans=42;
        bool A1=A(a),G1=G(a),s=0;
        if(A1==1)
        {
            int d=a[1]-a[0];
            ans=a[3]+d;
            s=1;
        }
        else if(G1==1)
        {
            int x=a[0],y=a[1];
            int z=x%y;
            while(z!=0)
            {
                x=y;
                y=z;
                z=x%y;
            }
            int A=a[0]/y,B=a[1]/y;
            int m=a[3]*B;
            if(m>=A)
            {
                int asd=m%A;
                if(asd==0)
                    ans=m/A;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

#include<cstdio>
#include<cmath>
bool A(int *a)
{
    int ind=a[1]-a[0];
    for(int i=2; i<4; i++)
    {
        if(a[i]-a[i-1]!=ind)
        {
            return 0;
        }
    }
    return 1;
}
bool G(int Ag,int Bg,int *a)
{
    for(int i=2; i<4; i++)
    {
        int x=a[i-1],y=a[i],z=x%y;
        while(z!=0)
        {
            x=y;
            y=z;
            z=x%y;
        }
        int Ai=a[i-1]/y,Bi=a[i]/y;
        if(Ai!=Ag||Bi!=Bg)
            return 0;
    }
    return 1;
}
int main()
{
    int a[4];
    while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])==4)
    {
        int ans=42;
        int x=a[0],y=a[1];
        int z=x%y;
        while(z!=0)
        {
            x=y;
            y=z;
            z=x%y;
        }
        int Ag=a[0]/y,Bg=a[1]/y;
        bool A1=A(a),G1=G(Ag,Bg,a);
        if(A1==1)
        {
            int d=a[1]-a[0];
            ans=a[3]+d;
        }
        else if(G1==1)
        {
            int m=a[3]*Bg;
            if(m>=Ag)
            {
                int asd=m%Ag;
                if(asd==0) ans=m/Ag;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int N = 1e9+7;

int main()
{
       double a,b,c,d;
       cin>>a>>b>>c>>d;
       if(a-b==b-c && b-c==c-d)
       {
           //arithmatic
           double r = a-b;
           cout<<d-r;
           return 0;
       }
       else if(b/a == c/b && c/b == d/c)
       {
           double r = b/a;
           if(r*d == (int)(r*d))
           {
               cout<<r*d;
               return 0;
           }
           else
           {
               cout<<42;
               return 0;
           }

       }
       else
           cout<<42;

    return 0;
}

#include<iostream>
#include<cstdio>
#include<cmath>
#define eps 1e-9
using namespace std ;
int seq[10] ;
bool arith(){

    int d =seq[1]-seq[0] ;
    for(int i=1;i<3;i++){
        if(d!=seq[i+1]-seq[i]) return 0 ;
    }
    int ans = seq[3]+d ;
    if(ans==0) return 0 ;
    cout<<ans<<"\n" ;
    return 1;
}
bool geo(){
    for(int i=0;i<4;i++){
        if(seq[i]==0) return 0 ;
    }

    if(seq[1]*seq[1]!=seq[0]*seq[2] || seq[2]*seq[2]!=seq[1]*seq[3]) return 0 ;
    double ans = (seq[3]*seq[3])/double(seq[2]) ;
    if(ceil(ans)!=floor(ans) || (int)ans==0) return 0 ;
    cout<<(int)ans<<"\n" ;
    return 1;
}

int main(void){

    //freopen("//home//mazhar//Desktop//in.txt", "r", stdin);
    for(int i=0;i<4;i++) scanf("%d",&seq[i]) ;
    if(arith()) return  0 ;
    if(geo()) return 0 ;
    cout<<"42"<<"\n" ;

return 0 ;
}

#include<cstdio>
using namespace std;
int a,b,c,d;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(b-a==c-b&&c-b==d-c) printf("%d\n",d+(b-a));
	else if(a*c==b*b&&b*d==c*c&&d*d%c==0) printf("%d\n",d*d/c);
	else puts("42");
	return 0;
}

#include<bits/stdc++.h>
using namespace std ;
int main()
{
    float x1 , x2 ,x3 ,x4 ;
    cin >> x1 >> x2 >> x3 >> x4 ;
    int ans = x2 - x1 ;
    float G = x2/x1 ;
    int X1 = x2 - x1  , X2 = x3 - x2 , X3 = x3 - x2 , X4 = x4 - x3 ;
    float G1 = x2 / x1 , G2 = x3 / x2 , G3 = x4/x3 ;
    if(X1 == X2 && X3 == X2 && X3 == X4)
    {
        cout << x4 + ans << endl;
    }
    else if (G1 == G2 && G2 == G3 && floor(x4 * G3)==x4 * G3)
    {
        cout << x4 *(G3) << endl;
    }
    else
        cout << "42" << endl;

}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long > pl;
#define po pop_back
#define pb push_back
#define mk make_pair
#define lw lower_bound
#define up upper_bound
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MAX 1e18
#define MIN -1e18
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define con continue
#define freopen freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628
typedef tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

ll a,b,c[1234567],d[5234567],c1[1234][1234],e[1234567],n,j,i,l,r,x,y,k,ans,sum;
bool used[3234567];
ll T;
vector<ll> v1,v[1234567];
string s,ss[1234567],s1;
char ch[1234][1234];
pl p[1234567];
priority_queue<ll> pq;
ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
map<ll,ll> mp[300],mp1;
map<string , ll> ms;
queue<pl> q;
set<ll> st;
ll N=5e6+1,mod;
map<int , bool> mb;
int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a - b == b - c && b - c == c - d)cout<<d - (a - b);
    else if(a * c == b * b && b * d == c * c && !((d * d) % c))cout<<(d*d)/c;
    else cout<<42;
}

#include <iostream>
#include<bits/stdc++.h>
#include<math.h>

using namespace std;

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back
#define popf pop_front
#define int long long int
#define PI 3.1415926535897932
#define vi       vector<int>
#define vll      vector<ll>
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define prec(x)  cout<<fixed<<setprecision(x)

int n,z,ans,quo,rem,sum,a,b,c,d,i,j,k,x,ind,l,r,left,right;

int ncr(int n,int r)
{

    int num=1;
    int deno=1;

    while(r)
    {
        num*=n;
        deno*=r;

        n--;
        r--;
    }

    int ans=num/deno;

    return ans;
}

signed main()
{
    fast

 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

   int t=1;
  // cin>>t;

   while(t--)
   {
     int a[4];

     rep(i,0,4)
     cin>>a[i];

     int d1,d2,d3;

     d1=a[1]-a[0];
     d2=a[2]-a[1];
     d3=a[3]-a[2];

     if(d1==d2 && d2==d3)
     {
      cout<<a[3]+d1<<endl;
      break;
     }

     if( a[1]*a[1]==a[0]*a[2] &&  a[2]*a[2]==a[1]*a[3])
     {
        float r=float(a[1])/a[0];

        float ans=a[3]*r;

        if(ans==floor(ans))
        {
            cout<<ans<<endl;
            break;
        }
         else
        cout<<42<<endl;
     }

     else
        cout<<42<<endl;

   }
    return 0;

    }

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod ((ll)1e9+7)
#define inf 0x3f3f3f3f
#define infl 0x3f3f3f3f3f3f3f3f
#define Ninf -0x3e3e3e3f
#define Ninfl -0x3e3e3e3e3e3e3e3f
#define maxx ((ll)1e5+5)
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
ll add(ll x, ll y) { x += y; if (x >= mod) return x-mod; return x;}
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + mod; return x;}
ll mult(ll x, ll y) { return (x * y) % mod;}
ll rev(ll x) { return expm(x, mod - 2);}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
bool comp(double a,double b){
  return abs(a-b)<1e-9;
}
signed main(){
  fast;
  //test
  {
    double a,b,c,d;
    cin>>a>>b>>c>>d;
    if(b-a==d-c&&c-b==b-a){
      int ans=d+d-c;
      cout<<ans;
    }
    else if(comp(b/a,c/b)&&comp(d/c,b/a)&&comp(d*d/c,(int)(d*d/c))){
      int ans=d*d/c;
      cout<<ans;
    }
    else
    {
      cout<<42;
    }
  }
  return 0;
}

//          <3           dreamparis7       <3    //
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define popb pop_back
#define countbits __builtin_popcountll
#define mp make_pair
#define ve vector
#define vii vector < int >
#define vll vector < ll >
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define sz size
#define len length
#define se second
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=10000000+6;
#define M_PI           3.14159265358979323846

//dreaming is easy,working to make dreams is tough!!
//everything is easy when you really want to do it!

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
       freopen ("INPUT.txt" , "r" , stdin);
       freopen ("OUTPUT.txt", "w" , stdout);
    #endif

          double a,b,c,d;
          cin>>a>>b>>c>>d;

          if(b-a == c-b && c-b == d-c)
          {
            cout<<b-a+d<<'\n';
            return 0;
          }

          if(b*b == a * c && c*c == b*d)
          {
            if((int)(d*d)%(int)c==0)
            {
                cout<<d*d/c<<'\n';
            return 0;

            }
          }

          cout<<42<<'\n';

return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e;
int main()
{
	cin>>a>>b>>c>>d;
	if(a+c==2*b and b+d==2*c)cout<<d+(b-a)<<endl;
	else if(a*c==b*b and b*d==c*c)cout<<((d*d%c)?42:(d*d/c))<<endl;
	else cout<<42<<endl;

}

#include<bits/stdc++.h>
using namespace std;

// define
# define loop(i,a,n) for(int i=a;i<n;++i)
# define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0);
# define ll long long int
# define endl '\n'
# define mp make_pair
# define mt make_tuple
# define pb push_back
# define eb emplace_back
# define in insert
# define rev(i,a,n) for(int i=n-1;i>=a;--i)
# define test int t; cin>>t; while(t--)

/* debug */
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _itRS(_ss); err(_itRS, args); }

void err(istream_iterator<string> itRS) {}
template<typename T, typename... Args>
void err(istream_iterator<string> itRS, T a, Args... args) {
    cerr << *itRS << " = " << a << endl;
    err(++itRS, args...);
}
int dx[8] = {-1,-1,-1, 0, 0, 1, 1, 1};
int dy[8] = {-1, 0, 1,-1, 1,-1, 0, 1};

const int MOD=1000000007;
int T[10001];
int main()
{
    fast
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int sl,sm,sr;
    sl=b-a;
    sm=c-b;
    sr=d-c;
    float ml,mm,mr;
    ml=(float)b/a;
    mm=(float)c/b;
    mr=(float)d/c;
   // cout<<sl<<" "<<sm<<" "<<sr<<endl;
   //cout<<ml<<" "<<mm<<" "<<mr<<endl;
    if(sl==sm && sm==sr)
    {
      //  cout<<d<<" "<<sl<<endl;
        cout<<d+sl;
    }
    else if(ml==mm && mm==mr)
    {
        if((int)d*mr-ceil(d*mr)==0)
            { cout<<d*mr;}
            else cout<<42<<endl;
    }
    else
    {
        cout<<42<<endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long double x,y,z,a;
    cin>>x>>y>>z>>a;
    long long b;
    if(abs(x-y)==abs(a-z)&&abs(a-z)==abs(z-y)){
        cout<<((y-x)+a)<<endl;
    }
    else if((y/x)==(z/y)&&(z/y)==(a/z)){
        b=((y/x)*a);
        if(b==((y/x)*a)){cout<<b<<endl;}
        else{cout<<42<<endl;}
    }
    else{
        cout<<42<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d;
	if ((b - a == c - b) && (c - b == d - c)) {
		e = d + (d - c);
		cout << e << endl;
		return 0;
	}
	else if ((a != 0 && b != 0 && c != 0 && d != 0) &&
			(b * b == a * c && c * c == b * d) &&
			(a != b && b != c && c != d)) {
				if ((d * d) % c == 0) {
					e = (d * d) / c;
					cout << e << endl;
					return 0;
				}
				else {
					cout << 42 << endl;
					return 0;
				}
			}
	else {
		cout << 42 << endl;
		return 0;
	}
}

#include<bits/stdc++.h>
using namespace std;
int arr[1000000];
int main(){
for(int i=0; i<4; i++)
    cin>>arr[i];
set<int> si1;
set<pair<int, int> > si2;
for(int i=1; i<4; i++){
    si1.insert(arr[i]-arr[i-1]);
    int hi1=arr[i-1], hi2=arr[i];
    int yo=__gcd(hi1, hi2);
    hi1/=yo, hi2/=yo;
    si2.insert(pair<int, int>(hi2, hi1));
}
if(si1.size()==1){
    int hi=*si1.begin();
    cout<<arr[3]+hi;
}
else{
    if(si2.size()==1){
        pair<int, int> hi=*si2.begin();
        arr[3]*=hi.first;
        if(arr[3]%hi.second==0){
            cout<<arr[3]/hi.second;
        }
        else
            cout<<42;
    }
    else
        cout<<42;
}
return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(abs(a-b)==abs(c-d)&&abs(c-d)==abs(b-c))
    {
        printf("%d\n",d+(b-a));
    }
    else
    if(a*c==b*b&&b*d==c*c)
    {
        if(!(d*d%c))printf("%d\n",d*d/c);
        else printf("42\n");
    }
    else
    printf("42\n");
    return 0;
}

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long double a,b,c,d,diff1,diff2,diff3;
	cin >> a >> b >> c >>d;
	diff1=d-c;diff2=c-b;diff3=b-a;
	if(diff1==diff2 && diff2==diff3)
	{
		cout << d+diff3 << endl;
	}
	else if((d/c)==(c/b) && (c/b)==(b/a))
	{
		if((ceil((d*d)/c)-1)==((d*d)/c) || (ceil((d*d)/c))==((d*d)/c))
		cout << (d*d)/c << endl;
		else
		{
			cout << 42 <<endl;
		}
	}
	else
	{
		cout << 42 << endl;
	}
	return 0;
}

#include <iostream>
#include <set>
#include <cmath>
using namespace std;

int main(int argc, char const *argv[])
{
    double a[4];
    set<int> A;
    set<double> B;
    cin >> a[0];
    for (int i = 1; i < 4; i++)
    {
        cin >> a[i];
        A.insert(a[i] - a[i - 1]);
        if (a[i - 1])
            B.insert(a[i] / a[i - 1]);
    }

    if (A.size() == 1)
        cout << a[3] + *A.begin() << endl;
    else if (B.size() == 1)
    {
        double t = (double)a[3] * *B.begin();
        if (t - floor(t) == 0)
            cout << (int)t << endl;
        else
            cout << 42 << endl;
    }
    else
        cout << 42 << endl;
    return 0;
}

/*
1 -1 1 -1
-1 1 -1 1
100 150 225 337.5

1000 1500 2250 3375
10000 15000 22500 33750
*/

#define _CRT_SECURE_NO_DEPRECATE
#define _SECURE_SCL 0
#pragma comment(linker, "/STACK:200000000")

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <fstream>
#include <iostream>
#include <map>
#include <memory.h>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
#include <stack>
#include <list>
#include <string>
#include <sstream>
#include <vector>
#include <utility>
#include <cmath>

using namespace std;
#define fvi(v) for(vector<int>::iterator it=v.begin();it!=v.end();it++)
#define fvs(v) for(vector<string>::iterator it=v.begin();it!=v.end();it++)
#define ff(i,n) for(int i=0;i<int(n);i++)
#define f(i,a,b) for(int i=int(a);i<int(b);i++)
#define i(n) for(int i=0;i<int(n);i++)
#define j(n) for(int j=0;j<int(n);j++)

#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vs vector<string>
#define pb push_back
#define	c(a) cout<<a<<endl;

#define si set<int>
#define ss set<string>
#define mp make_pair
#define mii map<int,int>

#define st string
#define l(a) a.length()

#define fr first
#define sc second

#define tr(container, it) \
	for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define ptr(z) \
	tr(z,it){cout<<(*it)<<" ";} c("");
#define sz(v) v.size()

#define pn c("");
#define ps cout<<" ";

#define all(v) v.begin(),v.end()
#define s(v) sort(v.begin(),v.end())

#define rs(v) sort(v.rbegin(),v.rend())
#define vmax(v) *max_element(all(v)) // value
#define vmin(v) *min_element(all(v)) // value
#define imin(v) max_element(all(v))-v.begin() // index
#define imax(v) min_element(all(v))-v.begin() // index

#define ifnd(v,val) find(all(v),val)-v.begin() //index
#define fnd(v,val) find(all(v),val) //iterator

#define mem(dp,a) memset(dp,a,sizeof(dp))
#define vit vector<int> :: iterator

#define eps 1e-6

typedef long long int ll;

int main()
{
	double a,b,x,y,s=0,c=0,k,n,m,p,q;
	vi z;char ch;
	cin>>a>>b>>x>>y;
	n=b-a;
	if(x-b==n && y-x==n){
		c(y+n);
		return 0;
	}

	if(b/a==x/b && x/b==y/x && ( (y*y)/x) - int((y*y)/x) ==0) {
		c((y*y)/x);
		return 0;
	}
	c(42);

	return 0;
}

#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int , int> pii;
typedef double DB;

int a[10];

int main(){

	ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

	for(int i = 0 ; i < 4 ; i++)
		cin >> a[i];

	int d = a[1] - a[0];
	DB q = (DB) a[1] / a[0];

	bool dd = 1 , qq = 1;

	for(int i = 1 ; i < 3 ; i++){
	   if(a[i] + d != a[i+1])
		  dd = 0;
		if((DB) a[i] * q != (DB) a[i+1])
		   qq = 0;
	}

	if(dd)
	   cout << a[3] + d << endl;
	else if(qq){
	   DB ans = (DB) a[3]*q;
	   if(ans - (int) ans == 0)
		  cout << ans << endl;
		else
		   cout << 42 << endl;
	}
	else
	   cout << 42 << endl;

	return 0;

}

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

// Fractional r is allowed as far as next element is not fractional
int a, b, c, d, ans = 42;

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );

	cin >> a >> b >> c >> d;
	if( b - a == c - b && c - b == d - c )
	{
		ans = d + d - c;
	}
	else if( b * b == a * c && c * c == b * d && ( d * b ) % a == 0 )
	{
		ans = ( d * b ) / a;
	}
	cout << ans << "\n";
	return 0;
}

#include <bits/stdc++.h>
#define PI = 3.141592654;
using namespace std;
int i , j ;
typedef long long  ll ;
bool f = 0;
int modu = 1e9 + 7;
int main(){
    int a[4] , r = 0 ;
    double g = 0;
    for (i = 0 ; i < 4 ; ++i)
        cin >> a[i];
    set<int> arth ;
    set<double> geo;
    for (i = 0 ; i < 3 ; ++i) {
        r = a[i+1] - a[i];
        arth.insert(r);
    }
    if (arth.size() == 1) {
        cout << a[3] + r << endl;
        return 0;
    }
    for (i = 1 ; i < 4 ; ++i) {
        g = (double)a[i] / a[i-1];
        geo.insert(g);
    }
    if (geo.size() == 1 ) {
        if (ceil(g*a[3]) == g*a[3]){
            cout << a[3] * g << endl;
            return 0;
        }
    }
    cout << 42 << endl;
}

#include <iostream>
#include <math.h>
#include <cmath>
#include <cstdlib>

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	bool made = false;
	int x1, x2, x3, x4;
	cin >> x1 >> x2 >> x3 >> x4;
	bool f1a = (x2-x1) == (x3-x2) && (x3-x2) == (x4-x3) && (x4 == (x1+3*(x2-x1)));
	bool f2g = (float(x2)/x1) == (float(x3)/x2) && (float(x3)/x2) == (float(x4)/x3);
	if(f1a)
	{
		cout << x1+4*(x2-x1);
		made = true;
	}
	else
	{
		if(f2g && !made)
		{
			if(x4*(float(x4)/float(x3)) == int(x4*(float(x4)/float(x3))))
			{
				cout << x4*(float(x4)/float(x3)) << endl;
				made = true;
			}
		}
		if(!made)
			cout << 42 << endl;
	}
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int a, b, c, d; cin>>a>>b>>c>>d;
	if( a + c == 2 * b and b + d == 2 * c) cout<<(2*d - c) <<endl;
	else if( a * c == b * b and b * d == c * c and (d * d) % c == 0) cout<< ((d * d) / c) <<endl;
	else cout<<42<<endl;
	return 0;
}

#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

int main(){

	double a,b,c,d;
	cin>>a>>b>>c>>d;

	if((d-c)==(c-b) && (c-b)==(b-a)){
		double r=(d-c);
		cout << d + r;
	}
	else{
		if((d/c)==(c/b) && (c/b)==(b/a)){
			double r=(d/c);
			double p=d*r;
			int q=d*r;
			if(p==q){
				cout << d*r;
			}
			else{
				cout << 42;
			}
		}
		else{
			cout << 42;
		}
	}

	return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int arr[4];
    bool isArith = true;
    bool isGeo   = false;
    for(int i=0; i<4; i++){
       cin >> arr[i];
    }//for
    int d = arr[1] - arr[0];
    int q;
    for(int i=2; i<4; i++){
         if(arr[i]-arr[i-1] != d){
            isArith = false;
         }//if
    }//for
    if(!isArith){
        isGeo = true;
        q = arr[1] / arr[0];
        for(int i=2; i<4; i++){
             if(arr[i]/arr[i-1] != q || arr[i]%arr[i-1] != 0){
                isGeo = false;
             }//if
        }//for
     }//if

     if(isArith){
        cout<<arr[3]+d;
     }else if (isGeo){
        cout<<arr[3]*q;
     }else{
        cout<<42;
     }
    return 0;
}//main

#include <stdio.h>

int main()
{
    int chislo1, chislo2, chislo3, chislo4;
    int inc=0, d, q;

    scanf("%d %d %d %d", &chislo1, &chislo2, &chislo3, &chislo4);

    if (chislo1<1||chislo1>1000||chislo2<1||chislo2>1000||chislo3<1||chislo3>1000||chislo4<1||chislo4>1000) return 0;

    d=chislo2-chislo1;

    if ((chislo3-chislo1==2*d)&&(chislo4-chislo1==3*d)&&(chislo1+4*d==(int)(chislo1+4*d)))
    {
        inc++;
        printf("%d", chislo1+4*d);
        return 0;
    }

    q=chislo2/chislo1;

    if ((chislo3==chislo1*q*q)&&(chislo4==chislo1*q*q*q)&&(chislo1*q*q*q*q==(int)(chislo1*q*q*q*q)))
    {
        inc++;
        printf("%d", chislo1*q*q*q*q);
        return 0;
    }

    if (inc==0) printf("%d", 42);

    return 0;
}

#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define each(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;

int a[5];
ll arith(){
	int d = a[1] - a[0];
	rep(i, 3) if(a[i + 1] != a[i] + d) return 1ll << 60;
	return a[3] + d;
}
ll geom(){
	if(a[0] == 0){
		rep(i, 4) if(a[i]) return 1ll << 60;
		return 0;
	}
	bool ok = 1;
	int r = a[1] / a[0];
	rep(i, 3) if(a[i + 1] != a[i] * r) ok = 0;
	if(ok) return a[3] * r;

	ok = 1;
	r = a[0] / a[1];
	rep(i, 3) if(a[i + 1] * r != a[i]) ok = 0;
	return ok && a[3] % r == 0 ? a[3] / r : 1ll << 60;
}

int main(){
	rep(i, 4) cin >> a[i];
	ll a = arith(), g = geom();

	if(a == 1ll<<60 && g == 1ll<<60 || a != 1ll << 60 && g != 1ll << 60 && a != g){
		cout << 42 << endl;
	}
	else{
		cout << (a != 1ll << 60 ? a : g) << endl;
	}

	return 0;
}

#include<stdio.h>
int main()
{
    int a1,a2,a3,a4;
    while(scanf("%d %d %d %d",&a1,&a2,&a3,&a4) != EOF)
    {
        int t1=a2-a1;
        int t2;
        t2=(float)a2/a1;
        if(t1==a3-a2 && t1==a4-a3)
            printf("%d\n",a4+t1);
        else if(t2==(float)a3/a2 && t2==(float)a4/a3)
            printf("%d\n",a4*t2);
        else
            printf("42\n");
    }
    return 0;
}

#include <iostream>
#include<cmath>

using namespace std;

int main()
{
    double arr[4],arr2[3];
    double arr3[3];
    for(int i=0;i<4;i++)
        cin>>arr[i];
    for(int i=0;i<3;i++){
        arr2[i]=arr[i+1]-arr[i];
        arr3[i]=arr[i+1]/arr[i];
    }

    if(arr2[1]==arr2[0] && arr2[0]==arr2[2])
        cout<<arr2[0]+arr[3];

    else if(arr3[0]==arr3[1] && arr3[0]==arr3[2])
        {
            double test;
            test=arr3[0]*arr[3];
            if((int)test==(double)test)
                cout<<test;
            else
                cout<<42;
        }

    else
        cout<<42;

    return 0;
}

#include<cstdio>
using namespace std;
int a,b,c,d;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(b-a==c-b&&c-b==d-c) printf("%d\n",d+(b-a));
	else if(a*c==b*b&&b*d==c*c&&d*d%c==0) printf("%d\n",d*d%c);
	else puts("42");
	return 0;
}

//
//  main.cpp
//  CF
//
//  Created by iMac on 28/11/2019.
//  Copyright © 2019 SSAU. All rights reserved.
//

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int e = b - a;
    if (c - b == e && d - c == e) cout << d + e << endl;
    else {
        long double q = (long double)b / a;
        if(b * q == c && c * q == d) cout << d * q << endl;
        else cout << 42 << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define F first
#define S second
#define ii pair < int , int >
#define ever (;;)

int a1,a2,a3,a4;

ii fact(int x,int y)
{
    int g = __gcd(x,y);

    x /= g;
    y /= g;

    return {x,y};
}

int main()
{
    scanf("%d%d%d%d",&a1,&a2,&a3,&a4);

    if( a2-a1 == a3-a2 && a4-a3 == a3-a2 )
    {
        printf("%d\n",a4+(a4-a3));
        return 0;
    }

    ii p1 = fact(a2,a1);
    ii p2 = fact(a3,a2);
    ii p3 = fact(a4,a3);

    if( p1 != p2 || p1 != p3 )
    {
        printf("42\n");
        return 0;
    }

    printf("%d\n",a4*p1.F/p1.S);
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long long x,y,z,a;
    cin>>x>>y>>z>>a;
    if(abs(x-y)==abs(a-z)){
        cout<<((y-x)+a)<<endl;
    }
    else if((y/x)==(z/y)&&(z/y)==(a/z)){
        cout<<((y/x)*a)<<endl;
    }
    else{
        cout<<42<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(register T &x){
    register long long ff=1;x=0;register char c=getchar();
    for(;!isdigit(c);c=getchar())if(c=='-')ff=-1;
    for(;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+c-'0';
    x*=ff;
}
template<typename T>inline void write(register T x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
template<typename T>inline void writeln(register T x){
    write(x);
    putchar('\n');
}
const int INF=0x3f3f3f3f;
int a,b,c,d;
int work(){
	if(d-c==c-b&&c-b==b-a)return d+d-c;
	if(a==0&&b==0&&c==0&&d==0)return 0;
//	if(d/c==c/b&&c/b==b/a)return d*(d/c);
	if(c*c==d*b&&b*b==a*c)return d*d/c;
	return 42;
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);

	read(a);read(b);read(c);read(d);

	writeln(work());
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
     cout.tie(0);
float arr[4];
for(int i=0;i<4;i++)cin>>arr[i];
  float  ar=arr[1]-arr[0];
  float go=arr[1]/arr[0];
  bool a=1,g=1;
for(int i=1;i<4;i++)
{
    if(arr[i-1]+ar!=arr[i])
    {
        a=0;
    }
    if(arr[i-1]*go!=arr[i])
    {
        g=0;
    }

}
if(a)
    cout<<arr[3]+ar;
 else if(g)
    cout<<arr[3]*go;
 else
    cout<<42;
    return 0;
}

#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int tmp;
	while(cin>>tmp)
	{
	vector <int> a(4,0);

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

		a[i]=tmp;
		if(i<3)
		cin>>tmp;
	}
	if(a[1]-a[0]==a[3]-a[2])
		tmp=a[3]+(a[2]-a[1]);
	else
		tmp=a[3]*(a[2]/a[1]);
	cout<<tmp<<endl;
	}
}

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(b-a == c-b && c-b == d-c)
        cout<<d+d-c;
    else if((float)b/a == (float)c/b && (float)c/b == (float)d/c) cout<<d*d/c;
    else cout<<"42";
    return 0;
}

#pragma comment(linker, "/STACK:36777216")
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <hash_map>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <queue>
#define PI 3.14159265358979323846
#define ull unsigned long long int
#define ll long long int
#define EPS 1e-11
#define pb push_back
#define EOS(c) (c != EOF && c != '\0' && c != '\n' && c != ' ')
#define oo 1000000005
#define ALL(v) v.begin(), v.end()
#define mp make_pair

using namespace std;

//#define FILE "sort"
//#define OUT "put.txt"

template<class telem>telem MAX(telem a, telem b)
{
    return (a > b) ? a : b;
}

template<class telem>telem MIN(telem a, telem b)
{
    return (a < b) ? a : b;
}

template<class telem>telem GCD(telem a, telem b)
{
    return b ? GCD(b, a % b) : a;
}

template<class telem>telem LCM(telem a, telem b)
{
    return a / GCD(a, b) * b;
}

template<class telem>telem UNSIGNED(telem a)
{
    return (a > 0) ? a : a * (-1);
}

template<class telem>void bez_swop(telem &a, telem &b)
{
    telem c = a;
    a = b;
    b = c;
}

void swop(int &a, int &b)
{
    a = a ^ b;
    b = a ^ b;
    a = a ^ b;
}

string a;
vector<int> ss;
int d;
int q;

int main()
{

#ifdef OUT
    freopen("in"OUT, "r", stdin);
    freopen("out"OUT, "w", stdout);
#endif

#ifdef FILE
    freopen(FILE".in", "r", stdin);
    freopen(FILE".out", "w", stdout);
#endif

    srand(time(NULL));
    time_t start = clock();

    cin >> a;

    bool dd = true;
    bool qq = true;

    while(a != "")
    {
        ss.pb(atoi(a.c_str()));
        a = "";
        cin >> a;
    }

    if(ss.size() == 1)
    {
        return !printf("42");
    }

    d = ss[1] - ss[0];

    for(int i = 2; i < ss.size() && dd; i++)
    {
        if(ss[i] - ss[i - 1] != d)
            dd = false;
    }

    if(dd)
        return !printf("%d", ss.back() + d);

    if(!ss[0])
        return !printf("42");

    q = ss[1] / ss[0];

    if(ss[0] * q != ss[1])
        return !printf("42");

    for(int i = 2; i < ss.size() && qq; i++)
    {
        if(!ss[i - 1])
            return !printf("42");
        int r = ss[i] / ss[i - 1];
        if(r != q || ss[i - 1] * r != ss[i])
            qq = false;
    }

    if(qq)
        return !printf("%d", ss.back() * q);

    printf("42");

    fprintf(stderr, "\n%0.3lf\n", (clock() - start) * 1.0 / CLOCKS_PER_SEC);

    return 0;
}

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <vector>
#include <queue>
#include <deque>/
#include <cmath>
#include <set>
#include <map>
#define ll long long
#define ld long double
#define sqr(a) (a)*(a)
#define mp make_pair
#define pb push_back
#define pi pair<int,int>
#define x first
#define y second
#define inf (int)1e9
#define frac(x) (x)-(int)(x)
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(d-c==c-b && c-b==b-a) return cout<<d+d-c,0;
    if(d/c==c/b && c/b==b/a) return cout<<d*(d/c),0;
    cout<<42;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a,b,c,d;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a > b)
	{
		if(a - b == b - c)
		{
			printf("%d",d - (b - c));
			return 0;
		}
		else if(a / b == b / c)
		{
			if(d / (a / b) != 0)
				printf("%d",d / (a / b));
			else
				printf("42");
			return 0;
		}
	}
	else if(a < b)
	{
		if(d - c == c - b)
		{
			printf("%d",d + (d - c));
			return 0;
		}
		else if(d / c == c / b)
		{
			printf("%d",d * (d / c));
			return 0;
		}
	}
	printf("42");
	return 0;
}

#include <iostream>
using namespace std;
template <class T>
int f1(T a[]){
    for(int i=0;i<2;i++)if(a[i]!=a[i+1])return 0;
    return 1;
}
int main(){
    int a[4];
    for(int i=0;i<4;i++) cin >> a[i];
    int b[3];
    double c[3];
    for(int i=1;i<4;i++)b[i-1]=a[i]-a[i-1];
    for(int i=1;i<4;i++)c[i-1]=double(a[i])/a[i-1];
    if(f1(b)) return cout << a[3]+b[2],0;
    if(a[0]!=0)if(c[0]!=1)if(f1(c)) return cout << int(a[3]*b[2]),0;
    return cout << 42 ,0;
}

#include<cstdio>
#include<cmath>
bool A(int *a)
{
    int ind=a[1]-a[0];
    for(int i=2; i<4; i++)
    {
        if(a[i]-a[i-1]!=ind)
        {
            return 0;
        }
    }
    return 1;
}
bool G(int *a)
{
    int x=a[0],y=a[1];
    int z=x%y;
    while(z!=0)
    {
        x=y;
        y=z;
        z=x%y;
    }
    int Ag=a[0]/y,Bg=a[1]/y;
    for(int i=2; i<4; i++)
    {
        x=a[i-1],y=a[i];
        z=x%y;
        while(z!=0)
        {
            x=y;
            y=z;
            z=x%y;
        }
        int Ai=a[i-1]/y,Bi=a[i]/y;
        if(Ai!=Ag||Bi!=Bg)
            return 0;
    }
    return 1;
}
int main()
{
    int a[4];
    while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])==4)
    {
        int ans=42;
        bool A1=A(a),G1=G(a),s=0;
        if(A1==1)
        {
            int d=a[1]-a[0];
            ans=a[3]+d;
            s=1;
        }
        else if(G1==1)
        {
            int x=a[0],y=a[1];
            int z=x%y;
            while(z!=0)
            {
                x=y;
                y=z;
                z=x%y;
            }
            int A=a[0]/y,B=a[1]/y;
            ans=a[3]*B/A;
        }
        printf("%d\n",ans);
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main(){
    int a[4+2];
    for(int i = 1; i <= 4; i++){
        cin >>a[i];
    }
    int s = a[2]-a[1];
    int q = a[3]-a[2];
    if(s == q){
        cout<<a[4]+s;
    }
    else{
        double p=a[2]/a[1];
        if(p != (int)p)
            cout<<42;
        else cout<<p*a[4];
    }
}

#include <cstdio>
#include <iostream>

using namespace std;

int main()
 {
    int a, b, c, d;
    float p;
    cin >> a >> b >> c >> d;
    if (b - a == c - b)
     {
       p = b - a;
       if (p == d - c) cout << d + p;
       else cout << 42;
     }
    else if (a == 0) cout << 42;
    else if (float(b / float(a)) == float(c / float(b)))
     {
       p = float(b / float(a));
       if (p == 1 || p != float(d / float(c)))  cout << 42;
       else cout << float(d * p);
     }
     else cout << 42;

    //system("pause");

 }

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;
#define mod 1000000007

#define LL long long
#define mp make_pair
#define pb push_back
LL gcd(LL m, LL n){
LL r; while (n != 0){ r=m%n; m=n; n=r;} return m; }

const double EPS = 1E-8;

int main()
{
    int a, b, c, d;
    cin>> a>> b>> c>> d;
    if((a-b == b-c) && (b-c== c-d))
    {
        cout << d-(a-b)<< endl;
        return 0;
    }
    else{
        double r=(double)a/(double)b;
        double s=(double)b/(double)c;
        double t=(double)c/(double)d;
        if(r<=s+EPS && s<=t+EPS){
            double res=(double)d/(double)r;
            if(res-EPS<=ceil(res))
                cout <<res<< endl;
            else
                cout << "42"<< endl;
        }
        else
            cout << "42"<< endl;
    }

    return 0;
}

#include <iostream>
using namespace std;
template <class T>
int f1(T a[]){
    for(int i=0;i<2;i++)if(a[i]!=a[i+1])return 0;
    return 1;
}
int main(){
    int a[4];
    for(int i=0;i<4;i++) cin >> a[i];
    int b[3];
    double c[3];
    for(int i=1;i<4;i++)b[i-1]=a[i]-a[i-1];
    for(int i=1;i<4;i++)c[i-1]=double(a[i])/a[i-1];
    if(f1(b)) return (cout << a[3]+b[2]),0;
    if(a[0]!=0)if(c[0]!=1)if(f1(c))if(int(a[3]*c[2])==a[3]*c[2]) return (cout << int(a[3]*c[2])),0;
    return (cout << 42),0;
}

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if (abs(a-b)==abs(b-c)&&abs(c-d)==abs(b-c)) cout<<d-a+b<<endl;
	else if (a*c==b*b && b*d==c*c) {
		if(!(d*d%c)) cout<<d*d/c;
		else cout<<42;
	}
	return 0;
}

#include <iostream>

using namespace std;

int main()
{
    float j, i, h, p;
    cin >> j >> i >> h >> p;
    if (i-j == h-i && h-i == p-h)
    {
        cout << p + (h-i);
        return 0;
    }
    if (i/j == h/i && h/i== p/h)
    {
        float d= p* (h/i);
        int b= p* (h/i);
        if (b==d)
        {
            cout << 42;
            return 0;
        }
        cout << p * (h/i);
        return 0;
    }
    cout << 42;
}

#include<iostream>
#include<math.h>
using namespace std;

long next = 42;
int d;

bool capsocong(long a[])
{
    for(int i = 1; i < 2; i++)
    {
        if(a[i] != (a[i-1]+a[i+1]) / 2)
            return false;
    }
    return true;
}

bool capsonhan(long a[])
{
    for(int i = 1; i < 2; i++)
    {
        if(a[i] != sqrt(a[i-1]*a[i+1]))
            return false;
    }
    return true;
}

int main(void)
{
    long a[4];
    cin>>a[0]>>a[1]>>a[2]>>a[3];
    if(capsocong(a))

    {
        d = a[1] - a[0];
        next = a[3] + d;
    }
    if(capsonhan(a))
    {
        d = a[1]/a[0];
        next = a[3]*d;
    }
    cout<<next;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int a,b,c,d,p,q;
    cin>>a>>b>>c>>d;
    if(b-a==c-b&&c-b==d-c){
        p=(b-a)+d;
        cout<<p;
    }
    else if(b/a==c/b&&c/b==d/c){
            p=(b/a)*d;
    cout<<p;
    }
    else cout<<42;

}

#include <bits/stdc++.h>
using namespace std;
int main() {
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if((b-a)==(c-b) && (c-b)==(d-c)) {
		printf("%d\n",2*d-c);
		return 0;
	} else if(1.0*b/a==1.0*c/b && 1.0*c/b==1.0*d/c) {
		printf("%d\n",d*d/c);
	} else {
		printf("%d\n",42);
	}
	return 0;
}

#include <iostream>
#include <vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

bool check_int(double n)
{
	long long x = n;
	if (x - n == 0)
		return true;
	return false;
}

int main()
{
	IOS
	double a1, a2 ,a3 , a4;
	cin >> a1 >> a2 >> a3 >> a4;
	bool arith = false , geom = false;
	if (abs(a1 - a2) == abs(a2 - a3))
		arith = true;
	if (a1 / a2 == a2 / a3)
		geom = true;
	if (arith)
	{
		if (a4 > a3)
		{
			cout << a4 + (a4 - a3) << endl;
		}
		else
			cout << a4 - (a3 - a4) << endl;
	}
	else if (geom)
	{
		double ratio = a1 / a2;
		double ans = a4*ratio;
		if (check_int(ans))
			cout << ans << endl;
		else
			cout << 42 << endl;
	}
	else
		cout << 42 << endl;
	return 0;
}

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>
#include<vector>
using namespace std;
typedef long long l;
l n;
bool c1=true,c2=true;

l inp(){
    l cur=0;
    char cu='0';
    while('0'<=cu and cu<='9'){
        cur=cur*10+cu-'0';
        cu=getchar();
    }
    return cur;
}
l f2,f1;

int main(){
    #ifdef MiyazonoKaori
        freopen("1.inp","r",stdin);
    #endif
    l last;
    for(int i=1;i<=4;++i){
        l x=inp();
        if(i==1){
            last=x;
        }
        else{
            if(i==2){
                if(x%last!=0 or x==last ) c2=false;
                if(c2==true) f2=x/last;
                f1=x-last;
                last=x;
            }
            else {
                if(c2){
                    if(x/last!=f2 or x==last) c2=false;
                }
                if(c1){
                    if((x-last)!=(f1)) c1=true;
                last=x;
            }
        }
    }
    }
        //cout<<last;
        if(c1) cout<<last+f1<<" ";
        else cout<<42<<" ";
        if(c2) cout<<last*f2;
        else cout<<42<<" ";

}

#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define eps 1E-5
#define pi acos(-1.0)
#define X first
#define Y second
#define ll long long
#define PB(x) push_back((x))
#define MP(x,y) make_pair((x),(y))
#define CLR(x) memset((x),0,sizeof((x)))
using namespace std;
const int                           Maxn=4010,Maxm=100005,Mo=1000000007,
sp[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
const ll                            oo=INT_MAX>>2;
struct Tree{
    int l,r,cnt;
};
struct edge {
    int u,v,len;
};
typedef pair<ll,ll>                     F;
typedef int                             IArr[Maxn];
typedef ll                              LArr[Maxn];
typedef double                          DArr[Maxn];
IArr                                    a,d;
DArr                                    q;
int                                     n,i,j;
int main()
{
    ios::sync_with_stdio(0);
//    freopen("/Users/MAC/Desktop/Error202/Error202/1.in","r",stdin);
//    freopen("/Users/MAC/Desktop/Error202/Error202/1.out","w",stdout);
    for (i=1;i<=4;i++) cin>>a[i];
    for (i=1;i<=3;i++) d[i]=a[i+1]-a[i];
    int ck=1;
    for (i=1;i<=2;i++) ck=ck&&(d[i]==d[i+1]);
    if (ck){
        cout<<a[4]+d[1]<<endl;
        return 0;
    }
    for (i=1;i<=4;i++) cin>>a[i];
    for (i=1;i<=3;i++)
        if (!a[i]) {cout<<42<<endl;return 0;}
        else q[i]=a[i+1]/(double)a[i];
    ck=1;
    for (i=1;i<=2;i++) ck=ck&&(q[i]==q[i+1]);
    if (ck&&(int)(a[4]*q[1])==a[4]*q[1])
    {
        cout<<(int)a[4]*q[1]<<endl;
        return 0;
    }
    cout<<42<<endl;
}

#include <iostream>

using namespace std;

int main () {
	int a,b,c,d;
	cin >> a >> b >> c >> d;

	double r = 0;
	bool log = false;
	double n;
	if(b/a == c/b && c/b == d/c){
		r = b/a;
		n = d * r;
		log = true;
	}
	if(b-a == c-b && c-b == d-c){
		r = b - a;
		n = r + d;
		log = true;
	}
	else{
		n = 3.1465176187611;
	}

	if(int(n) == n){
		cout << n << endl;
	}
	else if(int(n) != n || log == false){
		cout << "42" << endl;
	}

}

#include<algorithm>
#include<iostream>
#define SIZE 4
#define DEFAULT 42
using namespace std;
//Function to Determine if Sequenece is Arithematic.
double isArithematic(double*);
//Function to Determine if Sequence is Geometric.
double isGeometric(double*);
//Function incoporating Solution.
void Solution(void);
void main(void)
{
Solution();
}
void Solution(void)
{
double *Numbers = new double [SIZE];
   for (int X = 0; X < SIZE; ++X)
	cin >> Numbers[X];
   if (isArithematic(Numbers))
	   cout<<isArithematic(Numbers);
   else if (isGeometric(Numbers))
	   cout<<isGeometric(Numbers);
   else cout << DEFAULT;
   delete [] Numbers;
   cout << endl;
}
double isArithematic(double*NumArr)
{
double CommDiff = NumArr[1]-NumArr[0];
	for (int X = 0; X < SIZE - 1; ++X)
		if (NumArr[X + 1] - NumArr[X] != CommDiff)
			return 0;
	return  CommDiff + NumArr[SIZE - 1];
}
double isGeometric(double* NumArr)
{
double CommRatio = NumArr[1]/NumArr[0];
	for (int X = 0; X < SIZE - 1; ++X)
	{
		if (NumArr[X + 1] / NumArr[X] != CommRatio)
			return 0;
	}
	return CommRatio*NumArr[SIZE - 1];
}

#include <iostream>
#include <set>
using namespace std;

int main(int argc, char const *argv[])
{
    int a[4];
    set<int> A;
    set<double> B;
    cin >> a[0];
    for (int i = 1; i < 4; i++)
    {
        cin >> a[i];
        A.insert(a[i] - a[i - 1]);
        if (a[i - 1])
            B.insert(a[i] / a[i - 1]);
    }

    if (A.size() == 1)
        cout << a[3] + *A.begin() << endl;
    else if (B.size() == 1)
    {
        double t = (double)a[3] * *B.begin();
        if (t == (int) t)
            cout << (int)t << endl;
        else
            cout << 42 << endl;
    }
    else
        cout << 42 << endl;
    return 0;
}

/*
1 -1 1 -1
-1 1 -1 1
*/

#include<stdio.h>
#include<math.h>
int main()
{
int i,d,arr[4],ap=0,gp=0,v=0;
float r;
  for(i=0;i<4;i++)
  {
  scanf("%d",&arr[i]);
  if(i==1)
  {
  d=arr[i]-arr[i-1];
  r=( float(arr[i])/ float (arr[i-1]));
  }
  if(i>1)
  {
    if(d==arr[i]-arr[i-1])
    {
     ap++;
    }
    else if(r==( float (arr[i])/ float (arr[i-1])))
          {
            gp++;
          }
           else {
                 v=1;
               }
  }
 }
if(v==1)
{
printf("%d",42);
}
else if((r-int (r))!=0 && gp==2)
{
printf("%d",42);
}
else if(ap==2)
{
printf("%d",arr[3]+d);
}
else if(gp==2)
{
printf("%d",int ((arr[3])*r));
}
else{
     printf("%d",42);
    }
//printf(" %f",r);
/*
int i,n,j;
scnaf("%d",&n);
int arr[5][2][4];
for(i=0;i<n;i++)
{
scanf("%d %d",&arr[i][0][0],&arr[i][][3]);
arr[i][][]
}*/
return 0;
}
/*
int factorial(int arr[],int n)
{
int varun=n,i,vex=1;
for(i=varun;i>=1;i--)
{
vex=vex*i;
}
return vex;
}
int main()
{
int i,n,k,j,a[4],arr[25],p;
scanf("%d",&n);
arr[0]=0;
for(i=1;i<=n;i++)
{
scanf("%d",&arr[i]);
}
scanf("%d",&k);
a[0]=0;
for(i=1;i<=k;i++)
{
scanf("%d",&a[i]);
}
p=factorial(arr,n);

return 0;
}*/

/*IN THE NAME OF GOD*/
/*year:2015 month: day: codeforces level:newbie*/
#include <iostream>
#include <conio.h>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <cmath>
using namespace std;

int main()
{
    double a1, a2, a3, a4; cin >> a1 >> a2 >> a3 >> a4;
    if (a1 - a2 == a2 - a3 && a2 - a3 == a3 - a4)
        cout << a4 + (a2 - a1);
    else if (a2 / a1 == a3 / a2 && a3 / a2 == a4 / a3)
        cout << a4*(a2 / a1);
    else
        cout << 42;

    return 0;
}

                #include <iostream>
                #include <cmath>
                #include <fstream>
                #include <string>
                #include <bits/stdc++.h>
                #include <iomanip>
                using namespace std;

                int isP(long int hj)
                {  long int op;
                	for(op=2;op<=sqrt(hj);op++)
                	{ if(hj%op==0)//&&kl%op==0)
                	  return 0;}
            		   return 1;
                }
                void swap(long long int *p,long long int *q)
                {long long int tmp=*p;
                *p=*q;
                *q=tmp;
        		}
                  int mind(long long int p)
                  {   int mindd=10;
					  while(p>0)
					  {	  if(p%10<mindd)
						  mindd=p%10;
						  p/=10;}
						  return mindd;}
						   int maxd(long long int p)
                  {   int maxdd=-1;
					  while(p>0)
					  {	  if(p%10>maxdd)
						  maxdd=p%10;
						  p/=10;}
						  return maxdd;}

            	string fdi(int hi)
            	{
            		switch(hi)
            		{
            			case 0:return "zero";
            			case 1:return "one";
    					case 2:return "two";
            			case 3:return "three";
            			case 4:return "four";
            			case 5:return "five";
            			case 6:return "six";
            			case 7:return "seven";
            			case 8:return "eight";
            			case 9:return "nine";}
            			return "";
            		}
            	/*		int isAlc(string hi)
            	{
            		switch(hi)
            		{
            			case 0:return "zero";
            			case 1:return "one";
    					case 2:return "twenty";
            			case 3:return "thirty";
            			case 4:return "forty";
            			case 5:return "fifty";
            			case 6:return "sixty";
            			case 7:return "seventy";
            			case 8:return "eighty";
            			case 9:return "ninety";}
            			return "";
            		}*/
            long long int bd(long long int mk,long long int nk)
            { long long int i;
			for(i=min(mk,nk);i>=1;i--)
			  {
			  	if(mk%i==0&&nk%i==0)
			  	return i;}
			  		  	return 0;
					  }

    		int dsm(long long int pkk)
    		{ //long long int smt=0;
    		if(pkk<0)
    		pkk*=-1;
   			while(pkk>0)
    			{
    				if(pkk%10==8)
    				return 1;
    				pkk/=10;
    			}
    		 return 0;
    		}
    		/*freopen ("input.txt","r",stdin);
	freopen ("output.txt","w", stdout);*/
    	           //use above snippet in io by file case just paste in the start rest
    	           //all same cin/cout etc
            void seving(int ar[],long long int n)
            {			long long int i,j;
               for(i=3;i<n;i+=2)
                 ar[i]=1;
                 ar[2]=1;
                 for(i=2;i<n;i++)
				{
					if(ar[i]==1)
					{	for(j=i*i;j<n;j+=i)
						ar[j]=0;}
					}
				}
				int tellme(int a,int b,int c)
				{
					if(c<a+b)
					return 1;
					else  if(a+b==c)
					return 2;
					else  return 0;}
				int vow(string  ch)
				{  int i;
					for(i=0;i<ch.size();i++)
					{	if(ch[i]>=48&&ch[i]<=57)
						return 1;}
						return 0;}
					int rk(char ch1,char ch2)
					{       char str[9]={'6','7','8','9','T','J','Q','K','A'};
						int i,j;
						for(i=0;i<9;i++)
						{if(str[i]==ch1)break;}
							for(j=0;j<9;j++)
						{	if(str[j]==ch2)break;}
						if(i>j)return 1;
						else return 0;}
								long long int gcd(long long int a, long long int b)
								{
									if(a==0)
									return b;
									else return gcd(b%a,a);}
									int isT(long long int b)
									{  long long int i,ct;
										ct=0;
										for(i=2;i<=(b-1);i++)
										{
											if(b%i==0)
											ct++;
											if(ct>1)return 0;}
											if(ct==1)return 1;
											else return 0;}

				long long int rerun(long long int i,long long int a,long long int k)
				{	if(i==k)return a;
					else return rerun(i+1,a+mind(a)*maxd(a),k);}
		int main() {
			long long int a,b,c,d,p,q,v,n1,n2,n3,d1,d2,d3;
cin>>a>>b>>c>>d;
p=b-a;
q=c-b;
v=d-c;
double h1,h2,h3;
h1=(double)b/a;
h2=(double)c/b;
h3=(double)d/c;
if(p==q&&q==v)
{	cout<<d+p;}
	else if(h1==h2&&h2==h3)
	{	if(d%a==0)
		cout<<(d*b)/a;
		else cout<<"42";}
		else cout<<"42";
					return 0;}

#include <iostream>

int main()
{
	float A, B, C, D;
	int ap;
	double gp;
	std::cin >> A >> B >> C >> D;
	ap = B - A;
	if(A) gp = B / A;

	if (ap == C - B && ap == D - C)
		std::cout << D + ap;
	else if ( gp != 0 && gp != 1 && gp == C / B && gp == D / C)
		std::cout << D * gp;
	else
		std::cout << 42;

	return 0;
}

#include <iostream>
#include<vector>
#include <map>
#include <queue>
#include<algorithm>
#include<set>
#include<functional>
#include<cstdio>
#include<cmath>
#include<stdlib.h>
#include <list>
#include<string>

typedef long long int64;
using namespace std;

int64 n;

int main()
{
    vector<int64> pr(4);

    for(int64 i=0; i<4; i++)
    {
       cin >> pr[i];
    }

    int64 s=pr[1]-pr[0];
    for(int64 i=2; i<4; i++)
    {
       if(pr[i]-pr[i-1]!=s)
        break;
      if(i==3)
      {
          cout << pr[i]+s;
          exit(0);
      }
    }

    s=pr[1]/pr[0];
    for(int64 i=2; i<4; i++)
    {
       if(pr[i]/pr[i-1]!=s || pr[i]/pr[i-1]==0 || s==0)
        break;
      if(i==3)
      {
          cout << pr[i]*s;
          exit(0);
      }
    }
    s=pr[0]/pr[1];
    for(int64 i=2; i<4; i++)
    {
       if(pr[i-1]/pr[i]!=s || pr[i-1]/pr[i]==0 || s==0)
        break;
      if(i==3)
      {
          cout << pr[i]/s;
          exit(0);
      }
    }

    cout << 42;
    return 0;
}

#include <iostream>
#include<vector>
#include <map>
#include <queue>
#include<algorithm>
#include<set>
#include<functional>
#include<cstdio>
#include<cmath>
#include<stdlib.h>
#include <list>
#include<string>

typedef long long int64;
using namespace std;

int64 n;

int main()
{
    vector<int64> pr(4);

    for(int64 i=0; i<4; i++)
    {
       cin >> pr[i];
    }

    int64 s=pr[1]-pr[0], ost;
    for(int64 i=2; i<4; i++)
    {
       if(pr[i]-pr[i-1]!=s)
        break;
      if(i==3)
      {
          cout << pr[i]+s;
          exit(0);
      }
    }

    s=pr[1]/pr[0];
    ost=pr[1]%pr[0];
    for(int64 i=2; i<4; i++)
    {
       if(pr[i]/pr[i-1]!=s || pr[i]/pr[i-1]==0 || s==0 || ost!=0 || pr[i]%pr[i-1]!=0)
        break;
      if(i==3)
      {
          cout << pr[i]*s;
          exit(0);
      }
    }
    s=pr[0]/pr[1];
    ost=pr[0]%pr[1];
    for(int64 i=2; i<4; i++)
    {
       if(pr[i-1]/pr[i]!=s || pr[i-1]/pr[i]==0 || s==0 || ost!=0 || pr[i-1]%pr[i]!=0)
        break;
      if(i==3)
      {
          cout << pr[i]/s;
          exit(0);
      }
    }

    cout << 42;
    return 0;
}

#include <iostream>
#include<cmath>

using namespace std;

int main()
{
    double arr[4],arr2[3];
    double arr3[3];
    for(int i=0;i<4;i++)
        cin>>arr[i];
    for(int i=0;i<3;i++){
        arr2[i]=arr[i+1]-arr[i];
        arr3[i]=arr[i+1]/arr[i];
    }

    if(arr2[1]==arr2[0] && arr2[0]==arr2[2])
        cout<<arr2[0]+arr[3];

    else if(arr3[0]==arr3[1] && arr3[0]==arr3[2])
        cout<<arr[3]*arr3[0];

    else
        cout<<42;

    return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define ci const int
#define ni ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define cd const double
#define cll const long long
#define ld long double
#define sh short int

using namespace std;

int main()
{

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    freopen("errors.txt", "w", stderr);
    ni;

    int a[4], l;
    bool aps = true, gps = true;
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    l = a[1] - a[0];

    for(int i =2; i < 4; i ++)
    {
    	if(a[i] - a[i - 1] != l)
    	{
    		aps = false;
    		break;
    	}
    }

    if(aps == true)
    {
    	cout << a[3] + l << '\n';
    	return 0;
    }

    double d = ((a[1] * 1.0) / (a[0] * 1.0));
    for(int i =2; i < 3; i ++)
    {
    	if((a[i] * 1.0) / (a[i - 1] * 1.0) != d)
    	{
    		gps = false;
    		break;
    	}
    }

    if(gps == true && (d * (a[3] * 1.0)) == round(d * a[3]))
    {
    	cout << d * a[3] * 1.0 << '\n';
    }

    else
    {
    	cout << 42 << '\n';
    }

    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	return 0;
}

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
struct fac
{
    int a;
    int b;
    void normalize()
    {
        int d=__gcd(a,b);
        a/=d;
        b/=d;
    }
    bool operator == (fac &f) const
    {
        return (a==f.a)&&(b==f.b);
    }
};
int main()
{
    int a[4],i,ans,d;
    fac p1,p2,p3;
    ans=42;
    for (i=0; i<4; i++)
        cin>>a[i];
    d=a[3]-a[2];
    if (a[1]-a[0] == d && a[2]-a[1] == d)
    {
        ans=a[3]+d;
        cout<<ans<<endl;
        return 0;
    }
    p1.a=a[3];
    p1.b=a[2];
    p2.a=a[2];
    p2.b=a[1];
    p3.a=a[1];
    p3.b=a[0];
    p1.normalize();
    p2.normalize();
    p3.normalize();
    if (p1 == p2 && p2 == p3)
    {
        if (a[3]%p1.b == 0 && a[3] >= p1.b)
        {
            ans=p1.a*(a[3]/p1.b);
            cout<<ans<<endl;
        }
    }
    cout<<ans<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	double a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a==b and b==c){
		cout<<a;
	}
	else if(b/a==c/b and (b-a)!=(c-b) and (d-c)!=(c-b) and c/b==d/c and c/b>=1){
		cout<<d*b/a;
	}
	else if(b/a!=c/b and (b-a)==(c-b) and (d-c)==(c-b) and c/b!=d/c){
		cout<<d+b-a;
	}
	else{
		cout<<42;
	}
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    double a,b,c,d;
    cin >>a>>b>>c>>d;
    if (a-b==c-d && a-b==b-c){
        cout << d-(a-b);
        cout<<"a";
    }
    else if( b/a==c/b && c/b==d/c){
        cout << a*pow(b/a,4)<<endl;
        cout<<"b";
    }
    else {
        cout << "42\n";
    }
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main ()
{
    double a,b,c,d;
    cin >> a >> b >> c >> d;
    int d1=d,c1=c;
    if (a - b == b - c && b - c == c - d)
        cout << d - (c-d) << endl;
    else if (b/a == c/b && c/b == d/c && a != 0 && b/a != 0 && b/a != 1 && d * (b/a) == d1 * (d1/c1))
        cout << d * (b/a) << endl;
    else
        cout << 42 << endl;
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <fstream>
#include <list>
#include <set>
#include <climits>
#include <map>
#include <stack>
#include <queue>
#include <complex>
#include <cmath>
#include <sstream>
#include <deque>
#include <utility>
#include <bitset>
using namespace std;

int main(){
	double a,b,c,d;
	cin>>a>>b>>c>>d;
	if( (b-a) == (c-a)/2 && (c-a)/2 == (d-a)/3 ){
		cout<<a+4*(b-a);
	}
	else
	if( b/a == sqrt(b/a) && (b*b*b)/(a*a*a) == sqrt(b/a) ){
		cout<<a*(b*b*b*b)/(a*a*a*a);
	}
	else
	cout<<42;

}

#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
	int A[4], i, d,d2;
	double q,q2;
	bool flag1 = true, flag2 = true;
	for (i = 0; i < 4; i++)
	{
		cin >> A[i];
	}
	d = A[2] - A[1];
	q = (double)A[2] /(double) A[1];
	for (i = 2; i < 4; i++)
	{
		if (!flag1 && !flag2)
			break;
		d2 = A[i] - A[i - 1];
		if (d2 != d)
			flag1 = false;
		q2 = (double)A[i] / (double)A[i - 1];
		if (q2 != q)
			flag2 = false;
	}
	if (flag1)
		cout << A[3] + d << endl;
	else if (flag2)
		cout << A[3] * q << endl;
	else cout << "42" << endl;
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main()
{
    int a, b, c, d;
    while (cin >> a >> b >> c >> d)
    {
        if (b - a == d - c)
        {
            printf("%d\n", (d-c)+d);
        }
        else if (b / a == d / c)
        {
            printf("%d\n", d/c * d);
        }
        else
            printf("42\n");
    }
    return 0;
}

#include <iostream>
#include<vector>
#include <map>
#include <queue>
#include<algorithm>
#include<set>
#include<functional>
#include<cstdio>
#include<cmath>
#include<stdlib.h>
#include <list>
#include<string>

typedef long long int64;
using namespace std;

int64 n;

int main()
{
    vector<double> pr(4);

    for(int64 i=0; i<4; i++)
    {
       cin >> pr[i];
    }

    double s=pr[1]-pr[0], ost;
    for(int64 i=2; i<4; i++)
    {
       if(pr[i]-pr[i-1]!=s)
        break;
      if(i==3)
      {
          cout << (int64)pr[i]+s;
          exit(0);
      }
    }
    s=pr[1]/pr[0];
    for(int64 i=2; i<4; i++)
    {
       if(pr[i]/pr[i-1]!=s)
        break;
      if(i==3)
      {
          cout << (int64)pr[i]*s;
          exit(0);
      }
    }

    cout << 42;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);

    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long diff = b - a;
    double ratio = (double)b / (double)a;
    if(c - b == diff && d - c == diff){
        cout << d + diff;
    }
    else if((double)c / (double)b == ratio && (double)d / (double)c == ratio && (long long)d*ratio == d*ratio){
        cout << d * ratio;
    }
    else{
        cout << "42";
    }

}

#include<stdio.h>
#include<string.h>

int main()
{
    int x1, x2, x3, x4,x5,operation_code = 0,test_code=0;
    int gap1, gap2, gap3;
    int dvd1, dvd2, dvd3;
    scanf("%d%d%d%d", &x1, &x2, &x3, &x4);
    gap1 = x2 - x1;
    gap2 = x3 - x2;
    gap3 = x4 - x3;
    if (gap1 == gap2 && gap2 == gap3) {
        operation_code = 1; goto te;
    }

    if (x1 >= x2)
    {
        dvd1 = x1 / x2;
        dvd2 = x2 / x3;
        dvd3 = x3 / x4;
        test_code = 1;
    }
    else if (x1 < x2)
    {
        dvd1 = x2 / x1;
        dvd2 = x3 / x2;
        dvd3 = x4 / x3;
        test_code = 2;
    }
    if (test_code == 1 && (x4*dvd3 != x3 || x3*dvd2 != x2 || x2*dvd1 != x1))
    {
        operation_code = 0;
        goto te;
    }
    else if (test_code == 1)
    {
        x5 = x4 / dvd1;
        if (x5*dvd1 != x4) operation_code = 0;
        else operation_code = 2;
        goto te;
    }

    if (test_code == 2 && (x3*dvd3 != x4 || x2*dvd2 != x3 || x1*dvd1 != x2))
    {
        operation_code = 0;
        goto te;
    }
    else if (test_code == 2)
    {
        x5 = x4 * dvd1;
        if (x5/dvd1 != x4) operation_code = 0;
        else operation_code = 2;
        goto te;
    }
te:

    if (operation_code == 0)
        printf("42\n");
    else if (operation_code == 1)
        printf("%d\n", x4 + gap1);
    else if (operation_code == 2)
        printf("%d\n", x5);
    return 0;
}

#include<iostream>
#include<cstdio>
using namespace std;
void main(){
float a,b,c,d;
cin>>a>>b>>c>>d;
float diff=b-a,ratio=b/a;
if(c-b==diff && d-c==diff)cout<<d+diff<<endl;
else if(c/b==ratio && d/c==ratio)cout<<d*ratio<<endl;
else cout<<"42"<<endl;
}

#include <bits/stdc++.h>
using namespace std;
int main (){
	long double a, b, c, d;
	cin >> a >> b >> c >> d;
	if(b - a == c - b && c - b == d - c){
		cout << d + (c - b);
		return 0;
	}
	if(b / a == c / b && c / b == d / c){
		cout << d * (b / a);
		return 0;
	}
	cout << 42;
	return 0;
}

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<ctype.h>
#include<deque>
#include<list>
#include<set>
#define INF 999999999
#define NEG -999999999
#define pi acos(-1.0)
#define LL long long int
#define LU unsigned long long int
#define EPS 1e-9
#define MOD 100000007
#define mem(a) memset(a,0,sizeof(a))

using namespace std;
int n,m,i,j,k,l,a[1000009],b[1000009],p[1000009],ans,cn,t,x,y,z,mx,mn,s;
char c[1000009],d[1000009],ch;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(scanf("%d %d %d %d",&i,&j,&k,&l)!=EOF)
    {
        ans=42;
        if((j-i==k-j)&&(k-j==l-k)&&(j-i!=0))
        {
            ans=l+j-i;
        }
        else if((j*j==i*k)&&(k*k==j*l)&&(j%i==0)&&(i!=0)&&(j/i!=0)&&(j/i!=1))
        {
            ans=l*(j/i);
        }
        printf("%d\n",ans);
    }
    return 0;
}

#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<locale>
using namespace std;
int main()
{
int a,b,c,d,div;
cin>>a>>b>>c>>d;
if(((b-a)==(c-b))&&((c-b)==(d-c)))
{
int diff=b-a;
cout<<d+diff<<endl;
}
else if(((float)((float)b/(float)a)==(float)((float)c/(float)b))&&((float)((float)c/(float)b)==(float)((float)d/(float)c)))
{
if(b>a)
{
 div=((int)b/a);
}
else div=((int)a/b);
if(d%div==0)
cout<<div*d<<endl;
else cout<<42<<endl;
}
else cout<<42<<endl;
return 0;
}

#include <iostream>
using namespace std;
template <class T>
int f1(T a[]){
    for(int i=0;i<2;i++)if(a[i]!=a[i+1])return 0;
    return 1;
}
int main(){
    int a[4];
    for(int i=0;i<4;i++) cin >> a[i];
    int b[3];
    double c[3];
    for(int i=1;i<4;i++)b[i-1]=a[i]-a[i-1];
    for(int i=1;i<4;i++)c[i-1]=double(a[i])/a[i-1];
    if(f1(b)) return (cout << a[3]+b[2]),0;
    if(a[0]!=0)if(c[0]!=1)if(f1(c))if(int(c[0]+0.0000001)==c[0]) return (cout << int(a[3]*c[2])),0;
    return (cout << 42),0;
}

#include <bits/stdc++.h>
#include <ext/numeric>
#include<stdlib.h>
using namespace std;
using namespace __gnu_cxx;
int d, q, a[5];
bool boo = 1, boo2 = 1;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    for (int i = 0; i < 4; i++)
        cin >> a[i];
    d = a[1] - a[0];
    for (int i = 1; i < 3; i++) {
//      cout << a[i + 1] - a[i] << ' ' << d << '\n';
        if (a[i + 1] - a[i] != d) {
            boo = 0;
            break;
        }
    }
    int q;
    for (int i = 1; i < 3; i++) {
//      cout << a[i + 1] / a[i] << ' ' << q << '\n';
        if (a[i + 1] / a[i] != q) {
            boo2 = 0;
            break;
        }
    }
    if (boo && (!boo2 || q == 0))
        cout << ((int) (a[3] + d) == a[3] + d && a[3] + d > 0 ? a[3] + d : 42)
                << '\n';
    else if (boo2 && (!boo || d == 0))
        cout << ((int) (a[3] * q) == a[3] * q && a[3] * q > 0 ? a[3] * q : 42)
                << '\n';
    else
        cout << 42 << '\n';
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;
#define mod 1000000007

#define LL long long
#define mp make_pair
#define pb push_back
LL gcd(LL m, LL n){
LL r; while (n != 0){ r=m%n; m=n; n=r;} return m; }

const double EPS = 1E-8;

int main()
{
    int a, b, c, d;
    cin>> a>> b>> c>> d;
    if((a-b == b-c) && (b-c== c-d))
    {
        cout << d-(a-b)<< endl;
        return 0;
    }
    else
    {
        if(b*b==a*c && c*c==b*d)
        {
            cout << d*d/c<< endl;
        }
        else
            cout << "42"<< endl;
    }

    return 0;
}

#include <iostream>
#include <cstdio>
using namespace std;

int in[4],d,q,r;
double b;

int main(){
    for(int i=0; i<4; i++)
        scanf("%d",in+i);
    r=in[1]-in[0];
    b=(double)in[1]/in[0];
    for(int i=2; i<4; i++){
        if(in[i]-in[i-1] != r)  d=1;
        if(in[i-1]*in[i-1]!=in[i-2]*in[i])  q=1;
    }
    if(d == 1 && q == 1)    cout << 42 << endl;
    else if(q == 1) cout << in[3]*2-in[2] << endl;
    else cout << in[3]*in[3]/in[2] << endl;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define double int
using namespace std;
int p=0;
void dc(int a,int b,int c,int d){
	if(a-b==b-c&&b-c==c-d)
    {
     cout<<d+b-a;
	 p=1;
	}
}
void db(int a,int b,int c,int d){
	 if(a*c==b*b&&b*d==c*c)
      if(d*d%c==0)
      {
       cout<<d*d/c;
	   p=1;
	  }
}
int main(){

	int a[5];
	cin>>a[1]>>a[2]>>a[3]>>a[4];
	dc(a[1],a[2],a[3],a[4]);
	db(a[1],a[2],a[3],a[4]);
	if(p==0)
	printf("42");

	return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
int main()
{
    vector<int> v;
    for(int i=0;i<4;i++)
    {
        int tem;
        cin>>tem;
        v.push_back(tem);
    }
    int d[5],q[5];
    int k=0,f=0;
    for(int j=0;j<3;j++)
    {
        d[k++]=v[j+1]-v[j];
        q[f++]=v[j+1]/v[j];
    }
    if(d[0]==d[1] && d[1]==d[2])
    {
        cout<<(v[3]+d[1]);
    }
    else if(q[0]==q[1] && q[1]==q[2])
        cout<<(v[3]*q[1]);
    else cout<<"42";

}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define LOCAL_TEST true
#define SZ(x) ((int)x.size())
#define clr(name,val) memset(name,(val),sizeof(name));
#define Assign(name,val) name.assign(val+1,vector<int>())
#define EPS .0000001
#define ll long long
#define psb(b) push_back((b))
#define ppb() pop_back()
#define oo 10000000
#define mp make_pair
#define fs first
#define sc second
#define rep(var,s,n) for(var=(s);var<(n);(var)++)
#define rvp(var,s,n) for(var=(n-1);var>(s-1);(var)--)
#define read_ freopen("input.txt","r",stdin)
#define write_ freopen("output.txt","w",stdout)

using namespace std;

int compare(string a,string b){if(a==b) return 0;if(SZ(a)==SZ(b)){for(int i=0;i<SZ(a);i++){if(a[i]>b[i]) return 1;else if(a[i]<b[i]) return -1;}return -1;}if(SZ(a)>SZ(b)) return 1;return -1;}
string string_add(string b,string a){if(SZ(a)>SZ(b)) swap(a,b);a=string((SZ(b)-SZ(a)),'0')+a;int carry=0,add;string res;for(int i=SZ(a)-1; i>-1; i--){add=(int)(a[i]-'0')+(int)(b[i]-'0')+carry;carry=add/10;res+=(add%10)+'0';}if(carry) res+=carry+'0';reverse(res.begin(),res.end());return res;}
string string_mul(string a,string b){if(SZ(a)>SZ(b)) swap(a,b);string res,tres;int l=0,carry,mul;for(int i=SZ(a)-1; i>-1; i--){tres=string(l,'0');carry=0;for(int j=SZ(b)-1; j>-1; j--){mul=(int)(a[i]-'0')*(int)(b[j]-'0')+carry;carry=mul/10;tres+=(mul%10)+'0';}if(carry) tres+=carry+'0';reverse(tres.begin(),tres.end());res=string_add(tres,res);l++;}return res;}
void cut_leading_zero(string &res){int i;for(i=0;i<SZ(res);i++){if(res[i]!='0') break;}res=res.substr(i);if(!SZ(res)) res="0";return;}
ll big_mod(ll a,ll p,ll MOD){if(p==0) return 1L;ll ret=big_mod(a,p/2,MOD);ret=((ret*ret)%MOD+MOD)%MOD;if(p%2) ret=((ret*a)%MOD+MOD)%MOD;return ret;}
ll power(ll a,ll p){if(p==0) return 1L;ll ret=power(a,p/2);ret=(ret*ret);if(p%2) ret=(ret*a);return ret;}

///int rr[]= {-1,-1,0,0,1,1};
///int cc[]= {-1,0,-1,1,0,1};
///int rr[]= {0,0,1,-1};/*4 side move*/
///int cc[]= {-1,1,0,0};/*4 side move*/
///int rr[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
///int cc[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
///int rr[]={1,1,2,2,-1,-1,-2,-2};/*night move*/
///int cc[]={2,-2,1,-1,2,-2,1,-1};/*night move*/

int main()
{
    int num[5],d[5],resd,resq;
    double q[5];
    bool flagq=true,flagd=true;
    cin>>num[0];
    for(int i=1;i<4;i++)
    {
        cin>>num[i];
        d[i]=num[i]-num[i-1];
        if(flagq)
        q[i]=(double)num[i]/(double)num[i-1];
    }
    d[0]=d[1];
    q[0]=q[1];
    for(int i=1;i<4;i++) d[i]-=d[3],q[i]-=q[3];
    if(flagd)
    {
//        cout<<"here"<<endl;
        int cnt=0;
        for(int i=1;i<4;i++)
        {
            if(d[i])
            {
                cnt++;
            }
        }
        if(!cnt)
        {
            cout<<num[3]+d[0]<<endl;
            return 0;
        }
    }
    if(flagq)
    {
        int cnt=3;
//        cout<<q[0]<<endl;
        for(int i=1;i<4;i++)
        {
            if(q[i]<EPS&&q[i]>-EPS)
            {
                cnt--;
            }
        }
//        cout<<cnt<<endl;
        if(!cnt)
        {
//            cout<<"here 2"<<endl;
            double vald=num[3]*q[0];
            int val=(int) vald;
            if(abs(val-vald)<EPS&&-abs(val-vald)>-EPS)
            cout<<vald<<endl;
            return 0;
        }
    }
    cout<<42<<endl;
    return 0;
}

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int a,b,c,d;
    int n;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if((b-a) == (c-b) && (c-b)== (d-c))
    {
        n=2*d-c;
        cout<<n;
        //system("pause");
        return 0;
    }
     if(a*c== b*b && b*d == c*c && a!=0 && b!=0 && c!=0 && a!=b)
     {
         if(d*d%c==0)
         {
             cout<<d*d/c;
            //system("pause");
           return 0;
       }
     }
    else
    cout<<42;
    //system("pause");
    return 0;
}

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <chrono>

using namespace std;
using namespace std::chrono;

#define endl '\n'
#define npos string::npos
#define MAX_INT pow(2, 31)-1
#define MIN_INT -1*(pow(2, 31)-1)
vector<string> alpha {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};

int GDC(int a, int b){
	if ( a == 0 ) return b;
	if ( b == 0 ) return a;
	return GDC(b, a%b);
}

int LCD(int a, int b){
	if ( a == b ) return a;
	if ( max(a, b) % min(a, b) == 0 )return max(a, b);
	return a*b;
}

int search(vector<int> a, int b){
	int m = a.size()/2;
	vector<int> h;
	int i = -1;
	if ( b == a [m] ) return m;
	if ( a.size() == 1 && b != a[m]) return -1;
	if ( b < a[m] ){ h = {a.begin(), a.begin()+m};i = 0;}
	else{h = {a.begin()+m, a.end()};i = m;}

	int s = search(h, b);

	return s < 0 ? -1 : i+s;
}

int searchU(vector<int> a, int b){

	for ( int i = 0; i < a.size(); i++ ){
		if ( a [i] == b ) return i;
	}
	return -1;
}

int min(vector<int> a){
	int best = MAX_INT;

	for ( auto b : a ){
		if ( b < best ) best = b;
	}

	return best;
}

int max(vector<int> a){
	int best = 0;

	for ( auto b : a ){
		if ( b > best ) best = b;
	}

	return best;
}

void printVector(vector<int> v ){
	for ( auto i : v ){
		cout << i << " ";
	}
	cout << endl;
}

bool in(int val, vector<int> v){
	for ( auto i : v ){
		if ( i == val ){
			return true;
		}
	}

	return false;
}

int sum(vector<int> v){
	int sum = 0;
	for ( auto i : v ){
		sum += i;
	}
	return sum;
}

int main(){
	int cases = 1;
	//cin >> cases;

	for ( int _case = 0; _case < cases; _case++ ){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		if ( b-a == c-b && c-b == d-c){
			cout << d + (b-a) << endl;
		} else if ( (float)b/a == (float)c/b && (float)c/b == (float)d/c ){
			cout << (float)d * (float)(b/a) << endl;
		} else{
			cout << 42 << endl;
		}
	}
}

#include<map>
#include<new>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<memory>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
using namespace std;

int cnt;
int seq[1111];
int d;
double q;

bool arithmetic()
{
	d=seq[1]-seq[0];
	for(int i=0;i<cnt-1;i++)
	{
		if(seq[i+1]-seq[i]==d) continue;
		else return false;
	}
	return true;
}

bool geometric()
{
	q=(double)seq[1]/seq[0];
	for(int i=0;i<cnt-1;i++)
	{
		if((double)seq[i+1]/seq[i]==q) continue;
		else return false;
	}
	return true;
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	while(cin>>seq[cnt]) cnt++;
	if(arithmetic()==true)
	{
		cout<<seq[cnt-1]+d<<endl;
		return 0;
	}
	else if(geometric()==true&&(int)seq[cnt-1]*q!=0)
	{
		cout<<(int)seq[cnt-1]*q<<endl;
		return 0;
	}
	cout<<42<<endl;
	return 0;
}

// http://codeforces.com/contest/328/problem/A

#include "iostream"
#include "vector"

#define FOR(x,a,b) for (x=a; x<=b; x++)

using namespace std;
long long kq;
unsigned long long a[4];

int main()
{
    FOR (kq,1,4)
        cin>>a[kq];
    if (a[2]-a[1]==a[3]-a[2] && a[4]-a[3]==a[3]-a[2])  kq=a[4]+(a[2]-a[1]);
    else if (a[2]*a[2]==a[3]*a[1] && a[3]*a[3]==a[4]*a[2])
    {
        if ((a[4]*a[2])%a[1]==0) kq=int((a[4]*a[2])/a[1]);
        else kq=42;
    }
    else kq=42;
    cout<<kq<<endl;
}

#include<stdio.h>
#include<stdlib.h>
#include <time.h>
//#include<conio.h>

int main(){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(b-a==c-b && d-c==c-b) printf("%d\n",d+(d-c));
    else{
      double x,y,z;
      x = 1.0*b/a;
      y = 1.0*c/b;
      z = 1.0*d/c;
      if(x==y && y==z) {
        int temp = (int)z*c;
        if((d*d)%c==0) printf("%d\n",d*d/c);
        else printf("%.10lf\n",1.0*d*z);
      }
      else printf("42\n");
    }
    //getch();
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
	int a,b,c,d,s=0,ans;

	   cin>>a>>b>>c>>d;
	   if(s!=0&&s!=1&&a!=0)
	   {
	   if((b-a)==(d-c)&&(c-b)==(b-a))
	   {
		   s=(b-a);
		   ans=s+d;
	   }
	   else	if((b/a)==(d/c)&&(c/b)==(b/a))
	   {

		   s=(b/a);

		   ans=s*d;
	   }
	   }
	   else
		   ans=42;
	cout<<ans;

}

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>

const double eps = 1e-10;

void read(int &x)
{
    static char ch;
    x = 0;
    do ch = getchar(); while (ch < '0' || ch >'9');
    do x = x * 10 + ch - 48, ch = getchar(); while (ch >= '0' && ch <='9');
}

int a[4];

bool check(int d)
{
     if (a[2] - a[1] != d) return 0;
     if (a[3] - a[2] != d) return 0;
     return 1;
}

bool check2(double q)
{
     if (std::abs((a[2]+0.0) / a[1] - q) > eps) return 0;
     if (std::abs((a[3]+0.0) / a[2] - q) > eps) return 0;
     return 1;
}

int main()
{
    for (int i = 0; i <= 3; i++)
        read(a[i]);
    int d = a[1] - a[0];
    if (check(d))
    {
        printf("%d\n",a[3] + d);
        return 0;
    }
    if (a[0] != 0 && a[1] != 0 && a[2] != 0 && a[3] != 0) {
    double q = (a[2]+0.0) / a[1];
    if (check2(q))
    {
        if (std::abs(a[3] * q - int(a[3] * q)) > eps)
        {
            printf("42\n");
            return 0;
        }
        printf("%d\n",int(a[3] * q));
        return 0;
    }
    }
    printf("42\n");
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long double
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vvi vector<vector<int>>;
#define mi  map<int,int>
#define mii map<pii,int>
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define sz(x) (int)x.size()
#define all(v) (v).begin(), (v).end()
#define ret(x) return cout<<x,0;
#define rety return cout<<"YES",0;
#define retn return cout<<"NO",0;
#define fl fflush(stdout)
#define hell 1000000007
#define hell2 998244353
#define pi 3.14159265358979323846

int solve(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x=b-a;
    if(c-b==x&&d-c==x){
        cout<<d+x;
        return 0;
    }
    if(a==0||b==0||c==0||d==0)ret(42);
    int r=b/a;
    if(c/b==r&&d/c==r&&a*r==b&&b*r==c&&c*r==d){
        cout<<d*r;
        return 0;
    }
    int rr=a/b;
    if(b/c==rr&&c/d==rr&&b*rr==a&&c*rr==b&&d*rr==c){
        int e=d/rr;
        if(e*rr==d){
            cout<<e;
            return 0;
        }
    }
    cout<<"42";
    return 0;
}

signed main(){
    IOS;
    int t=1;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output3.txt", "w", stdout);
    #endif
   // cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main ()
{
    double a,b,c,d;
    cin >> a >> b >> c >> d;
    int d1=d,c1=c;
    if (a - b == b - c && b - c == c - d)
        cout << d - (c-d) << endl;
    else if (b/a == c/b && c/b == d/c && a != 0 && b/a != 0 && b/a != 1 && d * (b/a) == d1 * (d1/c1))
        cout << d * (b/a) << endl;
    else
        cout << 42 << endl;
    return 0;
}

#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(b - a == c - b && c - b == d - c) printf("%d",d + (d - c));
	else if(a * c == b * b && b * d == c * c) printf("%d",d * d / c);
	else puts("42");
	return 0;
}

#include <iostream>
#include <set>
using namespace std;

int main(int argc, char const *argv[])
{
    double a[4];
    set<int> A;
    set<double> B;
    cin >> a[0];
    for (int i = 1; i < 4; i++)
    {
        cin >> a[i];
        A.insert(a[i] - a[i - 1]);
        if (a[i - 1])
            B.insert(a[i] / a[i - 1] + 10e-20);
    }

    if (A.size() == 1)
        cout << a[3] + *A.begin() << endl;
    else if (B.size() == 1)
    {
        double t = (double)a[3] * *B.begin();
        if (t == (double)((int)t))
            cout << (int)t << endl;
        else
            cout << 42 << endl;
    }
    else
        cout << 42 << endl;
    return 0;
}

/*
1 -1 1 -1
-1 1 -1 1
100 150 225 337.5

1000 1500 2250 3375
10000 15000 22500 33750
*/

#include <iostream>
using namespace std;

int main(void) {
    int a[4];
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    int d = a[1] - a[0];
    double q = a[1] / a[0];
    int flagd = true, flagq = true;

    for (int i = 2; i < 4; i++) {
        if (flagd && d == a[i] - a[i - 1]) { continue; }
        else { flagd = false; }
        if (flagq && q == a[i] / a[i - 1]) { continue; }
        else { flagq = false; }
    }

    if (flagd) cout << d;
    else if (flagq) cout << q;
    else cout << 42;
    return 0;
}

#include <iostream>
using namespace std;

long long a, b, c ,d;

int main() {
    cin >> a >> b >> c >> d;
    if(d-c == c-b && c-b == b-a) {
        cout << 1LL*(d+(d-c));
        return 0;
    }
    if(b%a == 0 && c%b == 0 && d%c == 0 && b/a == c/b && c/b == d/c) {
        cout << 1LL*(d*(d/c));
        return 0;
    }
    if(a%b == 0 && b%c == 0 && c%d == 0 && a/b == b/c && b/c == c/d && d%(a/b) == 0) {
        cout << 1LL*(d/(a/b));
        return 0;
    }
    cout << 42;
}

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
const int INF=0x3f3f3f3f;
#define LL long long
double a[5];
int i;

double isas(){
    for (i = 1;i<3;i++){
        if(a[i+1]-a[i] != a[i]-a[i-1]){
            return INF;
        }
    }
    return a[1]-a[0];
}
double isgc(){
    for (i=1;i<3;i++){
        if(a[i+1]/a[i] != a[i]/a[i-1]){
            return INF;
        }
    }
    return a[1]/a[0];
}

int main(){
    ios_base::sync_with_stdio(false);
    for (i = 0;i<4;i++){
        cin >> a[i];
    }
    if (isas()!=INF){
        cout << a[3]+isas();
    }
    else if (isgc() != INF){
        cout << a[3]*isgc();
    }
    else{
        cout << 42;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
     cout.tie(0);
int arr[4];
for(int i=0;i<4;i++)cin>>arr[i];
  int  ar=arr[1]-arr[0];
  float go=arr[1]/arr[0];
  bool a=1,g=1;
for(int i=1;i<4;i++)
{
    if(arr[i-1]+ar!=arr[i])
    {
        a=0;
    }
    if(arr[i-1]*go!=arr[i])
    {
        g=0;
    }

}
 if(!a&&!g)
    cout<<42;
 else if(a)
    cout<<arr[3]+ar;
 else
    cout<<arr[3]*go;
    return 0;
}

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <vector>

using namespace std;

int main()
{
    float a1,a2,a3,a4 = 0;
    float tmp = 0;
    cin >> a1 >> a2 >> a3 >> a4;

    //check algo prog
    tmp = a2 - a1;
    if (((a3 + tmp) == a4) && (a2 + tmp) == a3)
    {
        cout << a4 + tmp << endl;
        return 0;
    }
    //check geom prog
    tmp = a2/a1;
    if (((a3*tmp) == a4) && (a3*tmp) == a4)
    {
        cout << a4*tmp << endl;
        return 0;
    } else
    {
        cout << 42 << endl;
        return 0;
    }
}

#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include <stack>
#include <queue>
using namespace std;
#define all(a) sort(a.begin(),a.end())
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define pB(x) push_back(x)
typedef vector < vector<int>> vvi;
#define ll long long
#define ull unsigned long long
#define print(x) cout<<x<<'\n';
#define rep(n) for(int i =0;i<n;i++)
#define rep1(n) for(int i =1;i<=n;i++)

//int long_div(int a, int b, int c){
//
//	a = a%b;
//	for (int i = 1; i <= b; i++){
//		a *= 10;
//		if (a / b == c)return i;
//		a %= b;
//	}
//	return -1;
//}

//void test_case(){
//
//
//
//}

void test_case(){
	int a, b, c, d; cin >> a >> b >> c >> d;
	if (b - a == c - b&&d - c == c - b){
		cout << d + (d - c)<<endl;
	}
	else if (b / a == c / b &&d / c == b / a)cout << d*(d / c)<<endl;
	else cout << 42 << endl;

}

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	/*int t; cin >> t;
	while (t--){
		test_case();
	}*/
	test_case();

	#ifndef ONLINE_JUDGE
	system("pause");
	#endif
	return 0;
}

# include <iostream>
# include <string>
# include <cstdio>
# include <cmath>
# include <cstdlib>
# include <cstring>
# include <algorithm>
using namespace std;
long long go[10001];
int zk[10001];
long long uk = 0;
int gh;
int main()
{
	for (int i = 0; i < 4; i++)
	{
		cin >> go[i];
	}
	if (go[1]*go[1]/go[0] == go[2])
	{
		uk = go[3]*(go[1]/go[0]);
		gh++;
	}
	else
	{
		if ((go[1]-go[0] == go[2]-go[1]))
		{
			gh+=2;
			uk = go[3]+go[1] - go[0];
		}
	}
	if (gh == 0)
		cout << 42 << endl;
	else
		cout << uk << endl;
	return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

#define FOR(i,a,b)   for(int(i)=int(a);(i)<int(b);(i)++)
#define FOREQ(i,a,b) for(int(i)=int(a);(i)<=int(b);(i)++)
#define RFOR(i,a,b)  for(int(i)=(a),_b(b);(i)>=_b;--(i))
#define FOREACH(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

#define FILL(arr,val) memset((arr),(val),sizeof(arr))
#define CLR(a)        memset((a),0,sizeof(a))
#define CPY(dest,src) memcpy((dest),(src),sizeof(dest))

#define ALL(a)       (a).begin(),(a).end()
#define SZ(a)        ((int)(a).size())
#define UNIQ(a)      sort(all(a)); (a).erase(unique(all(a)),(a).end())
#define IDX(arr,ind) (lower_bound(all(arr),ind)-arr.begin())

#define fst first
#define snd second
#define pb  push_back
#define mp  make_pair

static int a[4];

int main()
{
	FOR(i,0,4)
    	scanf("%d", &a[i]);

	bool ap = true;
	int diff = a[1] - a[0];
	FOR(i,2,4)
		if (a[i] - a[i-1] != diff)
			ap = false;
	if (ap)
		printf("%d", a[3]+diff);
	else
	{
		if (a[2]*a[0]==a[1]*a[1] && a[3]*a[0]==a[1]*a[2])
			printf("%f", a[3]*a[1]/(double)a[0]);
		else
			printf("42");
	}
    return 0;
}

#include <vector>
#include <iostream>
#include <algorithm>
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
double abs(double val)
{
        if(val<0)return -val;
        return val;
}
int gcd(int a,int b)
{
        int r;
        while(b!=0) {
                r=a%b;
                a=b;
                b=r;
        }
        return a;
}
using namespace std;
int main()
{
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        //lets assume it to be AP
        int diff1=b-a,diff2=c-b;
        if(diff1==diff2) {
                cout<<d+diff1<<endl;
        } else {
                //lets assume it to be AP;
                if(b*b==a*c&&c*c==b*d) {
                        int val=gcd(c,b);
                        c/=val;
                        b/=val;
                        val=d*c;
                        if(val%b!=0) {
                                cout<<42<<endl;
                        } else {
                                cout<<val/b<<endl;
                        }
                } else {
                        cout<<42<<endl;
                }
        }
        return 0;
}

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if((a-b)==(b-c)&&(a-b)==(c-d))
	{
		cout<<d-(a-b);
	}
	else if((a*c)==(b*b)&&(b*d)==(c*c))
	{
		cout<<d*d%c;
	}
	else{
		cout<<"42";
	}
	return 0;
}

#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(b-a)==abs(c-b)&&abs(d-c)==abs(c-b))  cout<<d+(b-a)<<endl;
  else
	if(a*c==b*b&&b*d==c*c)
	{
       if(d*d%c==0)  cout<<d*(b/a)<<endl;
         else  cout<<42<<endl;
	}
	else  cout<<42<<endl;
  return 0;
}

#include <iostream>

using namespace std;

int main() {

	int aver[4];
	int l=0;
	int resta;
	int div;
	bool hazlo=true;

	for (int i=0; i<=3; i++){
		cin>> aver[i];
		if (i==1){
			resta=aver[i]-aver[i-1];
			div=aver[i]/aver[i-1];
		}
	}

	if (aver[2]-aver[1]== resta and aver[3]-aver[2]==resta){
		cout<<aver[3]+resta;
		hazlo== !hazlo;
	}

	if (hazlo){
		if (aver[2]/aver[1]== div and aver[3]/aver[2]==div and div!=0){
			cout<<aver[3]*div;
			hazlo== !hazlo;
		}
	}

	if (hazlo){
		cout<<"42";
	}

	return 0;
}

#include<cstdio>
using namespace std;
int i,n,a,b,c,d;
int main(){
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a+c==b+b&&b+d==c+c){printf("%d",2*d-c);return 0;}
	if(a*c==b*b&&b*d==c*c)printf("%d",d*d/c);
	else printf("42");
}

#include <iostream>

using namespace std;

int main()
{
    double x1,x2,x3,x4;
    cin >> x1 >> x2 >> x3 >> x4;
    if ((x2-x1)==(x3-x2))
    {
        int d=(x2-x1);
        cout << x4+(x2-x1);
        //system ("Pause");
        return 0;
    }
    double b1=(x2/x1),b2=(x3/x2);
    //cout << b1<<endl;
    if (((double)b1==b2)&&(b1!=0))
    {
        cout << x4*(x2/x1);
        return 0;
    }
    cout << "42";
    return 0;
}

#include <iostream>
using namespace std;
int a,b,c,d;
int main(){
	       cin>>a>>b>>c>>d;
	       if(b-a==c-b && c-b==d-c){cout<<d+(b-a); return 0;}
	       if(b/a==c/b && c/b==d/c && b%a==c%b && c%b==d%c){if(d*(d/c)/1!=0) cout<<d*(d/c);return 0;}
           cout<<"42";
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long long x,y,z,a;
    cin>>x>>y>>z>>a;
    if(abs(x-y)==abs(a-z)&&abs(a-z)==abs(z-y)){
        cout<<((y-x)+a)<<endl;
    }
    else if((y/x)==(z/y)&&(z/y)==(a/z)){
        cout<<((y/x)*a)<<endl;
    }
    else{
        cout<<42<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod ((ll)1e9+7)
#define inf 0x3f3f3f3f
#define infl 0x3f3f3f3f3f3f3f3f
#define Ninf -0x3e3e3e3f
#define Ninfl -0x3e3e3e3e3e3e3e3f
#define maxx ((ll)1e5+5)
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
ll add(ll x, ll y) { x += y; if (x >= mod) return x-mod; return x;}
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + mod; return x;}
ll mult(ll x, ll y) { return (x * y) % mod;}
ll rev(ll x) { return expm(x, mod - 2);}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
signed main(){
  fast;
  //test
  {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(b-a==d-c&&c-b==b-a){
      cout<<d+d-c;
    }
    else if(b/a==c/b&&d/c==b/a&&b%a==0&&c%b==0&&d%c==0){
      cout<<d*d/c;
    }
    else
    {
      cout<<42;
    }

  }
  return 0;
}

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
using namespace std;

int main()
{
	ifstream ff("file.txt");
	vector <int> A;
	int ii=0;
	while(!cin.eof())
	{
		int oo;
		cin>>oo;
		A.push_back(oo);
		ii++;
	}
	int n = A.size();
	if(n==1)
	{
		cout<<42<<endl;
		return 0;
	}
	bool pos;
	if(A[0]>A[n-1])
	{
		pos=false;
	}
	else
	{
		pos=true;
	}
	sort(A.begin(), A.end());
	int y, x;

	for(int i=1; i<n; i++)
	{
		if(i==1)
		{
			y = A[1]-A[0];
		}
		if(A[i]-A[i-1]!=y)
		{
			break;
		}
		if(i==n-1)
		{
			if(pos==false)
			{
				cout<<A[0]-y<<endl;
			}
			else
			{
				cout<<A[n-1]+y<<endl;
			}
			return 0;
		}
	}
	x=A[1]/A[0];
	for(int i=1; i<n; i++)
	{
		if(i==1)
		{
			x = A[1]/A[0];
		}
		if(A[i]/A[i-1]!=x)
		{
			break;
		}
		if(i==n-1)
		{
			if(pos==false)
			{
				cout<<A[0]/x<<endl;
			}
			else
			{
				cout<<A[n-1]*x<<endl;
			}
			return 0;
		}
	}

	cout<<A.size()<<endl;
	cout<<42<<endl;
	return 0;
}