In a Canadian Math Olympiad Problem's solution, They used triangle inequality . The problem is as follows. the problem is the fourth problem from the 2019 Canada national olympiad.

Let $n$ be an integer greater than 1.Let $a_0,a_1,a_2,...a_n$ be real numbers with $a_1=a_{n-1}$=0 prove that for any real number k, \begin{align*}|a_0|-|a_n|\le\sum_{i=0}^{n-2}|a_i+ka_{i+1}+a_{i+2}|\end{align*} here is the official solution https://www2.cms.math.ca/Competitions/CMO/archive/sol2019.pdf How triangle inequality is used here in algebra.Can anyone tell me how triangle inequality is used in algebra?


From $$0 = -a_0 z^2 + \sum_{i=0}^{n-2}(a_i - k a_{i+1} - a_{i+2})z^{i+2} + a_n z^n \text{,}$$ we have \begin{align*} a_0 z^2 &= \sum_{i=0}^{n-2}(a_i - k a_{i+1} - a_{i+2})z^{i+2} + a_n z^n \\ |a_0 z^2| &= \left|\sum_{i=0}^{n-2}(a_i - k a_{i+1} - a_{i+2})z^{i+2} + a_n z^n \right| \\ \end{align*} The left-hand side is $|a_0| \, |z|^2$. Applying the triangle inequality to the right hand side twice, we obtain \begin{align*} &\left|\sum_{i=0}^{n-2}(a_i - k a_{i+1} - a_{i+2})z^{i+2} + a_n z^n \right| \\ &\qquad\leq \left|\sum_{i=0}^{n-2}(a_i - k a_{i+1} - a_{i+2})z^{i+2}\right| + \left|a_n z^n \right| \\ &\qquad = \left|a_n z^n \right| + \left|\sum_{i=0}^{n-2}(a_i - k a_{i+1} - a_{i+2})z^{i+2}\right| \\ &\qquad \leq \left|a_n z^n \right| + \sum_{i=0}^{n-2}\left|( a_i - k a_{i+1} - a_{i+2})z^{i+2} \right| \\ &\qquad = |a_n| \, |z|^n + \sum_{i=0}^{n-2}\left|a_i - k a_{i+1} - a_{i+2} \right| |z|^{i+2} \text{.} \end{align*}


With the equation $$a_0z^2=a_nz^n+\sum_{i=0}^{n-2}(a_i-ka_{i+1}-a_{i+2})z^{i+2}$$ using the triangle inequality, we have \begin{align*} |a_0z^2|&=\left|a_nz^n+\sum_{i=0}^{n-2}(a_i-ka_{i+1}-a_{i+2})z^{i+2}\right|\\ &\leq |a_nz^n|+\left|\sum_{i=0}^{n-2}(a_i-ka_{i+1}-a_{i+2})z^{i+2}\right| \end{align*} and using again $n-1$ times with $\sum_{i=0}^{n-2}(a_i-ka_{i+1}-a_{i+2})z^{i+2}$ you get the inequality showed