Exercise 7. Let $k$ be a strictly positive integer. For any real number $x$, the real number $|x|$ is the absolute value of $x$, which is $x$ if $x$ is positive, $-x$ if $x$ is negative. Find the number of triplets $(x, y, z)$ where $x, y, z$ are integers such that $x+y+z=0$ and $|x|+|y|+|z|=2k$.
Solution to exercise 7 Let's first analyze the first condition: if $x+y+z=0$, necessarily the largest of the three numbers is positive, and the smallest is negative. Let's see what this gives if $x \geqslant 0$ and $z \leqslant 0$:

$\triangleright$ If $y \geqslant 0$, then $z=-(x+y)$ and $x+y$ is positive, so $2 k=|x|+|y|+|z|=x+y+(x+y)=2(x+y)$, thus $x+y=k$ and $z=-k$. Therefore, the solutions are of the form $(x, k-x,-k)$, with $x \geqslant 0$ and $k-x \geqslant 0$ i.e., $0 \leqslant x \leqslant k$.

Thus, let's try to count the number of solutions of the form $(x, y, z)$ with two positive numbers and one negative: since the equation is symmetric, all solutions are permutations of $(x, k-x,-k)$ with $0 \leqslant x \leqslant k$. Since there is only one strictly negative number, there are three choices for which one it is ($x, y$, or $z$), and then $k+1$ possibilities for choosing the remaining two variables because there are $k+1$ integers between 0 and $k$. Therefore, there are $3(k+1)$ possibilities.

$\triangleright$ We have already counted all the solutions where among $x, y, z$ two are positive. Since every solution contains one negative and one positive number, it remains to count the solutions containing one positive and two strictly negative numbers: we will assume that $y$ and $z$ are strictly negative and $x$ is positive. Then $x=-(y+z)$ which is positive, so $|x|+|y|+|z|=-(y+z)-y-z=-2(y+z)$, thus $y+z=-k$ and $x=k$. Therefore, the solutions are of the form $(k, y,-k-y)$, with $y>-k$. Since $y$ is an integer, the previous condition is equivalent to $-1 \geqslant y \geqslant-(k-1)$.

Thus, let's try to count the number of solutions of the form $(x, y, z)$ with two strictly negative numbers and one positive: since the equation is symmetric, all solutions are permutations of $(k, y,-k-y)$ with $-1 \geqslant y \geqslant-(k-1)$. Since there is only one strictly negative number, there are three choices for which one it is ($x, y$, or $z$), and then $k-1$ possibilities for choosing the remaining two variables because there are $k-1$ integers between -1 and $-(k-1)$. Therefore, there are $3(k-1)$ possibilities.

By summing, we obtain that there are $3(k+1)+3(k-1)=6 k$ solutions.