#P1487. Determining the m-th Student's Score
Determining the m-th Student's Score
Determining the m-th Student's Score
In this problem, you are given a real number sequence \(A_1, A_2, \dots, A_n\) that satisfies the recurrence relation \[ A_i = \frac{A_{i-1} - A_{i+1}}{2} + d \quad \text{for } 2 \le i \le n-1, \] where \(d\) is a given constant. The first term \(A_1\) and the last term \(A_n\) of the sequence are known. The teacher is interested in finding the score of the \(m\)-th student, i.e. \(A_m\).
You are given the total number of terms \(n\), the index \(m\), the constant \(d\), \(A_1\), and \(A_n\) as input. Your task is to compute \(A_m\) based on the recurrence relation. It is guaranteed that the recurrence leads to a unique solution.
Note: The answer will be accepted if its absolute or relative error does not exceed \(10^{-6}\).
inputFormat
The input consists of a single line containing five space-separated numbers:
- \(n\) — the total number of students (length of the sequence).
- \(m\) — the index of the student whose score you need to find.
- \(d\) — the constant in the recurrence.
- \(A_1\) — the first term of the sequence.
- \(A_n\) — the last term of the sequence.
The sequence satisfies the relation \[ A_i = \frac{A_{i-1} - A_{i+1}}{2} + d, \quad 2 \le i \le n-1. \]
outputFormat
Output a single number representing \(A_m\), the score of the \(m\)-th student. Print the result with at least 6 decimal places of precision.
sample
5 2 3 10 20
4.500000