#include <bits/stdc++.h>
int arith_test(int, int, int, int);
int geo_test(int, int, int, int);
int main() {
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  if (arith_test(a, b, c, d))
    printf("%d", 2 * d - c);
  else if (geo_test(a, b, c, d))
    printf("%d", d * d / c);
  else
    printf("42");
  return 0;
}
int arith_test(int a, int b, int c, int d) {
  if (2 * b == a + c && 2 * c == b + d)
    return 1;
  else
    return 0;
}
int geo_test(int a, int b, int c, int d) {
  if (a != b && a && b && b * b == a * c && c * c == b * d && (d * d) % c == 0)
    return 1;
  else
    return 0;
}
