#include <bits/stdc++.h>
using namespace std;
long long a[4];
bool check_ap() {
  set<long long> d;
  for (long long i = 1; i < 4; i++) d.insert(a[i] - a[i - 1]);
  if ((long long)d.size() != 1) return 0;
  return 1;
}
bool check_gp() {
  bool ok = true;
  for (long long i = 1; i < 3; i++) {
    ok &= (a[i] * a[i] == a[i - 1] * a[i + 1]);
  }
  ok &= (a[3] * a[3] % a[2] == 0);
  return ok;
}
void solve() {
  for (long long i = 0; i < 4; i++) cin >> a[i];
  if (check_ap())
    cout << a[3] + (a[3] - a[2]) << endl;
  else if (check_gp())
    cout << a[3] * a[3] / a[2] << endl;
  else
    cout << 42 << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
