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