if boundary_value <= (min_value + max_value):
    if boundary_value <= min_value:
        print(boundary_value * max(x, y))
    elif (a == max_value and y <= x) or (b == max_value and x <= y):
        print(boundary_value * max(x, y))
    else:
        print(boundary_value * (max(x, y) - abs(x - y)) +
              min_value * abs(x - y))
elif (min_value + max_value) < boundary_value:
    print(a * x + b * y)
