The problem in brief
A ship's distance over time follows a parabola , and three points of the graph were recorded before the sensor failed. Your program reads six numbers and must print , and . The twist is in how the points are encoded: the first and third points are given directly, but the second is described relative to the others, to the left of the first point and above the third one. So the actual second point is .
How you are scored
Hidden tests compare the three printed numbers with the true coefficients (the tolerance is not stated, so we print 10 decimals). The README gives no sample, so we check the program on 10 000 random inputs against a generic linear solver.
The key idea
Three points determine a parabola, through a linear system. Each point gives one equation that is linear in the unknowns:
This is a Vandermonde system. It has exactly one solution when the three are distinct, because a nonzero polynomial of degree at most 2 cannot vanish at three different points. (If two points shared the same , there would be no function through them at all.)
Rather than inverting a matrix, we can read the coefficients off divided differences, the discrete cousins of derivatives. Write for the three points:
the slopes of two chords. For a parabola, the slope of the chord between and is exactly (the derivative taken at the chord's midpoint). Subtracting the two chord slopes eliminates :
Then and . The second divided difference measures how fast the slope changes: it is half the (constant) second derivative of the trajectory, that is, half the acceleration.

The full solution
x1, y1, x2, y2, x3, y3 = map(float, input().split())
(u1, v1), (u2, v2), (u3, v3) = (x1, y1), (x1 - x2, y3 + y2), (x3, y3)
s12 = (v2 - v1) / (u2 - u1)
s23 = (v3 - v2) / (u3 - u2)
a = (s23 - s12) / (u3 - u1)
b = s12 - a * (u1 + u2)
c = v1 - a * u1 * u1 - b * u1
For example, the input 6 50 4 30 9 40 describes the points , and , and the program prints 0.2380952381 -6.9047619048 82.8571428571.
Results
| check | result |
|---|---|
10 000 random inputs in : coefficients vs numpy.linalg.solve | identical (relative tolerance ) |
| worst relative residual | |
reading the second point as instead, input 1 2 3 4 5 6 | instead of : wrong |
What to remember
- "Passes through these points" is a linear system in the coefficients, even though the curve is not a line: the model is linear in its parameters. This is the same fact that makes polynomial regression a linear regression.
- points with distinct determine a unique polynomial of degree ; divided differences compute it without a matrix inverse.
- The second divided difference is a discrete second derivative: for a trajectory, is the acceleration.
- Rebuild the data exactly as described before modelling: here the whole difficulty is the relative encoding of the second point.