a, b, c = io.read("*n", "*n", "*n") d = io.read("*n") print(math.max(a+b+c+d, c * 3))