So, the main reason why I am writing this blog is because I think that it may be useful for everybody who struggles with ideas but knows hoe to code well.
First trick concerns almost every task of finding a minimum of the function among every continuous subsequence of the array if \begin{equation}f(l,r)\end{equation} is defined as \begin{equation} f(i, j) (1 ≤ i, j ≤ n)=(i - j)^2 + g(i, j)^2\end{equation} And \begin{equation} g(i,j)=g(1,j)-g(1,i) \end{equation} The way to solve this is by rewriting this formula into \begin{equation} f(i,j)=a^2+b^2\end{equation} I think that if you learnt geometry in school, you certainly understand that this is eulers distance formula.