Let denote the number of cards required to build a card house of height . For example, f(1) = 2, f(2) = 7, and f(3) = 15.
To build a house of height , one must place houses of height at the base, which requires cards, as well as h - 1 horizontal cards forming the overlaps. On top of this base, a house of height h - 1 is placed, which requires f(h - 1) cards.
Therefore,
or equivalently,
Let us derive an explicit formula. By successively expanding the recursion, we obtain:
Example
A house of height requires cards.
A house of height requires cards.
A house of height can be built using cards.

Algorithm implementation
Read the height of the house .
scanf("%lld", &n);Compute and print the number of cards required to build the house.
res = n * (3 * n + 1) / 2;
printf("%lld\n", res);