Let $x_1, x_2, \dots, x_n$ be $n$ positive, distinct real numbers such that $x_1 < x_2 < \cdots < x_n$. I'd like to find some $y \in \{ x_1, x_2, \dots, x_n \}$ such that
$$\sum_{x_i \le y} \left(x_i - \frac{1}{L}\sum_{x_j \le y} x_j\right)^2 + \sum_{x_i > y} \left(x_i - \frac{1}{R}\sum_{x_j > y} x_j\right)^2$$
is minimized. Here, $L$ is the total number of $x_i$'s such that $x_i \le y$, and $R$ is the total number of $x_i$'s such that $x_i > y$.
I apologize if this is a trivial question, but I couldn't figure it out. I thought the answer might be mean or median of $\{ x_1, x_2 \dots, x_n \}$, but some simulations proved my idea to be wrong.
We can formulate a continuous version
$$ F(y) = \int_{0}^{y} \left(f(x)-\frac{\int_{0}^{x} f(\zeta) \, d\zeta}{L}\right)^2 \, dx+\int_{y}^{x_n} \left(f(x)-\frac{\int_{y}^{x} f(\zeta) \, d\zeta}{R}\right)^2 \, dx $$
and then specify $f(x)$. For instance, for $f(x) = x$ we have
$$ F(y) = \frac{y^5}{20 L^2}-\frac{y^4}{4 L}-\frac{20 R^2 \left(y^3-125\right)+15 R \left(y^2-25\right)^2+\left(8 y^2+45 y+75\right) (y-5)^3}{60 R^2}+\frac{y^3}{3} $$
now assuming $x_n=5,L=R=1$
Follows a MATHEMATICA script which is a discrete version
NOTE
dxwas introduced in the script to have comparable results.