#include <bits/stdc++.h>
using namespace std;
int arr[4], i = 4, j, n;
double a, b;
int main() {
  i = 4;
  for (i = 0; i < 4; i++) scanf("%d", arr + i);
  j = arr[1] - arr[0];
  n = 0;
  for (i = 1; i < 3; i++) {
    n = arr[i + 1] - arr[i];
    if (n != j) break;
  }
  if (i == 3)
    printf("%d\n", arr[3] + j);
  else {
    a = (double)arr[1] / arr[0];
    for (i = 1; i < 3; i++) {
      b = (double)arr[i + 1] / arr[i];
      if (b > (a + 0.000001) || b < (a - 0.000001)) break;
    }
    b = arr[3] * a;
    b -= (int)(b);
    if (i == 3 && b < 0.0000001)
      printf("%d\n", (int)(arr[3] * a));
    else
      printf("42\n");
  }
  return 0;
}
