Author, developer, author of the solution: Andriy Stolitniy
Let's consider the pyramid by levels. At level , there will be a filled perfect triangle with a side of . At the first level, the triangle consists of ball. You can calculate the number of balls at the next level, knowing the number of balls at the previous one. We add balls to the number of balls at level — we add all the balls as a new side. Thus, two sides are extended by , and the new side has a length of .
In this problem, the constraints allowed simply writing a loop and summing up for each level. There is also a formula: \dfrac{n (n+1) (n + 2) }{6}.