Peak or valley of a quadratic

A quadratic has exactly one place where its slope is zero, and its second derivative tells what that place is.

What to build

Find where a quadratic has its extreme value and say whether it is a maximum or a minimum.

Requirements

  • Solve f′(x) = 0 for f(x) = a·x² + b·x + c.
  • Print x, the value f(x) and the kind.
  • Use 4 decimal places.

Input

One line with three whole numbers a, b, c. The number a is not 0.

Output

Three lines: x X, value V and kind maximum or kind minimum. X and V have 4 decimal places.

Constraints

a, b and c are between -20 and 20.

Example

Input:

-1 20 0

Output:

x 10.0000
value 100.0000
kind maximum

Why it works

The derivative 2a·x + b is zero at x = −b ÷ (2a). The second derivative is the constant 2a, so the sign of a decides between a minimum (positive) and a maximum (negative).

Examples

Example 1 · Input
-1 20 0
Expected output
x 10.0000
value 100.0000
kind maximum
Example 2 · Input
1 -6 10
Expected output
x 3.0000
value 1.0000
kind minimum

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

For a·x² + b·x + c the derivative is 2a·x + b, which is zero at x = −b ÷ (2a).

Hint 2

If a is negative the curve bends down, so the point is a maximum; if positive, a minimum.

Hint 3

Round with `round(v, 4) + 0.0` before printing to avoid `-0.0000`.

Solution

Show one correct solution (try it yourself first)
a, b, c = [int(v) for v in input().split()]
x = -b / (2 * a)
value = a * x * x + b * x + c

def r(v):
    return f"{round(v, 4) + 0.0:.4f}"

print("x", r(x))
print("value", r(value))
print("kind", "maximum" if a < 0 else "minimum")

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Maxima, minima and gradient descent →