6. Let's call the distance between numbers the absolute value of their difference. It is known that the sum of the distances from eighteen consecutive natural numbers to some number $a$ is 1005, and the sum of the distances from these same eighteen numbers to the number $a^{2}$ is 865. Find all possible values of $a$.
Answer: $a=-\frac{7}{3}$.

Solution. Let the given consecutive natural numbers be denoted by $k, k+1, \ldots, k+17$. Note that if some number lies on the segment $[k ; k+17]$, then the sum of the distances from it to the given eighteen numbers does not exceed $9 \cdot 17=153$ (the sum of the distances to the two extreme numbers is exactly 17, the sum of the distances to $k+1$ and $k+16$ does not exceed 17, the sum of the distances to $k+2$ and $k+15$ also does not exceed 17, and so on). Therefore, the numbers $a$ and $a^{2}$ lie outside the segment $[k ; k+17]$. Then the sum of the distances from the number $a$ to each of the given consecutive numbers is expressed by the formula $|18 a-k-(k+1)-\ldots-(k+17)|=|18 a-18 k-153|$. Similarly, the sum of the distances from the number $a^{2}$ to each of the given numbers is equal to $\left|18 a^{2}-18 k-153\right|$. We obtain the system of equations

$$
\left\{\begin{array}{l}
\left|18 a^{2}-18 k-153\right|=865 \\
|18 a-18 k-153|=1005
\end{array}\right.
$$

Consider four cases of opening the modulus.

1) Both numbers $a$ and $a^{2}$ lie to the right of the segment $[k ; k+17]$. Then

$$
\left\{\begin{array} { l } 
{ 1 8 a ^ { 2 } - 1 8 k - 1 5 3 = 8 6 5 , } \\
{ 1 8 a - 1 8 k - 1 5 3 = 1 0 0 5 }
\end{array} \Leftrightarrow \left\{\begin{array}{l}
18 a-18 k-153=1005 \\
9 a^{2}-9 a+70=0
\end{array}\right.\right.
$$

The discriminant of the quadratic equation is negative, so there are no solutions.

2) Both numbers $a$ and $a^{2}$ lie to the left of the segment $[k ; k+17]$. Then

$$
\left\{\begin{array} { l } 
{ 1 8 k + 1 5 3 - 1 8 a ^ { 2 } = 8 6 5 , } \\
{ 1 8 k + 1 5 3 - 1 8 a = 1 0 0 5 }
\end{array} \Leftrightarrow \left\{\begin{array} { l } 
{ 1 8 k + 1 5 3 - 1 8 a = 1 0 0 5 , } \\
{ 9 a ^ { 2 } - 9 a - 7 0 = 0 }
\end{array} \Leftrightarrow \left\{\begin{array}{l}
k=a+47 \frac{1}{3} \\
{\left[\begin{array}{l}
a=-\frac{7}{3} \\
a=\frac{10}{3}
\end{array}\right.}
\end{array}\right.\right.\right.
$$

Since $k \in \mathbb{Z}$, only the case $a=-\frac{7}{3}$ fits (then $k=45$); in the case $a=\frac{10}{3}$, it turns out that $k=50 \frac{2}{3}$.

3) The number $a$ lies to the left, and $a^{2}$ - to the right of the segment $[k ; k+17]$. Then

$$
\left\{\begin{array} { l } 
{ 1 8 a ^ { 2 } - 1 8 k - 1 5 3 = 8 6 5 , } \\
{ 1 8 k + 1 5 3 - 1 8 a = 1 0 0 5 }
\end{array} \Leftrightarrow \left\{\begin{array}{l}
18 k+153-18 a=1005 \\
9 a^{2}-9 a-935=0
\end{array}\right.\right.
$$

The quadratic equation is equivalent to the following: $3 a^{2}-3 a-\frac{935}{3}=0 ; D=9+4 \cdot 935=3749$; $a=\frac{3 \pm \sqrt{3749}}{6}$. Then from the first equation of the system it follows that $k$ is an irrational number, which does not satisfy the condition.

4) The number $a$ lies to the right, and $a^{2}$ - to the left of the segment [ $\left.k ; k+17\right]$. Obviously, this case does not fit, because if $a>a^{2}$, then both numbers $a$ and $a^{2}$ lie on the segment $[0 ; 1]$, but then there cannot be any integer between them.

Thus, it is possible only that $a=-\frac{7}{3}$.