Find the maximum finite number of roots $$\sum_{i=1}^{40} |x-a_i| = \sum_{i=1}^{40} |x-b_i|$$
I assume the answer is 1, but I don't know how to prove it.
On
An image worth thousand words. Follows the plot of $F(x)-G(x)$
with
$$ F(x) = |x-1|+|x-4|+|x-5|+|x-8|+|x-9|+|x-12|+|x-13|+|x-16|+|x-17|\\ G(x) = |x-2|+|x-3|+|x-6|+|x-7|+|x-10|+|x-11|+|x-14|+|x-15|+|x-18| $$
The corresponding MATHEMATICA script.
f[x_, a_] := Abs[x - a] - Abs[x - a - 1]
Plot[f[x, 1] - f[x, 3] + f[x, 5] - f[x, 7] + f[x, 9] - f[x, 11] + f[x, 13] - f[x, 15] + f[x, 17], {x, -2, 20}, PlotStyle -> {Blue, Thick}]
Here is a construction showing that at least $39$ zeros is possible.
Let $n \geq 1$ be a positive integer. Suppose that $n$ real numbers $a_1 < \cdots < a_n$ are given. Write $\delta$ for the minimum distance between any successive values of $a_i$'s, and assume that $(\epsilon_i)$ satisfies $\epsilon_i \in (0, \delta/2)$. Finally, set $(b_i)$ by $b_i = a_i + (-1)^i \epsilon_i$. Then we know that
$$ b_1 < a_1 < a_2 < b_2 < b_3 < a_3 < a_4 < b_4 < b_5 <\cdots $$
Set $I_k = (a_k, a_{k+1}) \cap (b_k ,b_{k+1})$ for each $k = 1, \cdots, n-1$. By our choice of $b_k$'s, each $I_k$ is non-empty. Moreover,
\begin{align*} \forall x \in I_k, \quad \sum_{i=1}^{n} |x-a_i| - \sum_{i=1}^{n} |x-b_i| &= \sum_{i=1}^{k} (b_i - a_i) + \sum_{i=k+1}^{n} (a_i - b_i)\\ &= \sum_{i=1}^{k} (-1)^i \epsilon_i - \sum_{i=k+1}^{n} (-1)^{i} \epsilon_i \\ &= 2\sum_{i=1}^{k} (-1)^i \epsilon_i - \left( \sum_{i=1}^{n} (-1)^{i} \epsilon_i \right). \tag{*} \end{align*}
Now write $s_k = \sum_{i=1}^{k} (-1)^i \epsilon_i$ and choose $(\epsilon_i)$ so as to satisfy
For instance, we may choose $s_k = (-1)^k\frac{\delta}{3}$ or $s_k = (-1)^k \frac{\delta}{2019k}$. Then
$$\text{(*)} = 2s_k - s_n,$$
and this changes signs between $I_k$ and $I_{k+1}$ for each $k = 1, \cdots, n-1$, and each sign reversal induces at least one zero. Therefore $(b_i)$ constructed as above provides an example of $\text{(*)}$ having at least $n-1$ zeros.
I think that the maximum number of finite zeros for $n$-terms is $n$ if $n$ is odd and $n-1$ if $n$ is even. I believe this can be proved by studying the sign changes of $f - g$ near each zero and extracting some restrictions, but so far I only proved that there are at most $n+1$ zeros.
Thank you @Cesareo, as I learned from the picture that my proof can be improved with easier choice of $\epsilon_i$'s.