#B3735. Rope Count for the Christmas Tree
Rope Count for the Christmas Tree
Rope Count for the Christmas Tree
A Christmas tree consists of n levels. The first level has 1 star, the second level has 2 stars, and so on, with the i-th level having i stars. The stars are connected by ropes as shown in the figure below.
For levels 1 to n-1, each star is connected with a rope to each of the two nearest stars on the level below. In the last level, every pair of adjacent stars is connected by a rope.
Your task is to compute the total number of rope segments needed for a Christmas tree with n levels.
Mathematically, the total number of rope segments can be expressed as:
\[ \text{total ropes} = n(n-1) + (n-1) = (n-1)(n+1)= n^2-1 \]inputFormat
The input consists of a single integer n (1 ≤ n ≤ 109), representing the number of levels in the Christmas tree.
outputFormat
Output a single integer, the total number of rope segments needed to decorate the tree.
sample
1
0