\[x\ км - горизонтальный\ путь;\]
\[y\ км - путь\ в\ гору\ (с\ горы).\]
\[\left\{ \begin{matrix} \frac{x}{8} + \frac{y}{5} = 5\ \ \ \ \ \ \ \ \ \ (1) \\ \frac{x}{8} + \frac{y}{10} = 3,5\ \ \ (2) \\ \end{matrix} \right.\ \]
\[(1) - (2):\ \ \frac{y}{10} = 1,5 \Longrightarrow y = 15.\]
\[\left\{ \begin{matrix} y = 15\ \ \ \ \ \ \ \\ \frac{x}{8} + \frac{15}{5} = 5 \\ \end{matrix} \right.\ \text{\ \ \ \ \ \ \ \ \ }\]
\[\left\{ \begin{matrix} y = 15\ \ \ \ \ \ \\ \frac{x}{8} + 3 = 5 \\ \end{matrix} \right.\ \text{\ \ \ \ \ \ \ \ }\]
\[\left\{ \begin{matrix} y = 15 \\ \frac{x}{8} = 2\ \ \\ \end{matrix} \right.\ \text{\ \ \ \ \ \ \ \ }\]
\[\left\{ \begin{matrix} y = 15 \\ x = 16 \\ \end{matrix} \right.\ \]
\[15 + 16 = 31\ км.\]
\[Ответ:\ \ 31\ км.\]