I can't understand the tutorial of this problem [ Andrey and Problem] codeforces

I can’t understand the tutorial of this problem.

specially first line in the equations.
Can someone explain it clearly please?