4B. The function $f$ satisfies the conditions
a) $f(0)=1$

b) For every $n \in \mathbb{N}$, it holds that

$$
1+f(0)+f(1)+\ldots+f(n-1)=f(n)
$$

Calculate the sum

$$
S=f(0)^{2}+f(1)^{2}+\ldots+f(n-1)^{2}+f(n)^{2}
$$
Solution. If in equation (1) we substitute $n$ with $n-1$, we get

$$
1+f(0)+f(1)+\ldots+f(n-2)=f(n-1)
$$

From (2), substituting in (1), we get

$$
f(n)=2 f(n-1)
$$

From $f(0)=1$ and (3), for $n=1,2,3$ we find

$$
f(1)=2 f(0)=2 \cdot 1
$$

$$
\begin{aligned}
& f(2)=2 f(1)=2 \cdot 2=2^{2} \\
& f(3)=2 f(2)=2 \cdot 2^{2}=2^{3}
\end{aligned}
$$

We will prove that $f(n)=2^{n}, \forall n \in \mathbb{N}$.

For $n=1$, the statement is true.

Let us assume that the statement is true for $n=k$, i.e., that $f(k)=2^{k}$. From the assumption and (3), for $n=k+1$ we have

$$
f(k+1)=2 f(k)=2 \cdot 2^{k}=2^{k+1}
$$

i.e., the statement is true for $n=k+1$. By the principle of mathematical induction, it follows that

$$
f(n)=2^{n}, \quad \forall n \in \mathbb{N}
$$

Finally, for the given sum, we get

$$
\begin{aligned}
S & =f(0)^{2}+f(1)^{2}+\ldots+f(n-1)^{2}+f(n)^{2} \\
& =1^{2}+2^{2}+\left(2^{2}\right)^{2}+\ldots+\left(2^{n}\right)^{2} \\
& =1+4+4^{2}+\ldots+4^{n} \\
& =\frac{4^{n+1}-1}{4-1}=\frac{1}{3}\left(4^{n+1}-1\right)
\end{aligned}
$$