P1487 The Lost Report Card
Background
Everyone knows recording grades is a hassle, but MC lost the report card....
Description
On this day, the teacher wants to check the $m$-th student's grade. To avoid getting scolded, MC tries hard to recall and remembers a pattern on the report card:
If the grades are viewed as a real-valued sequence, then $A_i=\dfrac{(A_{i-1})-(A_{i+1})}{2}+d$ (that is, each term equals the difference between its previous and next terms divided by $2$, then plus $d$). At this point, I told MC the first term $A_1$ and the last term $A_n$ of an $n$-term sequence, as well as $d$. The rest is up to you!
Input Format
The first line contains two integers $n, m$.
The second line contains three real numbers, in order: $d, A_1, A_n$.
Output Format
Output a real number $A_m$, rounded to $3$ decimal places.
Explanation/Hint
Constraints: $1 \le n \le 60$, $0 \le m \le n$, $|d|, |A_1|, |A_n| < 10^4$.
Translated by ChatGPT 5